How to make apollo server and gateway use graphql@17?

I’m trying to test out @defer/incremental delivery feature. The documentation said it requries graphql@17. So, I added "graphql": "^17" to my dependencies. But npm install gives me this error.

npm ERR! Found: graphql@undefined
npm ERR! node_modules/graphql
npm ERR!   graphql@"^17" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer graphql@"^16.6.0" from @apollo/server@4.3.2
npm ERR! node_modules/@apollo/server
npm ERR!   @apollo/server@"^4.3.2" from the root project

Hey there @Dulguun_Otgon,

@defer is supported on Apollo Router, starting with version 1.8. This unfortunately doesn’t include Apollo Server.

Edit: I was mistaken! Please see Trevor’s answer below.

1 Like

Does @apollo/gateway support this feature as well?

@Dulguun_Otgon - in order to use defer and graphql v17 with Apollo Server you have to “force” install it using the npm --legacy-peer-deps flag like so:

npm i --legacy-peer-deps graphql@alpha

Is it about the server or gateway? I’ve tried what you suggested but I get the unknown directive error.
I think --legacy-peer-deps option still lets other packages use what they specified in their peerDependencies.

Another question. Will Apollo gateway and server support @defer in the future without force installing dependencies?

Even this doesn’t work for me

{
  "name": "experiments",
  "private": true,
  "workspaces": [
    "packages/*"
  ],
  "dependencies": {
    "@apollo/gateway": "^2.3.0",
    "@apollo/server": "^4.3.2",
    "@apollo/subgraph": "^2.3.0",
    "graphql": "^17.0.0-alpha.2",
    // other dependencies
  },
  "overrides" : {
    "graphql" : "$graphql"
  }
}

Apollo Gateway will never support defer, but Router does (with some caveats). Apollo Server on its own (no federation) does support defer, and will eventually support it without any workarounds once graphql v17 is generally available.

1 Like

Thank you. I’ve decided to migrate to router.

What are the caveats you mentioned? Detailed info on that would be really useful to me in the future.

I would recommend reading the docs page for that so you’ve got the full picture.