Files
What you'll learn
- Register a TypeScript enum with registerEnumType(), with descriptions, and use it for fields and arguments
- Use Date fields and arguments, which GraphQL carries as the DateTime scalar in ISO 8601
- Write a custom scalar with GraphQLScalarType: serialize for answers, parseValue for variables, parseLiteral for inline values
- Tell where each kind of value is checked: enums and scalars by GraphQL before any resolver runs
Press Run tests to start the app. Its log appears here.Graded endpoints
breed is a Breed enum value, arrivedAt an ISO 8601 DateTime, microchip null or its digits in groups of three
An enum value is written without quotes and reaches the resolver as the TypeScript enum's value
GraphQL refuses it with a 400 before the resolver runs
The DateTime argument arrives as a Date, so the service can compare it: cats that arrived after August 1st
registerEnumType published the name, the description and the description of one value
breed is the Breed enum, not a String; arrivedAt the DateTime scalar; microchip the Microchip scalar, nullable
parseLiteral accepts the digits grouped by spaces and stores the 15 digits; serialize writes them back in groups of three
parseValue handles the same value when it comes as a variable
The scalar refuses it while the query is validated: a 400 carrying the scalar's own GraphQLError
The same refusal from parseValue, reported on the variable