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].
What happens
SchemaGenerator.GetArgDefaultValueprints any value type withToString(), unquoted:An arguments object with a
Guidproperty therefore produces invalid SDL:GraphQL Code Generator then refuses the schema:
Syntax Error: Invalid number, unexpected digit after 0: "0".Other cases on the same path
DateTime,DateTimeOffset,DateOnly,TimeOnly,TimeSpanandchar. Each should be a quoted string literal.de-DE, a default of3.14prints as3,14.TestGetArgDefaultValue_Decimalpasses only because of the culture the tests run under.$"\"{value}\""breaks on a default containing",\or a newline.Suggested fix
Format by type:
CultureInfo.InvariantCulture;booland enums as they are today.Add cases for
Guid,DateTime, a string containing a quote, and a decimal under a non-invariant culture toToGraphQLSchemaStringTests.Related (possibly a separate issue)
ExpressionUtil.ObjectToDictionaryArgstreats any non-null property value as a declared default (new DefaultArgValue(value != null, value)). A value type's implicitdefault(T)therefore becomes a schema default:int Turnbecomesturn: Int! = 0. Once the quoting is fixed, aGuidbecomesID! = "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
0making an argument optional. So it probably needs to be opt-in or wait for a major version. The current workaround is aGuid?property marked[GraphQLNotNull].