RevereCRE/relay-nextjs

Crashes with serverless functions

Closed this issue · 1 comments

Hey all,

Great work with this library! It's been helpful on my Relay + Next journey.

I have a GraphQL server that is currently running on a Serverless Function, but I noticed that it returns a 413 Error when the payload is bigger than 250kb.

From my research, serverless functions seem to have a limit of 250kb for Asynchronous invocation and 6MB for Synchronous invocation (see here), so that could be happening because of the way that the fetch call is executed. So I experimented with fetching directly from my GraphQL server in getServerInitialProps, and it did work.

I am currently suspecting it can be related to #70 and the way loadQuery works. I tried making the getClientInitialProps async and calling the ensureQueryFlushed, but no success so far.

Any advice is appreciated and I'd be happy to work on a PR that addresses this if it's interesting for anyone else.

Hey Julio! I'm not sure getServerInitialProps being an asynchronous function is causing an asynchronous invocation for AWS Lambda. I don't think there's a way to ensure calling an RPC over a network will ever be synchronous and I believe it has to do with how the Lambda is called, rather than the implementation.

To work around the size limit I recommend using useLazyLoadQuery to defer loading some of the data the page needs. Regardless of the 413 error, 250kb is definitely a lot to send in an RPC response payload.