FSharp.Data.GraphQL
FSharp.Data.GraphQL copied to clipboard
Bug in support for LongType?
Description
It appears that the LongType included with the SchemaDefinition implementation is not actually supported. If I define a mutation field in my schema with input type LongType, like this:
let ContactInformationWithAddressIdInputType =
Define.InputObject<Models.ContactInformationWithAddressId>("ContactInformationWithAddressIdInput", [
Define.Input("name", StringType)
Define.Input("addressId", LongType)
Define.Input("email", Nullable StringType)
Define.Input("phone", Nullable StringType)
])
things build just fine, but when I try to post a mutation using this, it fails in the validation phase before it ever gets to my code.
mutation {
createContactInformationWithAddressId(
contactInformation: {
name: "ben",
addressId: 1,
email: "[email protected]",
phone: "555-555-5555"
}
) {
id
}
The resulting error:
{
"documentId": -105406704,
"errors": [
{
"message": "Argument field or value named 'addressId' can not be coerced. It does not match a valid literal representation for the type.",
"path": [
"createContactInformationWithAddressId"
],
"extensions": {
"kind": "Validation"
}
}
]
}
This appears to be cause by this code: https://github.com/fsprojects/FSharp.Data.GraphQL/blob/d96b065b95d553cdaac68cd2697490c5b618be44/src/FSharp.Data.GraphQL.Shared/Validation.fs#L920C1-L923C36
| IntValue _ ->
match tref.Name, tref.Kind with
| Some ("ID" | "Int" | "Float"), TypeKind.SCALAR -> Success
| _ -> canNotCoerce
where the input literal is interpreted as an IntType, which is fine, but this code doesn't allow for coercion to LongType. The coercion functions do exist (here, for example: https://github.com/fsprojects/FSharp.Data.GraphQL/blob/d96b065b95d553cdaac68cd2697490c5b618be44/src/FSharp.Data.GraphQL.Shared/SchemaDefinitions.fs#L79)
I tried working around this by wrapping the value in quotes:
mutation {
createContactInformationWithAddressId(
contactInformation: {
name: "ben",
addressId: "1",
email: "[email protected]",
phone: "555-555-5555"
}
) {
id
}
The resulting error: Error:
{
"documentId": -2060341738,
"errors": [
{
"message": "Inline value '1' of type string cannot be converted into integer of range from -9223372036854775808 to 9223372036854775807",
"extensions": {
"kind": "InputCoercion",
"path": [
"addressId"
],
"argumentName": "contactInformation",
"argumentType": "ContactInformationWithAddressIdInput!",
"objectType": "ContactInformationWithAddressIdInput!",
"fieldType": "Long!"
}
}
]
}
This is even more confusing, because the validation code seems to be ok with strings here, but I didn't quite see how it should get over to the actual coercion functions defined in the schema.
Expected behavior
Integer literals should be coercible to LongType
Actual behavior
LongType is filtered out by the cited code above.
Known workarounds
Can use IntType, potentially, in the input object definition.
Related information
- Operating system: Windows 11
- Branch:
master(or whatever is published to Nuget) - .NET Runtime, CoreCLR or Mono Version: .NET SDK 8.0.303
Let's fix the validation
Would you mind preparing a test in the tests project which I can pick up and make a fix?
Yeah, I can do that. Unsure how fast I can get to it, but I'll try to get to it in the next week or so