question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Compile-time error: "Argument field or value named 'order_by' can not be coerced"

See original GitHub issue

Description

I am using Hasura, and trying to run the following query:

let operation = MyProvider.Operation<"""query q {
      test_table (order_by: {some_name: asc}) {
        id
        some_name
      }
    }""">

The query is valid and works if run manually, but I get a compile-time error with the F# Type Provider:

error FS3033: The type provider 'FSharp.Data.GraphQL.Client.GraphQLTypeProvider'
reported an error:
Argument field or value named 'order_by' can not be coerced.
It does not match a valid literal representation for the type.
Path: ["q"; "test_table"]

The relevant part of the schema:

{
  "inputFields": null,
  "kind": "ENUM",
  "possibleTypes": null,
  "interfaces": null,
  "name": "order_by",
  "enumValues": [
    {
      "isDeprecated": false,
      "deprecationReason": null,
      "name": "asc",
      "description": "in the ascending order, nulls last"
    },
  ...
  ],
  "description": "column ordering options",
  "fields": null
}

I’ve tried other parameters, such as offset, limit, where (this one works now: https://github.com/fsprojects/FSharp.Data.GraphQL/issues/263), and they work. distinct_on, however, results in the same compile time error. Could this have something to do with the _ in the name?

Repro steps

See description.

Expected behavior

The application compiles, the query returns the same result as when run manually.

Actual behavior

Compile-time error.

Known workarounds

None.

Related information

  • Mac OS X
  • Version 1.0.3
  • .NET Core 3.1

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
treetcommented, Jun 13, 2020

I had the exact same problem, a workaround is to wrap the order_by value in a list (credits to @Yakimych):

Does not work: order_by: {some_name: asc} Works: order_by: [{some_name: asc}]

This appears to be a bug in how FSharp.Data.GraphQL does input coercion:

image

0reactions
Yakimychcommented, Apr 14, 2020

@johnberzy-bazinga Got the same problem when trying to create a mutation against the same schema:

[FS3033] The type provider 'FSharp.Data.GraphQL.Client.GraphQLTypeProvider'
reported an error:
Argument field or value named 'objects' can not be coerced.
It does not match a valid literal representation for the type.
Path: ["addPlayer"; "insert_players"]

The mutation itself:

  mutation addPlayer {
    insert_players(objects: {name: "somename", communityId: 1}) {
      returning {
        id
      }
    }
  }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Ordering by specific field value first - mysql
SELECT id, name, priority FROM mytable ORDER BY FIELD(name, "core", ... If the value of the field is not in the list, it...
Read more >
GraphQL specification
A GraphQL server, when preparing a field of a given scalar type, must uphold the contract the scalar type describes, either by coercing...
Read more >
Conversion rules | BigQuery
Literal conversion is evaluated at analysis time, and gives an error if the input literal cannot be converted successfully to the target type....
Read more >
Troubleshooting F# | F# for fun and profit
As the saying goes, “if it compiles, it's correct”, but it can be extremely frustrating just trying to get the code to compile...
Read more >
Runtime and compile-time metaprogramming
Exactly one constructor will be produced. Attempting to use an initial value will produce an error. Map-style named arguments won't be available.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found