Cannot use Apollo GraphQL with new _middleware API
See original GitHub issueWhat version of Next.js are you using?
12.0.4
What version of Node.js are you using?
16.9.0
What browser are you using?
n/a
What operating system are you using?
macOS
How are you deploying your application?
n/a
Describe the Bug
Inside of pages/_middleware
I initialize a new instance of ApolloClient
with createHttpLink
in @apollo/client
.
When I try to run next build
it fails:
./node_modules/ts-invariant/lib/invariant.esm.js
Dynamic Code Evaluation (e. g. 'eval', 'new Function') not allowed in Middleware pages/_middleware
Import trace for requested module:
./node_modules/apollo-link/lib/bundle.esm.js
./node_modules/apollo-link-context/lib/bundle.esm.js
./pages/_middleware.ts
Expected Behavior
Build succeeds
To Reproduce
I will provide a reproduction if necessary.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:6
- Comments:9 (9 by maintainers)
Top Results From Across the Web
API Reference: ApolloServer - Apollo GraphQL Docs
You can use the ApolloServer class to create an instance of Apollo Server that ... integration function (e.g., startStandaloneServer or expressMiddleware ).
Read more >Integrating with Node.js middleware - Apollo GraphQL Docs
Apollo Server integrates easily with several popular Node.js middleware libraries. To integrate, first install the appropriate package from the table below ...
Read more >Configuring CORS - Apollo GraphQL Docs
To do so, you'll first need to swap to using expressMiddleware (or any other Apollo Server integration). ⚠️ If your app is only...
Read more >Authentication and authorization - Apollo GraphQL Docs
Control access to your GraphQL API · Authentication is determining whether a given user is logged in, and subsequently determining which user someone...
Read more >Setting Up Authentication and Authorization with Apollo ...
In this tutorial, we set up a GraphQL API using Apollo Federation and Express and issued JWTs to authenticate users via a mutation....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Woo! The issue has been discovered and the fixes are incoming on the apollo side!
https://github.com/apollographql/apollo-client/issues/9128
_middleware runs in a new environment that does not allow for eval. This ensures that any new code written is compatible with the standard web apis which will allow executing them in Workers and even in the browser in development, it’s a preparation for future work to improve more of the Next.js rendering cycle and where code can run.