Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

GraphQL · Class

GraphQLSchema

GraphQLSchema represents the schema of a GraphQL service: the typed contract describing what data clients can query. Requests are validated and executed against this schema.

How it works

GraphQLSchema is the executable representation of a GraphQL service’s schema. It combines the supported type system with root operation types, allowing incoming operations to be checked and executed against the service definition.

Syntax

new GraphQLSchema({ query, mutation?, subscription?, types?, directives? })

Returns

A schema describing the GraphQL service’s supported types and queryable capabilities.

Key points

  • A schema expresses the API’s queryable data through a formal type system.
  • The schema is the combined description of the capabilities offered by a GraphQL service.
  • Named definitions include object, scalar, enum, interface, union, and input object types.
  • Object types are the primary units for representing entities clients can fetch.
  • Each object type specifies both the kind of returned object and its available fields.

Common mistakes

  • The schema must describe the complete set of queryable data and types; it is not merely a list of resolver functions.
  • Operations are validated against the schema before execution, so fields or types absent from it cannot be requested successfully.

Example: Create a minimal GraphQLSchema

import { GraphQLObjectType, GraphQLSchema, GraphQLString } from "graphql";

const Query = new GraphQLObjectType({
  name: "Query",
  fields: {
    greeting: { type: GraphQLString, resolve: () => "Hello, GraphQL!" },
  },
});

const schema = new GraphQLSchema({ query: Query });
console.log(schema.getQueryType()?.name);

Creates a minimal executable schema with a query root and one field, then reads the root type name.

When to use it

Define an executable API contract

Build a GraphQL server

Reject fields and types outside the schema

Validate client operations

Expose a discoverable type system for clients and tools

Generate developer tooling

Interview questions

QWhat is a GraphQL schema?

A GraphQL schema is the contract describing the types and fields a service exposes. Incoming operations are checked against that contract and then executed to produce results.

Follow-up: What does the schema determine for an operation? It determines which types and fields are valid and where execution begins through the relevant root operation type.

QWhat kinds of types make up a GraphQL schema?

Object types represent fetchable objects and define the fields available on each object. The broader type system also includes scalar, enum, interface, union, and input object types.

Follow-up: Why use interfaces or unions? They model relationships where a field may resolve to one of several object types, while preserving a typed contract.

QHow does a schema affect request processing?

The schema is used both for validation and execution. A request can only use fields and types defined by the service, and valid fields are then resolved to produce the response.

Follow-up: How can clients discover the contract? GraphQL’s introspection system exposes schema metadata so tooling and clients can inspect available types and fields.

  • GraphQL type system
  • Object types
  • Scalar types
  • Enum types
  • Interface types
  • Union types
  • Input object types
  • Introspection

Source: Schemas and Types. Checked 2026-10-15.