diff --git a/README.md b/README.md index 34fc24e..eb55fa8 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,14 @@ make test For any requests, bug or comments, please [open an issue][issues] or [submit a pull request][pulls]. +## Development + +When developing new APIs locally, you can overwrite the API endpoint. +Specify `MONDOO_API_ENDPOINT` environment variable for the `generate` command, e.g.,: +``` +MONDOO_API_ENDPOINT=http://127.0.0.1 make generate +``` + ## Kudos This implementation is heavily inspired by the [GitHub GraphQL Go Client](https://github.com/shurcooL/githubv4). diff --git a/gen/gen.go b/gen/gen.go index edfdd63..8fb6841 100644 --- a/gen/gen.go +++ b/gen/gen.go @@ -13,6 +13,7 @@ import ( "io" "log" "net/http" + "net/url" "os" "path/filepath" "sort" @@ -176,10 +177,19 @@ fragment TypeRef on __Type { } } ` + apiEndpoint := "https://" + apiHost + "/query" + endpoint, ok := os.LookupEnv("MONDOO_API_ENDPOINT") + if ok { + apiEndpoint, err = url.JoinPath(endpoint, "/query") + if err != nil { + log.Fatalf("invalid MONDOO_API_ENDPOINT: %v", err) + } + } + fmt.Printf("using endpoint %s\n", apiEndpoint) // do introspection query req, err := http.NewRequest( "POST", - "https://"+apiHost+"/query", + apiEndpoint, strings.NewReader(`{"query":`+strconv.Quote(introspection)+`}`), ) if err != nil {