Libraries & Frameworks
There are several tools that help you in building a GraphQL gateway server. In this section, an overview of the avaialble libraries and their specific purpose is provided.
graphql-yoga
graphql-yoga
is a simple GraphQL server based on various other libraries like express
, graphql-tools
, apollo-server
, graphql-subscriptions
and more.
Its main goal is to provide a convenience API for creating GraphQL servers by choosing sensible defaults for the underlying configuration.
The main features of graphql-yoga
are:
- Miminal and easy setup (no other dependencies required)
- Built-in subscription support for realtime functionality
- Integrates by default with graphql-playground
- Out-of-the-box support for Apollo Tracing
This is what a simple setup looks like:
import { GraphQLServer } from 'graphql-yoga'
// ... or using `require()`
// const { GraphQLServer } = require('graphql-yoga')
const typeDefs = `
type Query {
hello(name: String): String!
}
`
const resolvers = {
Query: {
hello: (_, { name }) => `Hello ${name || 'World'}`,
},
}
const server = new GraphQLServer({ typeDefs, resolvers })
server.start(() => console.log('Server is running on localhost:3000'))
You can find a number of examples in the GitHub repository.
graphql-tools
graphql-tools
is a library offering a variety of functionality around building GraphQL servers. It has three main features:
- Generate a
GraphQLSchema
based on the GraphQL SDL - Easy mocking of GraphQL APIs
- An API for schema stitching based on
mergeSchemas
graphql-remote
graphql-remote
is a toolbelt for creating remote GraphQL schemas with built-in subscriptions and DataLoader
support. This is particularly helpful in the context of schema stitching.
Qewl
Qewl is a GraphQL Application Framework. It is inspired by Koa, built on Apollo Server, and turns your GraphQL endpoint into a Koa-like application, with support for context, middleware, and many other features.
It is great for setting up an API gateway on top of existing GraphQL endpoints, applying concepts like remote schemas and schema stitching. But it also makes it very easy to set up a GraphQL server from scratch.
GrAMPS
GrAMPS (short for GraphQL Apollo Microservice Pattern Server) is a thin layer of helper tools designed for the Apollo GraphQL server that allows independent data sources — a schema, resolvers, and data access model — to be composed into a single GraphQL schema, while keeping the code within each data source isolated, independently testable, and completely decoupled from the rest of your application.
Read more in the documentation.