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


TypeScript apollo-utilities.getFragmentDefinitions函數代碼示例

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


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

示例1: graphql

export function graphql(
  resolver: Resolver,
  document: DocumentNode,
  rootValue?: any,
  contextValue?: any,
  variableValues?: VariableMap,
  execOptions: ExecOptions = {},
) {
  const mainDefinition = getMainDefinition(document);

  const fragments = getFragmentDefinitions(document);
  const fragmentMap = createFragmentMap(fragments);

  const resultMapper = execOptions.resultMapper;

  // Default matcher always matches all fragments
  const fragmentMatcher = execOptions.fragmentMatcher || (() => true);

  const execContext: ExecContext = {
    fragmentMap,
    contextValue,
    variableValues,
    resultMapper,
    resolver,
    fragmentMatcher,
  };

  return executeSelectionSet(
    mainDefinition.selectionSet,
    rootValue,
    execContext,
  );
}
開發者ID:softden2006,項目名稱:apollo-client,代碼行數:33,代碼來源:graphql.ts

示例2: executeStoreQuery

  /**
   * Based on graphql function from graphql-js:
   *
   * graphql(
   *   schema: GraphQLSchema,
   *   requestString: string,
   *   rootValue?: ?any,
   *   contextValue?: ?any,
   *   variableValues?: ?{[key: string]: any},
   *   operationName?: ?string
   * ): Promise<GraphQLResult>
   *
   * The default export as of graphql-anywhere is sync as of 4.0,
   * but below is an exported alternative that is async.
   * In the 5.0 version, this will be the only export again
   * and it will be async
   *
   */
  private executeStoreQuery({
    query,
    rootValue,
    contextValue,
    variableValues,
    // Default matcher always matches all fragments
    fragmentMatcher = defaultFragmentMatcher,
  }: ExecStoreQueryOptions): ExecResult {
    const mainDefinition = getMainDefinition(query);
    const fragments = getFragmentDefinitions(query);
    const fragmentMap = createFragmentMap(fragments);
    const execContext: ExecContext = {
      query,
      fragmentMap,
      contextValue,
      variableValues,
      fragmentMatcher,
    };

    return this.executeSelectionSet({
      selectionSet: mainDefinition.selectionSet,
      rootValue,
      execContext,
    });
  }
開發者ID:apollostack,項目名稱:apollo-client,代碼行數:43,代碼來源:readFromStore.ts

示例3: storeRoundtrip

function storeRoundtrip(query: DocumentNode, result: any, variables = {}) {
  const fragmentMap = createFragmentMap(getFragmentDefinitions(query));
  const store = writeQueryToStore({
    result,
    query,
    variables,
    fragmentMap,
  });

  const reconstructedResult = readQueryFromStore({
    store,
    query,
    variables,
    fragmentMatcherFunction,
  });

  expect(reconstructedResult).toEqual(result);
}
開發者ID:NewSpring,項目名稱:apollo-client,代碼行數:18,代碼來源:roundtrip.ts

示例4: getMainDefinition

  private async resolveDocument<TData>(
    document: DocumentNode,
    rootValue: TData,
    context: any = {},
    variables: VariableMap = {},
    fragmentMatcher: FragmentMatcher = () => true,
    onlyRunForcedResolvers: boolean = false,
  ) {
    const mainDefinition = getMainDefinition(document);
    const fragments = getFragmentDefinitions(document);
    const fragmentMap = createFragmentMap(fragments);

    const definitionOperation = (mainDefinition as OperationDefinitionNode)
      .operation;

    const defaultOperationType = definitionOperation
      ? capitalizeFirstLetter(definitionOperation)
      : 'Query';

    const { cache, client } = this;
    const execContext: ExecContext = {
      fragmentMap,
      context: {
        ...context,
        cache,
        client,
      },
      variables,
      fragmentMatcher,
      defaultOperationType,
      exportedVariables: {},
      onlyRunForcedResolvers,
    };

    return this.resolveSelectionSet(
      mainDefinition.selectionSet,
      rootValue,
      execContext,
    ).then(result => ({
      result,
      exportedVariables: execContext.exportedVariables,
    }));
  }
開發者ID:apollostack,項目名稱:apollo-client,代碼行數:43,代碼來源:LocalState.ts


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