Skip to content

GraphQL schema documentation: descriptions, deprecation, and how the reference renders

Last checked and updated

In GraphQL the documentation lives in the schema. A string written immediately before a type, field, argument or enum value is its description, and the @deprecated(reason: "...") directive marks a field, argument, input field or enum value that clients should stop using. Both are part of the schema, so they are returned by introspection and shown by any reference generated from the SDL; a # comment is not.

Quotes on this page are from the current edition of the GraphQL specification, September 2026, unless another edition is named. Its section on type system descriptions: "Documentation is a first-class feature of GraphQL type systems, written immediately alongside definitions in a TypeSystemDocument and made available via introspection." And: "GraphQL schema and all other definitions (e.g. types, fields, arguments, etc.) which can be described should provide a Description unless they are considered self descriptive."

A described schema

"""
A product in the catalog.
"""
type Product {
  "The product's identifier."
  id: ID!
  "The name shown to customers."
  name: String!
  "Price in the store's currency."
  price: Float!
  "Use `price` instead."
  cost: Float @deprecated(reason: "Use `price`.")
  status: ProductStatus!
}

"""
Where a product is in its life cycle.
"""
enum ProductStatus {
  ACTIVE
  "No longer sold."
  RETIRED @deprecated(reason: "Products are now deleted instead.")
}

type Query {
  """
  Look up one product by its identifier. Returns null when there is none.
  """
  product("The identifier from `Product.id`." id: ID!): Product
  "All products, newest first."
  products: [Product!]!
}
$ apigit lint schema.graphql
No problems found.

The rules, from the specification's Descriptions section:

  • A description is a string, "..." for one line or a block string """...""" for several: "Description strings (often BlockString) occur immediately before the definition they describe."
  • "GraphQL descriptions are provided as Markdown (as specified by CommonMark)", so backticks and links work.
  • An argument is described the same way, inside the parentheses: product("The identifier." id: ID!).

Deprecation

The September 2026 edition defines the directive as @deprecated(reason: String! = "No longer supported") on FIELD_DEFINITION | ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION | ENUM_VALUE | DIRECTIVE_DEFINITION, and its reason "is formatted using Markdown syntax (as specified by CommonMark)". A deprecated field stays in the schema and keeps working; it is marked, so that tools can warn the client that still asks for it.

Where it may appear has grown. October 2021 had reason: String and only FIELD_DEFINITION | ENUM_VALUE; September 2025 made the reason String! and added arguments and input fields; September 2026 added directives:

WhereOctober 2021September 2025 and later
Field of an object or interface typeYesYes
Enum valueYesYes
ArgumentNoYes, but not on a required one
Input fieldNoYes, but not on a required one
Directive definitionNoFrom September 2026
A type (type Product @deprecated)NoNo

The linter follows these rules in part. @deprecated on a type (line 1 of this file is type Product @deprecated(reason: "x") {) is reported as a schema warning:

$ apigit lint dep-type.graphql
dep-type.graphql
  1:14  warn   graphql-schema  Directive "@deprecated" may not be used on OBJECT.

1 problem (0 errors, 1 warning, 0 info, 0 hints)

@deprecated on an argument passes, and so does @deprecated on a required argument (limit: Int! @deprecated(...)), which the current edition forbids: "The @deprecated directive must not appear on required (non-null without a default) arguments or input object field definitions." Check that one by reading. A graphql-schema finding is a warning, not an error, because a file can be one part of a larger schema; --fail-severity warn makes it fail a CI run.

What clients get through introspection

Descriptions are data, not comments. A GraphQL mock of a similar schema (see schema-first GraphQL) answers an introspection query with them:

$ curl -s 'http://127.0.0.1:4671/graphql?query=%7B%20__type(name%3A%20%22Book%22)%20%7B%20description%20fields%20%7B%20name%20description%20%7D%20%7D%20%7D'
{"data":{"__type":{"description":"A book in the catalog.","fields":[{"name":"id","description":null},{"name":"title","description":null},{"name":"year","description":"Publication year."},{"name":"author","description":null}]}}}

A field without a description returns null: that is the gap a reader of the reference sees too.

How the reference renders

Rendered with apigit preview, which uses the viewer of APIGit's published pages, the schema above became a reference with an overview and three groups: Queries (product, products), Objects (Product) and Enums (ProductStatus). On each:

  • The block description of a type is shown under its name ("A product in the catalog.").
  • Each field shows its type, non-null for !, and its description.
  • The deprecated field cost is marked deprecated and shows its description and a Deprecation reason ("Use price.").
  • The query product(id) shows its description, the argument id as required with its description, the return type with its fields, and a query sample with variables.
  • The enum shows its description and the values; RETIRED is marked deprecated with its description, "No longer sold." The reason given in @deprecated was not on that page.

So put what a reader must know about a deprecated enum value in its description too, as "No longer sold." does here. A schema that does not parse is shown as an error with its source, for example This GraphQL schema could not be rendered: Syntax Error: Expected ":", found Name "String".; GraphQL syntax errors explains those messages.

Checklist

ItemHow
Every type has a description"""...""" before type, enum, input, interface
Fields and arguments that are not self-explanatory have one"..." before the name
Deprecated fields say what to use instead@deprecated(reason: "Use `price`.")
Deprecated enum values explain it in the description toothe reference above showed only the description
No # comments meant for readersthey are dropped

Publishing the schema with an OpenAPI file in one site: GraphQL and OpenAPI in one repository.

Sources

Related pages

Try it with your own API

Create a free workspace, add an OpenAPI file, and publish its documentation and a mock server from the same repository.

Free for individuals. No credit card.

$ npm install -g @apigit/cli$ apigit auth login$ apigit doc publish