Skip to content

Schema and type utilities

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.

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
}

type

type GraphQLNamedTypeBase = {
name: string;
description: string | null;
};

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.

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)

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)

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)

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)

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)

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)

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.

type

type GraphQLEnumValue = {
name: string;
description: string | null;
isDeprecated: boolean;
deprecationReason: string | null;
};

Value of an enum type (graphql.schema.GraphQLEnumValueDefinition)

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.

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.

type

type GraphQLModifiedTypeRef = GraphQLList | GraphQLNonNull;

One of the two type modifiers (graphql.schema.GraphQLModifiedType)

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.

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.

type

type GraphQLTypeKind = GraphQLNamedTypes | GraphQLModifiedTypes;

All GraphQL type kinds. Named types and modified type wrappers.

type

type GraphQLNamedTypes = "SCALAR" | "OBJECT" | "INTERFACE" | "UNION" | "ENUM" | "INPUT_OBJECT";

Kind of a named type, i.e. one of the graphql.schema.GraphQLNamedType implementations.

type

type GraphQLModifiedTypes = "LIST" | "NON_NULL";

Kind of a type modifier, i.e. one of the graphql.schema.GraphQLModifiedType implementations wrapping another type.

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

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

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

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

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

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

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

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

constant

declare const NON_NULL = "NON_NULL";

Name of the NON_NULL type modifier