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