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

GraphQL · Const

schema

A GraphQL schema defines the types and capabilities available from a service. GraphQL validates incoming operations against this contract before executing them, so clients can request supported data predictably.

How it works

A GraphQL schema is the contract describing the types, fields, arguments, and directives available through a service. Incoming operations are validated against that contract and then executed, allowing clients to request only supported fields and receive predictable results.

Syntax

schema { query: Query }

Key points

  • The schema describes the complete set of data capabilities that a GraphQL service makes queryable.
  • GraphQL checks an incoming operation against the schema before executing it.
  • Object types are the fundamental schema units for representing entities that clients can fetch.
  • Named definitions include Object, Scalar, Enum, Interface, Union, and Input Object types.
  • Directives attach metadata or behavior to types, fields, and arguments.
  • Descriptions can be written in Markdown and may occupy one line or multiple lines.

Common mistakes

  • Schema documentation is part of the API contract, so descriptions should accompany types, fields, and arguments rather than being maintained only externally.

Example: Query fields described by a schema

query ProductName($id: ID!) {
  product(id: $id) {
    name
  }
}

A client sends a query whose fields are checked against the service schema before execution.

When to use it

Describe available data

Define an API contract

Reject unsupported selections

Validate client operations

Document the service

Generate API reference material

Inspect capabilities with introspection

Enable client discovery

Interview questions

QWhat is a GraphQL schema?

A schema is the collection of capabilities exposed by a GraphQL service. It defines the available types and the relationships between them, and requests are validated and executed against it.

Follow-up: How can clients discover the contract? They can use GraphQL introspection, including the __schema and __type meta-fields, when the service exposes introspection.

QWhat are the main building blocks of a schema?

Object types represent fetchable kinds of objects, and their fields describe the data that can be selected. Fields can also declare arguments and return types, forming the structure clients query.

Follow-up: What other named type categories exist? The documentation identifies Scalar, Enum, Interface, Union, and Input Object types in addition to Object types.

QHow does a schema affect query execution?

The schema is used during request processing: an incoming operation is checked against the defined types and fields, then executed only if it conforms to that contract. This lets clients make predictable selections.

Follow-up: What role do directives play? They annotate schema elements so validation or execution can treat those elements differently.

  • Object types
  • Scalar types
  • Enum types
  • Interface types
  • Union types
  • Input Object types
  • Directives
  • Introspection

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