Skip to content

Commit

Permalink
circle ci
Browse files Browse the repository at this point in the history
  • Loading branch information
vektah committed Feb 11, 2018
1 parent 8fa5f62 commit 951f41b
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 16 deletions.
19 changes: 19 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: 2
jobs:
build:
docker:
- image: golang:1.9
working_directory: /go/src/github.com/vektah/gqlgen
steps: &steps
- checkout
- run: >
curl -L -o /bin/dep https://github.com/golang/dep/releases/download/v0.4.1/dep-linux-amd64 &&
chmod +x /bin/dep &&
go get -u github.com/alecthomas/gometalinter &&
gometalinter --install &&
dep ensure --vendor-only
- run: go install -v .
- run: go generate ./... && if [[ $(git diff) ]] ; then echo "you need to run go generate" ; git diff ; exit 1 ; fi
- run: go vet ./...
- run: go test -race ./...
- run: gometalinter --disable gocyclo ./example
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/internal/tests/testdata/graphql-js
/vendor
2 changes: 1 addition & 1 deletion .gometalinter.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"PartitionStrategy": "packages"
}
},
"Disable": ["gas","golint","gocyclo"]
"Disable": ["gas","golint","gocyclo","goconst", "gotype"]
}
47 changes: 47 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[[constraint]]
branch = "master"
name = "github.com/mitchellh/mapstructure"

[[constraint]]
name = "github.com/stretchr/testify"
version = "1.2.1"

[[constraint]]
branch = "master"
name = "golang.org/x/tools"

[prune]
go-tests = true
unused-packages = true
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This is a library for quickly creating a strictly typed graphql servers in golan

#### Try it

Create a graphql schema somewhere
Define your schema first:
```graphql schema
schema {
query: Query
Expand Down Expand Up @@ -34,7 +34,7 @@ type User {
}
```

Then define your apps models somewhere:
Then define your models:
```go
package yourapp

Expand All @@ -51,7 +51,7 @@ type User struct {
}
```

Tell the generator how your types line up by creating a `types.json`
Tell the generator how to map between the two in `types.json`
```json
{
"Todo": "github.com/you/yourapp.Todo",
Expand All @@ -61,19 +61,19 @@ Tell the generator how your types line up by creating a `types.json`

Then generate the runtime from it:
```bash
gqlgen -schema schema.graphql -typemap types.json -out gen/generated.go
gqlgen -out generated.go
```

At the top of the generated file will be an interface with the resolvers that are required to complete the graph:
```go
package yourapp

type Resolvers interface {
Mutation_createTodo(ctx context.Context, text string) (readme.Todo, error)
Mutation_createTodo(ctx context.Context, text string) (Todo, error)

Query_todos(ctx context.Context) ([]readme.Todo, error)
Query_todos(ctx context.Context) ([]Todo, error)

Todo_user(ctx context.Context, it *readme.Todo) (readme.User, error)
Todo_user(ctx context.Context, it *Todo) (User, error)
}
```

Expand Down
4 changes: 3 additions & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ func (p *Client) Post(query string, response interface{}, options ...Option) err
if err != nil {
return fmt.Errorf("post: %s", err.Error())
}
defer rawResponse.Body.Close()
defer func() {
_ = rawResponse.Body.Close()
}()

if rawResponse.StatusCode >= http.StatusBadRequest {
responseBody, _ := ioutil.ReadAll(rawResponse.Body)
Expand Down
12 changes: 6 additions & 6 deletions example/dataloader/dataloaders.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ type loaders struct {

func LoaderMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
loaders := loaders{}
ldrs := loaders{}

// set this to zero what happens without dataloading
wait := 250 * time.Microsecond

// simple 1:1 loader, fetch an address by its primary key
loaders.addressByID = &AddressLoader{
ldrs.addressByID = &AddressLoader{
wait: wait,
maxBatch: 100,
fetch: func(keys []int) ([]*Address, []error) {
Expand All @@ -54,7 +54,7 @@ func LoaderMiddleware(next http.Handler) http.Handler {
}

// 1:M loader
loaders.ordersByCustomer = &OrderSliceLoader{
ldrs.ordersByCustomer = &OrderSliceLoader{
wait: wait,
maxBatch: 100,
fetch: func(keys []int) ([][]Order, []error) {
Expand All @@ -76,15 +76,15 @@ func LoaderMiddleware(next http.Handler) http.Handler {
}

// if you had another customer loader you would prime its cache here
// by calling `loaders.ordersByID.Prime(id, orders[i])`
// by calling `ldrs.ordersByID.Prime(id, orders[i])`
}

return orders, errors
},
}

// M:M loader
loaders.itemsByOrder = &ItemSliceLoader{
ldrs.itemsByOrder = &ItemSliceLoader{
wait: wait,
maxBatch: 100,
fetch: func(keys []int) ([][]Item, []error) {
Expand All @@ -109,7 +109,7 @@ func LoaderMiddleware(next http.Handler) http.Handler {
},
}

dlCtx := context.WithValue(r.Context(), ctxKey, loaders)
dlCtx := context.WithValue(r.Context(), ctxKey, ldrs)
next.ServeHTTP(w, r.WithContext(dlCtx))
})
}
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func main() {
_ = syscall.Unlink(*output)
}

if err := e.introspect(); err != nil {
if err = e.introspect(); err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
}
Expand Down

0 comments on commit 951f41b

Please sign in to comment.