Skip to main content

GraphQLSchemaImpl

Schema Definition

A Schema is created by supplying the root types of each type of operation, query and mutation (optional). A schema definition is then supplied to the validator and executor.

Example:

const MyAppSchema = new GraphQLSchemaImpl({
query: MyAppQueryRootType,
mutation: MyAppMutationRootType,
})

Note: When the schema is constructed, by default only the types that are reachable by traversing the root types are included, other types must be explicitly referenced.

Example:

const characterInterface = new GraphQLInterfaceTypeImpl({
name: 'Character',
...
});

const humanType = new GraphQLObjectTypeImpl({
name: 'Human',
interfaces: [characterInterface],
...
});

const droidType = new GraphQLObjectTypeImpl({
name: 'Droid',
interfaces: [characterInterface],
...
});

const schema = new GraphQLSchemaImpl({
query: new GraphQLObjectTypeImpl({
name: 'Query',
fields: {
hero: { type: characterInterface, ... },
}
}),
...
// Since this schema references only the `Character` interface it's
// necessary to explicitly list the types that implement it if
// you want them to be included in the final schema.
types: [humanType, droidType],
})

Note: If an array of directives are provided to GraphQLSchema, that will be the exact list of directives represented and allowed. If directives is not provided then a default set of the specified directives (e.g. @include and @skip) will be used. If you wish to provide additional directives to these specified directives, you must explicitly declare them. Example:

const MyAppSchema = new GraphQLSchemaImpl({
...
directives: specifiedDirectives.concat([ myCustomDirective ]),
})

Hierarchy

  • GraphQLEntityImpl
    • GraphQLSchemaImpl

Implements

  • GraphQLSchema

Index

Constructors

constructor

Properties

readonly[GRAPHQL_SCHEMA_SYMBOL]

[GRAPHQL_SCHEMA_SYMBOL]: true = true

readonly[GRAPHQL_VERSION_SYMBOL]

[GRAPHQL_VERSION_SYMBOL]: undefined = undefined

__validationErrors

__validationErrors: Maybe<readonly GraphQLError[]>

astNode

astNode: Maybe<SchemaDefinitionNode>

description

description: Maybe<string>

extensionASTNodes

extensionASTNodes: readonly SchemaExtensionNode[]

extensions

extensions: Readonly<GraphQLSchemaExtensions>

Accessors

[toStringTag]

  • get [toStringTag](): string
  • Returns string

Methods

getDirective

  • getDirective(name: string): Maybe<GraphQLDirective>
  • Parameters

    • name: string

    Returns Maybe<GraphQLDirective>

getDirectives

  • getDirectives(): readonly GraphQLDirective[]
  • Returns readonly GraphQLDirective[]

getField

  • This method looks up the field on the given type definition. It has special casing for the three introspection fields, __schema, __type and __typename.

    __typename is special because it can always be queried as a field, even in situations where no other fields are allowed, like on a Union.

    __schema and __type could get automatically added to the query type, but that would require mutating type definitions, which would cause issues.


    Parameters

    Returns undefined | GraphQLField<unknown, unknown, any>

getImplementations

  • getImplementations(interfaceType: GraphQLInterfaceType): { interfaces: readonly GraphQLInterfaceType[]; objects: readonly GraphQLObjectType<any, any>[] }
  • Parameters

    • interfaceType: GraphQLInterfaceType

    Returns { interfaces: readonly GraphQLInterfaceType[]; objects: readonly GraphQLObjectType<any, any>[] }

    • interfaces: readonly GraphQLInterfaceType[]
    • objects: readonly GraphQLObjectType<any, any>[]

getMutationType

  • getMutationType(): Maybe<GraphQLObjectType<any, any>>
  • Returns Maybe<GraphQLObjectType<any, any>>

getPossibleTypes

  • Parameters

    Returns readonly GraphQLObjectType<any, any>[]

getQueryType

  • getQueryType(): Maybe<GraphQLObjectType<any, any>>
  • Returns Maybe<GraphQLObjectType<any, any>>

getRootType

  • Parameters

    Returns Maybe<GraphQLObjectType<any, any>>

getSubscriptionType

  • getSubscriptionType(): Maybe<GraphQLObjectType<any, any>>
  • Returns Maybe<GraphQLObjectType<any, any>>

getType

  • Parameters

    • name: string

    Returns undefined | GraphQLNamedType

getTypeMap

  • getTypeMap(): TypeMap
  • Returns TypeMap

isSubType

  • isSubType(abstractType: GraphQLAbstractType, maybeSubType: GraphQLObjectType<any, any> | GraphQLInterfaceType): boolean
  • Parameters

    • abstractType: GraphQLAbstractType
    • maybeSubType: GraphQLObjectType<any, any> | GraphQLInterfaceType

    Returns boolean

toConfig

  • toConfig(): GraphQLSchemaNormalizedConfig
  • Returns GraphQLSchemaNormalizedConfig