Created
April 5, 2022 14:53
-
-
Save maciekrb/866b49761fa868f2593fec27e259f367 to your computer and use it in GitHub Desktop.
Python GraphQL Storyblok sgqlc 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
# Run the following to obtain storyblok_schema | |
# python -m sgqlc.introspection \ | |
# --exclude-deprecated \ | |
# --exclude-description \ | |
# -H "Token: <some-token>" \ | |
# https://gapi.storyblok.com/v1/api storyblok_schema.json | |
# sgqlc-codegen schema storyblok_schema.json storyblok_schema.py | |
import pytest | |
from sgqlc.endpoint.http import HTTPEndpoint | |
from sgqlc.operation import Operation | |
from storyblok_schema import storyblok_schema as schema | |
@pytest.fixture | |
def sgqlc_client(): | |
url = "https://gapi.storyblok.com/v1/api" | |
headers = {"Token": "<some-token>"} | |
return HTTPEndpoint(url, headers) | |
def test_storyblok_sgqlc(sgqlc_client): | |
page = 1 | |
per_page = 25 | |
op = Operation(schema.QueryType) | |
topics = op.legaltopic_items(page=page, per_page=per_page) | |
topics.__fields__("total") | |
topics.items.__fields__("uuid", "name", "slug", "is_startpage") | |
topics.items.content.parent.__fields__("uuid", "name", "slug") | |
data = sgqlc_client(op) | |
legal_topics = (op + data).legaltopic_items | |
pages = -(legal_topics.total // -per_page) | |
print(f"Records: {legal_topics.total}, Pages: {pages}") | |
for legal_topic in legal_topics.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