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

IDEA: Investigate Next.js Edge Runtime compatibility #4193

Open
ardatan opened this issue Jul 25, 2022 · 1 comment
Open

IDEA: Investigate Next.js Edge Runtime compatibility #4193

ardatan opened this issue Jul 25, 2022 · 1 comment

Comments

@ardatan
Copy link
Owner

ardatan commented Jul 25, 2022

https://nextjs.org/docs/api-routes/edge-api-routes

@paales
Copy link

paales commented Jan 9, 2023

So I'm giving it another try to get Edge functions working and this is what I've got so far. PR where progress can be tracked

Motivation

We currently deploy the Mesh in Next.js API functions which is running on AWS Lambda. Which has two considerable issues:

  • Lambda's are billed by execution time instead of CPU time it becomes very costly very quickly. Edge functions are billed by CPU time which is way more interesting for a gateway like GraphQL Mesh
  • The cold boot time in next.js is 10-13+ seconds which should be considerable less.

I do have my reservations about edge functions if they are good enough: They currently allow for 50ms of CPU time and 128MB of RAM. I'm not quite sure how all this is measured and if this is split in 'bootup' and 'execution'. Trying to get this to find out :)

Current issues

Updating the api/graphql.ts file to be this allows it to somewhat work on my machine:

import { createBuiltMeshHTTPHandler } from '@graphcommerce/graphql-mesh'
import { NextRequest } from 'next/server'

const handler = createBuiltMeshHTTPHandler()

export default async function handle(request: NextRequest) {
  return handler.fetch(request.url, request)
}

export const config = { runtime: 'edge' }

To even get to a buildable state we need to patch quite a few packages, to remove occurrences of new Function('x') and remove occurrences of node function calls: https://github.com/graphcommerce-org/graphcommerce/pull/1772/files#diff-19ef71a73a1e9cd311b0aa5f2fee0802a62b54794e4d12bc676f2ce42a57c35b

After that it seems to be doing something, during development:

Schermafbeelding_2023-01-05_om_23 01 57

Trace: using console.trace here
    at new NonErrorThrown (webpack-internal:///(middleware)/../../node_modules/graphql/jsutils/toError.mjs:19:15)
    at toError (webpack-internal:///(middleware)/../../node_modules/graphql/jsutils/toError.mjs:14:7)
    at locatedError (webpack-internal:///(middleware)/../../node_modules/graphql/error/locatedError.mjs:18:86)
    at eval (webpack-internal:///(middleware)/../../node_modules/@graphql-tools/executor/esm/execution/execute.js:328:84)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Promise.all (index 0)
    at async promiseForObject (webpack-internal:///(middleware)/../../node_modules/@graphql-tools/executor/esm/execution/promiseForObject.js:15:28)
    at async subschemaExecute (webpack-internal:///(middleware)/../../node_modules/@graphql-mesh/runtime/esm/useSubschema.js:66:32)
    at async eval (webpack-internal:///(middleware)/../../node_modules/@envelop/core/esm/orchestrator.js:378:27)
    at async YogaServer.getResultForParams (webpack-internal:///(middleware)/../../node_modules/graphql-yoga/esm/server.js:294:26)
    at async YogaServer.getResponse (webpack-internal:///(middleware)/../../node_modules/graphql-yoga/esm/server.js:360:23)
    at async YogaServer.handle (webpack-internal:///(middleware)/../../node_modules/graphql-yoga/esm/server.js:70:34)
    at async handle (webpack-internal:///(middleware)/../../node_modules/itty-router/dist/itty-router.min.mjs:6:569)
    at async adapter (webpack-internal:///(middleware)/../../node_modules/next/dist/esm/server/web/adapter.js:112:20)
    at async /Users/paulhachmang/Sites/reachdigital-next/node_modules/next/dist/server/web/sandbox/sandbox.js:73:24
    at async DevServer.runEdgeFunction (/Users/paulhachmang/Sites/reachdigital-next/node_modules/next/dist/server/next-server.js:1411:24)
    at async DevServer.runApi (/Users/paulhachmang/Sites/reachdigital-next/node_modules/next/dist/server/next-server.js:467:47)
    at async Object.fn (/Users/paulhachmang/Sites/reachdigital-next/node_modules/next/dist/server/next-server.js:749:37)
    at async Router.execute (/Users/paulhachmang/Sites/reachdigital-next/node_modules/next/dist/server/router.js:253:36)
    at async DevServer.run (/Users/paulhachmang/Sites/reachdigital-next/node_modules/next/dist/server/base-server.js:384:29)
    at async DevServer.run (/Users/paulhachmang/Sites/reachdigital-next/node_modules/next/dist/server/dev/next-dev-server.js:741:20)
    at async DevServer.handleRequest (/Users/paulhachmang/Sites/reachdigital-next/node_modules/next/dist/server/base-server.js:322:20)

Since it build I've tried to deploy it to the online environment, but running into issues there:

  • No available storage method found
/api/graphql
08:36:29:10
Error: No available storage method found.
    at ../../node_modules/localforage/dist/localforage.js:2762:0

I tried configuring INMEMORY_LRU directly but then getting the same error.

@ardatan Running into quite a few roadblock to get this to work unfortunately, not sure how to resolve these. Would be nice to get over a few bumps so I can investigate further.

@theguild-bot theguild-bot mentioned this issue Sep 28, 2023
This was referenced Apr 30, 2024
This was referenced May 7, 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

2 participants