Inputs
GraphQL input types can be defined by placing a @gqlInput
docblock directly before a:
- Type alias declaration
- Interface declaration
/**
* Description of my input type
* @gqlInput <optional name of the input, if different from type name>
*/
type MyInput = {
name: string;
};
/** @gqlInput */
interface MyInput {
name: string;
}
Unlike with type or interface fields, every property of an input type is automatically included as part of the GraphQL definition. You do not need to annotate individual properties with @gqlField
.
Deprecated fields
Individual optional fields can be marked as @deprecated
in the GraphQL schema using the @deprecated
JSDoc tag:
/** @gqlInput */
type MyInput = {
name: string;
/** @deprecated Don't ask for age any more */
age?: number;
};
Merged Interfaces
TypeScript merges interfaces if you to define multiple interfaces with the same name in the same scope. For example, Node
is a built-in interface that describes DOM nodes. So, if you define a Node
interface in your code, TypeScript will merge your interface with the built-in one.
To avoid ambiguity, Grats will error if you try to define a GraphQL input type using a merged TypeScript interface. To avoid this error you can define a new interface, with a unique name, and then rename it to the name you want to use in your schema.