How to use the graphql-tools.delegateToSchema function in graphql-tools

To help you get started, we’ve selected a few graphql-tools 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 dotansimha / graphql-binding / src / Delegate.ts View on Github external
private delegateToSchema(
    operation: Operation,
    fieldName: string,
    args?: { [key: string]: any },
    infoOrQuery?: GraphQLResolveInfo | string,
    options?: Options,
  ): { info: any; result: Promise } {
    const info = buildInfo(fieldName, operation, this.schema, infoOrQuery)

    const transforms = options && options.transforms ? options.transforms : []
    const result = delegateToSchema({
      schema: this.schema,
      operation,
      fieldName,
      args: args || {},
      context: options && options.context ? options.context : {},
      info,
      transforms: [
        ...transforms,
        new ReplaceFieldWithFragment(this.schema, this.fragmentReplacements),
      ],
    })

    return { info, result }
  }
}
github prisma-labs / prisma-binding / src / Handler.ts View on Github external
return (
      args?: { [key: string]: any },
      info?: GraphQLResolveInfo | string,
    ): Promise => {
      this.before()

      const operation = this.operation
      info = buildInfo(rootFieldName, operation, this.schema, info)

      return delegateToSchema(
        this.schema,
        this.fragmentReplacements,
        operation,
        rootFieldName,
        args || {},
        {},
        info,
      )
    }
  }
github DevanB / graphql-binding-yelp / src / index.ts View on Github external
delegate(
    operation: "query" | "mutation",
    fieldName: string,
    args: { [key: string]: any },
    context: any,
    info: GraphQLResolveInfo
  ) {
    return delegateToSchema(
      this.schema,
      {},
      operation,
      fieldName,
      args,
      context,
      info
    );
  }
github dotansimha / graphql-binding / src / handler.ts View on Github external
return async (
      args?: { [key: string]: any },
      infoOrQuery?: GraphQLResolveInfo | string,
      context?: { [key: string]: any },
    ): Promise> => {
      this.before()

      const info = buildInfo(
        rootFieldName,
        'subscription',
        this.schema,
        infoOrQuery,
      )

      const iterator = await delegateToSchema(
        this.schema,
        this.fragmentReplacements,
        'subscription',
        rootFieldName,
        args || {},
        context || {},
        info,
      )

      return {
        async next() {
          const { value } = await iterator.next()
          const data = { [info.fieldName]: value.data[rootFieldName] }
          return { value: data, done: false }
        },
        return() {
github dotansimha / graphql-binding / src / handler.ts View on Github external
return (
      args?: { [key: string]: any },
      info?: GraphQLResolveInfo | string,
      context?: { [key: string]: any },
    ): Promise => {
      this.before()

      const operation = this.operation
      info = buildInfo(rootFieldName, operation, this.schema, info)

      return delegateToSchema(
        this.schema,
        this.fragmentReplacements,
        operation,
        rootFieldName,
        args || {},
        context || {},
        info,
      )
    }
  }
github StephenCodesThings / merge-remote-graphql-schemas / src / merge-remote-schemas.ts View on Github external
info = {
          ...info,
          fieldNodes: [{
            kind: "Field",
            name: {
              kind: "Name",
              value: mergeQuery,
            },
            selectionSet: {
              kind: "SelectionSet",
              selections: info.fieldNodes,
            },
          } as FieldNode],
        };
      }
      const request = delegateToSchema({
        schema,
        operation: "query",
        fieldName: mergeQuery || info.fieldName,
        args: mergeQuery ? { id: parent.id } : args,
        context,
        info,
      });
      if (mergeQuery) {
        return request.then((requestResult) => requestResult ? requestResult[responseKey] : null);
      } else {
        return request;
      }
    }
  };
}
github nikolasburk / github-schema-delegation / src / index.js View on Github external
graphcool: (parent, args, context, info) => {
      return delegateToSchema(
        schema,
        {},
        'query',
        'repositoryOwner',
        {login: 'graphcool'},
        context,
        info
      )
    }
  }
github supergraphql / graphql-cli-binding / example / binding.ts View on Github external
delegate(operation: 'query' | 'mutation', prop: string, args, info?: GraphQLResolveInfo | string): Promise {
    if (!info) {
      info = buildTypeLevelInfo(prop, this.remoteSchema, operation)
    } else if (typeof info === 'string') {
      info = buildFragmentInfo(prop, this.remoteSchema, operation, info)
    }

    return delegateToSchema(
      this.remoteSchema,
      this.fragmentReplacements,
      operation,
      prop,
      args || {},
      {},
      info,
    )
  }