Q21: How do you implement a Custom Scalar in GraphQL?

Difficulty:IntermediateTopic:Schema Extension

When built-in primitives are insufficient, custom scalars (e.g., Date, JSON, URL) can be defined in SDL and provided custom logic for:

  1. serialize: Converts back-end output to JSON.
  2. parseValue: Parses variables sent in JSON requests.
  3. parseLiteral: Parses inline AST literal values inside queries.
Key Takeaways
  • Custom scalars validate and transform specialized datatypes at the framework boundary.
Knowledge Check

Which custom scalar method parses inline literal values written directly inside a query string?