Open alvarlagerlof opened 1 year ago
We don't introduce integration packages for each platform. We use Fetch API just like Vercel Edge does. When I check the documentation, I see that it needs a function that takes Request
and returns Response
so it should be simple as;
import { createYoga, createSchema } from 'graphql-yoga'
export const config = {
runtime: 'edge',
};
const yoga = createYoga({
schema: createSchema({
typeDefs: /* GraphQL */ `
type Query {
greetings: String!
}
`,
resolvers: {
Query: {
greetings: () =>
'This is the `greetings` field of the root `Query` type',
},
},
}),
})
export default yoga
Working great, although I did have to remap it to a NextResponse.
Would be great if we have an example with integration tests in this repo.
@alvarlagerlof How did you map it to NextReponse?
What kind of remapping do you mean? NextResponse
is also Response
like Yoga returns right? So isn't it working as expected?
Yes, I'm having some issues.
If I copy and paste the code above into a file called /api/graphql.ts
(I did add the graphqlEndpoint config to match the URL).
I keep getting this error:
I tried wrapping the handler like this:
const handler = async (request: Request): Promise<Response> => {
return await yoga.handleRequest(request, {});
};
That works better, but I get an error in Vercel saying:
URLPattern is not a constructor
Did you not have to do anything else than copy the code above? What version of Next are you running?
I ended up using yoga.fetch() and then creating a NextResponse and passing in text and the status.
Polyfilling URLPattern did the trick, no idea why, Vercel says edge functions support URLPattern. I might try the fetch as-well.
Hey @sigginjals @alvarlagerlof, I am working on adding an end2end integration test in https://github.com/dotansimha/graphql-yoga/pull/2471 to ensure a smooth integration.
Is your feature request related to a problem? Please describe.
Support for using the Vercel Edge runtime with Next.js.
Describe the solution you'd like
Integration from the library, like how api routes work now.