proper test wiring for example test in github actions

This commit is contained in:
Ben Kraft
2021-04-02 18:01:12 -07:00
parent efc6549d7e
commit 9c8cf02181
6 changed files with 51 additions and 33 deletions
+2 -4
View File
@@ -1,9 +1,7 @@
# example of genqlient
## Getting a token
Get a token from [GitHub](https://github.com/settings/tokens/new) (no scopes needed).
## Invoking the example
Create a [personal access token](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) with no scopes.
To run the example:
@@ -15,7 +13,7 @@ csilvers is Craig Silverstein
## Running genqlient
It's already checked in to github, but to generate `generated.go`:
It's already checked in to github, but to regenerate `generated.go`:
```sh
go generate ./...
```
+17 -15
View File
@@ -34,12 +34,6 @@ func Main() {
return
}
if len(os.Args) != 2 {
err = fmt.Errorf("usage: %v <username>", os.Args[0])
return
}
username := os.Args[1]
httpClient := http.Client{
Transport: &authedTransport{
key: key,
@@ -48,17 +42,25 @@ func Main() {
}
graphqlClient := graphql.NewClient("https://api.github.com/graphql", &httpClient)
viewerResp, err := getViewer(context.Background(), graphqlClient)
if err != nil {
return
}
fmt.Println("you are", viewerResp.Viewer.MyName)
switch len(os.Args) {
case 1:
viewerResp, err := getViewer(context.Background(), graphqlClient)
if err != nil {
return
}
fmt.Println("you are", viewerResp.Viewer.MyName)
userResp, err := getUser(context.Background(), graphqlClient, username)
if err != nil {
return
case 2:
username := os.Args[1]
userResp, err := getUser(context.Background(), graphqlClient, username)
if err != nil {
return
}
fmt.Println(username, "is", userResp.User.TheirName)
default:
err = fmt.Errorf("usage: %v [username]", os.Args[0])
}
fmt.Println(username, "is", userResp.User.TheirName)
}
//go:generate go run github.com/Khan/genqlient genqlient.yaml