• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript ts-invariant.invariant函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中ts-invariant.invariant函数的典型用法代码示例。如果您正苦于以下问题:TypeScript invariant函数的具体用法?TypeScript invariant怎么用?TypeScript invariant使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了invariant函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: checkDocument

export function checkDocument(doc: DocumentNode) {
  invariant(
    doc && doc.kind === 'Document',
    `Expecting a parsed GraphQL document. Perhaps you need to wrap the query \
string in a "gql" tag? http://docs.apollostack.com/apollo-client/core.html#gql`,
  );

  const operations = doc.definitions
    .filter(d => d.kind !== 'FragmentDefinition')
    .map(definition => {
      if (definition.kind !== 'OperationDefinition') {
        throw new InvariantError(
          `Schema type definitions not allowed in queries. Found: "${
            definition.kind
          }"`,
        );
      }
      return definition;
    });

  invariant(
    operations.length <= 1,
    `Ambiguous GraphQL document: contains ${operations.length} operations`,
  );

  return doc;
}
开发者ID:apollostack,项目名称:apollo-client,代码行数:27,代码来源:getFromAST.ts


示例2: invariant

  return directives ? directives.filter(isInclusionDirective).map(directive => {
    const directiveArguments = directive.arguments;
    const directiveName = directive.name.value;

    invariant(
      directiveArguments && directiveArguments.length === 1,
      `Incorrect number of arguments for the @${directiveName} directive.`,
    );

    const ifArgument = directiveArguments[0];
    invariant(
      ifArgument.name && ifArgument.name.value === 'if',
      `Invalid argument for the @${directiveName} directive.`,
    );

    const ifValue: ValueNode = ifArgument.value;

    // means it has to be a variable value if this is a valid @skip or @include directive
    invariant(
      ifValue &&
        (ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'),
      `Argument for the @${directiveName} directive must be a variable or a boolean value.`,
    );

    return { directive, ifArgument };
  }) : [];
开发者ID:apollostack,项目名称:apollo-client,代码行数:26,代码来源:directives.ts


示例3: match

  public match(
    idValue: IdValue,
    typeCondition: string,
    context: ReadStoreContext,
  ) {
    invariant(
      this.isReady,
      'FragmentMatcher.match() was called before FragmentMatcher.init()',
    );

    const obj = context.store.get(idValue.id);

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

    invariant(
      obj.__typename,
      `Cannot match fragment because __typename property is missing: ${JSON.stringify(
        obj,
      )}`,
    );

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

    const implementingTypes = this.possibleTypesMap[typeCondition];
    if (implementingTypes && implementingTypes.indexOf(obj.__typename) > -1) {
      return true;
    }

    return false;
  }
开发者ID:apollostack,项目名称:apollo-client,代码行数:35,代码来源:fragmentMatcher.ts


示例4: getOperationDefinitionOrDie

export function getOperationDefinitionOrDie(
  document: DocumentNode,
): OperationDefinitionNode {
  const def = getOperationDefinition(document);
  invariant(def, `GraphQL document is missing an operation`);
  return def;
}
开发者ID:apollostack,项目名称:apollo-client,代码行数:7,代码来源:getFromAST.ts


示例5: invariant

  public fetchMore<K extends keyof TVariables>(
    fetchMoreOptions: FetchMoreQueryOptions<TVariables, K> &
      FetchMoreOptions<TData, TVariables>,
  ): Promise<ApolloQueryResult<TData>> {
    // early return if no update Query
    invariant(
      fetchMoreOptions.updateQuery,
      'updateQuery option is required. This function defines how to update the query data with the new results.',
    );

    let combinedOptions: any;
    const qid = this.queryManager.generateQueryId();

    return Promise.resolve()
      .then(() => {
        if (fetchMoreOptions.query) {
          // fetch a new query
          combinedOptions = fetchMoreOptions;
        } else {
          // fetch the same query with a possibly new variables
          combinedOptions = {
            ...this.options,
            ...fetchMoreOptions,
            variables: Object.assign(
              {},
              this.variables,
              fetchMoreOptions.variables,
            ),
          };
        }

        combinedOptions.fetchPolicy = 'network-only';

        return this.queryManager.fetchQuery(
          qid,
          combinedOptions as WatchQueryOptions,
          FetchType.normal,
          this.queryId,
        );
      })
      .then(
        fetchMoreResult => {
          this.updateQuery((previousResult: any) =>
            fetchMoreOptions.updateQuery(previousResult, {
              fetchMoreResult: fetchMoreResult.data as TData,
              variables: combinedOptions.variables,
            }),
          );

          this.queryManager.stopQuery(qid);

          return fetchMoreResult as ApolloQueryResult<TData>;
        },
        error => {
          this.queryManager.stopQuery(qid);
          throw error;
        },
      );
  }
开发者ID:apollostack,项目名称:apollo-client,代码行数:59,代码来源:ObservableQuery.ts


示例6: getQueryDefinition

export function getQueryDefinition(doc: DocumentNode): OperationDefinitionNode {
  const queryDef = getOperationDefinition(doc) as OperationDefinitionNode;

  invariant(
    queryDef && queryDef.operation === 'query',
    'Must contain a query definition.',
  );

  return queryDef;
}
开发者ID:apollostack,项目名称:apollo-client,代码行数:10,代码来源:getFromAST.ts


示例7: return

 getCacheKey: (obj: { __typename: string; id: string | number }) => {
   if ((cache as any).config) {
     return (cache as any).config.dataIdFromObject(obj);
   } else {
     invariant(false,
       'To use context.getCacheKey, you need to use a cache that has ' +
         'a configurable dataIdFromObject, like apollo-cache-inmemory.',
     );
   }
 },
开发者ID:apollostack,项目名称:apollo-client,代码行数:10,代码来源:LocalState.ts


示例8: getFragmentDefinition

export function getFragmentDefinition(
  doc: DocumentNode,
): FragmentDefinitionNode {
  invariant(
    doc.kind === 'Document',
    `Expecting a parsed GraphQL document. Perhaps you need to wrap the query \
string in a "gql" tag? http://docs.apollostack.com/apollo-client/core.html#gql`,
  );

  invariant(
    doc.definitions.length <= 1,
    'Fragment must have exactly one definition.',
  );

  const fragmentDef = doc.definitions[0] as FragmentDefinitionNode;

  invariant(
    fragmentDef.kind === 'FragmentDefinition',
    'Must be a fragment definition.',
  );

  return fragmentDef as FragmentDefinitionNode;
}
开发者ID:apollostack,项目名称:apollo-client,代码行数:23,代码来源:getFromAST.ts



注:本文中的ts-invariant.invariant函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript ts-invariant.invariant类代码示例发布时间:2022-05-25
下一篇:
TypeScript ts-disposables.CompositeDisposable类代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap