@graphql-tools/schema

  • Version 8.3.11
  • Published
  • 59.4 kB
  • 4 dependencies
  • MIT license

Install

npm i @graphql-tools/schema
yarn add @graphql-tools/schema
pnpm add @graphql-tools/schema

Overview

A set of utils for faster development of GraphQL tools

Index

Functions

function addResolversToSchema

addResolversToSchema: (
schemaOrOptions: GraphQLSchema | IAddResolversToSchemaOptions,
legacyInputResolvers?: IResolvers,
legacyInputValidationOptions?: IResolverValidationOptions
) => GraphQLSchema;

    function assertResolversPresent

    assertResolversPresent: (
    schema: GraphQLSchema,
    resolverValidationOptions?: IResolverValidationOptions
    ) => void;

      function chainResolvers

      chainResolvers: <TArgs extends { [argName: string]: any }>(
      resolvers: Array<Maybe<GraphQLFieldResolver<any, any, TArgs>>>
      ) => (root: any, args: TArgs, ctx: any, info: GraphQLResolveInfo) => any;

        function checkForResolveTypeResolver

        checkForResolveTypeResolver: (
        schema: GraphQLSchema,
        requireResolversForResolveType?: ValidatorBehavior
        ) => void;

          function extendResolversFromInterfaces

          extendResolversFromInterfaces: (
          schema: GraphQLSchema,
          resolvers: IResolvers
          ) => IResolvers;

            function makeExecutableSchema

            makeExecutableSchema: <TContext = any>({
            typeDefs,
            resolvers,
            resolverValidationOptions,
            parseOptions,
            inheritResolversFromInterfaces,
            pruningOptions,
            updateResolversInPlace,
            schemaExtensions,
            }: IExecutableSchemaDefinition<TContext>) => GraphQLSchema;
            • Builds a schema from the provided type definitions and resolvers.

              The type definitions are written using Schema Definition Language (SDL). They can be provided as a string, a DocumentNode, a function, or an array of any of these. If a function is provided, it will be passed no arguments and should return an array of strings or DocumentNodes.

              Note: You can use graphql-tag to not only parse a string into a DocumentNode but also to provide additional syntax highlighting in your editor (with the appropriate editor plugin).

              const typeDefs = gql`
              type Query {
              posts: [Post]
              author(id: Int!): Author
              }
              `;

              The resolvers object should be a map of type names to nested object, which themselves map the type's fields to their appropriate resolvers. See the [Resolvers](/docs/resolvers) section of the documentation for more details.

              const resolvers = {
              Query: {
              posts: (obj, args, ctx, info) => getAllPosts(),
              author: (obj, args, ctx, info) => getAuthorById(args.id)
              }
              };

              Once you've defined both the typeDefs and resolvers, you can create your schema:

              const schema = makeExecutableSchema({
              typeDefs,
              resolvers,
              })

            function mergeSchemas

            mergeSchemas: (config: MergeSchemasConfig) => GraphQLSchema;
            • Synchronously merges multiple schemas, typeDefinitions and/or resolvers into a single schema.

              Parameter config

              Configuration object

            Interfaces

            interface IExecutableSchemaDefinition

            interface IExecutableSchemaDefinition<TContext = any> {}
            • Configuration object for creating an executable schema

            property inheritResolversFromInterfaces

            inheritResolversFromInterfaces?: boolean;
            • GraphQL object types that implement interfaces will inherit any missing resolvers from their interface types defined in the resolvers object

            property parseOptions

            parseOptions?: BuildSchemaOptions & GraphQLParseOptions;
            • Additional options for parsing the type definitions if they are provided as a string

            property pruningOptions

            pruningOptions?: PruneSchemaOptions;
            • Additional options for removing unused types from the schema

            property resolvers

            resolvers?: IResolvers<any, TContext> | Array<IResolvers<any, TContext>>;
            • Object describing the field resolvers for the provided type definitions

            property resolverValidationOptions

            resolverValidationOptions?: IResolverValidationOptions;
            • Additional options for validating the provided resolvers

            property schemaExtensions

            schemaExtensions?: SchemaExtensions | Array<SchemaExtensions>;
            • Schema extensions

            property typeDefs

            typeDefs: TypeSource;
            • The type definitions used to create the schema

            property updateResolversInPlace

            updateResolversInPlace?: boolean;
            • Do not create a schema again and use the one from buildASTSchema

            Type Aliases

            type MergeSchemasConfig

            type MergeSchemasConfig<T = any> = Partial<IExecutableSchemaDefinition<T>> &
            IExecutableSchemaDefinition<T>['parseOptions'] & {
            /**
            * The schemas to be merged
            */
            schemas?: GraphQLSchema[];
            };
            • Configuration object for schema merging

            Package Files (9)

            Dependencies (4)

            Dev Dependencies (0)

            No dev dependencies.

            Peer Dependencies (1)

            Badge

            To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

            You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@graphql-tools/schema.

            • Markdown
              [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@graphql-tools/schema)
            • HTML
              <a href="https://www.jsdocs.io/package/@graphql-tools/schema"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>