-
Notifications
You must be signed in to change notification settings - Fork 559
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 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: