Skip to content
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

Vercel Edge Runtime support #2247

Open
Tracked by #2700 ...
alvarlagerlof opened this issue Dec 23, 2022 · 9 comments
Open
Tracked by #2700 ...

Vercel Edge Runtime support #2247

alvarlagerlof opened this issue Dec 23, 2022 · 9 comments
Assignees

Comments

@alvarlagerlof
Copy link

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.

@ardatan
Copy link
Collaborator

ardatan commented Dec 23, 2022

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

@alvarlagerlof
Copy link
Author

alvarlagerlof commented Dec 25, 2022

Working great, although I did have to remap it to a NextResponse.

@n1ru4l
Copy link
Collaborator

n1ru4l commented Jan 2, 2023

Would be great if we have an example with integration tests in this repo.

@sigginjals
Copy link

@alvarlagerlof How did you map it to NextReponse?

@ardatan
Copy link
Collaborator

ardatan commented Jan 21, 2023

What kind of remapping do you mean? NextResponse is also Response like Yoga returns right? So isn't it working as expected?

@sigginjals
Copy link

sigginjals commented Jan 21, 2023

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:
image

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?

@alvarlagerlof
Copy link
Author

I ended up using yoga.fetch() and then creating a NextResponse and passing in text and the status.

@sigginjals
Copy link

sigginjals commented Jan 22, 2023

Polyfilling URLPattern did the trick, no idea why, Vercel says edge functions support URLPattern. I might try the fetch as-well.

@n1ru4l n1ru4l self-assigned this Feb 20, 2023
@n1ru4l
Copy link
Collaborator

n1ru4l commented Feb 20, 2023

Hey @sigginjals @alvarlagerlof, I am working on adding an end2end integration test in #2471 to ensure a smooth integration.

This was referenced May 7, 2024
This was referenced May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants