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

[REQUEST] support vercel edge functions by default #341

Open
sgrund14 opened this issue Jun 2, 2023 · 4 comments
Open

[REQUEST] support vercel edge functions by default #341

sgrund14 opened this issue Jun 2, 2023 · 4 comments

Comments

@sgrund14
Copy link

sgrund14 commented Jun 2, 2023

What problem are you trying to solve?

support the vercel edge runtime for dataloaders without workaround. see discussion here vercel/next.js#44711 (edge does not support process.nextTick, which is being checked in the Dataloader package)

right now, you have to pass in the batchScheduleFn with a setTimeout to the DataLoader to make the package work on the edge runtime like so

 batchScheduleFn: (cb) => setTimeout(cb, 0),

but this might not be ideal? not totally sure what happens in this case, I would just worry about adding latency or breaking the batching with the setTimeout instead of relying on the default behavior (batching per execution context)

Describe the solution you'd like

Dataloader should work in the edge runtime without having to pass in a setTimeout

Describe alternatives you've considered

using the setTimeout workaround

Additional context

nice to support edge functions so that you can have zero cold start graphql functions in a serverless environment

@sgrund14 sgrund14 changed the title [support vercel edge functions by default] [REQUEST] support vercel edge functions by default Jun 2, 2023
@ardatan
Copy link
Member

ardatan commented Jun 2, 2023

Dataloader doesn't use process.nextTick already if not available;

typeof process === 'object' && typeof process.nextTick === 'function'

I think Next.js checks the code and throws an error even if it is not called. I think it needs to be fixed on Next.js side.

@sgrund14
Copy link
Author

sgrund14 commented Jun 2, 2023

hm, not possible to fix here? I only ask because while you have responded right away (thanks!), the vercel team hasn't taken a look at that issue for 5 months :(

wonder how they are actually determining that the code is getting run when it's not 🤔 like why does it work when the batchScheduleFn is passed in?

@ardatan
Copy link
Member

ardatan commented Jun 2, 2023

Hmm you are right. I missed that. Maybe they throw this error when you try to acces the global "process" variable.

@sgrund14
Copy link
Author

sgrund14 commented Jun 6, 2023

yea, seems like that could be the case. how to avoid even accessing the process variable tho... would dataloader have to somehow check what environment it's in? or do a typeof process !== 'undefined' check?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants