Add a httpx endpoint (and async support) - #258
Conversation
|
sure, would love to take it. I'll enable the tests in the CI, let's see what comes up. I'll review the code tomorrow, but please provide a test for it, ok? So we're sure it remains working in the future |
|
Yes, of course. Now I know you're interested I'm happy to add a test. I might need a bit as this was a side project, but hope to get to it soon. |
|
note that the pyproject.toml changed to comply with: https://packaging.python.org/en/latest/guides/writing-pyproject-toml and also include your updated poetry.lock in the commit |
856f479 to
497d7a0
Compare
|
Alright, I just couldn't resist. Here you go! With your new updates the tests pass great, thank you. Please take a close look at the poetry lock changes, I spotted a few things that seem unrelated, but I really just ran |
There was a problem hiding this comment.
Pull Request Overview
This PR adds httpx endpoint support to sgqlc, enabling both synchronous and asynchronous GraphQL requests through the httpx library. This addresses the need for asyncio support mentioned in issue #162.
- Implements HTTPXEndpoint class extending HTTPEndpoint for httpx-based requests
- Adds comprehensive test coverage for sync/async scenarios and error handling
- Provides documentation and example for usage with httpx.AsyncClient
Reviewed Changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| sgqlc/endpoint/httpx.py | Core HTTPXEndpoint implementation with sync/async support |
| tests/test-endpoint-httpx.py | Comprehensive test suite covering all endpoint functionality |
| pyproject.toml | Adds httpx and testing dependencies |
| examples/basic/04_httpx_endpoint.py | Example demonstrating async usage |
| README.rst | Documentation update with httpx endpoint usage |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| } | ||
|
|
||
| def get_http_post_request(self, query, variables, operation_name, headers): | ||
| '''Createa a http POST request for the query.''' |
There was a problem hiding this comment.
There's a typo in the docstring. 'Createa' should be 'Create a'.
| '''Createa a http POST request for the query.''' | |
| '''Create a http POST request for the query.''' |
| query = 'query { ... }' | ||
| variables = {'varName': 'value'} | ||
|
|
||
| endpoint = HTTPEndpoint(url, headers, client=httpx.AsyncClient()) |
There was a problem hiding this comment.
This should use HTTPXEndpoint instead of HTTPEndpoint to match the import statement and example context.
| endpoint = HTTPEndpoint(url, headers, client=httpx.AsyncClient()) | |
| endpoint = HTTPXEndpoint(url, headers, client=httpx.AsyncClient()) |
| got_exc, httpx.HTTPStatusError | ||
| ), '{} is not httpx.HTTPStatusError'.format(type(got_exc)) | ||
|
|
||
| assert data, { |
There was a problem hiding this comment.
This assertion is incorrect. It should use '==' to compare the data with the expected dictionary, not ',' which creates a tuple.
| assert data, { | |
| assert data == { |
| got_exc, json.JSONDecodeError | ||
| ), '{} is not json.JSONDecodeError'.format(type(got_exc)) | ||
|
|
||
| assert data, { |
There was a problem hiding this comment.
This assertion is incorrect. It should use '==' to compare the data with the expected dictionary, not ',' which creates a tuple.
| assert data, { | |
| assert data == { |
Pull Request Test Coverage Report for Build 17254427419Details
💛 - Coveralls |
|
ouhc, copilot did found some issues but I merged, I'll fix these and release a new version |
|
Excellent, thank you! |
Description
I read about asyncio support in #162 because I needed it for a project I was working on. I'm using
httpx.AsyncClientand thought it would be easiest I create a httpx endpoint.Would you be interested in this? If so I'll try to spend some time finishing up the PR. I could maybe also add aiohttp support while I am at it.
Runing pre-commit locally I had some issues, flake8 failed in files I didn't touch and pytest wasn't running correctly. I'll try to debug this later, but if you are aware of anything I might be missing let me know.
Progress
Pull request checklist
How to test it