How to use the apollo-utilities.resultKeyNameFromField 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 Lucifier129 / graphql-dynamic / src / graphql-anywhere / index.js View on Github external
async function executeField(field, rootValue, execContext) {
  const { variables, contextValue, resolver } = execContext

  const fieldName = field.name.value
  const args = argumentsObjectFromField(field, variables)

  const info = {
    isLeaf: !field.selectionSet,
    resultKey: resultKeyNameFromField(field),
    directives: getDirectivesFromField(field, variables)
  }

  const result = await resolver(fieldName, rootValue, args, contextValue, info)

  // Handle all scalar types here
  if (!field.selectionSet) {
    return result
  }

  // From here down, the field has a selection set, which means it's trying to
  // query a GraphQLObjectType
  return executeObjectSelection(field, result, execContext)
}
github apollographql / apollo-client / packages / apollo-cache-inmemory / src / executeStoreQuery.ts View on Github external
selectionSet.selections.forEach(selection => {
    if (!shouldInclude(selection, variables)) {
      // Skip this entirely
      return;
    }

    if (isField(selection)) {
      const fieldResult = handleMissing(executeField(selection, rootValue, execContext));

      if (typeof fieldResult !== 'undefined') {
        merge(finalResult.result, {
          [resultKeyNameFromField(selection)]: fieldResult,
        });
      }

    } else {
      let fragment: InlineFragmentNode | FragmentDefinitionNode;

      if (isInlineFragment(selection)) {
        fragment = selection;
      } else {
        // This is a named fragment
        fragment = fragmentMap[selection.name.value];

        if (!fragment) {
          throw new Error(`No fragment named ${selection.name.value}`);
        }
      }
github apollographql / apollo-client / packages / graphql-anywhere / src / async.ts View on Github external
const execute = async selection => {
    if (!shouldInclude(selection, variables)) {
      // Skip this entirely
      return;
    }

    if (isField(selection)) {
      const fieldResult = await executeField(selection, rootValue, execContext);

      const resultFieldKey = resultKeyNameFromField(selection);

      if (fieldResult !== undefined) {
        if (result[resultFieldKey] === undefined) {
          result[resultFieldKey] = fieldResult;
        } else {
          merge(result[resultFieldKey], fieldResult);
        }
      }

      return;
    }

    let fragment: InlineFragmentNode | FragmentDefinitionNode;

    if (isInlineFragment(selection)) {
      fragment = selection;
github apollographql / apollo-client / packages / graphql-anywhere / src / graphql.ts View on Github external
selectionSet.selections.forEach(selection => {
    if (!shouldInclude(selection, variables)) {
      // Skip this entirely
      return;
    }

    if (isField(selection)) {
      const fieldResult = executeField(selection, rootValue, execContext);

      const resultFieldKey = resultKeyNameFromField(selection);

      if (fieldResult !== undefined) {
        if (result[resultFieldKey] === undefined) {
          result[resultFieldKey] = fieldResult;
        } else {
          merge(result[resultFieldKey], fieldResult);
        }
      }
    } else {
      let fragment: InlineFragmentNode | FragmentDefinitionNode;

      if (isInlineFragment(selection)) {
        fragment = selection;
      } else {
        // This is a named fragment
        fragment = fragmentMap[selection.name.value];
github apollographql / apollo-client / packages / apollo-client / src / core / LocalState.ts View on Github external
private async resolveField(
    field: FieldNode,
    rootValue: any,
    execContext: ExecContext,
  ): Promise {
    const { variables } = execContext;
    const fieldName = field.name.value;
    const aliasedFieldName = resultKeyNameFromField(field);
    const aliasUsed = fieldName !== aliasedFieldName;
    const defaultResult = rootValue[aliasedFieldName] || rootValue[fieldName];
    let resultPromise = Promise.resolve(defaultResult);

    // Usually all local resolvers are run when passing through here, but
    // if we've specifically identified that we only want to run forced
    // resolvers (that is, resolvers for fields marked with
    // `@client(always: true)`), then we'll skip running non-forced resolvers.
    if (
      !execContext.onlyRunForcedResolvers ||
      this.shouldForceResolvers(field)
    ) {
      const resolverType =
        rootValue.__typename || execContext.defaultOperationType;
      const resolverMap = this.resolvers && this.resolvers[resolverType];
      if (resolverMap) {
github Grantimus9 / vuegraphqlphx / assets / node_modules / graphql-anywhere / src / graphql.ts View on Github external
function executeField(
  field: FieldNode,
  rootValue: any,
  execContext: ExecContext,
): any {
  const { variableValues: variables, contextValue, resolver } = execContext;

  const fieldName = field.name.value;
  const args = argumentsObjectFromField(field, variables);

  const info: ExecInfo = {
    isLeaf: !field.selectionSet,
    resultKey: resultKeyNameFromField(field),
    directives: getDirectiveInfoFromField(field, variables),
  };

  const result = resolver(fieldName, rootValue, args, contextValue, info);

  // Handle all scalar types here
  if (!field.selectionSet) {
    return result;
  }

  // From here down, the field has a selection set, which means it's trying to
  // query a GraphQLObjectType
  if (result == null) {
    // Basically any field in a GraphQL response can be null, or missing
    return result;
  }
github apollographql / apollo-client / packages / apollo-cache-inmemory / src / executeStoreQuery.ts View on Github external
function executeField(
  field: FieldNode,
  rootValue: any,
  execContext: ExecContext,
): ExecResult {
  const { variableValues: variables, contextValue } = execContext;
  const fieldName = field.name.value;
  const args = argumentsObjectFromField(field, variables);

  const info: ExecInfo = {
    resultKey: resultKeyNameFromField(field),
    directives: getDirectiveInfoFromField(field, variables),
  };

  const readStoreResult = readStoreResolver(
    fieldName,
    rootValue,
    args,
    contextValue,
    info,
  );

  // Handle all scalar types here
  if (!field.selectionSet) {
    return readStoreResult;
  }
github apollographql / apollo-client / packages / apollo-cache-inmemory / src / readFromStore.ts View on Github external
private executeField(
    object: StoreObject,
    typename: string | void,
    field: FieldNode,
    execContext: ExecContext,
  ): ExecResult {
    const { variableValues: variables, contextValue } = execContext;
    const fieldName = field.name.value;
    const args = argumentsObjectFromField(field, variables);

    const info: ExecInfo = {
      resultKey: resultKeyNameFromField(field),
      directives: getDirectiveInfoFromField(field, variables),
    };

    const readStoreResult = readStoreResolver(
      object,
      typename,
      fieldName,
      args,
      contextValue,
      info,
    );

    if (Array.isArray(readStoreResult.result)) {
      return this.combineExecResults(
        readStoreResult,
        this.executeSubSelectedArray({
github awslabs / aws-mobile-appsync-sdk-js / packages / aws-appsync-react / src / offline-helpers.tsx View on Github external
props: (props) => {
            const { ownProps: { client } } = props;
            const mutationName = resultKeyNameFromField((mutation.definitions[0] as OperationDefinitionNode).selectionSet.selections[0] as FieldNode);

            return {
                [mutationName]: (variables) => {
                    return props.mutate({
                        variables,
                        ...(buildMutation(client, mutation, variables, cacheUpdateQuery, typename, idField, operationType) as MutationOpts),
                    });
                }
            }
        },
    });
github apollographql / apollo-client / packages / apollo-client / src / core / LocalState.ts View on Github external
fieldResult => {
            if (typeof fieldResult !== 'undefined') {
              resultsToMerge.push({
                [resultKeyNameFromField(selection)]: fieldResult,
              } as TData);
            }
          },
        );