plugeth/vendor/github.com/graph-gophers/graphql-go
Kris Shinn f91312dbdb GraphQL master FF for review (#18445)
* Initial work on a graphql API

* Added receipts, and more transaction fields.

* Finish receipts, add logs

* Add transactionCount to block

* Add types  and .

* Update Block type to be compatible with ethql

* Rename nonce to transactionCount in Account, to be compatible with ethql

* Update transaction, receipt and log to match ethql

* Add  query operator, for a range of blocks

* Added ommerCount to Block

* Add transactionAt and ommerAt to Block

* Added sendRawTransaction mutation

* Add Call and EstimateGas to graphQL API

* Refactored to use hexutil.Bytes instead of HexBytes

* Replace BigNum with hexutil.Big

* Refactor call and estimateGas to use ethapi struct type

* Replace ethgraphql.Address with common.Address

* Replace ethgraphql.Hash with common.Hash

* Converted most quantities to Long instead of Int

* Add support for logs

* Fix bug in runFilter

* Restructured Transaction to work primarily with headers, so uncle data is reported properly

* Add gasPrice API

* Add protocolVersion API

* Add syncing API

* Moved schema into its own source file

* Move some single use args types into anonymous structs

* Add doc-comments

* Fixed backend fetching to use context

* Added (very) basic tests

* Add documentation to the graphql schema

* Fix reversion for formatting of big numbers

* Correct spelling error

* s/BigInt/Long/

* Update common/types.go

* Fixes in response to review

* Fix lint error

* Updated calls on private functions

* Fix typo in graphql.go

* Rollback ethapi breaking changes for graphql support
Co-Authored-By: Arachnid <arachnid@notdot.net>
2019-01-21 15:38:13 +01:00
..
errors GraphQL master FF for review (#18445) 2019-01-21 15:38:13 +01:00
internal GraphQL master FF for review (#18445) 2019-01-21 15:38:13 +01:00
introspection GraphQL master FF for review (#18445) 2019-01-21 15:38:13 +01:00
log GraphQL master FF for review (#18445) 2019-01-21 15:38:13 +01:00
relay GraphQL master FF for review (#18445) 2019-01-21 15:38:13 +01:00
trace GraphQL master FF for review (#18445) 2019-01-21 15:38:13 +01:00
Gopkg.lock GraphQL master FF for review (#18445) 2019-01-21 15:38:13 +01:00
Gopkg.toml GraphQL master FF for review (#18445) 2019-01-21 15:38:13 +01:00
graphql.go GraphQL master FF for review (#18445) 2019-01-21 15:38:13 +01:00
id.go GraphQL master FF for review (#18445) 2019-01-21 15:38:13 +01:00
introspection.go GraphQL master FF for review (#18445) 2019-01-21 15:38:13 +01:00
LICENSE GraphQL master FF for review (#18445) 2019-01-21 15:38:13 +01:00
README.md GraphQL master FF for review (#18445) 2019-01-21 15:38:13 +01:00
time.go GraphQL master FF for review (#18445) 2019-01-21 15:38:13 +01:00

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

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 := `
                schema {
                        query: Query
                }
                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 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 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
}

Community Examples

tonyghita/graphql-go-example - A more "productionized" version of the Star Wars API example given in this repository.

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 authentication