Skip to content

Valid GraphQL literals for argument defaults (#562), [Required] args have no default - 6.3.0 - #563

Merged
lukemurray merged 4 commits into
mainfrom
fix/562-arg-default-literals
Oct 9, 2026
Merged

lukemurray merged 4 commits into
mainfrom
fix/562-arg-default-literals

Conversation

@lukemurray

@lukemurray lukemurray commented Sep 29, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #562.

Changes: [Required] arguments have no default

[Required] on an argument now behaves like ArgumentHelper.Required<T>(). Before, a value type kept its implicit default(T) as the schema default: [Required] int Take printed take: Int! = 0, which clients treat as optional, and a query that left it out ran with 0. ArgType.FromMember now clears the default for [Required] the same way it already did for RequiredField<>. The argument is take: Int!, and leaving it out gives a missing required argument error.

This is a behaviour change for anyone relying on that default, so the version goes to 6.3.0. Value types without [Required] still get default(T) as their default, as before. The fields.md docs now mention [Required] next to ArgumentHelper.Required<T>().

Fixes: SDL

SchemaGenerator.GetArgDefaultValue printed any non-bool/enum value type with ToString():

  • Guid, DateTime, DateTimeOffset, DateOnly, TimeOnly, TimeSpan, char came out unquoted (runId: ID! = 00000000-0000-…), which is invalid SDL.
  • floats/decimals used the current culture (3,14 under de-DE).
  • string defaults were not escaped.

Strings and value types are now formatted with System.Text.Json (relaxed encoder). A JSON number or string is also a valid GraphQL value, so numbers are invariant and everything else is an escaped, quoted string (dates in ISO format). Structs, which would serialize to a JSON object, still go through the existing object formatting.

Changes: introspection defaultValue keeps its quotes

SchemaIntrospection.BuildArgs removed every leading/trailing " from the default value (.Trim('"')). The spec defines __InputValue.defaultValue as the GraphQL literal, and buildClientSchema parses it back as one. So string defaults were silently dropped (hello parsed as an enum value), and Guid defaults, or strings containing spaces, failed to parse. The trim is removed, so introspection now returns the same text as the SDL, which is what graphql-js returns ("defaultValue":"\"hello\""). The trim has been there since 4.1.1, and before that the value was a raw ToString(), so code that reads defaultValue as plain text will now see the quotes. That is why this is listed under Changes.

Tests

  • ToGraphQLSchemaStringTests: Guid, DateTime, an escaped string, decimal/double under de-DE, and a Guid/string argument checked in both the SDL and introspection.
  • ArgumentTests.RequiredAttributeValueTypeHasNoDefault: SDL, missing-argument errors, and a successful query.

The EntityGraphQL, AspNet and EF test projects all pass on net10.0.

🤖 Generated with Claude Code

lukemurray and others added 2 commits September 29, 2026 15:23
Value-type defaults other than bool/enum (Guid, DateTime, DateOnly,
TimeSpan, char, ...) were printed with ToString(), unquoted and
culture-dependent, and string defaults were not escaped. Format strings
and value types via System.Text.Json, whose number and string literals
are valid GraphQL literals. Structs still use the object formatting.

Stop trimming quotes off introspection defaultValue - the spec defines it
as the GraphQL literal, and the trimmed form broke buildClientSchema for
Guid/string defaults. Bump to 6.2.5.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
… 6.3.0

[Required] marked the argument non-null but kept a value type's implicit
default(T) as the schema default, so `[Required] int Take` printed
`take: Int! = 0` and a query leaving it out ran with 0. Clear the default
for [Required] the same way RequiredField<> already does, so the argument
must be supplied.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@lukemurray lukemurray changed the title Print argument defaults as valid GraphQL literals (#562) Valid GraphQL literals for argument defaults (#562), [Required] args have no default - 6.3.0 Sep 29, 2026
lukemurray and others added 2 commits September 29, 2026 15:35
…imeSpan and char

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@lukemurray
lukemurray merged commit e02b00c into main Oct 9, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Schema printer writes value-type argument defaults unquoted (Guid, DateTime, …) and culture-dependent

1 participant