ChilliCream / graphql-platform

Welcome to the home of the Hot Chocolate GraphQL server for .NET, the Strawberry Shake GraphQL client for .NET and Banana Cake Pop the awesome Monaco based GraphQL IDE.
https://chillicream.com
MIT License
5.26k stars 746 forks source link

HotChocolate emits check error SS0002 for valid GraphQL #5374

Closed nightroman closed 1 month ago

nightroman commented 2 years ago

Is there an existing issue for this?

Describe the bug

HotChocolate emits check error SS0002 for valid GraphQL

Steps to reproduce

The issue may be reproduced in different HotChocolate products, server and client.

Server

Use Banana Cake Pop in order to reproduce the issue. Create a document with the following parts:

Schema endpoint

https://api.nexar.com/graphql/

Query

query Search($product: String!, $capacitance: Float!, $tolerance: Int!, $voltagerating_dc: Int!) {
  supSearch(
    country: "NL"
    currency: "EUR"
    distributorApiTimeout: "3s"
    q: $product
    filters: {capacitance: $capacitance, tolerance: $tolerance, voltagerating_dc_: $voltagerating_dc}
    start: 0
    limit: 5
  ) {
    hits
    results {
      part {
        id
        name
        mpn
        specs {
          attribute {
            name
          }
          value
        }
      }
    }
  }
}

The filter type is the custom scalar Map. The type Map is added to the server combined schema by AddType(new AnyType("Map")).

Variables

{
   "product": "ceramic capacitor",
    "capacitance" : 0.0000001,
    "voltagerating_dc": 50,
    "tolerance": 10
}

Run query...

Actual result

The server returns an error:

"message": "The following variables were not used: capacitance, tolerance, voltagerating_dc."

Note, this is the server error, not client. BCP is happy with the definition of the query. BCP correctly treats all variables as defined.

If we, for example, remove the line with filter then only BCP show wiggles and tooltips "Variable $capacitance is never used in the operation Search.".

Expected result

With a proper token specified, the query should work and return data.

Without a token, the expected result is this error:

"message": "Token validation failed. Please provide a valid access token."

Client

The attached project is StrawberryShake client configured for the same scenario. It contains the single query, the above problematic.

Nexar.Client.zip

Build the project. The build fails with this error:

...\Nexar.Client\Query.graphql(2,2): error SS0002: The following variables were not used: capacitance, tolerance, voltagerating_dc.

Relevant log output

No response

Additional Context?

No response

Product

Hot Chocolate

Version

12.12.1

nightroman commented 1 year ago

:( 12.16.0 has the same bug.

RobAltium commented 10 months ago

Internal reference: NEX-2488

michaelstaib commented 2 months ago

I am closing this issue as this should not be problem with HC 13 and 14.

nightroman commented 2 months ago

We still have this issue with HC 13.9.4 I have not tried yet with Fusion, it may take some time.

nightroman commented 2 months ago

The same issue exists in Fusion 14.0.0-rc.2 @michaelstaib Could you please reopen the issue?

nightroman commented 2 months ago

@michaelstaib Any action please? I will have to open the exact same issue in order not to be forgotten, this will be rather odd.

michaelstaib commented 1 month ago

I have reproduced the error. But this is not allowed by the GraphQL spec. You have a filters: Map here where Map is a scalar. Basically an any scalar. The spec rule on validation does not have any notion of such scalars and the relation of variables in it. I guess the coercion at runtime would also have errors as variables in scalars is not specified.

I am closing this issue, as this is not a bug. However, I will do a PR with an error message specific to this problem. Something like variables are not allowed in scalar types.

nightroman commented 1 month ago

I guess the coercion at runtime would also have errors as variables in scalars is not specified.

We do not have this issue with actual subgraph (GraphQL server in Go). But the HC gateway is not happy about "unused" variables.

Banana Cake Pop should show wiggles as it does in other cases of unused variables.

nightroman commented 1 month ago

The spec about unused variables:

Each variable in variables must be used at least once in either the operation scope itself or any fragment transitively referenced by that operation.

There is no mention of scalars as a special case. To me, not a GraphQL guru, in our case all variables are used, our GraphQL is valid.

Maybe the spec should be explicit on this case with scalars (are scalar expressions in "operation scope itself" or not?). But until it's not, it's rather Hot Chocolate opinionated interpretation of the spec, in my hamble opinion.

nightroman commented 1 month ago

I have started the discussion at the GraphQL spec repository https://github.com/graphql/graphql-spec/discussions/1115 and talked to several colleagues. So far everybody thinks variables are used in our case and the server error "sounds like a bug".