03 / 10

What are scalar types?

Difficulty: 4/10
built-in scalars, custom scalars, validation

Scalar types represent primitive leaf values in a GraphQL type system. GraphQL responses take the form of a hierarchical tree; the leaves of this tree are typically GraphQL Scalar types

Types of Scalars
  1. 1

    GraphQL specifies a basic set of well-defined Scalar types: Int, Float, String, Boolean, and ID

  2. 2

    Custom scalars are a way to define new scalar types that extend the default set of built-in scalar types (Int, Float, String, Boolean, and ID). Custom scalars are useful when you need to handle specific types of data in your GraphQL API that aren't covered by the default scalars, such as dates, email addresses, or JSON objects.

Scenario Questions

0-2 years experience

  1. 1We need to add a new field `price` to a Product type that returns a decimal value. Which GraphQL scalar would you use and why?
  2. 2If a client queries a field of type `Int` but the resolver returns a floating‑point number, what will happen and how would you fix it?

2-5 years experience

  1. 1Your team introduced a custom `DateTime` scalar, but after deployment some clients start receiving null for date fields. Walk me through how you'd debug the issue.
  2. 2When extending an existing schema, you need to replace the built‑in `String` scalar with a custom `Email` scalar that validates format. What trade‑offs do you consider and how would you implement it without breaking existing clients?

5-8 years experience

  1. 1At scale we have multiple microservices each exposing GraphQL APIs that share a `UUID` scalar. How would you ensure consistency and avoid versioning problems across services?
  2. 2Design a strategy for handling deprecation of a custom scalar (e.g., `Money`) while maintaining backward compatibility for downstream services.

8+ years experience

  1. 1Our organization is migrating from a monolithic GraphQL server to a federated architecture. How would you approach standardizing custom scalar definitions (like `Date`, `Currency`) across teams to prevent duplication and runtime errors?
  2. 2Discuss the long‑term maintenance implications of allowing teams to create arbitrary custom scalars versus enforcing a shared library of vetted scalars. How would you govern this at the platform level?

Follow-up Questions

  • Can you walk me through a simple implementation of a custom scalar in JavaScript?
  • What security concerns arise when parsing input for a custom scalar?
  • How would you test that your scalar correctly validates and serializes data?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.