Skip to content

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

Description

@lukemurray

What happens

SchemaGenerator.GetArgDefaultValue prints any value type with ToString(), unquoted:

else if (valueType.IsValueType)
{
    return defaultArgValue.Value.ToString();
}

An arguments object with a Guid property therefore produces invalid SDL:

public sealed class RunMessagesArgs
{
    public Guid RunId { get; set; }
}

query.AddField("runMessages", new RunMessagesArgs(), (db, args) => /* … */);
runMessages(runId: ID! = 00000000-0000-0000-0000-000000000000): RunMessagePage

GraphQL Code Generator then refuses the schema: Syntax Error: Invalid number, unexpected digit after 0: "0".

Other cases on the same path

  • String-like value types are printed bare as well: DateTime, DateTimeOffset, DateOnly, TimeOnly, TimeSpan and char. Each should be a quoted string literal.
  • Floating point and decimal values use the current culture. Under de-DE, a default of 3.14 prints as 3,14. TestGetArgDefaultValue_Decimal passes only because of the culture the tests run under.
  • String defaults are not escaped. $"\"{value}\"" breaks on a default containing ", \ or a newline.

Suggested fix

Format by type:

  • quote and escape strings and the string-like value types above;
  • format numbers with CultureInfo.InvariantCulture;
  • leave bool and enums as they are today.

Add cases for Guid, DateTime, a string containing a quote, and a decimal under a non-invariant culture to ToGraphQLSchemaStringTests.

Related (possibly a separate issue)

ExpressionUtil.ObjectToDictionaryArgs treats any non-null property value as a declared default (new DefaultArgValue(value != null, value)). A value type's implicit default(T) therefore becomes a schema default: int Turn becomes turn: Int! = 0. Once the quoting is fixed, a Guid becomes ID! = "00000000-…". That is valid SDL, but it turns a required argument into an optional one for clients.

Changing this would break anyone who relies on an implicit 0 making an argument optional. So it probably needs to be opt-in or wait for a major version. The current workaround is a Guid? property marked [GraphQLNotNull].

Activity

  1. added a commit that references this issue on Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions