Created
April 5, 2022 14:47
-
-
Save maciekrb/be722570b7544ef12234468311b0874a to your computer and use it in GitHub Desktop.
Python GraphQL qlient StoryBlok example
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
import pytest | |
import requests | |
from qlient import Client, Fields, HTTPBackend | |
@pytest.fixture | |
def qlient(): | |
url = "https://gapi.storyblok.com/v1/api" | |
headers = {"Token": "<some-token>"} | |
session = requests.Session() | |
session.headers.update(headers) | |
authed_backend = HTTPBackend(endpoint=url, session=session) | |
return Client(authed_backend) | |
def test_storyblok_qlient(qlient): | |
page = 1 | |
per_page = 25 | |
fields = Fields( | |
"total", | |
items=Fields("uuid", "name", "slug", "is_startpage", content=Fields(parent=Fields("uuid", "name", "slug"))), | |
) | |
res = qlient.query.LegaltopicItems(page=page, per_page=per_page, _fields=fields) | |
print(res.query) | |
print(res.variables) | |
pages = -(res.data["LegaltopicItems"]["total"] // -per_page) | |
print(f"Records: {res.data['LegaltopicItems']['total']}, Pages: {pages}") | |
for legal_topic in res.data["LegaltopicItems"]["items"]: | |
parent = legal_topic["content"]["parent"]["slug"] if legal_topic["content"]["parent"] else "" | |
print(f"{legal_topic['slug']} ({parent})") | |
assert True is False | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment