How to use the apollo-utilities.getDirectiveInfoFromField 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
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;
  }

  // From here down, the field has a selection set, which means it's trying to
github apollographql / apollo-client / packages / 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 Canner / apollo-link-firebase / src / rtdb / subscriptionLink.ts View on Github external
const queryWithTypename = addTypenameToDocument(query);
    const mainDefinition = getMainDefinition(query);

    const context: ResolverContext = {
      database: this.database,
      findType: fieldDirectives =>
        (fieldDirectives.rtdbSub && fieldDirectives.rtdbSub.type) ||
        (fieldDirectives.rtdbQuery && fieldDirectives.rtdbQuery.type),
      exportVal: {}
    };

    // Subscription operations must have exactly one root field.
    const onlyRootField: FieldNode = mainDefinition.selectionSet.selections[0] as FieldNode;

    // get directives
    const directives = getDirectiveInfoFromField(onlyRootField, operation.variables);
    const rtdbDirectives: SubDirectiveArgs = directives.rtdbSub as any;

    return new Observable(observer => {
      // we fetch the query outside the graphql-anywhere resolver
      // because subscription need to listen to event change
      const subQuery = createQuery({
        database: this.database,
        directives: rtdbDirectives
      });
      const {event} = rtdbDirectives;
      const callback = (snapshot: firebaseDatabase.DataSnapshot) => {
        const root: ResolverRoot = {rootSnapshot: snapshot};
        graphql(
          queryResolver,
          queryWithTypename,
          root,
github apollographql / apollo-client / packages / graphql-anywhere / src / async.ts View on Github external
async function executeField(
  field: FieldNode,
  rootValue: any,
  execContext: ExecContext,
): Promise {
  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),
    field,
  };

  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
  if (result == null) {
    // Basically any field in a GraphQL response can be null, or missing
    return result;
  }
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 / 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({
          field,
github sprusr / ethpollo / src / utils / ast.ts View on Github external
export const fieldHasDirective = (node: FieldNode, directive: string) =>
  Object.keys(getDirectiveInfoFromField(node, {}) || {}).some((dir) => dir === directive);
github sprusr / ethpollo / src / utils / ast.ts View on Github external
export const getTrackerId = (field: FieldNode, args?: object) => {
  const directives = getDirectiveInfoFromField(field, args || {});
  if (!(directives.ethpollo && directives.ethpollo.id)) {
    throw new Error('Tracker directive not found');
  }
  return directives.ethpollo.id;
};