⬡ GraphQL Intermediate

What are custom scalars in GraphQL?

Answer

Custom scalars extend GraphQL beyond the five built-in scalar types to handle domain-specific primitive values. Common examples include Date (ISO 8601 string), DateTime, Email, URL, JSON, and UUID. You declare them in the schema: scalar Date, then implement the scalar in code with three methods: serialize (output coercion — how to send to client), parseValue (input coercion — how to parse from variable), and parseLiteral (how to parse from inline query literal). The graphql-scalars library provides production-ready implementations of dozens of common custom scalars.