All Projects → graph-gophers → Graphql Go

graph-gophers / Graphql Go

Licence: bsd-2-clause
GraphQL server with a focus on ease of use

Programming Languages

go
31211 projects - #10 most used programming language
shell
77523 projects

Labels

Projects that are alternatives of or similar to Graphql Go

Responder
A familiar HTTP Service Framework for Python.
Stars: ✭ 3,569 (-10.73%)
Mutual labels:  graphql
Wp Graphql Acf
WPGraphQL for Advanced Custom Fields
Stars: ✭ 358 (-91.05%)
Mutual labels:  graphql
Django Api Domains
A pragmatic styleguide for Django API Projects
Stars: ✭ 365 (-90.87%)
Mutual labels:  graphql
Spikenail
A GraphQL Framework for Node.js
Stars: ✭ 358 (-91.05%)
Mutual labels:  graphql
Vim Graphql
A Vim plugin that provides GraphQL file detection, syntax highlighting, and indentation.
Stars: ✭ 357 (-91.07%)
Mutual labels:  graphql
Re Graph
A graphql client for clojurescript and clojure
Stars: ✭ 366 (-90.85%)
Mutual labels:  graphql
Graphene Django Extras
Extras functionalities for Graphene-Django
Stars: ✭ 356 (-91.1%)
Mutual labels:  graphql
Firestore Apollo Graphql
An example of a GraphQL setup with a Firebase Firestore backend. Uses Apollo Engine/Server 2.0 and deployed to Google App Engine.
Stars: ✭ 371 (-90.72%)
Mutual labels:  graphql
Yuna
ツ An anime player that integrates with AniList, Simkl, Crunchyroll, and Hidive.
Stars: ✭ 361 (-90.97%)
Mutual labels:  graphql
Juniper
GraphQL server library for Rust
Stars: ✭ 4,187 (+4.73%)
Mutual labels:  graphql
Stargate
An open source data gateway
Stars: ✭ 356 (-91.1%)
Mutual labels:  graphql
Apollo Upload Examples
A full stack demo of file uploads via GraphQL mutations using Apollo Server and apollo-upload-client.
Stars: ✭ 358 (-91.05%)
Mutual labels:  graphql
Java Dataloader
A Java 8 port of Facebook DataLoader
Stars: ✭ 367 (-90.82%)
Mutual labels:  graphql
Pupilfirst
A learning management system (LMS) that lets you run an asynchronous online school, where learning is achieved through focused tasks, directed feedback, an iterative workflow, and community interaction.
Stars: ✭ 357 (-91.07%)
Mutual labels:  graphql
Graphqlite
Use PHP Annotations to declare your GraphQL API
Stars: ✭ 370 (-90.75%)
Mutual labels:  graphql
Aws Appsync Community
The AWS AppSync community
Stars: ✭ 356 (-91.1%)
Mutual labels:  graphql
Graphql Binding
Auto-generated SDK for your GraphQL API (supports schema stitching & codegen)
Stars: ✭ 367 (-90.82%)
Mutual labels:  graphql
Graphql Auto Generating Cms
Use your existing graphQL schema to generate CMS in a couple steps. DEMO: http://cms-demo.web4fly.com/
Stars: ✭ 373 (-90.67%)
Mutual labels:  graphql
Bootcamp 2020
Learn to Build Modern Full Stack Serverless Multi-Tenant SaaS Apps and APIs
Stars: ✭ 369 (-90.77%)
Mutual labels:  graphql
Introspected Rest
An alternative to REST and GraphQL
Stars: ✭ 368 (-90.8%)
Mutual labels:  graphql

graphql-go Sourcegraph Build Status GoDoc

The goal of this project is to provide full support of the GraphQL draft specification with a set of idiomatic, easy to use Go packages.

While still under heavy development (internal APIs are almost certainly subject to change), this library is safe for production use.

Features

  • minimal API
  • support for context.Context
  • support for the OpenTracing standard
  • schema type-checking against resolvers
  • resolvers are matched to the schema based on method sets (can resolve a GraphQL schema with a Go interface or Go struct).
  • handles panics in resolvers
  • parallel execution of resolvers
  • subscriptions

Roadmap

We're trying out the GitHub Project feature to manage graphql-go's development roadmap. Feedback is welcome and appreciated.

(Some) Documentation

Basic Sample

package main

import (
        "log"
        "net/http"

        graphql "github.com/graph-gophers/graphql-go"
        "github.com/graph-gophers/graphql-go/relay"
)

type query struct{}

func (_ *query) Hello() string { return "Hello, world!" }

func main() {
        s := `
                type Query {
                        hello: String!
                }
        `
        schema := graphql.MustParseSchema(s, &query{})
        http.Handle("/query", &relay.Handler{Schema: schema})
        log.Fatal(http.ListenAndServe(":8080", nil))
}

To test:

curl -XPOST -d '{"query": "{ hello }"}' localhost:8080/query

Resolvers

A resolver must have one method or field for each field of the GraphQL type it resolves. The method or field name has to be exported and match the schema's field's name in a non-case-sensitive way. You can use struct fields as resolvers by using SchemaOpt: UseFieldResolvers(). For example,

opts := []graphql.SchemaOpt{graphql.UseFieldResolvers()}
schema := graphql.MustParseSchema(s, &query{}, opts...)

When using UseFieldResolvers schema option, a struct field will be used only when:

  • there is no method for a struct field
  • a struct field does not implement an interface method
  • a struct field does not have arguments

The method has up to two arguments:

  • Optional context.Context argument.
  • Mandatory *struct { ... } argument if the corresponding GraphQL field has arguments. The names of the struct fields have to be exported and have to match the names of the GraphQL arguments in a non-case-sensitive way.

The method has up to two results:

  • The GraphQL field's value as determined by the resolver.
  • Optional error result.

Example for a simple resolver method:

func (r *helloWorldResolver) Hello() string {
	return "Hello world!"
}

The following signature is also allowed:

func (r *helloWorldResolver) Hello(ctx context.Context) (string, error) {
	return "Hello world!", nil
}

Schema Options

  • UseStringDescriptions() enables the usage of double quoted and triple quoted. When this is not enabled, comments are parsed as descriptions instead.
  • UseFieldResolvers() specifies whether to use struct field resolvers.
  • MaxDepth(n int) specifies the maximum field nesting depth in a query. The default is 0 which disables max depth checking.
  • MaxParallelism(n int) specifies the maximum number of resolvers per request allowed to run in parallel. The default is 10.
  • Tracer(tracer trace.Tracer) is used to trace queries and fields. It defaults to trace.OpenTracingTracer.
  • ValidationTracer(tracer trace.ValidationTracer) is used to trace validation errors. It defaults to trace.NoopValidationTracer.
  • Logger(logger log.Logger) is used to log panics during query execution. It defaults to exec.DefaultLogger.
  • PanicHandler(panicHandler errors.PanicHandler) is used to transform panics into errors during query execution. It defaults to errors.DefaultPanicHandler.
  • DisableIntrospection() disables introspection queries.

Custom Errors

Errors returned by resolvers can include custom extensions by implementing the ResolverError interface:

type ResolverError interface {
	error
	Extensions() map[string]interface{}
}

Example of a simple custom error:

type droidNotFoundError struct {
	Code    string `json:"code"`
	Message string `json:"message"`
}

func (e droidNotFoundError) Error() string {
	return fmt.Sprintf("error [%s]: %s", e.Code, e.Message)
}

func (e droidNotFoundError) Extensions() map[string]interface{} {
	return map[string]interface{}{
		"code":    e.Code,
		"message": e.Message,
	}
}

Which could produce a GraphQL error such as:

{
  "errors": [
    {
      "message": "error [NotFound]: This is not the droid you are looking for",
      "path": [
        "droid"
      ],
      "extensions": {
        "code": "NotFound",
        "message": "This is not the droid you are looking for"
      }
    }
  ],
  "data": null
}

Examples

Companies that use this library

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].