Schema and type utilities
GraphQLSchema
Section titled “GraphQLSchema”type
type GraphQLSchema = { /** * All types of the schema, including the introspection types themselves */ types: GraphQLType[];};GraphQL introspection data (__Schema), starting with the value of the “__schema” key.
GraphQLType
Section titled “GraphQLType”type
type GraphQLType = GraphQLScalarType | GraphQLObjectType | GraphQLInterfaceType | GraphQLUnionType | GraphQLEnumType | GraphQLInputObjectType;One of the named types of the schema, discriminated by “kind”. The members not applying to a kind are present as null, so they can be accessed without narrowing first:
// GraphQLField[] | null const fields = type.fields
if (type.kind === "OBJECT") { // GraphQLField[] const fields = type.fields }GraphQLNamedTypeBase
Section titled “GraphQLNamedTypeBase”type
type GraphQLNamedTypeBase = { name: string; description: string | null;};GraphQLScalarType
Section titled “GraphQLScalarType”type
type GraphQLScalarType = GraphQLNamedTypeBase & { kind: "SCALAR"; fields: null; inputFields: null; interfaces: null; enumValues: null; possibleTypes: null;};Scalar type (graphql.schema.GraphQLScalarType). Has none of the kind specific members.
GraphQLObjectType
Section titled “GraphQLObjectType”type
type GraphQLObjectType = GraphQLNamedTypeBase & { kind: "OBJECT"; /** * Fields of the object, deprecated ones included */ fields: GraphQLField[]; inputFields: null; /** * Interfaces implemented by this object */ interfaces: GraphQLNamedTypeRef[]; enumValues: null; possibleTypes: null;};Object type (graphql.schema.GraphQLObjectType)
GraphQLInterfaceType
Section titled “GraphQLInterfaceType”type
type GraphQLInterfaceType = GraphQLNamedTypeBase & { kind: "INTERFACE"; /** * Fields of the interface, deprecated ones included */ fields: GraphQLField[]; inputFields: null; /** * Interfaces implemented by this interface */ interfaces: GraphQLNamedTypeRef[]; enumValues: null; /** * Object types implementing this interface */ possibleTypes: GraphQLNamedTypeRef[];};Interface type (graphql.schema.GraphQLInterfaceType)
GraphQLUnionType
Section titled “GraphQLUnionType”type
type GraphQLUnionType = GraphQLNamedTypeBase & { kind: "UNION"; fields: null; inputFields: null; interfaces: null; enumValues: null; /** * Object types that are part of this union */ possibleTypes: GraphQLNamedTypeRef[];};Union type (graphql.schema.GraphQLUnionType)
GraphQLEnumType
Section titled “GraphQLEnumType”type
type GraphQLEnumType = GraphQLNamedTypeBase & { kind: "ENUM"; fields: null; inputFields: null; interfaces: null; /** * Values of the enum, deprecated ones included */ enumValues: GraphQLEnumValue[]; possibleTypes: null;};Enum type (graphql.schema.GraphQLEnumType)
GraphQLInputObjectType
Section titled “GraphQLInputObjectType”type
type GraphQLInputObjectType = GraphQLNamedTypeBase & { kind: "INPUT_OBJECT"; fields: null; /** * Fields of the input object */ inputFields: GraphQLInputValue[]; interfaces: null; enumValues: null; possibleTypes: null;};Input object type (graphql.schema.GraphQLInputObjectType)
GraphQLField
Section titled “GraphQLField”type
type GraphQLField = { name: string; description: string | null; args: GraphQLInputValue[]; type: GraphQLTypeRef; isDeprecated: boolean; deprecationReason: string | null;};Field of an object or interface type (graphql.schema.GraphQLFieldDefinition)
GraphQLInputValue
Section titled “GraphQLInputValue”type
type GraphQLInputValue = { name: string; description: string | null; type: GraphQLTypeRef; /** * Default value as GraphQL literal source, null if there is none */ defaultValue: string | null;};Argument of a field (graphql.schema.GraphQLArgument) or field of an input object (graphql.schema.GraphQLInputObjectField). Both are introspected as __InputValue.
GraphQLEnumValue
Section titled “GraphQLEnumValue”type
type GraphQLEnumValue = { name: string; description: string | null; isDeprecated: boolean; deprecationReason: string | null;};Value of an enum type (graphql.schema.GraphQLEnumValueDefinition)
GraphQLTypeRef
Section titled “GraphQLTypeRef”type
type GraphQLTypeRef = GraphQLNamedTypeRef | GraphQLModifiedTypeRef;Reference to the type of a field, argument or input field, i.e. a named type potentially wrapped in LIST / NON_NULL modifiers.
GraphQLNamedTypeRef
Section titled “GraphQLNamedTypeRef”type
type GraphQLNamedTypeRef = { kind: GraphQLNamedTypes; name: string; /** * Named types wrap nothing. Missing on the innermost level (see * GraphQLModifiedTypeRef.ofType). */ ofType?: null;};Reference to one of the named types in GraphQLSchema.types.
GraphQLModifiedTypeRef
Section titled “GraphQLModifiedTypeRef”type
type GraphQLModifiedTypeRef = GraphQLList | GraphQLNonNull;One of the two type modifiers (graphql.schema.GraphQLModifiedType)
GraphQLList
Section titled “GraphQLList”type
type GraphQLList = { kind: "LIST"; name: null; /** * The wrapped type. * * Missing if the modifier sits on the innermost of the four nesting levels * the introspection query selects. Only reachable with more than four * modifiers on one type, e.g. [[String!]!]! */ ofType?: GraphQLTypeRef;};LIST modifier wrapping another type reference. Has no name of its own.
GraphQLNonNull
Section titled “GraphQLNonNull”type
type GraphQLNonNull = { kind: "NON_NULL"; name: null; /** * The wrapped type. Missing on the innermost nesting level, see * GraphQLListTypeRef.ofType */ ofType?: GraphQLTypeRef;};NON_NULL modifier wrapping another type reference. Has no name of its own.
GraphQLTypeKind
Section titled “GraphQLTypeKind”type
type GraphQLTypeKind = GraphQLNamedTypes | GraphQLModifiedTypes;All GraphQL type kinds. Named types and modified type wrappers.
GraphQLNamedTypes
Section titled “GraphQLNamedTypes”type
type GraphQLNamedTypes = "SCALAR" | "OBJECT" | "INTERFACE" | "UNION" | "ENUM" | "INPUT_OBJECT";Kind of a named type, i.e. one of the graphql.schema.GraphQLNamedType implementations.
GraphQLModifiedTypes
Section titled “GraphQLModifiedTypes”type
type GraphQLModifiedTypes = "LIST" | "NON_NULL";Kind of a type modifier, i.e. one of the graphql.schema.GraphQLModifiedType implementations wrapping another type.
findType()
Section titled “findType()”function
declare function findType(name: string): GraphQLType;Returns the named type of the given name.
Parameters
name |
GraphQL type name |
Returns the type
Throws if the schema has no type of that name
objectFields()
Section titled “objectFields()”function
declare function objectFields(type: string): GraphQLField[];The fields of the given object type.
Parameters
type |
GraphQL type name |
Returns the fields, in schema order
Throws if the schema has no type of that name, or it is not an object type
primaryKeyFields()
Section titled “primaryKeyFields()”function
declare function primaryKeyFields(type: string): string[];The fields of a type’s primary key, from its uniqueKeys meta, or id for a type without one.
Parameters
type |
GraphQL type name |
unwrapAll()
Section titled “unwrapAll()”function
declare function unwrapAll(type: GraphQLTypeRef): GraphQLNamedTypeRef;Unwraps all LIST and NON_NULL modifiers off the given type reference and returns the named type at the heart of it.
Parameters
type |
GraphQL type reference |
Returns the named type reference wrapped by the modifiers
unwrapNonNull()
Section titled “unwrapNonNull()”function
declare function unwrapNonNull(type: GraphQLTypeRef): GraphQLTypeRef;Unwraps a NON_NULL modifier off the given type reference, if there is one.
Parameters
type |
GraphQL type reference |
Returns the wrapped type, or the type itself if it is nullable
isListType()
Section titled “isListType()”function
declare function isListType(type: GraphQLTypeRef): boolean;Returns true if the given type reference is a list or a non-null list.
Parameters
type |
GraphQL type reference |
Returns true if list
isNonNull()
Section titled “isNonNull()”function
declare function isNonNull(type: GraphQLTypeRef): boolean;Returns true if the given type reference is non-null, i.e. a value of that type is guaranteed to be present.
Parameters
type |
GraphQL type reference |
Returns true if non-null
isQueryDocumentType()
Section titled “isQueryDocumentType()”function
declare function isQueryDocumentType(type: string): boolean;Returns true if the given type name was derived from QueryDocument
Parameters
type |
constant
declare const LIST = "LIST";Name of the LIST type modifier
NON_NULL
Section titled “NON_NULL”constant
declare const NON_NULL = "NON_NULL";Name of the NON_NULL type modifier