question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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 https://github.com/graphql/graphql-js/pull/2906

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:11
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
tgriessercommented, Nov 5, 2021

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.

5reactions
7coilcommented, 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)
Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: Class constructor GraphQLNonNull cannot be ...
In my case 14.5.8 (from GitHub nexus example) workes correctly There's pull-request with fixes for graphql 16+ version: ...
Read more >
graphql/type
class GraphQLNonNull. A type wrapper around other types that represents a non-null version of those types. Predicates. function isInputType
Read more >
graphql - npm
This defines a simple schema, with one type and one field, that resolves to a fixed value. The resolve function can return a...
Read more >
Javascript ES6 TypeError Class constructor Client cannot be ...
When I try to execute nodemon command I always see this error TypeError: Class constructor Client cannot be invoked without 'new'.
Read more >
Migrating to Apollo Server 4 - Apollo GraphQL Docs
There are no integration-specific subclasses in Apollo Server 4. Instead, there's a single ApolloServer class with a single API that all integrations use....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found