-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathgenerate.go
39 lines (32 loc) · 914 Bytes
/
generate.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
package main
import (
"context"
"errors"
"fmt"
"net/http"
"os"
"github.com/Khan/genqlient/generate"
"github.com/suessflorian/gqlfetch"
)
//go:generate go run generate.go
func main() {
const schemaFile = "schema.graphql"
if _, err := os.Stat(schemaFile); errors.Is(err, os.ErrNotExist) {
var headers http.Header = http.Header{
"Authorization": []string{fmt.Sprintf("Bearer %s", os.Getenv("BUILDKITE_GRAPHQL_TOKEN"))},
}
fmt.Printf("Generating new schema file at %s\n", schemaFile)
schema, err := gqlfetch.BuildClientSchemaWithHeaders(context.Background(), "https://graphql.buildkite.com/v1", headers, false)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
if err = os.WriteFile(schemaFile, []byte(schema), 0o644); err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Printf("Schema written to %s\n", schemaFile)
}
fmt.Println("Generating GraphQL code")
generate.Main()
}