init
This commit is contained in:
26
src/app/api/graphql/route.ts
Normal file
26
src/app/api/graphql/route.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import resolvers from "@/graphql/resolvers";
|
||||
import typeDefs from "@/graphql/types";
|
||||
import { createSchema, createYoga } from "graphql-yoga";
|
||||
|
||||
interface NextContext {
|
||||
params: Promise<Record<string, string>>;
|
||||
}
|
||||
|
||||
const { handleRequest } = createYoga<NextContext>({
|
||||
schema: createSchema({
|
||||
typeDefs: typeDefs,
|
||||
resolvers: resolvers
|
||||
}),
|
||||
|
||||
// While using Next.js file convention for routing, we need to configure Yoga to use the correct endpoint
|
||||
graphqlEndpoint: "/api/graphql",
|
||||
|
||||
// Yoga needs to know how to create a valid Next response
|
||||
fetchAPI: { Response }
|
||||
});
|
||||
|
||||
export {
|
||||
handleRequest as GET,
|
||||
handleRequest as POST,
|
||||
handleRequest as OPTIONS
|
||||
};
|
||||
Reference in New Issue
Block a user