I was trying to learn nexus, but got a problems.
I created index.ts file with this 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'
}
})
Then I tryied to run script:
ts-node-dev --transpily-only --no-notify index.ts
And get an error in 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
at Array.forEach (<anonymous>)
at SchemaBuilder.buildNexusTypes (/home/zelleaz/Projects/mui/server/node_modules/nexus/src/builder.ts:782:38)
at SchemaBuilder.getFinalTypeMap (/home/zelleaz/Projects/mui/server/node_modules/nexus/src/builder.ts:835:10)
at Object.makeSchemaInternal (/home/zelleaz/Projects/mui/server/node_modules/nexus/src/builder.ts:1684:92)
at makeSchema (/home/zelleaz/Projects/mui/server/node_modules/nexus/src/makeSchema.ts:14:49)
at Object.<anonymous> (/home/zelleaz/Projects/mui/server/index.ts:11:33)
at Module._compile (internal/modules/cjs/loader.js:1201:30)
I tried to reinstall nexus, but it doesn’t work
Project files and dirs:
/node_modules
index.ts
package.json:
dependencies: apollo-server, graphql, nexus
dev-dep: ts-node-dev typescript
package-lock.js
2
4 Answers
NexusJS for this moment doesn’t work with graphql 16+
So you must use older versions.
In my case 14.5.8 (from GitHub nexus example) workes correctly
There’s pull-request with fixes for graphql 16+ version:
https://github.com/graphql-nexus/nexus/pull/977
They haven’t put a stable release right now but the version [email protected] seems to work fine for me atm ref https://github.com/graphql-nexus/nexus/pull/1017
It’s not officially supported yet so you’ll have to put in .env or env.local "PEER_DEPENDENCY_CHECK=’false’" for now in order for it to disable this peer dependency check.
then you can have the latest graphql 16+
it’s definitely saved me from having to a prisma migrate dev and prisma db push to remove type errors.
Hopefully they’ll get a stable version 1.2.0 by Q1/Q2 2022 my guess
for some reason, it doesn't work with graphql package version 16+ I used graphql v 14.5.8 and it solved the problem. nexus version is 1.1.0
Dec 10, 2021 at 11:55
nexus doesn't work with graphql 16+ Github pull-request with fixes or something: github.com/graphql-nexus/nexus/pull/977
Dec 10, 2021 at 12:08