To define a GraphQL input type, put a @gqlInput docblock directly before a:

  • type alias declaration;
  • interface declaration.

As with other tags, the name after the tag, if any, is the input's name in the schema, when it differs from the type's name.

MyInput.ts
/**
 * Description of my input type
 * @gqlInput
 */
type MyInput = {
  name: string;
};
MyInput.ts
/** @gqlInput */
interface MyInput {
  name: string;
}

Unlike the fields of a type or an interface, every property of an input type is part of its GraphQL definition. You do not annotate each property with @gqlField.

Deprecated fields

An optional field can be marked @deprecated in the GraphQL schema with the @deprecated JSDoc tag:

MyInput.ts
import type { Int } from "gratos";

/** @gqlInput */
type MyInput = {
  name: string;
  /** @deprecated Don't ask for age any more */
  age?: Int;
};

Merged interfaces

TypeScript merges interfaces when you define several interfaces with the same name in the same scope. For example, Node is a built-in interface that describes DOM nodes, so a Node interface of your own is merged with the built-in one.

To avoid ambiguity, Gratos reports an error when a GraphQL input type is defined with a merged TypeScript interface. To avoid the error, define an interface with a unique name, and rename it to the name you want in your schema.