Any — GraphQL Custom Scalar

Author – ChilliCream

Date – 2026-01-06

1Overview

The Any scalar type represents any valid GraphQL value. It is intended for scenarios where the type of data is dynamic or not known at schema definition time, such as configuration objects, metadata, flexible schemas, or polymorphic data structures.

Unlike typed GraphQL objects which have a fixed schema, Any allows for any valid GraphQL value including objects, lists, strings, numbers, booleans, and null. This provides flexibility at the cost of losing GraphQL’s type safety for that field.

Note: Object field names must be valid GraphQL names (matching the pattern /[_A-Za-z][_0-9A-Za-z]*/).

3Result spec

An Any scalar serializes as any valid GraphQL value. This can be:

The serialized format depends on the transport mechanism used (typically JSON over HTTP, but GraphQL is transport-agnostic).

3.1Examples

These are valid result values:

Value Explanation
{ "name": "John", "age": 30 } An object value.
[1, 2, 3, 4, 5] A list value.
"Hello, World!" A string value.
42 An integer value.
3.14159 A float value.
true A boolean value.
null A null value.
{ "nested": { "data": [1, 2, 3] } } Nested structure.

These are invalid result values:

Value Why is it invalid
{ "123invalid": "value" } Field name doesn’t match name pattern.
ACTIVE Enum values are not valid.

4Input spec

An Any scalar accepts any valid GraphQL value, both as GraphQL literals and as input values.

The input can be:

4.1Examples

Valid input values:

GraphQL Literal:

mutation {
  updateMetadata(data: { theme: "dark", notifications: true }) {
    id
  }
}

JSON input:

{
  "data": {
    "theme": "dark",
    "notifications": true
  }
}
{
  "tags": ["important", "urgent", "review"]
}
{
  "count": 42
}

Invalid input values:

Value Why is it invalid
{ "123invalid": "value" } Field name doesn’t match name pattern.
ACTIVE Enum values are not valid.

5References

  1. 1Overview
  2. 2Recommended name
  3. 3Result spec
    1. 3.1Examples
  4. 4Input spec
    1. 4.1Examples
  5. 5References