question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot use Apollo GraphQL with new _middleware API

See original GitHub issue

What 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:closed
  • Created 2 years ago
  • Reactions:6
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
ncphillipscommented, Dec 7, 2021

Woo! The issue has been discovered and the fixes are incoming on the apollo side!

https://github.com/apollographql/apollo-client/issues/9128

1reaction
timneutkenscommented, Nov 26, 2021

_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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found