GraphQL in 2023 - Still Relevant?

Rate this content
Bookmark
Slides
GraphQL in 2023 remains relevant with features like GraphQL Federation, which allows combining multiple GraphQL graphs into one super graph. This reduces the need for extensive team coordination and aids in schema evolution. The video discusses the benefits of GraphQL Federation and how it helps in creating a unified schema for data integration. It also highlights the use of Wegger UI and tRPC for easier schema exploration and type safety. Developers can benefit from GraphQL's normalized cache, like Apollo's in-memory cache, to reduce data redundancy and improve data integrity. The defer directive is another feature that allows receiving data incrementally, enhancing performance. The video compares data fetching between REST and GraphQL, emphasizing how GraphQL helps in avoiding overfetching and reducing wasted bytes. It also covers how GraphQL's fragment co-location enables reusable components with specific data needs and how parent components can render child components without knowing their data requirements. Lastly, the video mentions the use of mutations to update data, such as changing a username, and how these updates are reflected across the application.

From Author:

With fetching libraries like TanStack Query, swr, or RTK Query becoming more widespread, some of the immediate “selling points” of GraphQL clients seem to be less unique - so it might be a good idea to take a step back and ask the question “is this even still relevant?”. And to already take the answer away - it is “yes”. The unique selling points of GraphQL go far beyond having a smooth data fetching experience by solving many inter-team and architectural problems. While it might not always be immediately evident as a benefit for us as Frontend Developers,  GraphQL gives us a lot of freedom and makes us less dependent on backend teams implementing a Backend-for-the-frontend for us. Also, while data-fetching libraries have made it a lot easier to work with REST nowadays, GraphQL still has properties that are just not present in traditional REST APIs, and on top of that GraphQL has kept evolving. New directives like @live or @defer enable developers to create a fantastic user experience with very little work - especially when combined with React’s new suspense features.

This talk has been presented at React Summit 2023, check out the latest edition of this React Conference.

Watch video on a separate page

FAQ

Yes, GraphQL remains relevant in 2023, offering unique benefits like normalized caching, fragment co-location, query composition, and the deferred directive, which continue to distinguish it in the field of API technologies.

Reasons to choose GraphQL include its ability to fetch only the needed data, use a single endpoint for requests, and facilitate easier data integration across different services using GraphQL Federation.

Yes, while GraphQL initially stood out for reducing boilerplate code, its primary advantage now lies in features like type-safe data fetching and the ability to precisely request and combine data from various resources.

GraphQL is beneficial for mobile applications as it allows developers to request exactly the necessary data, reducing bandwidth usage and improving mobile data transfer efficiency.

GraphQL enhances integration by providing a consistent, language-agnostic schema across frontend and backend, which simplifies development and maintains type safety across different programming environments.

GraphQL Federation is a feature that allows multiple GraphQL services to be combined into a single data graph, facilitating seamless access to a unified API without extensive inter-service communication.

Yes, GraphQL can minimize the need for specific BFF architectures by allowing frontend developers to fetch data directly from a unified GraphQL API, reducing dependencies on backend changes for frontend adjustments.

The defer directive in GraphQL allows developers to defer loading parts of a query until later, enabling faster initial data loading and improving user experience by streaming non-critical data as it becomes available.

Lenz Weber-Tronic
Lenz Weber-Tronic
Jerel Miller
Jerel Miller
24 min
06 Jun, 2023

Comments

Sign in or register to post your comment.

Video Transcription

1. Is GraphQL Still Relevant in 2023?

Short description:

Today, we're going to talk about whether GraphQL is still relevant in 2023. We'll cover reasons to use GraphQL and discuss the growth of the ecosystem. The biggest selling point of GraphQL used to be boilerplate, but that's not the case anymore. Another selling point is its language-agnostic contract.

Hey, there. Today, we're going to talk about the question if GraphQL is still relevant in the year 2023.

First, a few words about us. That's me. My name is Lenzi Wirtronics. I'm a Senior Staff Software Engineer at Apollo GraphQL. That means I'm a maintainer of Apollo Client. I'm the author of RTK Query. I'm a Redux 2 co-maintainer, and I'm one of those ADHD persons with a million weird hobbies. And I'm just saying that because I think as a person with ADHD in our industry, we need representation. And that's what I'm here for. You can find me on GitHub as franiris, on Twitter on fry, or on mastodon as franiris at chaos.social.

I'm today joined by my colleague, Gerald, who will be introducing himself. Thanks, Lenz. My name is Gerald Miller, and I'm a Principle Software Engineer at Apollo. I work alongside Lenz as a maintainer of the Apollo Client Library. You can find me both on Twitter and GitHub under my handle geraldmiller. And with that, we start into the talk.

First, let's talk about why we wanted to do this talk. A lot of times people are getting into Graph QL for reasons that might not be unique to Graph QL nowadays. There are very good reasons to still use Graph QL, and we're also going to cover those. But first, we're going to cover where the ecosystem has grown up, and maybe you don't need to go for Graph QL to get those benefits. Because honestly, while I work at Apollo, and I'm happy for everyone out there who is using Graph QL, I also don't want people to use Graph QL for the wrong reasons and get frustrated with it.

So the biggest selling point of Graph QL back in the day was boilerplate, because what you're seeing right now is the amount of code that was necessary to catch data from an API and Redux. And if you compare that to the amount of code that was necessary in Apollo Client to do the same thing, there's a striking difference. But this selling point isn't really true anymore nowadays. Because if you compare this to how it's done in Redux today and that's all the code you get a hook for it, or how it would be done in TANStackQuery, which is also known as ReactQuery, there's not so much of a difference. So this wouldn't be one of those reasons where I say, yeah, you have to use Graph QL just for this. Another very big selling point of Graph QL was also that you had this language-agnostic contract. So you could use it in the front end and in the back end, and everything was type safe and you could use it with TypeScript or JavaScript or Go or Java.

2. Exploring GraphQL Benefits

Short description:

With GraphQL, you can explore the schema, add fields, and see the results. Tools like Wegger UI and tRPC make exploration and type safety easier. Code generation in GraphQL provides types for queries. Open API specifications can be used with REST APIs. Alternatives to GraphQL should be considered, but it still has unique benefits.

And yeah, that's true, but never was really unique. There was stuff like SOAP, the old among us might remember, or the Swagger specification, which over time has been renamed, has become the open API specification and is something that nowadays is very common and most services can just auto-generate it for you.

With such a schema or specification in place, we can look at exploring it. This was magic for me when I started using Graph QL, like just clicking through the whole schema, having documentation everywhere, just being able to add fields and send off requests and seeing all of that come back. For example, there's Wegger UI, which lets you do the same and it might not let you combine different results, but you can explore everything. You can read the documentation that's embedded. You already see what will be coming back. This is an amazing tool.

Also, if you're just using TypeScript in your backend and your frontend, and you happen to use a monorepo, you could use something like tRPC to make RPC calls between your frontend and your backend, that are just perfectly type safe and super easy to explore because you have autocomplete in your browser. This stuff will become even more common once we start adopting React Server Component. Another big benefit would be code generation. In GraphQL, you just write your query out and from that, the GraphQL code generator in the past would have generated a hook or nowadays, it just annotates your query with types and everywhere you use that query, you will have all the types at your fingertips. But of course, that's possible within REST API as well. If you have that open API specification, you can use the RTK Query OpenAPI CodeChain to get the RTK query endpoints. Generated for you, or you use Orble, which will generate all the code you need, for example, for react query or also for SWR. So going from here, if these are all the benefits that you would personally see from using something like GraphQL, you might want to consider alternatives. But of course, GraphQL still has very unique benefits, and that's what we're going to talk about in the next part.