Skip to content

Instantly share code, notes, and snippets.

@Oldes
Last active February 14, 2020 09:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Oldes/777fb32915fe2f9dbcd8175c98b1a3c5 to your computer and use it in GitHub Desktop.
Save Oldes/777fb32915fe2f9dbcd8175c98b1a3c5 to your computer and use it in GitHub Desktop.
GitHub's GraphQl request test
Red [
title: "GitHub's graphql request test"
author: "Oldes"
reference: https://developer.github.com/v4/
]
;@@ https://developer.github.com/apps/building-oauth-apps/creating-an-oauth-app/
graphql-header: [Authorization: "token YOUR_OAUTH_TOKEN_HERE"]
graphql-request: func[
query [string!]
/v variables [map!]
/local data retry result
][
data: copy #()
data/query: query
if v [data/variables: variables]
retry: 3
while [retry > 0][
result: try [
load-json to-string probe write https://api.github.com/graphql reduce [
'POST
to-block any [graphql-header []]
to-json data
]
]
either not error? result [return result][
print "GraphQl request error:"
print result
print ["^/RETRY:" retry: retry - 1]
]
]
none
]
;-- some query to use as a test...
;@@ https://developer.github.com/v4/explorer/
last-20-closed-issues: {
query($owner:String!,$repo:String!) {
repository(owner:$owner, name:$repo) {
issues(last:20, states:CLOSED) {
edges {
node {
title
url
labels(first:5) {
edges {
node {
name
} } } } } } } } }
repo-labels: {
query($owner:String!,$repo:String!) {
repository(owner:$owner, name:$repo) {
labels(first:100){
edges {
node {
name
description
} } } } } }
variables: #(owner: "red" repo: "red")
probe graphql-request {query {viewer {login bio location isBountyHunter}}}
probe graphql-request/v :last-20-closed-issues :variables
probe graphql-request/v :repo-labels :variables
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment