Zaid-Ajaj / Snowflaqe

A dotnet CLI to generate type-safe GraphQL clients for F# and Fable with automatic deserialization, static query verification and type checking
MIT License
154 stars 25 forks source link

Query with parameters gives 400: Bad Request #56

Closed bdaniel7 closed 2 years ago

bdaniel7 commented 2 years ago

When I'm using a query with parameters, I'm getting an error: { message = "400: Bad Request" }

// with params
query getDataByImo ($imo: Imo!){
                  ships(imo: [$imo]) {
                    pageInfo {
                      hasNextPage
                      endCursor
                    }
                    totalCount{ relation value }

When I'm not using parameters, that errors is gone, test is green.

// without params
query getDataByImo {
                  ships(imo: [9758428]) {
                    pageInfo {
                      hasNextPage
                      endCursor
                    }
                    totalCount{ relation value }

So maybe the resulting query text is not correctly generated. From Fiddler I see that the generated query looks like in the attached file: query.txt

Zaid-Ajaj commented 2 years ago

Hi @bdaniel7, can you please a bit more information about your query:

I see something interesting, the type Imo, is that a custom scalar? Because custom scalars are usually strings but in your query without parameters, it looks like it is an integer, maybe that's the issue?

bdaniel7 commented 2 years ago

I'm targeting F#. The error from server is {"errors":[{"message":"400: Bad Request","extensions":{"code":"INTERNAL_SERVER_ERROR"}}]} The Imo is a scalar

"Vessel's Imo number"
scalar Imo

Indeed, in Postman when I use the variable {"imo": 9758428} it works, when I use it { "imo": "9758428" } I'm getting the Bad request error.

So I've changed the definition of type InputVariables = { imo: string } to { imo: int } and now it works.

Zaid-Ajaj commented 2 years ago

Custom scalars are almost always strings unless they are known custom scalars such as BigFloat, Decimal, DateTimeOffset etc. So your server has to accept strings or be able to convert the string value to the required type (string to int in your case)