Skip to content

Instantly share code, notes, and snippets.

@lagenorhynque
Created February 16, 2021 12:33
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 lagenorhynque/672b945952f4b5cf324259c00519987d to your computer and use it in GitHub Desktop.
Save lagenorhynque/672b945952f4b5cf324259c00519987d to your computer and use it in GitHub Desktop.
A minimal GitHub GraphQL API client implemented as a Python script
#!/usr/bin/env python
import os
import pprint
import requests
AUTH_TOKEN = os.getenv('AUTH_TOKEN')
GRAPHQL_QUERY = '''
query ($query: String!, $last: Int) {
search(type: ISSUE, query: $query, last: $last) {
nodes {
... on Issue {
title
url
repository {
name
}
labels(first: 10) {
nodes {
name
}
}
}
}
}
}
'''
def run_query(query, variables):
return requests.post(
'https://api.github.com/graphql',
headers={
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': f'bearer {AUTH_TOKEN}'
},
json={
'query': query,
'variables': variables
}).json()
if __name__ == '__main__':
res = run_query(GRAPHQL_QUERY, {
'query': 'org:my-org is:issue is:open label:"docs" sort:updated',
'last': 100
})
pprint.pprint(res)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment