Repository navigation
Valid GraphQL literals for argument defaults (#562), [Required] args have no default - 6.3.0 - #563
Merged
Merged
Conversation
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>
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #562.
Changes:
[Required]arguments have no default[Required]on an argument now behaves likeArgumentHelper.Required<T>(). Before, a value type kept its implicitdefault(T)as the schema default:[Required] int Takeprintedtake: Int! = 0, which clients treat as optional, and a query that left it out ran with0.ArgType.FromMembernow clears the default for[Required]the same way it already did forRequiredField<>. The argument istake: Int!, and leaving it out gives amissing required argumenterror.This is a behaviour change for anyone relying on that default, so the version goes to 6.3.0. Value types without
[Required]still getdefault(T)as their default, as before. Thefields.mddocs now mention[Required]next toArgumentHelper.Required<T>().Fixes: SDL
SchemaGenerator.GetArgDefaultValueprinted any non-bool/enum value type withToString():Guid,DateTime,DateTimeOffset,DateOnly,TimeOnly,TimeSpan,charcame out unquoted (runId: ID! = 00000000-0000-…), which is invalid SDL.3,14underde-DE).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
defaultValuekeeps its quotesSchemaIntrospection.BuildArgsremoved every leading/trailing"from the default value (.Trim('"')). The spec defines__InputValue.defaultValueas the GraphQL literal, andbuildClientSchemaparses it back as one. So string defaults were silently dropped (helloparsed 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 rawToString(), so code that readsdefaultValueas plain text will now see the quotes. That is why this is listed under Changes.Tests
ToGraphQLSchemaStringTests: Guid, DateTime, an escaped string, decimal/double underde-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