Skip to content

Commit

Permalink
generates something mostly plausiblegit add .
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminjkraft committed Dec 24, 2019
1 parent 7a20e2a commit e8b5ccb
Show file tree
Hide file tree
Showing 8 changed files with 23,487 additions and 17 deletions.
1 change: 1 addition & 0 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ Config options:

Misc:
- replace __ with some unicode garbage
- handle graphql errors in a reasonable way
7 changes: 7 additions & 0 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Generate the schemas by getting a token from [GitHub](https://github.com/settings/tokens/new) (no scopes needed), then:
```
npm install -g graphql-introspection-json-to-sdl
curl -H "Authorization: bearer <your token>" https://api.github.com/graphql >example/schema.json
graphql-introspection-json-to-sdl example/schema.json >example/schema.graphql
```
TODO: something better
17 changes: 13 additions & 4 deletions example/generate_me.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import (
"io/ioutil"
"net/http"
"strings"

"github.com/vektah/gqlparser/gqlerror"
)

type GetViewerResponse = struct {
Viewer struct {
Name string `json:"name"`
} `json:"viewer"`
Name *string
}
}

// GetViewer gets the current user's name.
Expand Down Expand Up @@ -42,11 +44,18 @@ query GetViewer {
return nil, err
}

retval := GetViewerResponse{}
var retval struct {
Data GetViewerResponse `json:"data"`
Errors gqlerror.List `json:"errors"`
}
err = json.Unmarshal(body, &retval)
if err != nil {
return nil, err
}

return &retval, nil
if len(retval.Errors) > 0 {
return nil, retval.Errors
}

return &retval.Data, nil
}
Loading

0 comments on commit e8b5ccb

Please sign in to comment.