What is the correct way to define ContextType?
See original GitHub issueI trying to get Prisma and Nexus working with NextJS, but I am having some trouble defining the contextType in the GraphQL schema.
I define the schema like this:
export const schema = makeSchema({
types: [Query, User, Mutation],
contextType: {
module: require.resolve("./graphql/context"),
export: "Context",
},
plugins: [nexusPrisma({ experimentalCRUD: true })],
outputs: {
typegen: path.join(process.cwd(), "generated", "nexus-typegen.ts"),
schema: path.join(process.cwd(), "generated", "schema.graphql"),
},
});
The error occurs when I start the development server by running npm run dev
. The error is as follows:
Module not found: Can't resolve './graphql/context'
46 | types: [Query, User, Mutation],
47 | contextType: {
> 48 | module: require.resolve("./graphql/context"),
| ^
49 | export: "Context",
50 | },
51 | plugins: [nexusPrisma({ experimentalCRUD: true })],
This is the context.ts
file:
import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient();
export interface Context {
prisma: PrismaClient;
}
export function createContext(): Context {
return { prisma };
}
My dependencies are these:
"dependencies": {
"@prisma/client": "^2.13.1",
"apollo-server-micro": "^2.19.1",
"next": "latest",
"nexus": "^1.0.0",
"nexus-plugin-prisma": "^0.27.0",
"react": "^16.12.0",
"react-dom": "^16.12.0"
},
"devDependencies": {
"@prisma/cli": "^2.13.1",
"@types/node": "^12.12.21",
"@types/react": "^16.9.16",
"@types/react-dom": "^16.9.4",
"typescript": "^4.1.3"
},
Any help is appreciated.
Project tree:
root
ββ generated
β ββ nexus-typegen.ts
β ββ schema.graphql
ββ graphql
β ββ context.ts
β ββ schema.ts
ββ interfaces
β ββ index.ts
ββ next-env.d.ts
ββ package-lock.json
ββ package.json
ββ pages
β ββ api
β β ββ graphql.ts
ββ prisma
β ββ schema.prisma
ββ tsconfig.json
I posted this question also to Stack Overflow.
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (4 by maintainers)
Top Results From Across the Web
What is the correct way to define a React component's ...
Type '{ router: Requireable<any>; }' is not assignable to type 'ValidationMap<any>'. Changing the contextTypes to static contextTypes: React.
Read more >What is contextType in React? - DEV Community β β
To use the new way, at the top of the class we declare a static property called contextType and set it equal to...
Read more >Context - React
Context provides a way to pass data through the component tree without having to ... Component { // Assign a contextType to read...
Read more >contextType property of a React component ... - DeepScan
This rule applies when the static contextType property of a React component is not properly specified. The contextType property is used toΒ ...
Read more >How to use React Context with TypeScript - Felix Gerschau
In this tutorial, you will learn how to use React Context with TypeScript, including function and class components.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
https://nexusjs.org/docs/adoption-guides/nextjs-users#sdl-and-type-generation
Solved for me.