Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,24 @@ hand-written query (see more at ``examples/basic/01_http_endpoint.py``):
endpoint = HTTPEndpoint(url, headers)
data = endpoint(query, variables)

To make an asynchronous query, use the `httpx` library with `HTTPXEndpoint`
(see more at ``examples/basic/04_httpx_endpoint.py``):

.. code-block:: python

from sgqlc.endpoint.httpx import HTTPXEndpoint
import httpx

async def main():
url = 'http://server.com/graphql'
headers = {'Authorization': 'bearer TOKEN'}

query = 'query { ... }'
variables = {'varName': 'value'}

endpoint = HTTPEndpoint(url, headers, client=httpx.AsyncClient())

Copilot AI Aug 27, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use HTTPXEndpoint instead of HTTPEndpoint to match the import statement and example context.

Suggested change
endpoint = HTTPEndpoint(url, headers, client=httpx.AsyncClient())
endpoint = HTTPXEndpoint(url, headers, client=httpx.AsyncClient())

Copilot uses AI. Check for mistakes.
data = await endpoint(query, variables)


However, writing GraphQL queries and later interpreting the results
may be cumbersome. That's solved by our ``sgqlc.types``, which is
Expand Down
46 changes: 46 additions & 0 deletions examples/basic/04_httpx_endpoint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env python3

import sys
import json
import httpx
import asyncio
from sgqlc.endpoint.httpx import HTTPXEndpoint


async def main():
try:
token, repo = sys.argv[1:]
except ValueError:
raise SystemExit('Usage: <token> <team/repo>')

query = '''
query GitHubRepoIssues($repoOwner: String!, $repoName: String!) {
repository(owner: $repoOwner, name: $repoName) {
issues(first: 100) {
nodes {
number
title
}
}
}
}
'''

owner, name = repo.split('/', 1)
variables = {
'repoOwner': owner,
'repoName': name,
}

url = 'https://api.github.com/graphql'
headers = {
'Authorization': 'bearer ' + token,
}

endpoint = HTTPXEndpoint(url, headers, client=httpx.AsyncClient())
data = await endpoint(query, variables)

json.dump(data, sys.stdout, sort_keys=True, indent=2, default=str)


asyncio.run(main())
135 changes: 132 additions & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ force-exclude = '/(doc/|examples/.*(schema|operations)[.]py)'

[tool.pytest.ini_options]
addopts = '--import-mode=importlib --doctest-modules --cov=sgqlc --cov-fail-under=100 --cov-report=term-missing --cov-report=xml --cov-report=html:cover'
asyncio_mode = 'auto'
python_files = ['test-*.py', 'test_*.py']
testpaths = [
'sgqlc',
Expand Down Expand Up @@ -69,14 +70,18 @@ sgqlc-codegen = 'sgqlc.codegen:main'
[project.optional-dependencies]
websocket = ['websocket-client']
requests = ['requests']
httpx = ['httpx']

[tool.poetry.group.dev.dependencies]
pytest = '*'
pytest-cov = '*'
pytest-asyncio = '*'
sphinx = '*'
sphinx-argparse = '*'
websocket-client = '*'
requests = '*'
httpx = '*'
respx = '*'

[tool.poetry.group.docs.dependencies]
sphinx = '*'
Expand Down
Loading