How to use the apollo-utilities.createFragmentMap function in apollo-utilities

To help you get started, we’ve selected a few apollo-utilities 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-cache-inmemory / src / executeStoreQuery.ts View on Github external
export const executeStoreQuery = wrap(function (
  query: DocumentNode,
  rootValue: IdValue,
  contextValue: ReadStoreContext,
  variableValues: VariableMap,
  // Default matcher always matches all fragments
  fragmentMatcher: FragmentMatcher = defaultFragmentMatcher,
): ExecResult {
  const mainDefinition = getMainDefinition(query);
  const fragments = getFragmentDefinitions(query);
  const fragmentMap = createFragmentMap(fragments);
  const execContext: ExecContext = {
    fragmentMap,
    contextValue,
    variableValues,
    fragmentMatcher,
  };

  return executeSelectionSet(
    mainDefinition.selectionSet,
    rootValue,
    execContext,
  );
}, {
  makeCacheKey(
github Lucifier129 / graphql-dynamic / src / graphql-anywhere / index.js View on Github external
function graphql(
  resolver,
  document,
  rootValue,
  contextValue,
  variables,
  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 = {
    fragmentMap,
    contextValue,
    variables,
    resultMapper,
    resolver,
    fragmentMatcher
  }

  return executeSelectionSet(
github apollographql / apollo-client / packages / graphql-anywhere / src / async.ts View on Github external
export function graphql(
  resolver: Resolver,
  document: DocumentNode,
  rootValue?: any,
  contextValue?: any,
  variableValues?: VariableMap,
  execOptions: ExecOptions = {},
): Promise {
  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(
github Grantimus9 / vuegraphqlphx / assets / node_modules / graphql-anywhere / src / graphql.ts View on Github external
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(
github apollographql / apollo-client / packages / apollo-cache-inmemory / src / readFromStore.ts View on Github external
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,
    });
  }
github apollographql / apollo-client / packages / apollo-client / src / core / LocalState.ts View on Github external
private async resolveDocument(
    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,
      },
github coralproject / talk / client / coral-framework / graphql / reduceDocument.js View on Github external
export default function reduceDocument(document, options = {}) {
  const mainDefinition = getMainDefinition(document);
  const fragments = getFragmentDefinitions(document);
  const operationDefinition = getOperationDefinition(document);
  const path = operationDefinition
    ? operationDefinition.operation
    : `type.${mainDefinition.typeCondition.name.value}`;

  const execContext = {
    rawFragmentMap: createFragmentMap(fragments),
    fragmentMap: options.fragmentMap || {},
    variables: options.variables,
    typeGetter: options.typeGetter || (() => null),
  };

  return {
    kind: 'Document',
    definitions: [transformDefinition(mainDefinition, execContext, path)],
  };
}
github Rsullivan00 / apollo-link-json-api / src / jsonApiLink.ts View on Github external
}
  const {
    credentials,
    endpoints,
    headers,
    customFetch,
    operationType,
    mainDefinition,
    fragmentDefinitions,
    typeNameNormalizer,
    fieldNameNormalizer,
    fieldNameDenormalizer: linkLevelNameDenormalizer,
    serializers,
  } = context;

  const fragmentMap = createFragmentMap(fragmentDefinitions);

  let {
    path,
    endpoint,
    pathBuilder,
  } = directives.jsonapi as JsonApiLink.DirectiveOptions;

  const endpointOption = getEndpointOptions(endpoints, endpoint);
  const neitherPathsProvided = path == null && pathBuilder == null;

  if (neitherPathsProvided) {
    throw new Error(
      `One of ("path" | "pathBuilder") must be set in the @jsonapi() directive. This request had neither, please add one`,
    );
  }
  if (!pathBuilder) {