NexusJS threw an error stating that the Class constructor GraphQLNonNull cannot be called without using the 'new' keyword

While attempting to learn Nexus, I encountered some issues.

I created an index.ts file with the following code:

const User = objectType({
  name: 'User',
  definition(t) {
    t.id('id')
    t.string('name')
  }
})

export const schema = makeSchema({
  types: [User],
  outputs: {
    typegen: __dirname + '/generated/nexus.generated.ts',
    schema: __dirname + 'schema.graphql'
  }
})

Next, I attempted to run the script:

ts-node-dev --transpily-only --no-notify index.ts

However, an error was displayed in the console:

TypeError: Class constructor GraphQLNonNull cannot be invoked without 'new'
    at SchemaBuilder.missingType (/home/zelleaz/Projects/mui/server/node_modules/nexus/src/builder.ts:1099:19)
    at SchemaBuilder.getOrBuildType (/home/zelleaz/Projects/mui/server/node_modules/nexus/src/builder.ts:1448:17)
    at /home/zelleaz/Projects/mui/server/node_modules/nexus/src/builder.ts:794:37
    ...

I attempted to reinstall Nexus, but that didn't resolve the issue.

The project files and directories are as follows:

/node_modules
index.ts
package.json:
 dependencies: apollo-server, graphql, nexus
 dev-dep: ts-node-dev typescript
package-lock.js

Answer №1

Updating to graphql@^15.8.0 fixed the problem I was experiencing.

Answer №2

NexusJS currently does not support graphql 16+. Therefore, it is recommended to use older versions instead. For example, version 14.5.8 (as seen in the GitHub Nexus example) works correctly for me. There is a pull request available with fixes specifically for graphql 16+ version: https://github.com/graphql-nexus/nexus/pull/977

Answer №3

Uncaught TypeError: Class constructor GraphQLNonNull cannot be called without the keyword 'new'

Resolution:

name:{type:new GraphQLNonNull(GraphQLString)},

age:{type:new GraphQLNonNull(GraphQLInt)},

Answer №4

As of now, there hasn't been a stable release yet, but the version [email protected] appears to be working well for me currently. You can check it out at https://github.com/graphql-nexus/nexus/pull/1017.

Although it's not officially supported yet, you can temporarily disable the peer dependency check by adding "PEER_DEPENDENCY_CHECK='false'" to your .env or env.local file.

This will allow you to use the latest graphql 16+ without any issues.

Personally, this has saved me from having to run prisma migrate dev and prisma db push to fix type errors.

I'm hoping they will release a stable version 1.2.0 by Q1/Q2 2022, that's my best guess.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How to vertically align Material UI ListItemSecondaryAction in a ListItem

I encountered an issue with @material-ui/core while trying to create a ListItem with Action. I am looking for a way to ensure that the ListItemSecondaryAction stays on top like ListItemAvatar when the secondary text becomes longer. Is there any solution to ...

Ways to get into the Directive class

@Directive({ selector: '[myHighlight]' }) export class HighlightDirective { static test: number = 5; constructor(private el: ElementRef) { } highlight(color: string) { this.el.nativeElement.style.backgroundColor = color; } } In re ...

Error: The specified property is not found in type 'never' - occurring with the ngFor loop variable

When working with API responses and dynamically sorting my view, I utilize an ngFor loop. Here's the snippet of code in question: <agm-marker *ngFor="let httpResponses of response" [latitude]= "httpResponses.lat" [longitude]=& ...

Ways to cancel a subscription once a specific parameter or value is met following a service/store interaction

I am working with a service that provides a changing object over time. I need to unsubscribe from this service once the object contains a specific property or later when the property reaches a certain value. In situations like these, I typically rely on t ...

Making a new object using a factory in TypeScript

My current endeavor involves developing a factory that is capable of generating instances based on a string identifier. Allow me to walk you through the code... class A { } class B { } class MyFactory { private static _instance: MyFactory; ...

The EAS build is unable to locate the aws-exports file

Currently, I am working on an Expo project integrated with AWS Amplify. To deploy on mobile, I utilize EAS from Expo. However, I frequently encounter this error message: ❌ Metro encountered an error: Unable to resolve module ./src/aws-exports from /Users ...

Exploring the functionalities of arrays in Typescript: A beginner's guide

Currently, I am working on a react project and building a store within it. Below is the code snippet I have implemented: import React, { useReducer, useEffect } from 'react'; import { v4 as uuid } from 'uuid'; import { Movie, MoviesAct ...

When attempting to import css-animator in Angular2/Typescript, a 404 error is displayed, indicating that the

Recently, I delved into the world of Angular2 and decided to experiment with some animations using css-animator package.json "dependencies": { "@angular/common": "2.0.0-rc.3", "@angular/compiler": "2.0.0-rc.3", "@angular/core": "2.0.0-rc.3", ...

Anticipate the middleware function to either invoke the next function or return a HTTP 400 status code

I am eager to delve into unit testing and am looking to test my Node API. I am utilizing Express with Typescript and Jest for testing. Prior to invoking the controller middleware, I apply the route input validation middleware to verify the validity of the ...

Tips for casting an object and simultaneously parsing a string within the object

In my custom Model definition, I have: class Person { age: number; personality: Personality; } class Personality { shy: boolean; moody: boolean; } Upon fetching data from an API, the response looks like this: { age: 20; personalit ...

Is there a way to access the filtered or organized rows in the Quasar Q-Table?

I have encountered a roadblock in my project. Despite installing Quasar version 2.0.0, I realized that it lacks a property to access the filtered or sorted rows. Previous versions of q-table had a computedRows property which was missing in the latest ver ...

Exploring the Functionality of Observables and HTTP Requests in Angular

When I use the http get method in Angular, it returns an observable. To test this, I created a local server that serves up a 50 MB JSON file containing all employee data. import { Injectable } from "@angular/core"; import { Http } from "@angular/http"; im ...

Challenges encountered when passing objects with Angular 2 promises

I am encountering a problem when using a promise to retrieve a Degree object in Angular 2. The initial return statement (not commented out) in degree.service functions correctly when paired with the uncommented implementation of getDegree() in build.compon ...

There was a DOMException in Angular because the transaction is not active when trying to execute 'getAll' on 'IDBObjectStore'

private get ctxMessage() { const messageTransaction = this.db.transaction('messages', 'readwrite'); const messageStore = messageTransaction.objectStore('messages'); return { messageTransaction, messageStore }; } ...

Managing recurring days and times in Angular and retrieving the next scheduled time

I'm currently working on a new feature that will allow users to set multiple wake alarms for specific days and times. For example, they may want alarms to go off on Mondays, Wednesdays, and Fridays at 7:00 AM and 8:00 PM, and on Tuesdays and Thursdays ...

Loop through the component name and route path in ReactJs to efficiently organize and structure your application

In my route file coding for ASP.NET, I am creating routes by fetching details from the backend. Successfully getting details like [Contacts, Pipelines, Stages]. import * as React from 'react'; import { BrowserRouter, Redirect, Route } from &apos ...

Is the type narrowed by type guards only when true is returned?

It was my understanding that a type guard handling multiple types instanceOfA(arg: A | B | C): arg is A, would narrow the type to either A (if the guard returns true) or B | C (if it returns false) However, in the case of instanceOfB below, when returning ...

Is there a way for me to obtain {...rest} in a similar manner as shown in the Typescript Deep form tutorial for Redux Form

While going through the tutorial, I came across the following code snippet: import React, { Component, PropTypes } from 'react' class PureInput extends Component { shouldComponentUpdate(nextProps) { return this.props.field !== nextProps.f ...

Protecting Routes in Angular 4+ with Subscriptions

When my scenario requires authentication/login of a Windows user upon route activation, I need to check if the user is authenticated. If not, I make a call to the server to generate a token and expect it to return true in order to activate the route. Howev ...

Error Uncovered: Ionic 2 Singleton Service Experiencing Issues

I have developed a User class to be used as a singleton service in multiple components. Could you please review if the Injectable() declaration is correct? import { Injectable } from '@angular/core'; import {Http, Headers} from '@angular/ht ...