DEV Community

Cover image for Apollo Server v4 Breaking Changes. Time to move away?
Roy Derks
Roy Derks

Posted on • Edited on • Originally published at hackteam.io

Apollo Server v4 Breaking Changes. Time to move away?

Apollo Server has been the go-to JavaScript library for building GraphQL servers for the last half-decade. But almost every year, there are breaking changes, and the latest version 4 is no exception. Not only did they announce breaking changes, they also announced that Apollo will drop support for Apollo Server v2 and v3 as early as October 2023. In this article, I will explain the breaking changes and why it might be time to move away from Apollo Server.

Click the image below to watch the YouTube video version of this blog post:

Apollo Server v4 Breaking Changes. Time to move away?

Biggest Breaking Changes

Let's look at the most significant breaking changes in Apollo Server v4. Together with these breaking changes, a migration path from earlier versions of Apollo Server was also published in the documentation.

"We recommend that all users of Apollo Server upgrade to Apollo Server 4 as soon as possible. Apollo Server 2 and Apollo Server 3 are deprecated, with an end-of-life date of October 22nd, 2023." - Apollo Server v4 Migration Guide

New project structure

Apollo Server v4 is the latest version of Apollo Server and is replacing Apollo Server v2 and v3. As part of this update, they've bundled some packages in @apollo/server to replace the apollo-server package. Part of this is the apollo-server-express package, the most popular package for building GraphQL servers in Node.js, which is now integrated into the @apollo/server package.

Thus, if you want to use Apollo Server v4, you must follow the migration guide and update your code to use the new packages. As shown in the migration guide flowchart below:

Apollo Server v4 Migration Path

This seems like a minor deal unless you're not using Express as your web framework. And an important note here is that Express GraphQL is being deprecated by the GraphQL Foundation. So if you're using Express for a GraphQL API, you should move away from it anyway.

Dropped support for other web frameworks

Now that Express is the default framework for running the GraphQL server, Apollo decided to remove support for all other web frameworks. This means Apollo is forcing developers to use Express to run their GraphQL servers. This is a big change as Apollo Server v2, and v3 allowed you to build on top of the apollo-server-* packages, such as apollo-server-fastify or apollo-server-koa. This is a huge change as it means you can no longer use Koa or Fastify to run your GraphQL servers unless someone builds a new package for it.

Apollo Server v4 Breaking Changes

Until someone decides to build a new package for the web framework you use, you're stuck with Apollo Server v3, which is deprecated and will be end-of-life in October 2023.

Updated concept of dataSources

Apollo Server v4 has a new concept of dataSources. In Apollo Server v2 and v3 you could use the dataSources property to pass in an object with all of your data sources. This is no longer the case in Apollo Server v4. Instead, you will need to create a class that extends the DataSource class and then pass in an array of instances of this class to the dataSources property.

Deprecated data sources in Apollo Server v4

As a "side effect" of this change, Apollo deprecated the data source implementations created for SQL, MongoDB, and Firestore. Similar to the web framework plugins, you will need to make your own data source implementation for these data sources.

What else has changed?

Besides no longer supporting any other web framework than Express, there are a a lot of other breaking changes. Not all of them are bad, and the new Apollo Server v4 seems to be fixing a lot of tech debt the team has been building up over the years. For example, Apollo Server v4 has better TypeScript support than previous versions. And the deprecation of ApolloError in favor of GraphQLError from the graphql package is a good step forward to keep Apollo Server more in line with other libraries to build your GraphQL API.

Should I move away from Apollo Server?

It's entirely up to you. But from a Reddit post of the Apollo team it seems the next "backwards incompatible" release of Apollo Server will be Apollo Server v5, in spring 2023(!). To me, that just shows that Apollo Server is not a stable library to build your GraphQL API. And if you're building a GraphQL API for a company, you don't want to be stuck with a library that is not stable and will be deprecated every few years.

That said, if you are using Express you can easily upgrade to Apollo Server v4. Keeping in mind that express-graphql has been deprecated as well. If you're using Koa or Fastify, you can still use Apollo Server v3 until October 2023. You're out of luck if you're using any other web framework. You will either need to switch to Express, stay on Apollo Server v3 or wait for community support for the web framework you're using. In that case, consider moving away from Apollo Server.

When moving away from Apollo Server, and you're looking for a replacement built with JavaScript or TypeScript, let me give you some options. If you want to keep building your GraphQL API schema first, you might want to consider Mercurius (which relies on Fastify) or GraphQL Yoga. If you're going to build your GraphQL API code or resolver first, have a look at TypeGraphQL or Nexus. Alternatively, there are great GraphQL-as-a-Service solutions such as StepZen in case you no longer want to build, maintain and host your own GraphQL API.

You can learn more about the differences between schema-first, code/resolver-first, or using a GraphQL-as-a-Service in this recording of my talk at GraphQL Galaxy 2021.

Are you using Apollo Server? What are your thoughts on the breaking changes? Let me know on Twitter at @gethackteam.


This post was originally published on hackteam.io. Reposted automatically with Reposted.io.

Top comments (0)