Skip to content
GraphQL server package for Go with a focus on simplicity and efficiency
Go
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github/workflows
.vscode
graphql
graphqlhttp
internal/gqlang
.gitignore
CHANGELOG.md
CODE_OF_CONDUCT.md
CONTRIBUTING.md
LICENSE
README.md
go.mod
go.sum

README.md

@zombiezen's GraphQL Go Server

GoDoc

This repository contains Go packages for creating a GraphQL server. The primary focus is on simplicity and efficiency of the server endpoints.

This library is pre-1.0, so there may still be API changes. You can find known issues about compliance to the specification or production-readiness in the issue tracker.

Getting Started

go get zombiezen.com/go/graphql-server/graphql

Then, look at the main package example for how to write a server type and the graphqlhttp package example for how to start serving over HTTP.

Comparison With Other Libraries

A quick look at the official GraphQL libraries for Go may leave you wondering, "why another server library?" Simply, @zombiezen hit roadblocks to writing apps with other libraries and wanted to try a different API approach.

This library intentionally focuses on:

github.com/graphql-go/graphql

github.com/graphql-go/graphql follows the graphql-js reference implementation, basically replicating its API verbatim. Unfortunately, this leads to a fairly verbose approach to defining the server's schema in code rather than the GraphQL IDL. Further, while you can do limited look-ahead of output selection sets via ResolveInfo, this only returns the ASTs and requires the caller to interpret the fragments themselves (graphql-go/graphql#157). The library also doesn't provide any out-of-the-box utilities for serving over HTTP.

github.com/graph-gophers/graphql-go

@zombiezen very much liked the approach that github.com/graph-gophers/graphql-go took toward the problem: it uses the IDL and the Go type system rather than a large package-specific data structure. This results in a small ramp-up time and application code that is fairly straightforward to follow.

However, the library has a few issues. It does not support look-ahead at all (graph-gophers/graphql-go#17). The API conflates schema parsing with server object binding (i.e. graphql.ParseSchema takes a resolver), so many servers end up passing dependencies through the Context. The library makes it difficult to test servers that use it, since its responses are always JSON-formatted, which makes it hard to compare specific fields. While JSON is a common serialization format used with GraphQL, the spec permits any serialization.

License

Apache 2.0

You can’t perform that action at this time.