當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript ts-invariant.invariant類代碼示例

本文整理匯總了TypeScript中ts-invariant.invariant的典型用法代碼示例。如果您正苦於以下問題:TypeScript invariant類的具體用法?TypeScript invariant怎麽用?TypeScript invariant使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了invariant類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: match

  public match(
    idValue: IdValue,
    typeCondition: string,
    context: ReadStoreContext,
  ): boolean | 'heuristic' {
    const obj = context.store.get(idValue.id);

    if (!obj) {
      // https://github.com/apollographql/apollo-client/pull/3507
      return idValue.id === 'ROOT_QUERY';
    }

    if (!obj.__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 (obj.__typename === typeCondition) {
      return true;
    }

    // XXX here we reach an issue - we don't know if this fragment should match or not. It's either:
    // 1. A fragment on a non-matching concrete type or interface or union
    // 2. A fragment on a matching interface or union
    // If it's 1, we don't want to return anything, if it's 2 we want to match. We can't tell the
    // difference, so we warn the user, but still try to match it (backcompat).
    if (shouldWarn()) {
      invariant.error(
        'You are using the simple (heuristic) fragment matcher, but your ' +
          'queries contain union or interface types. Apollo Client will not be ' +
          'able to accurately map fragments. To make this error go away, use ' +
          'the `IntrospectionFragmentMatcher` as described in the docs: ' +
          'https://www.apollographql.com/docs/react/advanced/fragments.html#fragment-matcher',
      );
    }

    return 'heuristic';
  }
開發者ID:apollostack,項目名稱:apollo-client,代碼行數:53,代碼來源:fragmentMatcher.ts

示例2: clientQuery

 // Client queries contain everything in the incoming document (if a @client
 // directive is found).
 public clientQuery(document: DocumentNode) {
   if (hasDirectives(['client'], document)) {
     if (this.resolvers) {
       return document;
     }
     invariant.warn(
       'Found @client directives in a query but no ApolloClient resolvers ' +
       'were specified. This means ApolloClient local resolver handling ' +
       'has been disabled, and @client directives will be passed through ' +
       'to your link chain.',
     );
   }
   return null;
 }
開發者ID:apollostack,項目名稱:apollo-client,代碼行數:16,代碼來源:LocalState.ts

示例3: onError

 : onError(({ graphQLErrors, networkError }) => {
     if (graphQLErrors) {
       graphQLErrors.map(({ 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}`);
     }
   });
開發者ID:apollostack,項目名稱:apollo-client,代碼行數:15,代碼來源:index.ts

示例4: constructor

  constructor(config: PresetConfig = {}) {
    if (config) {
      const diff = Object.keys(config).filter(
        key => PRESET_CONFIG_KEYS.indexOf(key) === -1,
      );

      if (diff.length > 0) {
        invariant.warn(
          'ApolloBoost was initialized with unsupported options: ' +
            `${diff.join(' ')}`,
        );
      }
    }

    const {
      request,
      uri,
      credentials,
      headers,
      fetch,
      fetchOptions,
      clientState,
      cacheRedirects,
      onError: errorCallback,
      name,
      version,
      resolvers,
      typeDefs,
      fragmentMatcher,
    } = config;

    let { cache } = config;

    invariant(
      !cache || !cacheRedirects,
      'Incompatible cache configuration. If providing `cache` then ' +
        'configure the provided instance with `cacheRedirects` instead.',
    );

    if (!cache) {
      cache = cacheRedirects
        ? new InMemoryCache({ cacheRedirects })
        : new InMemoryCache();
    }

    const errorLink = errorCallback
      ? onError(errorCallback)
      : onError(({ graphQLErrors, networkError }) => {
          if (graphQLErrors) {
            graphQLErrors.map(({ 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}`);
          }
        });

    const requestHandler = request
      ? new ApolloLink(
          (operation, forward) =>
            new Observable(observer => {
              let handle: any;
              Promise.resolve(operation)
                .then(oper => request(oper))
                .then(() => {
                  handle = forward(operation).subscribe({
                    next: observer.next.bind(observer),
                    error: observer.error.bind(observer),
                    complete: observer.complete.bind(observer),
                  });
                })
                .catch(observer.error.bind(observer));

              return () => {
                if (handle) {
                  handle.unsubscribe();
                }
              };
            }),
        )
      : false;

    const httpLink = new HttpLink({
      uri: uri || '/graphql',
      fetch,
      fetchOptions: fetchOptions || {},
      credentials: credentials || 'same-origin',
      headers: headers || {},
    });

    const link = ApolloLink.from([errorLink, requestHandler, httpLink].filter(
      x => !!x,
    ) as ApolloLink[]);

//.........這裏部分代碼省略.........
開發者ID:apollostack,項目名稱:apollo-client,代碼行數:101,代碼來源:index.ts

示例5:

 graphQLErrors.map(({ message, locations, path }) =>
   // tslint:disable-next-line
   invariant.warn(
     `[GraphQL error]: Message: ${message}, Location: ` +
       `${locations}, Path: ${path}`,
   ),
開發者ID:apollostack,項目名稱:apollo-client,代碼行數:6,代碼來源:index.ts


注:本文中的ts-invariant.invariant類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。