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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for graphql 16: GraphQLNonNull cannot be invoked without 'new' #1009

Closed
ulysset opened this issue Nov 3, 2021 · 6 comments 路 Fixed by #1017
Closed

Fix for graphql 16: GraphQLNonNull cannot be invoked without 'new' #1009

ulysset opened this issue Nov 3, 2021 · 6 comments 路 Fixed by #1017

Comments

@ulysset
Copy link

ulysset commented Nov 3, 2021

Hi! 馃憢

Firstly, thanks for your work on this project! 馃檪

Today I used patch-package to patch nexus@1.1.0 for the project I'm working on.

Nexus wasn't working anymore with graphql version 16.0.0 nor 16.0.1

My error message was

Class constructor GraphQLNonNull cannot be invoked without 'new'

Here is the diff that solved my problem:

diff --git a/node_modules/nexus/src/definitions/wrapping.ts b/node_modules/nexus/src/definitions/wrapping.ts
index 9af7565..c60aa00 100644
--- a/node_modules/nexus/src/definitions/wrapping.ts
+++ b/node_modules/nexus/src/definitions/wrapping.ts
@@ -246,10 +246,10 @@ export function rewrapAsGraphQLType(baseType: GraphQLNamedType, wrapping: NexusF
   let finalType: GraphQLType = baseType
   wrapping.forEach((wrap) => {
     if (wrap === 'List') {
-      finalType = GraphQLList(finalType)
+      finalType = new GraphQLList(finalType)
     } else if (wrap === 'NonNull') {
       if (!isNonNullType(finalType)) {
-        finalType = GraphQLNonNull(finalType)
+        finalType = new GraphQLNonNull(finalType)
       }
     } else {
       throw new Unreachable(wrap)

It happened because of this PR graphql/graphql-js#2906

@7coil
Copy link

7coil commented Nov 5, 2021

You may need to additionally patch (add new) in the following places, if you're temporarily patching it so it works for your project.

  • /node_modules/nexus/dist/definitions/wrapping.js
  • /node_modules/nexus/dist-esm/definitions/wrapping.js
  • /node_modules/nexus/src/definitions/wrapping.ts
  • /node_modules/nexus/dist/builder.js
  • /node_modules/nexus/dist-esm/builder.js
  • /node_modules/nexus/src/wrapping.ts

Something a bit like this...

diff --git a/node_modules/nexus/dist-esm/builder.js b/node_modules/nexus/dist-esm/builder.js
index 202ad18..8894254 100644
--- a/node_modules/nexus/dist-esm/builder.js
+++ b/node_modules/nexus/dist-esm/builder.js
@@ -649,7 +649,7 @@ export class SchemaBuilder {
                 name: 'Query',
                 fields: {
                     ok: {
-                        type: GraphQLNonNull(GraphQLBoolean),
+                        type: new GraphQLNonNull(GraphQLBoolean),
                         resolve: () => true,
                     },
                 },
diff --git a/node_modules/nexus/dist-esm/definitions/wrapping.js b/node_modules/nexus/dist-esm/definitions/wrapping.js
index 252c38c..72d18ee 100644
--- a/node_modules/nexus/dist-esm/definitions/wrapping.js
+++ b/node_modules/nexus/dist-esm/definitions/wrapping.js
@@ -138,11 +138,11 @@ export function rewrapAsGraphQLType(baseType, wrapping) {
     let finalType = baseType;
     wrapping.forEach((wrap) => {
         if (wrap === 'List') {
-            finalType = GraphQLList(finalType);
+            finalType = new GraphQLList(finalType);
         }
         else if (wrap === 'NonNull') {
             if (!isNonNullType(finalType)) {
-                finalType = GraphQLNonNull(finalType);
+                finalType = new GraphQLNonNull(finalType);
             }
         }
         else {
diff --git a/node_modules/nexus/dist/builder.js b/node_modules/nexus/dist/builder.js
index b410a20..199ca56 100644
--- a/node_modules/nexus/dist/builder.js
+++ b/node_modules/nexus/dist/builder.js
@@ -652,7 +652,7 @@ class SchemaBuilder {
                 name: 'Query',
                 fields: {
                     ok: {
-                        type: graphql_1.GraphQLNonNull(graphql_1.GraphQLBoolean),
+                        type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLBoolean),
                         resolve: () => true,
                     },
                 },
diff --git a/node_modules/nexus/dist/definitions/wrapping.js b/node_modules/nexus/dist/definitions/wrapping.js
index 2369cd2..7526942 100644
--- a/node_modules/nexus/dist/definitions/wrapping.js
+++ b/node_modules/nexus/dist/definitions/wrapping.js
@@ -165,11 +165,11 @@ function rewrapAsGraphQLType(baseType, wrapping) {
     let finalType = baseType;
     wrapping.forEach((wrap) => {
         if (wrap === 'List') {
-            finalType = graphql_1.GraphQLList(finalType);
+            finalType = new graphql_1.GraphQLList(finalType);
         }
         else if (wrap === 'NonNull') {
             if (!graphql_1.isNonNullType(finalType)) {
-                finalType = graphql_1.GraphQLNonNull(finalType);
+                finalType = new graphql_1.GraphQLNonNull(finalType);
             }
         }
         else {
diff --git a/node_modules/nexus/src/builder.ts b/node_modules/nexus/src/builder.ts
index f771ead..06ae929 100644
--- a/node_modules/nexus/src/builder.ts
+++ b/node_modules/nexus/src/builder.ts
@@ -1096,7 +1096,7 @@ export class SchemaBuilder {
         name: 'Query',
         fields: {
           ok: {
-            type: GraphQLNonNull(GraphQLBoolean),
+            type: new GraphQLNonNull(GraphQLBoolean),
             resolve: () => true,
           },
         },
diff --git a/node_modules/nexus/src/definitions/wrapping.ts b/node_modules/nexus/src/definitions/wrapping.ts
index 9af7565..c60aa00 100644
--- a/node_modules/nexus/src/definitions/wrapping.ts
+++ b/node_modules/nexus/src/definitions/wrapping.ts
@@ -246,10 +246,10 @@ export function rewrapAsGraphQLType(baseType: GraphQLNamedType, wrapping: NexusF
   let finalType: GraphQLType = baseType
   wrapping.forEach((wrap) => {
     if (wrap === 'List') {
-      finalType = GraphQLList(finalType)
+      finalType = new GraphQLList(finalType)
     } else if (wrap === 'NonNull') {
       if (!isNonNullType(finalType)) {
-        finalType = GraphQLNonNull(finalType)
+        finalType = new GraphQLNonNull(finalType)
       }
     } else {
       throw new Unreachable(wrap)

@tgriesser
Copy link
Member

Thanks, I had started on this in #977 but now that it's officially released I'll look to get this landed, hopefully by this weekend.

@reconbot
Copy link
Contributor

reconbot commented Nov 5, 2021

Should this be covered by a peer dep? It's probably a trade off in developer experience but it would have prevented this bug.

edit never mind we already have a peer dep and it doesn't cover graphql 16.

@KristianBjornstad
Copy link

Any status on this issue?

@lohnsonok
Copy link

When next release for fix this ?

@reconbot
Copy link
Contributor

It's a beautiful thing @tgriesser thank you 馃檹

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants