Skip to content

Add a httpx endpoint (and async support) - #258

Merged
barbieri merged 1 commit into
profusion:masterfrom
kewisch:httpx
Aug 27, 2025
Merged

Add a httpx endpoint (and async support)#258
barbieri merged 1 commit into
profusion:masterfrom
kewisch:httpx

Conversation

@kewisch

@kewisch kewisch commented Aug 16, 2025

Copy link
Copy Markdown
Contributor

Description

I read about asyncio support in #162 because I needed it for a project I was working on. I'm using httpx.AsyncClient and 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

  • New endpoint created;
  • Create tests;
  • Add documentation;
  • Add async example to README

Pull request checklist

  • Tests: This PR includes tests for covering the features or bug fixes (if applicable).
  • Docs: This PR updates/creates the necessary documentation.
  • CI: Make sure your Pull Request passes all CI checks. If not, clarify the motif behind that and the action plan to solve it (may reference a ticket)

How to test it

    endpoint = HTTPXEndpoint(
        url="https://api.github.com/graphql",
        base_headers={"Authorization": f"Bearer {token}"},
        client=httpx.AsyncClient(),
    )

    await endpoint(op)

@barbieri

Copy link
Copy Markdown
Member

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

@barbieri
barbieri marked this pull request as ready for review August 26, 2025 12:29
@kewisch

kewisch commented Aug 26, 2025

Copy link
Copy Markdown
Contributor Author

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.

@barbieri

Copy link
Copy Markdown
Member

Hi @kewisch, I did merge #259 with the updated pyproject.toml and also ignoring the RST299 that was being incorrectly reported.

Please git rebase your branch on top of the new master

@barbieri

Copy link
Copy Markdown
Member

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

@kewisch
kewisch force-pushed the httpx branch 2 times, most recently from 856f479 to 497d7a0 Compare August 27, 2025 01:01
@kewisch

kewisch commented Aug 27, 2025

Copy link
Copy Markdown
Contributor Author

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 poetry lock after adding the modules to the pyproject.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Comment thread sgqlc/endpoint/httpx.py
}

def get_http_post_request(self, query, variables, operation_name, headers):
'''Createa a http POST request for the query.'''

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.

There's a typo in the docstring. 'Createa' should be 'Create a'.

Suggested change
'''Createa a http POST request for the query.'''
'''Create a http POST request for the query.'''

Copilot uses AI. Check for mistakes.
Comment thread README.rst
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.
got_exc, httpx.HTTPStatusError
), '{} is not httpx.HTTPStatusError'.format(type(got_exc))

assert data, {

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 assertion is incorrect. It should use '==' to compare the data with the expected dictionary, not ',' which creates a tuple.

Suggested change
assert data, {
assert data == {

Copilot uses AI. Check for mistakes.
got_exc, json.JSONDecodeError
), '{} is not json.JSONDecodeError'.format(type(got_exc))

assert data, {

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 assertion is incorrect. It should use '==' to compare the data with the expected dictionary, not ',' which creates a tuple.

Suggested change
assert data, {
assert data == {

Copilot uses AI. Check for mistakes.
@coveralls

Copy link
Copy Markdown

Pull Request Test Coverage Report for Build 17254427419

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 100.0%

Totals Coverage Status
Change from base Build 17243770913: 0.0%
Covered Lines: 1687
Relevant Lines: 1687

💛 - Coveralls

@barbieri
barbieri merged commit 1f9d8dd into profusion:master Aug 27, 2025
6 checks passed
@barbieri

Copy link
Copy Markdown
Member

ouhc, copilot did found some issues but I merged, I'll fix these and release a new version

@barbieri

Copy link
Copy Markdown
Member

https://pypi.org/project/sgqlc/17/ thanks!

@kewisch
kewisch deleted the httpx branch August 27, 2025 20:11
@kewisch

kewisch commented Aug 27, 2025

Copy link
Copy Markdown
Contributor Author

Excellent, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants