<img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=1063935717132479&amp;ev=PageView&amp;noscript=1 https://www.facebook.com/tr?id=1063935717132479&amp;ev=PageView&amp;noscript=1 "> Bitovi Blog - UX and UI design, JavaScript and Front-end development

Backend |

What's New in Node.js and GraphQL for 2023?

Learn about the latest changes in GraphQL and Node.js, including upgrades to Node.js v16 and v18 and improvements to Apollo Federation and Apollo Server.

Emil Kais

Emil Kais

Twitter Reddit

Lots of things change year over year, especially in backend development. GraphQL, as well as Node.js, are no exception! We’ll cover some background context for the changes leading up to 2023 and then highlight the most relevant changes that happened last year. Without further ado, let’s hop in!

What Changed in 2022?

Node.js has upgraded from Node v16.13.2 as the LTS in early January to Node v18.12.1 in November and has since added more features that make initial development much easier for new developers. Meanwhile, for GraphQL, several upgrades to packages like Apollo Server and Apollo Federation have been paving the way for GraphQL development at scale.

Node.js v16 changes

Before we go into the new stuff, we should refresh ourselves on what was added in Node 16:

  • An experimental implementation of the standard Web crypto API
  • Stable Timers are no longer in an experimental state
  • A global AbortController that can be used to cancel select promised-based APIs 
  • Adding native methods for converting data in base64 encoded strings atob and btoa

What do these updates mean?

  • Since cryptography has generated more and more interest since 2017, there was most likely some effort put in to support it out of the box with Node.js.
  • Stable Timers gives us a reliable method to handle setTimeouts
  • The AbortController provides a nice way to deal with canceling promises and removing event listeners

  • Adding atob and btoa is intended for legacy web platform APIs

State of GraphQL Apollo

GraphQL 16 was released back in 2021, so the actual GraphQL package has mostly been consistent in terms of notable features throughout the year. However, Apollo has continued to tackle the problem of GraphQL at scale:

  • In 2019 Apollo Federation 1.0 was released, and since then, large companies like Netflix, Walmart, RetailMeNot, and Paypal have been using this technology
  • Apollo Federation required two major libraries: @apollo/subgraph and @apollo/gateway
  • Those two libraries were the basis of separating out subgraphs and creating a gateway to have a resolution strategy
  • This philosophy followed the recent trend towards serverless and microservice-oriented development in the past few years

Brief Recap of Apollo Federation

Apollo Federation is a powerful, open architecture for creating a super-graph that combines multiple GraphQL APIs. By using federation, you can separate responsibilities and share ownership of your super-graph across multiple teams. This idea extends the concept of schema stitching and takes it to a whole new level where subgraphs can now have their own repository. This works by querying the super-graphs router (known as a gateway), which serves as a public access point for the super-graph, and routes them to the correct subgraph.


Notable Experimental Changes in Node 18

  • A global fetch API from unidici removes the need to download your own library and instead use the one provided by Node.js

  • An implementation of the Web Streams API, which gives you global access to break large resources down into smaller chunks to process them bit by bit

  • A test runner module that allows you to create JavaScript tests as easily as including the following line in your code:

  • A build-time, user-land snapshot that allows users to build a Node.js binary with a custom V8 startup snapshot using --node-snapshot-main flag of the configure script. This feature enables the Node executable to create a single binary that contains both Node.js and an embedded snapshot without building Node.js from the source, which decreases startup time of scripts

  • npm was upgraded to 8.19.3

  • As of Node v18.11.0, there is watch mode which will restart the process when an imported file is changed, like nodemon or similar packages, which you can use by running this command:


Notable changes with V8 Engine 10.1

Summary of GraphQL Changes in 2022

It’s not just Node.js that has seen some improvements and changes this year. GraphQL and Apollo have been shifting their focus towards using Federated Graphs with Apollo Federation, which you can look at here as a primer.

Apollo Server Upgraded from 3 → 4

It now combines numerous smaller packages, including startStandaloneServer and expressMiddleware functions.

The new @apollo/server package contains the following:

  • The ApolloServer class
  • An Express 4 integration (similar to Apollo Server 3’s apollo-server-express package)
  • A standalone server (similar to Apollo Server 3’s apollo-server package)
  • A set of core plugins (similar to Apollo Server 3’s apollo-server-core package)

Instead of having the Apollo Core team support every integration package, they rely on the open-source community for Apollo Server integrations. This affects the following integrations: fastify, hapi, koa, lambda, micro, cloud-functions, and azure-functions.

Note: If your project uses these packages, it’s worthwhile to see what is there in the open-source community to see how to upgrade to Apollo Server 4.

Apollo Federation 2.0 Launch

Common tasks like extending a federated type or denormalizing a field for better performance are now possible without special directives and keywords (like @external and extends).

node-graphql-2023-4 Tth09IXvAfRDmvKmYCcJbbf0klD1uKsVNPyK-AocWfnPhOpCEhoT2szNETrxIdup_LFka4eomKVJ1bb_gzDhoqls-ZG6mZRBT-iAi55OA6jNrT2B33FHtij9-DLeNuWoXd1pywCxwS85NkxPcOX-qhIIDQ=s2048

In this example, the Product entity now doesn’t need the extends keyword in the Inventory subgraph and no longer needs the @external directive for the id field.

Federation 2 adds Flexible type merging, which means that types no longer need to be identical across every subgraph. This means that incremental changes can often be added one subgraph at a time. The @shareable directive is required to indicate a field that can be resolved by multiple subgraphs. Federated types have improved shared ownership, meaning that fields can now exist in multiple subgraphs simultaneously, improving ease of ownership transfer from one subgraph to another.

node-graphql-2023-6 node-graphql-2023-7

Subgraph A initializes the entity definition of Book, while Subgraph B can now change some of the field types and even add new fields to it!

Other Notable Features Added:

Federation 2 included better error messages and can help catch more errors during build-time rather than runtime. Because it’s backward-compatible, you’ll see the error message improvements just by upgrading, even if you don’t opt-in for other Federation 2 features!

You now have the option to use either Apollo Router, which is written in Rust, or to use @apollo/gateway, which works with Apollo Server 4.

You can incrementally upgrade your subgraphs from 1.0 to 2.0 using Rover CLI and Apollo Studio, both providing tools to make the process as seamless as possible! Upgrading your federated graph from 1.0 to 2.0 can be easy as pressing one button in Apollo Studio! To use Apollo Federation 2.0, you will need to upgrade your @apollo/subgraph package to 2.x.x and @apollo/gateway to 2.x.x.

GraphQL upgraded packages in 2022 (and their dependencies)

Through this process, it may seem a bit daunting to upgrade to federation 2.0 to use the new features, but this is a short list of the new versions and their dependencies to help you upgrade your project (we would recommend upgrading your packages in this order):

Predictions for 2023

We believe that in terms of GraphQL, large-scale Apollo Federation 2.0 adoption will be the focus moving forward in this coming year. There are many big companies that will be in the process of moving to 2.0, and continuously addressing making changes to a global-scale federated Graph will be at the forefront of Apollo’s mind. Another useful feature that we think will get more support is the ability to create more powerful custom directives and a community consensus on how to build them.

Do you have Node.js and GraphQL Predictions for 2023?

We’d love to hear them! Join our Community Discord to talk tech with the Bitovi Community 🥚