All jobs

Migrate From apollo-server-express to @apollo/server

Yes. An agent moves an Express app from the end-of-life apollo-server-express to @apollo/server and shows which GraphQL responses change.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

npm marks apollo-server-express as deprecated: the notice says it belongs to Apollo Server 2 and 3, both end-of-life, and that its function now lives in @apollo/server. The agent starts from what is locked. In a tool like ngduc/api-now, package.json asks for apollo-server-express ^2.12.0 and yarn.lock resolves 2.12.0. graphql is not listed at all; version 14.6.0 arrives as someone else's dependency. lib/routes/apolloServer.js imports ApolloServer and gql, defines the schema and resolvers and exports the server, and lib/server.js mounts it with apolloServer.applyMiddleware({ app: server, path: '/graphql' }).

Before touching it, the agent records how the endpoint answers, because the Jest suite has only three GraphQL tests. It starts the server and sends a fixed set of requests with curl: a valid query by POST, a query for a field that does not exist, the same valid query as a GET with ?query=, a bare GET, and a GET that asks for text/html. It saves each status, content type and body.

Three things in the old code have no direct successor. gql is no longer exported, so the schema becomes a plain string. applyMiddleware is gone; the server must be started with await server.start() and mounted with expressMiddleware, which for version 5 comes from the separate package @as-integrations/express4. And lib/server.js builds the app in a synchronous function, so the agent wraps the mount in a handler that waits on the start promise instead of making every caller async. The existing server.use(jsonServer.bodyParser) line above the mount already parses JSON, which the new middleware requires.

Dependencies need the same care. @apollo/server 5.5.1 declares graphql ^16.11.0 as a peer and Node 20 or later in engines. A plain yarn add graphql selects 17.1.0, outside that range, so the agent pins a 16 release, and it raises the CI matrix in .github/workflows/nodejs.yml, which lists Node 8, 10 and 12. Then it replays the saved requests. POST results are identical. The GET with ?query= that used to return data now returns 400 with a message about cross-site request forgery, unless the request carries an apollo-require-preflight header, and the HTML answer is Apollo's landing page where GraphQL Playground used to be.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "Migrate this Express app from apollo-server-express to @apollo/server. Read package.json and the lockfile for the resolved versions of apollo-server-express, graphql and express, and find where the ApolloServer is constructed and where applyMiddleware is called. Install with the lockfile and run the tests. Start the app and record, with curl, the status, content type and body for: a valid query by POST, a query for an unknown field, a valid query by GET with ?query=, a GET with no query, and a GET with Accept: text/html. Then port: ApolloServer from @apollo/server, the schema as a string or with graphql-tag since gql is no longer exported, server.start() awaited before requests are handled, expressMiddleware from the integration package that matches the installed Express major, mounted on the same path with JSON body parsing and CORS in front of it. Keep any context, plugins, upload or subscription settings working or list them as needing a decision. Add graphql as a direct dependency inside the peer range @apollo/server declares. Compare the engines field with the Node versions in CI and update the workflow. Replay the same curl requests and show every difference, including CSRF prevention on GET and the landing page. Run the tests. Open a pull request with the commands, both sets of responses and the list of behaviour changes.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

A pull request that edits lib/routes/apolloServer.js, lib/server.js, package.json, yarn.lock and the CI workflow. The lockfile accounts for most of the changed lines. The description puts the two sets of responses next to each other and names each difference, then lists the Node versions dropped from CI and the reason graphql is now a direct dependency with a pinned major.

What the reviewer has to decide is the GET behaviour. Clients that fetch /graphql?query=... from a browser or a script with no extra headers were served before and are refused after, by design of the new server's default protection. The fix on the client is one header; the description gives it and also names the server option that turns the check off, without choosing for the team. They should notice too that the suite passes on both sides for an accidental reason: the test that expects 400 from a bare GET still gets 400, now with a different body. The agent adds assertions on the body so the next change cannot hide behind the status code.

Run it on every Linear issue labelled upgrade

Upgrades like this are usually written down long before anyone has an afternoon for them. Connect Linear under Settings → Connections and add an automation on the Project with a linear trigger on linear.issue.labeled, your label in labels, and the prompt above. When a member of your Rush org adds the label, a run starts in the Project's repository with the issue appended after the prompt as third-party data.

A label added by an app integration does not fire the trigger, so a bulk relabel through another tool starts nothing. To queue the same job for several services, call POST /o/{org}/sessions once per repository with a request_id that is a UUID v5 of the repository name.

The use case this job follows, with its automation and trigger: Turn a Linear label into a PR.

Why run it on Rush?

A framework major upgrade can pass its tests and still change the service's answers, and this one does. The only way to know is to run the server on both versions and compare real responses, which means two installs, two processes and a saved set of requests. The agent does that in its own sandbox, and both sets of responses stay in the run's transcript and in the pull request, so the review starts from observed behaviour.

The run also catches the edges of the dependency change that a quick local attempt skips: a peer range the default install violates, and a CI matrix that cannot install the new package at all. Those are reported with the registry fields they come from.

Frequently asked questions

What replaces applyMiddleware?

expressMiddleware(server), mounted with app.use on the path you choose, after await server.start(). For Apollo Server 5 the function comes from @as-integrations/express4 or the Express 5 variant. You place JSON body parsing and CORS in front of it yourself, since the server no longer adds them.

Why do GET queries return 400 after the upgrade?

The server blocks requests a browser could send across sites without a preflight. A GET with no content-type and no apollo-require-preflight header is refused with a message naming cross-site request forgery. Adding that header to the client makes the same GET return data again.

Which graphql version should I install?

One inside the peer range of the @apollo/server release you chose. For 5.5.1 that is ^16.11.0. An unpinned install picked 17.1.0 when this was checked, so the agent writes the range explicitly and reruns the tests on a 16 release.

Can I stop at Apollo Server 4?

The registry marks version 4 as end-of-life since January 26, 2026, so it is a stop on the way at best. Its engines field accepts older Node releases than version 5 does, which is the only reason to pause there, and the agent says which Node versions your CI would keep in each case.

More jobs like this: Turn a Linear label into a PR

Keep reading