@graphql-tools/schema

Interfaces

Functions

Functions

addCatchUndefinedToSchema

addCatchUndefinedToSchema(schema: GraphQLSchema): GraphQLSchema

Defined in packages/schema/src/addCatchUndefinedToSchema.ts:15

Parameters:

NameType
schemaGraphQLSchema

Returns: GraphQLSchema


addErrorLoggingToSchema

addErrorLoggingToSchema(schema: GraphQLSchema, logger?: ILogger): GraphQLSchema

Defined in packages/schema/src/addErrorLoggingToSchema.ts:6

Parameters:

NameType
schemaGraphQLSchema
logger?ILogger

Returns: GraphQLSchema


addResolversToSchema

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

Defined in packages/schema/src/addResolversToSchema.ts:36

Parameters:

NameType
schemaOrOptionsGraphQLSchema | IAddResolversToSchemaOptions
legacyInputResolvers?IResolvers
legacyInputValidationOptions?IResolverValidationOptions

Returns: GraphQLSchema


addSchemaLevelResolver

addSchemaLevelResolver(schema: GraphQLSchema, fn: GraphQLFieldResolver‹any, any›): GraphQLSchema

Defined in packages/schema/src/addSchemaLevelResolver.ts:6

Parameters:

NameType
schemaGraphQLSchema
fnGraphQLFieldResolver‹any, any›

Returns: GraphQLSchema


assertResolversPresent

assertResolversPresent(schema: GraphQLSchema, resolverValidationOptions: IResolverValidationOptions): void

Defined in packages/schema/src/assertResolversPresent.ts:5

Parameters:

NameTypeDefault
schemaGraphQLSchema-
resolverValidationOptionsIResolverValidationOptions{}

Returns: void


attachDirectiveResolvers

attachDirectiveResolvers(schema: GraphQLSchema, directiveResolvers: IDirectiveResolvers): GraphQLSchema

Defined in packages/schema/src/attachDirectiveResolvers.ts:5

Parameters:

NameType
schemaGraphQLSchema
directiveResolversIDirectiveResolvers

Returns: GraphQLSchema


buildDocumentFromTypeDefinitions

buildDocumentFromTypeDefinitions(typeDefinitions: ITypeDefinitions, parseOptions?: GraphQLParseOptions): DocumentNode

Defined in packages/schema/src/buildSchemaFromTypeDefinitions.ts:30

Parameters:

NameType
typeDefinitionsITypeDefinitions
parseOptions?GraphQLParseOptions

Returns: DocumentNode


buildSchemaFromTypeDefinitions

buildSchemaFromTypeDefinitions(typeDefinitions: ITypeDefinitions, parseOptions?: GraphQLParseOptions): GraphQLSchema

Defined in packages/schema/src/buildSchemaFromTypeDefinitions.ts:8

Parameters:

NameType
typeDefinitionsITypeDefinitions
parseOptions?GraphQLParseOptions

Returns: GraphQLSchema


chainResolvers

chainResolvers(resolvers: Array‹GraphQLFieldResolver‹any, any››): (Anonymous function)

Defined in packages/schema/src/chainResolvers.ts:3

Parameters:

NameType
resolversArray‹GraphQLFieldResolver‹any, any››

Returns: (Anonymous function)


checkForResolveTypeResolver

checkForResolveTypeResolver(schema: GraphQLSchema, requireResolversForResolveType?: boolean): void

Defined in packages/schema/src/checkForResolveTypeResolver.ts:4

Parameters:

NameType
schemaGraphQLSchema
requireResolversForResolveType?boolean

Returns: void


concatenateTypeDefs

concatenateTypeDefs(typeDefinitionsAry: Array‹ITypedef›, calledFunctionRefs: any): string

Defined in packages/schema/src/concatenateTypeDefs.ts:5

Parameters:

NameTypeDefault
typeDefinitionsAryArray‹ITypedef-
calledFunctionRefsany[] as any

Returns: string


decorateWithLogger

decorateWithLogger(fn: GraphQLFieldResolver‹any, any›, logger: ILogger, hint: string): GraphQLFieldResolver‹any, any›

Defined in packages/schema/src/decorateWithLogger.ts:9

Parameters:

NameType
fnGraphQLFieldResolver‹any, any›
loggerILogger
hintstring

Returns: GraphQLFieldResolver‹any, any›


extendResolversFromInterfaces

extendResolversFromInterfaces(schema: GraphQLSchema, resolvers: IResolvers): IResolvers

Defined in packages/schema/src/extendResolversFromInterfaces.ts:5

Parameters:

NameType
schemaGraphQLSchema
resolversIResolvers

Returns: IResolvers


extractExtensionDefinitions

extractExtensionDefinitions(ast: DocumentNode): object

Defined in packages/schema/src/extensionDefinitions.ts:3

Parameters:

NameType
astDocumentNode

Returns: object

  • definitions: OperationDefinitionNode | FragmentDefinitionNode | SchemaDefinitionNode | ScalarTypeDefinitionNode | ObjectTypeDefinitionNode | InterfaceTypeDefinitionNode | UnionTypeDefinitionNode | EnumTypeDefinitionNode | InputObjectTypeDefinitionNode | DirectiveDefinitionNode | SchemaExtensionNode | ScalarTypeExtensionNode | ObjectTypeExtensionNode | InterfaceTypeExtensionNode | UnionTypeExtensionNode | EnumTypeExtensionNode | InputObjectTypeExtensionNode[] = extensionDefs

filterExtensionDefinitions

filterExtensionDefinitions(ast: DocumentNode): object

Defined in packages/schema/src/extensionDefinitions.ts:21

Parameters:

NameType
astDocumentNode

Returns: object

  • definitions: OperationDefinitionNode | FragmentDefinitionNode | SchemaDefinitionNode | ScalarTypeDefinitionNode | ObjectTypeDefinitionNode | InterfaceTypeDefinitionNode | UnionTypeDefinitionNode | EnumTypeDefinitionNode | InputObjectTypeDefinitionNode | DirectiveDefinitionNode | SchemaExtensionNode | ScalarTypeExtensionNode | ObjectTypeExtensionNode | InterfaceTypeExtensionNode | UnionTypeExtensionNode | EnumTypeExtensionNode | InputObjectTypeExtensionNode[] = extensionDefs

makeExecutableSchema

makeExecutableSchemaTContext›(__namedParameters: object): GraphQLSchema‹›

Defined in packages/schema/src/makeExecutableSchema.ts:58

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 additinal syntax hightlighting 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 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,
})

Type parameters:

TContext

Parameters:

__namedParameters: object

NameTypeDefault
allowUndefinedInResolvebooleantrue
directiveResolversIDirectiveResolvers‹any, TContext›-
inheritResolversFromInterfacesbooleanfalse
loggerILogger-
parseOptionsGraphQLParseOptions-
pruningOptionsPruneSchemaOptions-
resolverValidationOptionsIResolverValidationOptions-
resolversobject | object[]-
schemaDirectivesobject-
schemaTransformsfunction[][]
typeDefsstring | function | DocumentNode | string | function | DocumentNode[]-

Returns: GraphQLSchema‹›