commits
When generating code with InputObject types, the serializer functions
use list.filter_map to handle optional fields, but the gleam/list
import was missing from the generated code.
This commit adds conditional import of gleam/list when input types
are present in the generated code.
Generates public *_to_json() functions for all response types, enabling
round-trip serialization (JSON → Gleam → JSON). This allows users to
serialize GraphQL responses back to JSON for caching, logging, debugging,
and forwarding to other services.
Features:
- Full scalar type support (String, Int, Float, Boolean, ID, JSON)
- Handles optional fields with json.nullable()
- Supports nested objects with recursive serialization
- Works with lists of both scalars and objects
- Fixes optional list serialization bug in codegen
Added 5 comprehensive tests with snapshot coverage for all type combinations.
Updated examples to demonstrate JSON serialization of API responses.
Changes input object serialization to omit optional fields when None,
rather than serializing them as null. Input serializers now use
Some/None pattern matching to conditionally include fields in the
generated JSON object.
Adds context-aware type mapping where JSON scalars map to json.Json
in input contexts and Dynamic in output contexts. This ensures proper
type safety when passing JSON values to mutations while maintaining
flexibility when receiving JSON from queries.
Optimizes imports to only include Some/None constructors when input
types have optional fields, reducing unnecessary imports for queries
with optional response fields.
Generates public *_to_json() functions for all response types, enabling
round-trip serialization (JSON → Gleam → JSON). This allows users to
serialize GraphQL responses back to JSON for caching, logging, debugging,
and forwarding to other services.
Features:
- Full scalar type support (String, Int, Float, Boolean, ID, JSON)
- Handles optional fields with json.nullable()
- Supports nested objects with recursive serialization
- Works with lists of both scalars and objects
- Fixes optional list serialization bug in codegen
Added 5 comprehensive tests with snapshot coverage for all type combinations.
Updated examples to demonstrate JSON serialization of API responses.
Changes input object serialization to omit optional fields when None,
rather than serializing them as null. Input serializers now use
Some/None pattern matching to conditionally include fields in the
generated JSON object.
Adds context-aware type mapping where JSON scalars map to json.Json
in input contexts and Dynamic in output contexts. This ensures proper
type safety when passing JSON values to mutations while maintaining
flexibility when receiving JSON from queries.
Optimizes imports to only include Some/None constructors when input
types have optional fields, reducing unnecessary imports for queries
with optional response fields.