-
-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support sqlalchemy select API #229
base: main
Are you sure you want to change the base?
Conversation
Reviewer's Guide by SourceryThis PR adds support for the SQLAlchemy select API in resolvers, enabling compatibility with asynchronous sessions and providing a more modern approach to querying. It maintains backward compatibility with the existing query style for synchronous sessions. Sequence diagram for async resolver with select APIsequenceDiagram
participant Client
participant Resolver
participant AsyncSession
participant SQLAlchemy
Client->>Resolver: Request data
Resolver->>AsyncSession: Execute select query
AsyncSession->>SQLAlchemy: select_page()
SQLAlchemy-->>AsyncSession: Return results
AsyncSession-->>Resolver: Return paginated data
Resolver-->>Client: Return connection response
Class diagram for updated resolver typesclassDiagram
class KeysetConnection {
+resolve_connection(nodes, info, before, after, first, last)
+resolve_nodes(session, nodes)
+resolve_nodes_async(session, nodes)
}
class StrawberrySQLAlchemyAsyncQuery {
+session: AsyncSession
+query: Callable[[], Select]
+iterator: Iterator
+limit: int
+offset: int
+__aiter__()
+__anext__()
}
note for StrawberrySQLAlchemyAsyncQuery "Updated to support Select API"
note for KeysetConnection "Modified to handle both Query and Select types"
State diagram for query resolution flowstateDiagram-v2
[*] --> CheckSessionType
CheckSessionType --> AsyncSession: is async
CheckSessionType --> SyncSession: is sync
AsyncSession --> SelectAPI: must use select()
SelectAPI --> ExecuteQuery
SyncSession --> QueryChoice
QueryChoice --> QueryAPI: use query()
QueryChoice --> SelectAPI: use select()
QueryAPI --> ExecuteQuery
ExecuteQuery --> ReturnResults
ReturnResults --> [*]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @novag - I've reviewed your changes - here's some feedback:
Overall Comments:
- Please add tests to cover the new select API functionality, particularly focusing on async use cases
- Documentation should be updated to explain the new select API usage and its differences from the query API
Here's what I looked at during the review
- 🟡 General issues: 1 issue found
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have skipped reviewing this pull request. It looks like we've already reviewed the commit d611352 in this pull request.
Thanks for your contribution, @novag ! |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #229 +/- ##
==========================================
- Coverage 85.51% 84.90% -0.62%
==========================================
Files 16 16
Lines 1629 1636 +7
Branches 139 147 +8
==========================================
- Hits 1393 1389 -4
Misses 173 173
- Partials 63 74 +11 |
CodSpeed Performance ReportMerging #229 will not alter performanceComparing Summary
|
I see that some tests failed, including the one I added a TODO comment. |
adec54d
to
cc36132
Compare
I was unpacking the StrawberrySQLAlchemyAsyncQuery too late for an assert I introduced. Now the SQLAlchemy 1.4 test still fails because 1.4 did not have the Select API. Do we want to continue to support 1.4? If so, I would conditionally import the select type and create an empty dummy select type if the test fails under 1.4. Before I go ahead and write more tests, I would also like to discuss the general approach regarding the return of the Select type. Would it perhaps make sense to force the user to always return a StrawberrySQLAlchemyAsyncQuery? Then we are able to return the correct iterable type, but it is a bit cumbersome. Sorry for all the pushes, when fixing some warnings I created a linter error that I didn't realize because for some reason the lint check wasn't run locally via pre-commit. |
Support the sqlalchemy select API in KeysetConnections. This is especially important for the async interface since async sqlalchemy only supports the select API.
Description
The change is backwards compatible so it supports the old style query as well as the select API for synchronous sessions. For async sessions only the select API is supported since there is no sqlalchemy async query support.
Currently, this PR is blocked by the fact that the
Select
type returned by theselect()
function does not inherit fromIterable
as theQuery
type id which make the linter fail. I'm not too familiar with the internals of strawberry yet, so I'd appreciate any feedback on how to best tackle this.There's also still stuff to do to be fully asynchronous. In
field.py
there are tworun_sync
calls I did not look into yet. Also I have not checked whetherStrawberrySQLAlchemyAsyncQuery
is really still needed.Examples:
Types of Changes
Issues Fixed or Closed by This PR
Checklist
Summary by Sourcery
New Features: