Skip to main content

Scalars

GraphQL custom sclars can be defined by placing a @gqlScalar docblock directly before a:

  • Type alias declaration
/** 
* A description of my custom scalar.
* @gqlScalar <optional name of the scalar, if different from type name>
*/
type MyCustomString = string;

Built-In Scalars

note

For built-in GraphQL scalars that don't have a corresponding TypeScript type, Grats ships with type aliases you can import. You may be promted to use one of these by Grat if you try to use number in a positon from which Grat needs to infer a GraphQL type.

import { Float, Int, ID } from "grats";

/** @gqlType */
class Math {
id: ID;
/** @gqlField */
round(args: {float: Float}): Int {
return Math.round(args.float);
}
}