Coder Social home page Coder Social logo

graphql-go's Introduction

graphql-go

Sourcegraph Build Status GoDoc

Status

Update: March 1, 2018

This project has transferred ownership from github.com/neelance/graphql-go to github.com/nathanburkett/graphql-go, which will enable us to maintain and evolve the library @neelance created, and let him focus on WebAssembly / Go development.

I'm super grateful to @neelance for all his work blazing the trail with graphql-go, and I'm ecstatic to work with the community to continue improving this library.

I'm going to help address issues, review and merge changes, and continue development with the same ethos as we started.

The immediate goal remains—full support of the GraphQL specification.

  • Tony (@tonyghita)

The project is under heavy development. It is stable enough so we use it in production at Sourcegraph, but expect changes.

Goals

  • full support of GraphQL spec (October 2016)
    • propagation of null on resolver errors
    • everything else
  • minimal API
  • support for context.Context and OpenTracing
  • early error detection at application startup by type-checking if the given resolver matches the schema
  • resolvers are purely based on method sets (e.g. it's up to you if you want to resolve a GraphQL interface with a Go interface or a Go struct)
  • nice error messages (no internal panics, even with an invalid schema or resolver; please file a bug if you see an internal panic)
    • nice errors on resolver validation
    • nice errors on all invalid schemas
    • nice errors on all invalid queries
  • panic handling (a panic in a resolver should not take down the whole app)
  • parallel execution of resolvers

(Some) Documentation

Resolvers

A resolver must have one method for each field of the GraphQL type it resolves. The method name has to be exported and match the field's name in a non-case-sensitive way.

The method has up to three 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.
  • Optional []selected.SelectedField argument to receive the tree of selected subfields in the GraphQL query (useful for preloading of database relations)

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
}

Community Examples

tonyghita/graphql-go-example

deltaskelta/graphql-go-pets-example - graphql-go resolving against a sqlite database

OscarYuen/go-graphql-starter - a starter application integrated with dataloader, psql and basic authenication

graphql-go's People

Contributors

neelance avatar tonyghita avatar xmirya avatar oscaryuen avatar caseymrm avatar dvic avatar amozoss avatar darh avatar fugitech avatar iandelahorne avatar jeffwillette avatar jargv avatar keegancsmith avatar nathanburkett avatar nicksrandall avatar rxminus avatar shnellpavel avatar kmarquardsen avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.