dotansimha / graphql-code-generator

A tool for generating code based on a GraphQL schema and GraphQL operations (query/mutation/subscription), with flexible support for custom plugins.
https://the-guild.dev/graphql/codegen/
MIT License
10.88k stars 1.34k forks source link

`yarn graphql-codegen` returns `Error: Query root type must be provided.` when query root is named other than `Query`. #5758

Closed carlpaten closed 3 years ago

carlpaten commented 3 years ago

Describe the bug yarn graphql-codegen returns Error: Query root type must be provided. when query root is named other than Query, for example query_root as in Hasura.

To Reproduce

Steps to reproduce the behavior: run this CodeSandbox, or clone this repo and yarn install && yarn graphql-codegen.

The operation succeeds if query_root is renamed Query, or if @graphql-codegen/cli is downgraded to 1.15.0 or below.

The operation fails if @graphql-codegen/cli version is set to 1.15.1 or any superior version. (Tested 1.15.1, 1.15.4, 1.17.10, 1.21.3).

  1. My GraphQL schema:
type query_root {
    user(id: ID!): User!
}

type User {
    id: ID!
    username: String!
    email: String!
}
  1. My GraphQL operations:
query user {
    user(id: 1) {
        id
        username
        email
    }
}
  1. My codegen.yml config file:
schema: schema.graphql
documents: document.graphql
generates:
  types.ts:
    plugins:
      - typescript
      - typescript-operations

Expected behavior: this should succeed I think?

Environment:

carlpaten commented 3 years ago

A cursory googling of the Query root type must be provided error shows it is associated with the package graphql-tools and also with schema stitching. This regression was introduced somewhere betweeen the 1.15.0 and 1.15.1 releases. From looking at a diff I can flag two potentially relevant changes: the change in the implementation of StitchingResolver (with the old strategy relegated to LegacyStitchingResolver), and the graphql-tools version bump from 6.0.1 to 6.0.6.

jjangga0214 commented 3 years ago

Add SchemaDefinition :)

schema {
  query: query_root
}

You're using the plugin typescript-operations. It requires(obviously) knowing which ObjectTypeDefinition is the query type. By convention, this is Query by default. However, your case is not, thus you should explicitly specify it.

carlpaten commented 3 years ago

So what you're seeing above is my attempt at a minimal repro. My actual use case has this schema definition, so this isn't the problem. I'll try to find the time to produce a minimal repro that includes the above annotation. Perhaps I'm hitting the same issue as #5756, who knows.

As an aside, I put a lot of effort into researching this issue and I never found the simple fix you mention. To me this looks like a documentation bug and/or an opportunity to clarify the error message. I don't have more time to put into this right now, maybe in a couple weeks I can submit a PR.

ItsWendell commented 3 years ago

@lilred I think you're hitting a very similar issue to ours. Your issue here was very helpful, our repositories now work again when reverting back and freezing the cli to 1.15.0.

I suspect, like you did too, that somewhere after 1.15.0 they stopped reading the schema {} SchemaDefinition in the schemas. What package / dependency exactly causes this I don't know, if someone has any pointers to where it should check for SchemaDefinition, we can try to solve this.

This shouldn't have happened and has caused many people a lot of wasted time, it's a breaking change and should have been defined as a breaking change in someone's package according to the widely used semantic versioning.

carlpaten commented 3 years ago

@ItsWendell when I add the schema {} declaration to my minimal repro above it works. I think the bug is only present on more complex schemas, such as those produced by Hasura in real-world usage. If you can manage to produce a repro that still features the schema {} declaration I'm sure that could be helpful to the implementers. (I could perhaps do this myself but again I've run out of time I can commit to this for now.)

zhigang1992 commented 3 years ago

Changed it to "@graphql-codegen/cli": "1.21.2", fixed it for us.

madmaxlax commented 3 years ago

i am running into this as well, also with a Hasura-generated schema, and seems to be an open issue on their side as well https://github.com/hasura/graphql-engine/issues/4460

downgrading to 1.15.0 worked for me, 1.21.2 did not

looking at the difference between 1.15.0 and 1.15.1 i dont see anything related to schemadefinition, cant tell what might have changed in the code (could have been a package/dependency) https://github.com/dotansimha/graphql-code-generator/compare/v1.15.0...v1.15.1

carlpaten commented 3 years ago

@madmaxlax at a glance hasura/graphql-engine#4460 seems to be a different issue entirely.

madmaxlax commented 3 years ago

@madmaxlax at a glance hasura/graphql-engine#4460 seems to be a different issue entirely. @lilred

It seems hasura has this issue of using the query_root for fields that have some sort of permission on them, which is what that Hasura issue is more about

iMuzz commented 3 years ago

Banged my head against the wall with this issue as well for a few hours 🙁

Downgrading graphql-codegen/cli from 1.21.2to 1.15.0 worked for me!

tmaximini commented 3 years ago

We're also using Hasura and downgrading to 1.15.0 fixed our issue.

madmaxlax commented 3 years ago

darn, now graphql-codegen/cli 1.15.0 isn't solving the issue for me anymore

Urigo commented 3 years ago

Hi everyone and thank you for the reports

Sorry but I'm not adding a lot here but just labeling it according to our new Contribution Guide and issue flow.

It seems already got into stage 1 thanks to your reproduction! Thank you for that!

Now in order to advance to stage 2 we'll need a failing test, would be great if someone could help progress the issues through the stages.

Thank you and sorry that this comment is not a complete solution (yet).

jackharrhy commented 3 years ago

The issue here seems to be with schemas like the following:

schema {
    query: query_root
}

type Query {
    one: String
}

type query_root {
    two: String
}

graphql-js will parse this fine, however the AST generated somewhere in seemingly graphql-tools outputs something that is then handed to graphql-js, which will happily overwrite query_root with Query.

Hasura is also what I've been using, and only once I started adding a Remote Schema did it actually break.

If you control the schema of the remote schema you are adding, you can modify it not to use Query, and instead define it similar to Hasura like so:

  type query_root {
    file_user(user_id: Int!, file_id: String!): String
    file_group(group_id: Int!, file_id: String!): String
  }

  schema {
    query: query_root
  }

such that it won't be eaten by graphql-tools.

This of course is a non-preferable workaround sadly.

madmaxlax commented 3 years ago

The issue here seems to be with schemas like the following: @jackharrhy

Ah interesting Mine was also Hasura with a remote schema

zhigang1992 commented 3 years ago

@jackharrhy great finding, do we know which version of graphql-tool start to have this issue?

Maybe we can pin our dependency to a version that doesn't have that issue?

carlpaten commented 3 years ago

@jackharrhy my repro only has one top-level query type, doesn't that contradict your hypothesis?

jackharrhy commented 3 years ago

@jackharrhy my repro only has one top-level query type, doesn't that contradict your hypothesis?

graphql-codegen does some post processing on the schemas it's handed so it's best to see what the schema that's failing to validate actually is vs. the schema you are handing to graphql-codegen

I did this by using printSchema from the graphql-js package just before the validation error was thrown and I saw the invalid schema that didn't match the schema that was passed in

ardatan commented 3 years ago

It seems working with the latest versions. Maybe I am missing something; https://codesandbox.io/s/nervous-sun-n4hd2

jackharrhy commented 3 years ago

https://codesandbox.io/s/nervous-sun-n4hd2

Try changing the schema you have there to:

schema {
  query: query_root
}

type Query {
  not_user: Int!
}

type query_root {
    user(id: ID!): User!
}

type User {
    id: ID!
    username: String!
    email: String!
}
ardatan commented 3 years ago

Hmm weird it happens on CodeSandbox while it doesn't happen on the repo https://github.com/dotansimha/graphql-code-generator/pull/5982/files#diff-05d8ab842f8e4f819c16d0463ea8d24766202b46ea194faa442d0a987b17bd5fR1 @dotansimha cc

ferm10n commented 3 years ago

I spent about an hour dealing with this, and fixed it by updating graphql from 14 to 15. not sure what else could have been involved but here are my other packages after I got it working:

I assume it's possible one of these packages had an incompatibility with graphql@14, but in my case it was just easier to start from a clean slate with yarn graphql-codegen init and incrementally move that clean slate back into my project.

commandodev commented 3 years ago

I'm having the same problem here. I've tried various different permutations of my dependencies, with no joy. Even going back to the version I had originally hasn't worked (presumably due to not pinning some internal dependency).

Does anyone have any insight into where the actual problem is, or what internal dependency I should try and pin?

ardatan commented 3 years ago

@commandodev Could you create a reproduction or failing test? So we can help you better.

erichiller commented 3 years ago

Same issue here. Doesn't matter the version of various dependencies it seems. The latest version I could get to work was also v1.15.0 (and not v1.15.4 for example) I am also using Hasura as the GraphQL server.

I'm guessing that v1.15.0 working has something to do with:

warning workspace-aggregator-ab9868c3-4eb4-44bc-af0a-323d281523fd > client > @graphql-codegen/cli > graphql-config > @graphql-toolkit/common@0.10.7: GraphQL Toolkit is deprecated and merged into GraphQL Tools, so it will no longer get updates. Use GraphQL Tools instead to stay up-to-date! Check out https://www.graphql-tools.com/docs/migration-from-toolkit for migration and https://the-guild.dev/blog/graphql-tools-v6 for new changes.
warning workspace-aggregator-ab9868c3-4eb4-44bc-af0a-323d281523fd > client > @graphql-codegen/cli > graphql-config > @graphql-toolkit/schema-merging > @graphql-toolkit/common@0.10.7: GraphQL Toolkit is deprecated and merged into GraphQL Tools, so it will no longer get updates. Use GraphQL Tools instead to stay up-to-date! Check out https://www.graphql-tools.com/docs/migration-from-toolkit for migration and https://the-guild.dev/blog/graphql-tools-v6 for new changes.
warning workspace-aggregator-ab9868c3-4eb4-44bc-af0a-323d281523fd > client > @graphql-codegen/cli > graphql-config > @graphql-toolkit/core > @graphql-toolkit/common@0.10.7: GraphQL Toolkit is deprecated and merged into GraphQL Tools, so it will no longer get updates. Use GraphQL Tools instead to stay up-to-date! Check out https://www.graphql-tools.com/docs/migration-from-toolkit for migration and https://the-guild.dev/blog/graphql-tools-v6 for new changes.
warning workspace-aggregator-ab9868c3-4eb4-44bc-af0a-323d281523fd > client > @graphql-codegen/cli > graphql-config > @graphql-toolkit/graphql-file-loader > @graphql-toolkit/common@0.10.7: GraphQL Toolkit is deprecated and merged into GraphQL Tools, so it will no longer get updates. Use GraphQL Tools instead to stay up-to-date! Check out https://www.graphql-tools.com/docs/migration-from-toolkit for migration and https://the-guild.dev/blog/graphql-tools-v6 for new changes.
warning workspace-aggregator-ab9868c3-4eb4-44bc-af0a-323d281523fd > client > @graphql-codegen/cli > graphql-config > @graphql-toolkit/json-file-loader > @graphql-toolkit/common@0.10.7: GraphQL Toolkit is deprecated and merged into GraphQL Tools, so it will no longer get updates. Use GraphQL Tools instead to stay up-to-date! Check out https://www.graphql-tools.com/docs/migration-from-toolkit for migration and https://the-guild.dev/blog/graphql-tools-v6 for new changes.
warning workspace-aggregator-ab9868c3-4eb4-44bc-af0a-323d281523fd > client > @graphql-codegen/cli > graphql-config > @graphql-toolkit/url-loader > @graphql-toolkit/common@0.10.7: GraphQL Toolkit is deprecated and merged into GraphQL Tools, so it will no longer get updates. Use GraphQL Tools instead to stay up-to-date! Check out https://www.graphql-tools.com/docs/migration-from-toolkit for migration and https://the-guild.dev/blog/graphql-tools-v6 for new changes.

That dependency being warned about works, and whatever the new dependency is ( I'm guessing graphql-tools ) is breaking things

msimon commented 3 years ago

@ardatan I create a very small repo with the error described in this ticket: https://github.com/msimon/codegen_hasura_remote_schema_bug

As @jackharrhy precised, the issues happens when Type Query/Type Mutation/Type Subscription is present but the schema is defined as:

schema {
    query: query_root
    mutation: mutation_root,
    subscription: subscription_root.
}

For the error to happen, the reference must be called in one of the document.

E.g: schema.graphql

schema {
    query: query_root
}

type Query {
    one: String
}

type query_root {
    two: String
}

This would have no problem to generate.

But defining a document that reference two will generate the error:

codegen_bug/src/graphql.d.ts:

query getTwo {
  two
}

I'll try to do a PR for failing test, but that will not be coming until end of next week at best.

msimon commented 3 years ago

For anyone using Hasura with remote schema, the comment for @jackharrhy does work well. (https://github.com/dotansimha/graphql-code-generator/issues/5758#issuecomment-835699251)

The goal is to remove the Type Query, Type Mutation & Type Subscription from the final schema that we get from hasura.

Since hasura merge the remote schema and its own, defining the remote server schema with same type name as hasura fixes the issue.

In NestJs, this is a bit hard to do, as the type are hardcoded. First you must rename the Resolver enum from NestJs Graphq:

import { Resolver as ResolverEnum } from '@nestjs/graphql/dist/enums/resolver.enum.js'
//@ts-ignore
ResolverEnum.QUERY = "query_root"
//@ts-ignore
ResolverEnum.MUTATION = "mutation_root"
//@ts-ignore
ResolverEnum.SUBSCRIPTION = "subscription_root"

This must executed before any @Query/@Mutation for the name to be taken into account.

Then modify the schema with the transformSchema & transformAutoSchemaFile:

    GraphQLModule.forRoot({
      ....
      transformAutoSchemaFile: true,
      transformSchema: (schema) => {
        const schemaConfig = schema.toConfig()
        const query = schemaConfig.query
        if (query) {
          query.name = "query_root"
        }
        const mutation = schemaConfig.mutation
        if (mutation) {
          mutation.name = "mutation_root"
        }
        const subscription = schemaConfig.subscription
        if (subscription) {
          subscription.name = "subscription_root"
        }
        return new GraphQLSchema(schemaConfig)
      }
    }),

This is a temporary hack of course. It may break when updating nestJs.

dotansimha commented 3 years ago

Seems like most of the use-cases here are around Hasura, and the solution suggested by @jackharrhy . @ardatan is there anything we can do in graphql-tools to solve that?

ardatan commented 3 years ago

@dotansimha If someone reproduces it :)

dotansimha commented 3 years ago

@dotansimha If someone reproduces it :)

Take a look at this comment: https://github.com/dotansimha/graphql-code-generator/issues/5758#issuecomment-835699251 , the flow there does makes sense, no?

ardatan commented 3 years ago

@dotansimha See https://github.com/dotansimha/graphql-code-generator/issues/5758#issuecomment-838601844 and https://github.com/ardatan/graphql-tools/pull/3092

I am not able to reproduce it on GraphQL Tools. GraphQL Tools respects schema definition as usual.

msimon commented 3 years ago

@ardatan Is it not reproduced in this project? https://github.com/msimon/codegen_hasura_remote_schema_bug

ardatan commented 3 years ago

@msimon I mean I am not able to create a failing test on GraphQL Tools repo.

msimon commented 3 years ago

@ardatan I may be wrong, but looking at the changes here: https://github.com/ardatan/graphql-tools/pull/3092/files, I think there is a misunderstanding of what the issue is.

The problem is not around generating the codegen for the schema itself. (e.g the graphql.d.ts) It is when there is another graphql file that references a query/mutation (e.g: queries.generated.ts)

In the small project I created, if you remove this folder https://github.com/msimon/codegen_hasura_remote_schema_bug/tree/master/src/graphql, everything works as expected.

Let me know if I can help in any way.

ardatan commented 3 years ago

@msimon I see what the issue is and I am trying to debug the issue and it seems like GraphQL Tools doesn't overwrite schema definition like said above. I couldn't figure out what causes that. And the test cases I added to GraphQL Tools seems working fine. You can see I added more but it still works fine https://github.com/ardatan/graphql-tools/pull/3092/files#diff-311682076d0958c6482f2bdaa569e6f84db27ef175d6145a6805e4bf11e237c1R1397

msimon commented 3 years ago

@AradAral Thanks! I'll take a look and see if I can find anything.

sfcgeorge commented 3 years ago

As @ferm10n suggested, upgrading to graphql v15+ fixed it for me too. Check your lock file to make sure you've actually updated to that version and you don't have something else depending on v14 holding you back.

dimbslmh commented 3 years ago

https://github.com/dotansimha/graphql-code-generator/commit/41e93585d3b23e2df1591ddbd6df398c25088934 1.15.0 https://github.com/dotansimha/graphql-code-generator/commit/1f2eeae38af3916e17fb7a52a8164f2fd9467eb4 @graphql-tools 6.0.1 -> 6.0.3 https://github.com/dotansimha/graphql-code-generator/commit/54fa48755d77e498f8c0118c575bae14b9c5b1e9 1.15.1

@ardatan It seems the schema returned by loadSchema was changed in 1.15.1 when @graphql-tools was upgraded from 6.0.1 -> 6.0.3 https://github.com/dotansimha/graphql-code-generator/blob/cbd99701739d9158211b686379412e2209edd94c/packages/graphql-codegen-cli/src/load.ts#L18

1.15.0 1.15.1
```diff { "_directives": [ "@include", "@skip", "@deprecated", "@specifiedBy" ], "_implementationsMap": {}, - "_queryType": "query_root", "_subTypeMap": {}, "_typeMap": { "__Directive": "__Directive", "__DirectiveLocation": "__DirectiveLocation", "__EnumValue": "__EnumValue", "__Field": "__Field", "__InputValue": "__InputValue", "__Schema": "__Schema", "__Type": "__Type", "__TypeKind": "__TypeKind", "AttUser": "AttUser", "Boolean": "Boolean", "ID": "ID", "Int": "Int", "Int_comparison_exp": "Int_comparison_exp", "order_by": "order_by", "Query": "Query", "query_root": "query_root", "String": "String", "String_comparison_exp": "String_comparison_exp", "users": "users", "users_bool_exp": "users_bool_exp", "users_order_by": "users_order_by", "users_select_column": "users_select_column" }, - "astNode": { - "directives": [], - "kind": "SchemaDefinition", - "loc": { - "end": 28, - "start": 0 - }, - "operationTypes": [ - { - "kind": "OperationTypeDefinition", - "loc": { - "end": 26, - "start": 9 - }, - "operation": "query", - "type": { - "kind": "NamedType", - "loc": { - "end": 26, - "start": 16 - }, - "name": { - "kind": "Name", - "loc": { - "end": 26, - "start": 16 - }, - "value": "query_root" - } - } - } - ] - }, - "extensionASTNodes": [], "extensions": {} } ``` ```diff { "_directives": [ "@include", "@skip", "@deprecated", "@specifiedBy" ], "_implementationsMap": {}, + "_queryType": "Query", "_subTypeMap": {}, "_typeMap": { "__Directive": "__Directive", "__DirectiveLocation": "__DirectiveLocation", "__EnumValue": "__EnumValue", "__Field": "__Field", "__InputValue": "__InputValue", "__Schema": "__Schema", "__Type": "__Type", "__TypeKind": "__TypeKind", "AttUser": "AttUser", "Boolean": "Boolean", "ID": "ID", "Int": "Int", "Int_comparison_exp": "Int_comparison_exp", "order_by": "order_by", "Query": "Query", "query_root": "query_root", "String": "String", "String_comparison_exp": "String_comparison_exp", "users": "users", "users_bool_exp": "users_bool_exp", "users_order_by": "users_order_by", "users_select_column": "users_select_column" }, + "extensionASTNodes": [ + { + "directives": [], + "kind": "SchemaExtension", + "loc": { + "end": 30, + "start": 0 + }, + "operationTypes": [ + { + "kind": "OperationTypeDefinition", + "loc": { + "end": 28, + "start": 11 + }, + "operation": "query", + "type": { + "kind": "NamedType", + "loc": { + "end": 28, + "start": 18 + }, + "name": { + "kind": "Name", + "loc": { + "end": 28, + "start": 18 + }, + "value": "query_root" + } + } + } + ] + } + ], "extensions": {} } ```

Validation fails when the schema is passed to graphql.validate in validateGraphQlDocuments. https://github.com/dotansimha/graphql-code-generator/blob/54fa48755d77e498f8c0118c575bae14b9c5b1e9/packages/graphql-codegen-core/src/codegen.ts#L79

https://github.com/ardatan/graphql-tools/blob/3f1c94790e9f07c630b5143b4786980c76c5ff3c/packages/utils/src/validate-documents.ts#L22

"@graphql-codegen/cli": "1.15.0" - https://codesandbox.io/s/competent-lichterman-9y4tv "@graphql-codegen/cli": "1.15.1"- https://codesandbox.io/s/festive-platform-g4xm1

ardatan commented 3 years ago

@dimbslmh I see but I am not able to reproduce it on GraphQL Tools. Could you help me with that? Otherwise I cannot fix it.

dimbslmh commented 3 years ago

@ardatan I'll try and take a look.

dimbslmh commented 3 years ago

@dimbslmh I see but I am not able to reproduce it on GraphQL Tools. Could you help me with that? Otherwise I cannot fix it.

@ardatan These are the actual versions installed from @graphql-tools:

"@graphql-codegen/cli": "1.15.0" ONLY - https://codesandbox.io/s/nifty-agnesi-f85q7 GraphQL Tools based on "@graphql-codegen/cli": "1.15.0" ONLY - https://codesandbox.io/s/trusting-surf-2lkcg

$ yarn list --depth=0 --pattern @graphql-tools
yarn list v1.22.10
warning package.json: No license field
warning graphql-codegen-cli-1.15.0@1.15.0: No license field
├─ @graphql-tools/apollo-engine-loader@6.0.1
├─ @graphql-tools/code-file-loader@6.0.1
├─ @graphql-tools/delegate@6.0.1
├─ @graphql-tools/git-loader@6.0.1
├─ @graphql-tools/github-loader@6.0.1
├─ @graphql-tools/graphql-file-loader@6.0.1
├─ @graphql-tools/graphql-tag-pluck@6.0.1
├─ @graphql-tools/import@6.0.1
├─ @graphql-tools/json-file-loader@6.0.1
├─ @graphql-tools/load@6.0.1
├─ @graphql-tools/merge@6.0.1
├─ @graphql-tools/prisma-loader@6.0.1
├─ @graphql-tools/schema@6.0.1
├─ @graphql-tools/url-loader@6.0.1
├─ @graphql-tools/utils@6.0.1
└─ @graphql-tools/wrap@6.0.1
Done in 0.24s.
type Query block (commented out) type Query block
```diff GraphQLSchema { __validationErrors: undefined, description: undefined, extensions: {}, astNode: { kind: 'SchemaDefinition', description: undefined, directives: [], operationTypes: [ [Object] ], loc: { start: 0, end: 28 } }, extensionASTNodes: [], _queryType: query_root, _mutationType: undefined, _subscriptionType: undefined, _directives: [ @include, @skip, @deprecated, @specifiedBy ], _typeMap: [Object: null prototype] { AttUser: AttUser, String: String, ID: ID, users: users, Int: Int, query_root: query_root, Int_comparison_exp: Int_comparison_exp, Boolean: Boolean, String_comparison_exp: String_comparison_exp, users_order_by: users_order_by, users_bool_exp: users_bool_exp, order_by: order_by, users_select_column: users_select_column, __Schema: __Schema, __Type: __Type, __TypeKind: __TypeKind, __Field: __Field, __InputValue: __InputValue, __EnumValue: __EnumValue, __Directive: __Directive, __DirectiveLocation: __DirectiveLocation }, _subTypeMap: [Object: null prototype] {}, _implementationsMap: [Object: null prototype] {} } ``` ```diff GraphQLSchema { __validationErrors: undefined, description: undefined, extensions: {}, astNode: { kind: 'SchemaDefinition', description: undefined, directives: [], operationTypes: [ [Object] ], loc: { start: 0, end: 28 } }, extensionASTNodes: [], _queryType: query_root, _mutationType: undefined, _subscriptionType: undefined, _directives: [ @include, @skip, @deprecated, @specifiedBy ], _typeMap: [Object: null prototype] { AttUser: AttUser, String: String, ID: ID, + Query: Query, users: users, Int: Int, query_root: query_root, Int_comparison_exp: Int_comparison_exp, Boolean: Boolean, String_comparison_exp: String_comparison_exp, users_order_by: users_order_by, users_bool_exp: users_bool_exp, order_by: order_by, users_select_column: users_select_column, __Schema: __Schema, __Type: __Type, __TypeKind: __TypeKind, __Field: __Field, __InputValue: __InputValue, __EnumValue: __EnumValue, __Directive: __Directive, __DirectiveLocation: __DirectiveLocation }, _subTypeMap: [Object: null prototype] {}, _implementationsMap: [Object: null prototype] {} } ```

"@graphql-codegen/cli": "1.15.1" ONLY - https://codesandbox.io/s/heuristic-hodgkin-pflf4

$ yarn list --depth=0 --pattern @graphql-tools
yarn list v1.22.10
warning package.json: No license field
warning graphql-codegen-cli-1.15.1@1.15.1: No license field
├─ @graphql-tools/apollo-engine-loader@6.2.5
├─ @graphql-tools/batch-execute@7.1.2
├─ @graphql-tools/code-file-loader@6.3.1
├─ @graphql-tools/delegate@7.1.5
├─ @graphql-tools/git-loader@6.2.6
├─ @graphql-tools/github-loader@6.2.5
├─ @graphql-tools/graphql-file-loader@6.2.7
├─ @graphql-tools/graphql-tag-pluck@6.5.1
├─ @graphql-tools/import@6.4.0
├─ @graphql-tools/json-file-loader@6.2.6
├─ @graphql-tools/load@6.2.8
├─ @graphql-tools/merge@6.2.17
├─ @graphql-tools/prisma-loader@6.3.1
├─ @graphql-tools/schema@7.1.5
├─ @graphql-tools/url-loader@6.10.1
├─ @graphql-tools/utils@7.10.0
└─ @graphql-tools/wrap@7.0.8
Done in 0.30s.

Based on this, I was able to reproduce it. GraphQL Tools based on "@graphql-codegen/cli": "1.15.1" ONLY - https://codesandbox.io/s/infallible-yonath-1g88o

type Query block (commented out) type Query block
```diff GraphQLSchema { __validationErrors: undefined, description: undefined, extensions: {}, astNode: undefined, extensionASTNodes: [ { kind: 'SchemaExtension', description: undefined, directives: [], operationTypes: [Array], loc: [Object] } ], - _queryType: query_root, _mutationType: undefined, _subscriptionType: undefined, _directives: [ @include, @skip, @deprecated, @specifiedBy ], _typeMap: [Object: null prototype] { AttUser: AttUser, String: String, ID: ID, Int_comparison_exp: Int_comparison_exp, Int: Int, Boolean: Boolean, String_comparison_exp: String_comparison_exp, order_by: order_by, query_root: query_root, users: users, users_bool_exp: users_bool_exp, users_order_by: users_order_by, users_select_column: users_select_column, __Schema: __Schema, __Type: __Type, __TypeKind: __TypeKind, __Field: __Field, __InputValue: __InputValue, __EnumValue: __EnumValue, __Directive: __Directive, __DirectiveLocation: __DirectiveLocation }, _subTypeMap: [Object: null prototype] {}, _implementationsMap: [Object: null prototype] {} } ``` ```diff GraphQLSchema { __validationErrors: undefined, description: undefined, extensions: {}, astNode: undefined, extensionASTNodes: [ { kind: 'SchemaExtension', description: undefined, directives: [], operationTypes: [Array], loc: [Object] } ], + _queryType: Query, _mutationType: undefined, _subscriptionType: undefined, _directives: [ @include, @skip, @deprecated, @specifiedBy ], _typeMap: [Object: null prototype] { AttUser: AttUser, String: String, ID: ID, Int_comparison_exp: Int_comparison_exp, Int: Int, Boolean: Boolean, + Query: Query, String_comparison_exp: String_comparison_exp, order_by: order_by, query_root: query_root, users: users, users_bool_exp: users_bool_exp, users_order_by: users_order_by, users_select_column: users_select_column, __Schema: __Schema, __Type: __Type, __TypeKind: __TypeKind, __Field: __Field, __InputValue: __InputValue, __EnumValue: __EnumValue, __Directive: __Directive, __DirectiveLocation: __DirectiveLocation }, _subTypeMap: [Object: null prototype] {}, _implementationsMap: [Object: null prototype] {} } ```

As you can see the _queryType has changed to Query instead of keeping it as query_root like the previous version. I am not sure if the switched data astNode and extensionASTNodes has any influence.

dimbslmh commented 3 years ago

@ardatan I have found out that @graphql-tools/load@6.2.4 is causing the above changes.

Adding a resolution to the package.json in "@graphql-codegen/cli": "1.15.1"- https://codesandbox.io/s/festive-platform-g4xm1 will pass the validation.

"resolutions": {
  "@graphql-tools/load": "6.2.3"
}

@dimbslmh I see but I am not able to reproduce it on GraphQL Tools. Could you help me with that? Otherwise I cannot fix it.

Hopefully this is enough for you to get it fixed.

ardatan commented 3 years ago

I am already seeing this issue on codegen side but reproduction with codegen doesn't help so I need a failing test on GraphQL Tools repo :) That's what I cannot reproduce and I need help there

dimbslmh commented 3 years ago

@ardatan I have here: https://github.com/dotansimha/graphql-code-generator/issues/5758#issuecomment-913202264

I have added the validation.

There is a working and reproduced version. GraphQL Tools (working validation) - https://codesandbox.io/s/trusting-surf-2lkcg GraphQL Tools (fails validation) - https://codesandbox.io/s/infallible-yonath-1g88o

ardatan commented 3 years ago

@dimbslmh I need a failing test like I said multiple times above :) https://github.com/ardatan/graphql-tools/pull/3489 Please see here it passes, I can try to fix it if you help me to reproduce it in GraphQL-Tools repo.

dimbslmh commented 3 years ago

@ardatan there must be something causing the test to pass in the monorepo, where we actually expect it to fail.

See following codesandbox. This is basically a replicate of https://github.com/ardatan/graphql-tools/blob/c5b0719c70d89c6a672705b6be98772097c8e9ab/packages/load/tests/loaders/schema/schema-from-typedefs.spec.ts

Run yarn test to see it fail.

Note: I disabled the mockGraphQLServer in testing/utils.ts, because I couldn't get it to pass the linting.

ardatan commented 3 years ago

I see but we still need it in the repo to move on :)

dimbslmh commented 3 years ago

@ardatan https://github.com/ardatan/graphql-tools/pull/3489/files#r703045378

ardatan commented 3 years ago

The issue is convertExtensions. See the fix for details; https://github.com/ardatan/graphql-tools/pull/3489

ardatan commented 3 years ago

Fixed in https://github.com/dotansimha/graphql-code-generator/pull/6622 ! Thanks everyone to help us to reproduce and fix the issue.