forked from Yamashou/gqlgenc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
42 lines (36 loc) · 1.1 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"context"
"fmt"
"net/http"
"os"
"github.com/vanillaricewraps/gqlgenc/client"
"github.com/vanillaricewraps/gqlgenc/example/github/gen"
)
func main() {
// This example only read public repository. You don't need to select scopes.
token := os.Getenv("GITHUB_TOKEN")
authHeader := func(req *http.Request) {
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token))
}
ctx := context.Background()
githubClient := &gen.Client{
Client: client.NewClient(http.DefaultClient, "https://api.github.com/graphql", authHeader),
}
getUser, err := githubClient.GetUser(ctx, 10, 10)
if err != nil {
if handledError, ok := err.(*client.ErrorResponse); ok {
fmt.Fprintf(os.Stderr, "handled error: %s\n", handledError.Error())
} else {
fmt.Fprintf(os.Stderr, "unhandled error: %s\n", err.Error())
}
os.Exit(1)
}
fmt.Println(*getUser.Viewer.Name, getUser.Viewer.Repositories.Nodes[0].Name)
for _, repository := range getUser.Viewer.Repositories.Nodes {
fmt.Println(repository.Name)
for _, language := range repository.Languages.Nodes {
fmt.Println(language.Name)
}
}
}