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