How to use the ts-invariant.invariant.warn function in ts-invariant

To help you get started, we’ve selected a few ts-invariant examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github apollographql / apollo-client / packages / apollo-boost / src / index.ts View on Github external
: onError(({ graphQLErrors, networkError }) => {
          if (graphQLErrors) {
            graphQLErrors.forEach(({ message, locations, path }) =>
              // tslint:disable-next-line
              invariant.warn(
                `[GraphQL error]: Message: ${message}, Location: ` +
                  `${locations}, Path: ${path}`,
              ),
            );
          }
          if (networkError) {
            // tslint:disable-next-line
            invariant.warn(`[Network error]: ${networkError}`);
          }
        });
github apollographql / apollo-client / packages / apollo-cache-inmemory / src / inMemoryCache.ts View on Github external
constructor(config: InMemoryCacheConfig = {}) {
    super();
    this.config = { ...defaultConfig, ...config };

    // backwards compat
    if ((this.config as any).customResolvers) {
      invariant.warn(
        'customResolvers have been renamed to cacheRedirects. Please update your config as we will be deprecating customResolvers in the next major version.',
      );
      this.config.cacheRedirects = (this.config as any).customResolvers;
    }

    if ((this.config as any).cacheResolvers) {
      invariant.warn(
        'cacheResolvers have been renamed to cacheRedirects. Please update your config as we will be deprecating cacheResolvers in the next major version.',
      );
      this.config.cacheRedirects = (this.config as any).cacheResolvers;
    }

    this.addTypename = !!this.config.addTypename;

    // Passing { resultCaching: false } in the InMemoryCache constructor options
    // will completely disable dependency tracking, which will improve memory
github apollographql / apollo-client / packages / apollo-cache-inmemory / src / writeToStore.ts View on Github external
// without having all of the selection set values available.
            // This is because the @client field values might have already
            // been written to the cache separately (e.g. via Apollo
            // Cache's `writeData` capabilities). Because of this, we'll
            // skip the missing field warning for fields with @client
            // directives.
            isClient = selection.directives.some(
              directive => directive.name && directive.name.value === 'client',
            );
          }

          if (!isDefered && !isClient && context.fragmentMatcherFunction) {
            // XXX We'd like to throw an error, but for backwards compatibility's sake
            // we just print a warning for the time being.
            //throw new WriteError(`Missing field ${resultFieldKey} in ${JSON.stringify(result, null, 2).substring(0, 100)}`);
            invariant.warn(
              `Missing field ${resultFieldKey} in ${JSON.stringify(
                result,
                null,
                2,
              ).substring(0, 100)}`,
            );
          }
        }
      } else {
        // This is not a field, so it must be a fragment, either inline or named
        let fragment: InlineFragmentNode | FragmentDefinitionNode;

        if (isInlineFragment(selection)) {
          fragment = selection;
        } else {
          // Named fragment
github apollographql / apollo-client / packages / apollo-cache-inmemory / src / fragmentMatcher.ts View on Github external
}

    const { __typename = isRootQuery && 'Query' } = obj;

    if (!__typename) {
      if (shouldWarn()) {
        invariant.warn(`You're using fragments in your queries, but either don't have the addTypename:
  true option set in Apollo Client, or you are trying to write a fragment to the store without the __typename.
   Please turn on the addTypename option and include __typename when writing fragments so that Apollo Client
   can accurately match fragments.`);
        invariant.warn(
          'Could not find __typename on Fragment ',
          typeCondition,
          obj,
        );
        invariant.warn(
          `DEPRECATION WARNING: using fragments without __typename is unsupported behavior ` +
            `and will be removed in future versions of Apollo client. You should fix this and set addTypename to true now.`,
        );
      }

      return 'heuristic';
    }

    if (__typename === typeCondition) {
      return true;
    }

    // At this point we don't know if this fragment should match or not. It's
    // either:
    //
    // 1. (GOOD) A fragment on a matching interface or union.
github cdmbase / fullstack-pro / servers / frontend-server / src / config / apollo-client.ts View on Github external
graphQLErrors.map(({ message, locations, path }) =>
            // tslint:disable-next-line
            invariant.warn(
                `[GraphQL error]: Message: ${message}, Location: ` +
                `${locations}, Path: ${path}`,
            ),
        );
github apollographql / apollo-client / packages / apollo-client / src / ApolloClient.ts View on Github external
public initQueryManager(): QueryManager {
    invariant.warn(
      'Calling the initQueryManager method is no longer necessary, ' +
        'and it will be removed from ApolloClient in version 3.0.',
    );
    return this.queryManager;
  }
github apollographql / apollo-link / packages / apollo-link / src / linkUtils.ts View on Github external
next: data => {
        if (completed) {
          invariant.warn(
            `Promise Wrapper does not support multiple results from Observable`,
          );
        } else {
          completed = true;
          resolve(data);
        }
      },
      error: reject,
github apollographql / apollo-client / src / link / utils / toPromise.ts View on Github external
next: data => {
        if (completed) {
          invariant.warn(
            `Promise Wrapper does not support multiple results from Observable`,
          );
        } else {
          completed = true;
          resolve(data);
        }
      },
      error: reject,
github apollographql / apollo-client / src / link / core / ApolloLink.ts View on Github external
public static concat(
    first: ApolloLink | RequestHandler,
    second: ApolloLink | RequestHandler,
  ) {
    const firstLink = toLink(first);
    if (isTerminating(firstLink)) {
      invariant.warn(
        new LinkError(
          `You are calling concat on a terminating link, which will have no effect`,
          firstLink,
        ),
      );
      return firstLink;
    }
    const nextLink = toLink(second);

    if (isTerminating(nextLink)) {
      return new ApolloLink(
        operation =>
          firstLink.request(
            operation,
            op => nextLink.request(op) || Observable.of(),
          ) || Observable.of(),
github apollographql / apollo-client / src / link / core / linkUtils.ts View on Github external
next: data => {
        if (completed) {
          invariant.warn(
            `Promise Wrapper does not support multiple results from Observable`,
          );
        } else {
          completed = true;
          resolve(data);
        }
      },
      error: reject,

ts-invariant

TypeScript implementation of invariant(condition, message)

MIT
Latest version published 2 years ago

Package Health Score

75 / 100
Full package analysis