---
title: graphql
---

{/* title can be removed in Nextra 4, since sidebar title will take from first h1 */}

# `graphql`

The `graphql` module exports a core subset of GraphQL functionality for creation
of GraphQL type systems and servers.

```js
import { graphql } from "graphql" // ES6
var { graphql } = require("graphql") // CommonJS
```

## Overview

### Entry Point

<ul className="apiIndex">
  <li>
    <a href="#graphql">
      `function graphql` Lexes, parses, validates, and executes a GraphQL
      request on a schema.
    </a>
  </li>
</ul>

### Schema

<ul className="apiIndex">
  <li>
    <a href="../type/#graphqlschema">
      `class GraphQLSchema` A representation of the capabilities of a GraphQL
      Server.
    </a>
  </li>
</ul>

### Type Definitions

<ul className="apiIndex">
  <li>
    <a href="../type/#graphqlscalartype">
      `class GraphQLScalarType` A scalar type within GraphQL.
    </a>
  </li>
  <li>
    <a href="../type/#graphqlobjecttype">
      `class GraphQLObjectType` An object type within GraphQL that contains
      fields.
    </a>
  </li>
  <li>
    <a href="../type/#graphqlinterfacetype">
      `class GraphQLInterfaceType` An interface type within GraphQL that defines
      fields implementations will contain.
    </a>
  </li>
  <li>
    <a href="../type/#graphqluniontype">
      `class GraphQLUnionType` A union type within GraphQL that defines a list
      of implementations.
    </a>
  </li>
  <li>
    <a href="../type/#graphqlenumtype">
      `class GraphQLEnumType` An enum type within GraphQL that defines a list of
      valid values.
    </a>
  </li>
  <li>
    <a href="../type/#graphqlinputobjecttype">
      `class GraphQLInputObjectType` An input object type within GraphQL that
      represents structured inputs.
    </a>
  </li>
  <li>
    <a href="../type/#graphqllist">
      `class GraphQLList` A type wrapper around other types that represents a
      list of those types.
    </a>
  </li>
  <li>
    <a href="../type/#graphqlnonnull">
      `class GraphQLNonNull` A type wrapper around other types that represents a
      non-null version of those types.
    </a>
  </li>
</ul>

### Scalars

<ul className="apiIndex">
  <li>
    <a href="../type/#graphqlint">
      `var GraphQLInt` A scalar type representing integers.
    </a>
  </li>
  <li>
    <a href="../type/#graphqlfloat">
      `var GraphQLFloat` A scalar type representing floats.
    </a>
  </li>
  <li>
    <a href="../type/#graphqlstring">
      `var GraphQLString` A scalar type representing strings.
    </a>
  </li>
  <li>
    <a href="../type/#graphqlboolean">
      `var GraphQLBoolean` A scalar type representing booleans.
    </a>
  </li>
  <li>
    <a href="../type/#graphqlid">
      `var GraphQLID` A scalar type representing IDs.
    </a>
  </li>
</ul>

### Errors

<ul className="apiIndex">
  <li>
    <a href="../error/#formaterror">
      `function formatError` Format an error according to the rules described by
      the Response Format.
    </a>
  </li>
</ul>

## Entry Point

### `graphql`

```ts
function graphql(
  schema: GraphQLSchema,
  requestString: string,
  rootValue?: any,
  contextValue?: any,
  variableValues?: {[key: string]: any},
  operationName?: string
): Promise<GraphQLResult>
```

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](/graphql-js/type#schema).

## Type Definitions

See the [Type System API Reference](/graphql-js/type#definitions).

## Scalars

See the [Type System API Reference](/graphql-js/type#scalars).

## Errors

See the [Errors API Reference](/graphql-js/error)