GraphQL supports descriptions on types, fields, arguments and more. Tools like GraphiQL and editor integrations show them to developers.

Gratos keeps these descriptions in sync with the implementation: the leading free text of a docblock is that construct's description.

Tip

Both TypeScript and GraphQL expect descriptions to be written in Markdown.

See Comment syntax for more details.

Example

User.ts
/**
 * A registered user of the system.
 * @gqlType
 */
class User {
  /**
   * A friendly greeting for the user, intended for
   * their first visit.
   * @gqlField
   */
  hello(
    /** The salutation to use */
    greeting: string,
  ): string {
    return `${greeting} World`;
  }
}

Tip

Depending upon your version of TypeScript, a description with an @ in its text, a GitHub handle for example, may get truncated. To avoid this, wrap the handle in quotes or backticks: /** This comment was added by `@captbaritone`. */.

Limitations

Caution

In some cases, TypeScript does not "attach" docblock comments to a construct. In these cases, Gratos cannot extract descriptions.

For example, Gratos cannot attach descriptions to the values of an enum defined as a union of string literals. This union:

GreetingStyle.ts
/** @gqlEnum */
type GreetingStyle =
  /** For a business greeting */
  | "formal"
  /** For a friendly greeting */
  | "casual";

has lost both descriptions. To describe enum values, define the enum with a TypeScript enum (see Enums).