Announcing GraphQL Yoga v3
After months of experimentation and learning from production use cases we are back again with a ground breaking release for GraphQL Yoga.
The Yoga V3 Experience
The goal with Yoga is to empower developers, improve the developer facing API and make caching, security and real-time easy and run anywhere. Let’s highlight some of the groundbreaking new features and improvements.
One Package, Runs Everywhere
From GraphQL Yoga v2 we figure that using the fetch
API as standard is the way to go. Now GraphQL
Yoga has a single NPM package for all environments graphql-yoga
instead of @graphql-yoga/common
and @graphql-yoga/node
. We
created a library that lets you create cross-platform HTTP servers which
GraphQL Yoga v3 uses under the hood.
The Makeover
GraphQL Yoga v3 comes with the brand new GraphiQL 2.0.
The development of GraphiQL 2.0 has been a long ongoing process and we are so happy to finally replace the outdated and old-fashioned GraphiQL IDE with the new fancy and snappy version 2.
Thanks to all parties involved that made this happen.
100% Compliant
As of today, GraphQL Yoga is the only GraphQL server in the JavaScript ecosystem that fully satisfies all mandatory and optional sections of the GraphQL over HTTP specification.
Name | Mandatory ✅ | Optional ⚠️ | Errors ❌ |
---|---|---|---|
graphql-yoga | 72 | 0 | 0 |
apollo-server@4.1.1 | 36 | 37 | 0 |
mercurius@11.3.0 | 43 | 30 | 0 |
express-graphql@0.12.0 | 38 | 35 | 0 |
graphql-helix@1.13.0 | 39 | 32 | 2 |
Yoga as a Gateway
The ease of using GraphQL Yoga anywhere and performance make it a great candidate to run as a gateway. Yoga is compliant with Apollo Federation spec, so you can use it for federated services as your Supergraph and/or as your Subgraph.
Defer and Stream Support
In
Yoga v2 we added support for @defer
and @stream
but it was not simple for users to use it, they had to deal with multiple versions of GraphQL.js
which is not easy thing to do.
For GraphQL Yoga v3 we created a custom execution engine (more detailed information and insights on that soon!) and you can simply enable powerful features like defer and stream by using a Yoga plugin.
import { createServer } from 'node:http'
import { createYoga } from 'graphql-yoga'
import { useDeferStream } from '@graphql-yoga/plugin-defer-stream'
import { schema } from './schema.js'
const yoga = createYoga({
schema,
plugins: [useDeferStream()]
})
const server = createServer(yoga)
server.listen(4000, () => {
console.info('Server is running on http://localhost:4000/graphql')
})
Not Only GraphQL but Also REST
There are many reasons why one would want a REST endpoint. The Sofa API plugin makes it easy to convert any GraphQL API to REST API and in Yoga v3.
import { createServer } from 'node:http'
import { createYoga } from 'graphql-yoga'
import { useSofaWithSwaggerUI } from '@graphql-yoga/plugin-sofa'
import { schema } from './schema.js'
export const yoga = createYoga({
schema,
plugins: [
useSofaWithSwaggerUI({
basePath: '/rest',
swaggerUIEndpoint: '/swagger',
servers: [
{
url: '/', // Specify Server's URL.
description: 'Development server'
}
],
info: {
title: 'Example API',
version: '1.0.0'
}
})
]
})
const server = createServer(yoga)
server.listen(4000, () => {
console.info('Server is running on http://localhost:4000/graphql')
})
Response Caching
We now have a dedicated response caching plugin that can help reducing server load by caching GraphQL Query operation execution results.
GraphQL Subscriptions
GraphQL Yoga supports GraphQL subscriptions over Server Sent Events (SSE). Executing an operation is a s simple as sending an HTTP request and does not require any additional complex protocol or libraries on the frontend. For convenience, we offer an optional client package for both Apollo Client and Urql for easily connecting to the server.
Request Batching
GraphQL Yoga v3 supports request batching out of the box. While we do not recommend using request batching for new projects, we know that there are many existing projects that use it, and we want to make it easy for them to migrate to Yoga.
File Uploads
Sometimes it is handy to directly upload and process a file on your GraphQL server. Yoga does not stop you from doing so and even better does not require any complicated setup.
What Is Next?
We want you to leverage all the GraphQL ecosystem by being compatible with most of the existing schema-design, HTTP server libraries, and deployment environments. There are many more features so don’t forget to check those out https://the-guild.dev/graphql/yoga-server/docs
We have migration guide try it out! We can’t wait answer your questions and get your feedback on how we can make GraphQL Yoga even more better!
Don’t hesitate to reach out to us on Twitter and support us by sharing this article!
Join our newsletter
Want to hear from us when there's something new?
Sign up and stay up to date!
*By subscribing, you agree with Beehiiv’s Terms of Service and Privacy Policy.