Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in support for LongType? #485

Open
aggieben opened this issue Aug 3, 2024 · 3 comments
Open

Bug in support for LongType? #485

aggieben opened this issue Aug 3, 2024 · 3 comments

Comments

@aggieben
Copy link

aggieben commented Aug 3, 2024

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:

let coerceLongValue (x : obj) : int64 option =
)

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
@xperiandri
Copy link
Collaborator

Let's fix the validation

@xperiandri
Copy link
Collaborator

Would you mind preparing a test in the tests project which I can pick up and make a fix?

@aggieben
Copy link
Author

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

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

No branches or pull requests

2 participants