Skip to content

Instantly share code, notes, and snippets.

@obcode
Created May 8, 2018 12:04
Show Gist options
  • Save obcode/a8d1a5632d3e69df24e02c4afacf39e1 to your computer and use it in GitHub Desktop.
Save obcode/a8d1a5632d3e69df24e02c4afacf39e1 to your computer and use it in GitHub Desktop.
GraphQL Query Golang
package main
import (
"fmt"
"net/http"
"bytes"
"io/ioutil"
)
func main() {
url := "https://api.github.com/graphql"
fmt.Println("URL:>", url)
jsonStr, _ := ioutil.ReadFile("query.json")
req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonStr))
req.Header.Set("Authorization", "token hier_das_token_einfügen")
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
fmt.Println("response Status:", resp.Status)
fmt.Println("response Headers:", resp.Header)
body, _ := ioutil.ReadAll(resp.Body)
fmt.Println("response Body:", string(body))
}
{"query": "{organization(login:\"ob-vss-ss18\") {repositories(first: 100) {edges {node {name}}}}}"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment