graphql
The graphql
module exports a core subset of GraphQL functionality for creation
of GraphQL type systems and servers.
import { graphql } from 'graphql'; // ES6
const { graphql } = require('graphql'); // CommonJS
Overview
Entry Point
Schema
Type Definitions
class GraphQLScalarType
A scalar type within GraphQL.class GraphQLObjectType
An object type within GraphQL that contains fields.class GraphQLInterfaceType
An interface type within GraphQL that defines fields implementations will contain.class GraphQLUnionType
A union type within GraphQL that defines a list of implementations.class GraphQLEnumType
An enum type within GraphQL that defines a list of valid values.class GraphQLInputObjectType
An input object type within GraphQL that represents structured inputs.class GraphQLList
A type wrapper around other types that represents a list of those types.class GraphQLNonNull
A type wrapper around other types that represents a non-null version of those types.
Scalars
const GraphQLInt
A scalar type representing integers.const GraphQLFloat
A scalar type representing floats.const GraphQLString
A scalar type representing strings.const GraphQLBoolean
A scalar type representing booleans.const GraphQLID
A scalar type representing IDs.
Errors
Entry Point
graphql
function graphql(
schema: GraphQLSchema,
requestString: string,
rootValue?: any,
contextValue?: any,
variableValues?: { [key: string]: any },
operationName?: string,
): Promise<GraphQLResult>;
interface ExecutionResult<
TData = ObjMap<unknown>,
TExtensions = ObjMap<unknown>,
> {
errors?: ReadonlyArray<GraphQLError>;
data?: TData | null;
extensions?: TExtensions;
}
The graphql
function lexes, parses, validates and executes a GraphQL request.
It requires a schema
and a requestString
. Optional arguments include a
rootValue
, which will get passed as the root value to the executor, a contextValue
,
which will get passed to all resolve functions,
variableValues
, which will get passed to the executor to provide values for
any variables in requestString
, and operationName
, which allows the caller
to specify which operation in requestString
will be run, in cases where
requestString
contains multiple top-level operations.
Schema
See the Type System API Reference.
Type Definitions
See the Type System API Reference.
Scalars
See the Type System API Reference.
Errors
See the Errors API Reference