Last active
February 23, 2022 04:47
-
-
Save chrisgoffinet/2fbf69869cd6d3715a386b1040d57806 to your computer and use it in GitHub Desktop.
Example code using gql and pagination
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from gql import gql, Client | |
from gql.transport.requests import RequestsHTTPTransport | |
from gql.dsl import DSLQuery, DSLSchema, dsl_gql | |
import os | |
base_url = 'https://api.linear.app/graphql' | |
token = os.getenv('LINEAR_TOKEN') | |
transport = RequestsHTTPTransport(url=base_url, headers={ | |
'Authorization': 'Bearer ' + token}) | |
client = Client(transport=transport, | |
fetch_schema_from_transport=True) | |
team = "Engineering" | |
with client as session: | |
cursor = None | |
ds = DSLSchema(client.schema) | |
while True: | |
query = dsl_gql( | |
DSLQuery( | |
ds.Query.issues(first=50, after=cursor, filter={ | |
"team": {"eq": team} | |
}).select( | |
ds.IssueConnection.nodes.select( | |
ds.Issue.id, | |
ds.Issue.title, | |
), | |
ds.IssueConnection.pageInfo.select( | |
ds.PageInfo.hasNextPage, | |
ds.PageInfo.endCursor, | |
), | |
) | |
) | |
) | |
result = session.execute(query) | |
print(len(result['issues']['nodes'])) | |
if not result['issues']['pageInfo']['hasNextPage']: | |
break | |
cursor = result['issues']['pageInfo']['endCursor'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment