-
Notifications
You must be signed in to change notification settings - Fork 575
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NextJS 13+ (app/api/graphql/route.js) Integration #2696
Comments
Did you try the following; export {
yoga as GET,
yoga as POST
}; Also as far as I see, our nextjs example still works; |
thanks @ardatan |
Could you share a reproduction on CodeSandbox or StackBlitz? Thanks! |
Here the CodeSandBox share link: 🔴 I guess |
Running into the same problem as well :( |
The way to solve is: export async function POST(request: Request) {
const result = await yoga.fetch(request.url, {
method: 'POST',
headers: request.headers,
body: await request.text(),
});
return new Response(result.body, {
status: result.status,
headers: result.headers,
});
} |
Could you add import { createYoga, createSchema } from 'graphql-yoga'
const yoga = createYoga({
graphqlEndpoint: '/api/graphql',
schema: createSchema({
typeDefs: /* GraphQL */ `
type Query {
greetings: String
}
`,
resolvers: {
Query: {
greetings: () =>
'This is the `greetings` field of the root `Query` type',
},
},
}),
fetchAPI: {
Response: Response
}
})
export {
yoga as GET,
yoga as POST,
} |
@ardatan your example works great locally. However, when deployed to Amplify, I got the following error:
Any idea how to address this? |
@thai-recurmetrics This is because it seems Next compiler doesn't check for routes export types on dev mode. Export import { createYoga, createSchema } from 'graphql-yoga'
const { handleRequest } = createYoga({
graphqlEndpoint: '/api/graphql',
schema: createSchema({
typeDefs: /* GraphQL */ `
type Query {
greetings: String
}
`,
resolvers: {
Query: {
greetings: () =>
'This is the `greetings` field of the root `Query` type',
},
},
}),
fetchAPI: {
Response: Response,
Request: Request,
},
})
export { handleRequest as GET, handleRequest as POST } |
It works great! |
@bahmanworld thanks for the example! I actually got it working. |
I have implemented graphql server with nextjs 14 app router src\app\api\graphql\route.ts
|
.next/types/app/api/graphql/route.ts:49:7 package.json:
Doesn't work with Next.js 15. |
Issue DescriptionIn setting up a GraphQL API with Next.js 15's route handlers and GraphQL Yoga, I initially encountered a type error. The error stemmed from a mismatch between Next.js's route handler types and the expected types within GraphQL Yoga’s Steps Taken to Fix
Additional InformationEnvironment:
This setup should work well for integrating GraphQL in Next.js 15 with robust type safety and secure query handling. |
Issue DescriptionIn setting up a GraphQL API with Next.js 15's route handlers and GraphQL Yoga, I initially encountered a type error. The error stemmed from a mismatch between Next.js's route handler types and the expected types within GraphQL Yoga’s Steps Taken to Fix
Additional InformationEnvironment:
This setup should work well for integrating GraphQL in Next.js 15 with robust type safety and secure query handling. |
Thank you for your detailed description @simpleneeraj We solved it a bit differently here - what do you think about that solution, does that work for you? |
Yes |
I wanna integrate graphql-yoga with nextjs 13 in
app/api/graphql/route.js
.Is there any way to do that?
I've tried some tricks before but i've got no answer:
or
The text was updated successfully, but these errors were encountered: