Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
carlpaten opened this issue Mar 26, 2021 · 52 comments
Labels
stage/6-released The issue has been solved on a released version of the library

Comments

@carlpaten
Copy link
Contributor

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:

  • OS: Ubuntu 20.10
  • @graphql-codegen/...: anything >= 1.15.1
  • NodeJS: 12
@carlpaten
Copy link
Contributor Author

carlpaten commented Mar 26, 2021

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
Copy link

jjangga0214 commented Mar 27, 2021

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
Copy link
Contributor Author

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
Copy link

@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
Copy link
Contributor Author

@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
Copy link

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

@madmaxlax
Copy link

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 hasura/graphql-engine#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)
v1.15.0...v1.15.1

@carlpaten
Copy link
Contributor Author

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

@madmaxlax
Copy link

madmaxlax commented Apr 7, 2021

@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
Copy link

iMuzz commented Apr 11, 2021

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
Copy link

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

@madmaxlax
Copy link

madmaxlax commented Apr 26, 2021

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

@Urigo
Copy link
Collaborator

Urigo commented Apr 27, 2021

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).

@Urigo Urigo added the stage/1-reproduction A reproduction exists label Apr 27, 2021
@jackharrhy
Copy link

jackharrhy commented May 9, 2021

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
Copy link

madmaxlax commented May 9, 2021

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

Ah interesting
Mine was also Hasura with a remote schema

@zhigang1992
Copy link

@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
Copy link
Contributor Author

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

@jackharrhy
Copy link

@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
Copy link
Collaborator

ardatan commented May 11, 2021

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

@jackharrhy
Copy link

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
Copy link
Collaborator

ardatan commented May 11, 2021

@ferm10n
Copy link

ferm10n commented May 19, 2021

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:

  • @apollo/client@3.3.19
  • @graphql-codegen/cli@1.24.1
  • @graphql-codegen/import-types-preset@1.18.1
  • @graphql-codegen/typescript@1.22.0
  • @graphql-codegen/typescript-vue-apollo@2.3.4
  • @graphql-codegen/typescript-operations@1.17.16
  • graphql@15.5.0

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
Copy link

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
Copy link
Collaborator

ardatan commented Jun 3, 2021

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

@erichiller
Copy link

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
Copy link

msimon commented Jun 16, 2021

@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
Copy link

msimon commented Jun 16, 2021

For anyone using Hasura with remote schema, the comment for @jackharrhy does work well. (#5758 (comment))

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
Copy link
Owner

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?

@dotansimha
Copy link
Owner

@dotansimha If someone reproduces it :)

Take a look at this comment: #5758 (comment) , the flow there does makes sense, no?

@ardatan
Copy link
Collaborator

ardatan commented Jun 20, 2021

@dotansimha
See #5758 (comment) and ardatan/graphql-tools#3092

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

@msimon
Copy link

msimon commented Jun 20, 2021

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

@ardatan
Copy link
Collaborator

ardatan commented Jun 20, 2021

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

@msimon
Copy link

msimon commented Jun 20, 2021

@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
Copy link
Collaborator

ardatan commented Jun 20, 2021

@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
Copy link

msimon commented Jun 20, 2021

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

@sfcgeorge
Copy link

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
Copy link

dimbslmh commented Sep 5, 2021

41e9358 1.15.0
1f2eeae @graphql-tools 6.0.1 -> 6.0.3
54fa487 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

export const loadSchema = async (

1.15.0 1.15.1
{
  "_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": {}
}
{
  "_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.

const errors = await validateGraphQlDocuments(options.schemaAst, [

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
Copy link
Collaborator

ardatan commented Sep 5, 2021

@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
Copy link

dimbslmh commented Sep 5, 2021

@ardatan I'll try and take a look.

@dimbslmh
Copy link

dimbslmh commented Sep 5, 2021

@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
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] {}
}
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
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] {}
}
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
Copy link

dimbslmh commented Sep 5, 2021

@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
Copy link
Collaborator

ardatan commented Sep 5, 2021

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
Copy link

dimbslmh commented Sep 5, 2021

@ardatan I have here: #5758 (comment)

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
Copy link
Collaborator

ardatan commented Sep 5, 2021

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

@dimbslmh
Copy link

dimbslmh commented Sep 6, 2021

@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
Copy link
Collaborator

ardatan commented Sep 6, 2021

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

@dimbslmh
Copy link

dimbslmh commented Sep 6, 2021

@ardatan
Copy link
Collaborator

ardatan commented Sep 7, 2021

The issue is convertExtensions. See the fix for details;
ardatan/graphql-tools#3489

@ardatan ardatan added stage/5-alpha-release-testing The pull request is merged, an alpha release is available, to be tested stage/6-released The issue has been solved on a released version of the library and removed stage/1-reproduction A reproduction exists stage/5-alpha-release-testing The pull request is merged, an alpha release is available, to be tested labels Sep 7, 2021
@ardatan
Copy link
Collaborator

ardatan commented Sep 7, 2021

Fixed in #6622 !
Thanks everyone to help us to reproduce and fix the issue.

@ardatan ardatan closed this as completed Sep 7, 2021
@dimbslmh
Copy link

dimbslmh commented Sep 7, 2021

@ardatan glad it's fixed now. Thank you!

@carlpaten
Copy link
Contributor Author

Thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stage/6-released The issue has been solved on a released version of the library
Projects
None yet
Development

No branches or pull requests