Skip to content

Commit

Permalink
Rewrite paths and add readme
Browse files Browse the repository at this point in the history
  • Loading branch information
vektah committed Feb 3, 2018
1 parent b466370 commit 5a756bd
Show file tree
Hide file tree
Showing 24 changed files with 71 additions and 123 deletions.
56 changes: 2 additions & 54 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,57 +1,5 @@
# graphql-go

[![Sourcegraph](https://sourcegraph.com/github.com/neelance/graphql-go/-/badge.svg)](https://sourcegraph.com/github.com/neelance/graphql-go?badge)
[![Build Status](https://semaphoreci.com/api/v1/neelance/graphql-go/branches/master/badge.svg)](https://semaphoreci.com/neelance/graphql-go)
[![GoDoc](https://godoc.org/github.com/neelance/graphql-go?status.svg)](https://godoc.org/github.com/neelance/graphql-go)
The two main existing (github.com/neelance/graphql-go, github/com/graphql-go/graphql) graphql libraries are both very weaky typed and verbose.

## Status

The project is under heavy development. It is stable enough so we use it in production at [Sourcegraph](https://sourcegraph.com), but expect changes.

## Goals

* [ ] full support of [GraphQL spec (October 2016)](https://facebook.github.io/graphql/)
* [ ] propagation of `null` on resolver errors
* [x] everything else
* [x] minimal API
* [x] support for context.Context and OpenTracing
* [x] early error detection at application startup by type-checking if the given resolver matches the schema
* [x] 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)
* [x] nice errors on resolver validation
* [ ] nice errors on all invalid schemas
* [ ] nice errors on all invalid queries
* [x] panic handling (a panic in a resolver should not take down the whole app)
* [x] 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](https://golang.org/ref/spec#Exported_identifiers) 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](https://golang.org/ref/spec#Exported_identifiers) 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:

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

The following signature is also allowed:

```go
func (r *helloWorldResolver) Hello(ctx context.Context) (string, error) {
return "Hello world!", nil
}
```
This is an experiment to use go generate to create a server quickly and with type safety based on the neelance codebase.
6 changes: 3 additions & 3 deletions example/starwars/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"log"
"net/http"

"github.com/neelance/graphql-go"
"github.com/neelance/graphql-go/example/starwars"
"github.com/neelance/graphql-go/relay"
"github.com/vektah/graphql-go"
"github.com/vektah/graphql-go/example/starwars"
"github.com/vektah/graphql-go/relay"
)

var schema *graphql.Schema
Expand Down
2 changes: 1 addition & 1 deletion example/starwars/starwars.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strconv"
"strings"

graphql "github.com/neelance/graphql-go"
graphql "github.com/vektah/graphql-go"
)

var Schema = `
Expand Down
2 changes: 1 addition & 1 deletion gqltesting/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strconv"
"testing"

graphql "github.com/neelance/graphql-go"
graphql "github.com/vektah/graphql-go"
)

// Test is a GraphQL test case to be used with RunTest(s).
Expand Down
22 changes: 11 additions & 11 deletions graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ import (

"encoding/json"

"github.com/neelance/graphql-go/errors"
"github.com/neelance/graphql-go/internal/common"
"github.com/neelance/graphql-go/internal/exec"
"github.com/neelance/graphql-go/internal/exec/resolvable"
"github.com/neelance/graphql-go/internal/exec/selected"
"github.com/neelance/graphql-go/internal/query"
"github.com/neelance/graphql-go/internal/schema"
"github.com/neelance/graphql-go/internal/validation"
"github.com/neelance/graphql-go/introspection"
"github.com/neelance/graphql-go/log"
"github.com/neelance/graphql-go/trace"
"github.com/vektah/graphql-go/errors"
"github.com/vektah/graphql-go/internal/common"
"github.com/vektah/graphql-go/internal/exec"
"github.com/vektah/graphql-go/internal/exec/resolvable"
"github.com/vektah/graphql-go/internal/exec/selected"
"github.com/vektah/graphql-go/internal/query"
"github.com/vektah/graphql-go/internal/schema"
"github.com/vektah/graphql-go/internal/validation"
"github.com/vektah/graphql-go/introspection"
"github.com/vektah/graphql-go/log"
"github.com/vektah/graphql-go/trace"
)

// ParseSchema parses a GraphQL schema and attaches the given root resolver. It returns an error if
Expand Down
6 changes: 3 additions & 3 deletions graphql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"testing"
"time"

"github.com/neelance/graphql-go"
"github.com/neelance/graphql-go/example/starwars"
"github.com/neelance/graphql-go/gqltesting"
"github.com/vektah/graphql-go"
"github.com/vektah/graphql-go/example/starwars"
"github.com/vektah/graphql-go/gqltesting"
)

type helloWorldResolver1 struct{}
Expand Down
2 changes: 1 addition & 1 deletion internal/common/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"text/scanner"

"github.com/neelance/graphql-go/errors"
"github.com/vektah/graphql-go/errors"
)

type syntaxError string
Expand Down
2 changes: 1 addition & 1 deletion internal/common/literals.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strings"
"text/scanner"

"github.com/neelance/graphql-go/errors"
"github.com/vektah/graphql-go/errors"
)

type Literal interface {
Expand Down
2 changes: 1 addition & 1 deletion internal/common/types.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package common

import (
"github.com/neelance/graphql-go/errors"
"github.com/vektah/graphql-go/errors"
)

type Type interface {
Expand Down
2 changes: 1 addition & 1 deletion internal/common/values.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package common

import (
"github.com/neelance/graphql-go/errors"
"github.com/vektah/graphql-go/errors"
)

type InputValue struct {
Expand Down
16 changes: 8 additions & 8 deletions internal/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import (
"reflect"
"sync"

"github.com/neelance/graphql-go/errors"
"github.com/neelance/graphql-go/internal/common"
"github.com/neelance/graphql-go/internal/exec/resolvable"
"github.com/neelance/graphql-go/internal/exec/selected"
"github.com/neelance/graphql-go/internal/query"
"github.com/neelance/graphql-go/internal/schema"
"github.com/neelance/graphql-go/log"
"github.com/neelance/graphql-go/trace"
"github.com/vektah/graphql-go/errors"
"github.com/vektah/graphql-go/internal/common"
"github.com/vektah/graphql-go/internal/exec/resolvable"
"github.com/vektah/graphql-go/internal/exec/selected"
"github.com/vektah/graphql-go/internal/query"
"github.com/vektah/graphql-go/internal/schema"
"github.com/vektah/graphql-go/log"
"github.com/vektah/graphql-go/trace"
)

type Request struct {
Expand Down
6 changes: 3 additions & 3 deletions internal/exec/packer/packer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"reflect"
"strings"

"github.com/neelance/graphql-go/errors"
"github.com/neelance/graphql-go/internal/common"
"github.com/neelance/graphql-go/internal/schema"
"github.com/vektah/graphql-go/errors"
"github.com/vektah/graphql-go/internal/common"
"github.com/vektah/graphql-go/internal/schema"
)

type packer interface {
Expand Down
6 changes: 3 additions & 3 deletions internal/exec/resolvable/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"fmt"
"reflect"

"github.com/neelance/graphql-go/internal/common"
"github.com/neelance/graphql-go/internal/schema"
"github.com/neelance/graphql-go/introspection"
"github.com/vektah/graphql-go/internal/common"
"github.com/vektah/graphql-go/internal/schema"
"github.com/vektah/graphql-go/introspection"
)

var MetaSchema *Object
Expand Down
6 changes: 3 additions & 3 deletions internal/exec/resolvable/resolvable.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"reflect"
"strings"

"github.com/neelance/graphql-go/internal/common"
"github.com/neelance/graphql-go/internal/exec/packer"
"github.com/neelance/graphql-go/internal/schema"
"github.com/vektah/graphql-go/internal/common"
"github.com/vektah/graphql-go/internal/exec/packer"
"github.com/vektah/graphql-go/internal/schema"
)

type Schema struct {
Expand Down
14 changes: 7 additions & 7 deletions internal/exec/selected/selected.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import (
"reflect"
"sync"

"github.com/neelance/graphql-go/errors"
"github.com/neelance/graphql-go/internal/common"
"github.com/neelance/graphql-go/internal/exec/packer"
"github.com/neelance/graphql-go/internal/exec/resolvable"
"github.com/neelance/graphql-go/internal/query"
"github.com/neelance/graphql-go/internal/schema"
"github.com/neelance/graphql-go/introspection"
"github.com/vektah/graphql-go/errors"
"github.com/vektah/graphql-go/internal/common"
"github.com/vektah/graphql-go/internal/exec/packer"
"github.com/vektah/graphql-go/internal/exec/resolvable"
"github.com/vektah/graphql-go/internal/query"
"github.com/vektah/graphql-go/internal/schema"
"github.com/vektah/graphql-go/introspection"
)

type Request struct {
Expand Down
4 changes: 2 additions & 2 deletions internal/query/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"strings"
"text/scanner"

"github.com/neelance/graphql-go/errors"
"github.com/neelance/graphql-go/internal/common"
"github.com/vektah/graphql-go/errors"
"github.com/vektah/graphql-go/internal/common"
)

type Document struct {
Expand Down
4 changes: 2 additions & 2 deletions internal/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"strings"
"text/scanner"

"github.com/neelance/graphql-go/errors"
"github.com/neelance/graphql-go/internal/common"
"github.com/vektah/graphql-go/errors"
"github.com/vektah/graphql-go/internal/common"
)

type Schema struct {
Expand Down
8 changes: 4 additions & 4 deletions internal/tests/all_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (

"encoding/json"

"github.com/neelance/graphql-go/errors"
"github.com/neelance/graphql-go/internal/query"
"github.com/neelance/graphql-go/internal/schema"
"github.com/neelance/graphql-go/internal/validation"
"github.com/vektah/graphql-go/errors"
"github.com/vektah/graphql-go/internal/query"
"github.com/vektah/graphql-go/internal/schema"
"github.com/vektah/graphql-go/internal/validation"
)

type Test struct {
Expand Down
8 changes: 4 additions & 4 deletions internal/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
"strings"
"text/scanner"

"github.com/neelance/graphql-go/errors"
"github.com/neelance/graphql-go/internal/common"
"github.com/neelance/graphql-go/internal/query"
"github.com/neelance/graphql-go/internal/schema"
"github.com/vektah/graphql-go/errors"
"github.com/vektah/graphql-go/internal/common"
"github.com/vektah/graphql-go/internal/query"
"github.com/vektah/graphql-go/internal/schema"
)

type varSet map[*common.InputValue]struct{}
Expand Down
4 changes: 2 additions & 2 deletions introspection.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"context"
"encoding/json"

"github.com/neelance/graphql-go/internal/exec/resolvable"
"github.com/neelance/graphql-go/introspection"
"github.com/vektah/graphql-go/internal/exec/resolvable"
"github.com/vektah/graphql-go/introspection"
)

// Inspect allows inspection of the given schema.
Expand Down
4 changes: 2 additions & 2 deletions introspection/introspection.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package introspection
import (
"sort"

"github.com/neelance/graphql-go/internal/common"
"github.com/neelance/graphql-go/internal/schema"
"github.com/vektah/graphql-go/internal/common"
"github.com/vektah/graphql-go/internal/schema"
)

type Schema struct {
Expand Down
2 changes: 1 addition & 1 deletion relay/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"net/http"
"strings"

graphql "github.com/neelance/graphql-go"
graphql "github.com/vektah/graphql-go"
)

func MarshalID(kind string, spec interface{}) graphql.ID {
Expand Down
6 changes: 3 additions & 3 deletions relay/relay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"strings"
"testing"

"github.com/neelance/graphql-go"
"github.com/neelance/graphql-go/example/starwars"
"github.com/neelance/graphql-go/relay"
"github.com/vektah/graphql-go"
"github.com/vektah/graphql-go/example/starwars"
"github.com/vektah/graphql-go/relay"
)

var starwarsSchema = graphql.MustParseSchema(starwars.Schema, &starwars.Resolver{})
Expand Down
4 changes: 2 additions & 2 deletions trace/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"context"
"fmt"

"github.com/neelance/graphql-go/errors"
"github.com/neelance/graphql-go/introspection"
"github.com/vektah/graphql-go/errors"
"github.com/vektah/graphql-go/introspection"
opentracing "github.com/opentracing/opentracing-go"
"github.com/opentracing/opentracing-go/ext"
"github.com/opentracing/opentracing-go/log"
Expand Down

0 comments on commit 5a756bd

Please sign in to comment.