0no-co / gql.tada

🪄 Magical GraphQL query engine for TypeScript
https://gql-tada.0no.co
MIT License
2.44k stars 34 forks source link

`generate` throw `Cannot query field 'isOneOf'` #316

Closed Hashs7 closed 3 weeks ago

Hashs7 commented 3 weeks ago

Describe the bug

When I'm running the command gql.tada generate output using version above 1.7.0, I encounter an error: Cannot query field 'isOneOf' on type '__Type'.

Behavior

The command should generate the file graphql-env.d.ts but it throw the error without creating the file. It seems like gql.tada is trying to query a field that doesn't exist in our schema. Our GraphQL API endpoint https://api.oees-kraken.energy/v1/graphql/ doesn't expose the isOneOf field on the __Type. This suspected PR might have introduce this bug.

There is an possible solution to ensure that the field exists before trying to query it ?

Reproduction

npx gql.tada generate schema 'https://api.oees-kraken.energy/v1/graphql/'

gql.tada version

gql.tada >= v1.7.0

Validations

JoviDeCroock commented 3 weeks ago

That would mean that when we run the supportQuery that the introspection of the introspection tells us we can use that property 😅 When we execute this query we derive whether you support isOneOf on __Type. When we see the property is present we'll add it to the introspection like this.

Would you mind running the support query on your endpoint and seeing what it comes up with? Mind also check the definition of __Type?

I wonder whether this is related to https://github.com/graphql/graphql-js/pull/4078

kitten commented 3 weeks ago

We could probably make this more obvious in the CLI, but the issue here is that the support query fails with authorization errors (see link)

The problem is pretty common with GraphQL APIs that, over HTTP, require someone to authenticate before sending requests, but that's why we often recommend to use a source SDL file instead.

In this case, the API seems to guard against __type selections, but does allow __schema, which is unusual and feels unintentional

kitten commented 3 weeks ago

I've submitted a fix, since I think we can have better fallback behaviour here