Skip to content

Bug in support for LongType? #485

Open
@aggieben

Description

@aggieben

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

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