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
Discriminate generics inside lists #3463
Conversation
(and update precommit, because, why not :D)
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #3463 +/- ##
==========================================
+ Coverage 96.50% 96.51% +0.01%
==========================================
Files 510 511 +1
Lines 32761 32859 +98
Branches 5430 5451 +21
==========================================
+ Hits 31615 31713 +98
Misses 914 914
Partials 232 232 |
for more information, see https://pre-commit.ci
Apollo Federation Subgraph Compatibility Results
Learn more: |
Random thought we might want to add support for something like this: return BlockRowType[str](total=3, items=[]), because when we have 0 items when don't know which type we should use, so for now we fallback to the first This is interesting, maybe it's useful: https://github.com/graphql-python/graphql-core/blob/3cf0d267b096ba92e7289d009800083166a5b7d9/src/graphql/execution/execute.py#L1947C1-L1957C16 |
CodSpeed Performance ReportMerging #3463 will not alter performanceComparing Summary
|
/pre-release |
Pre-release👋 Releasing commit [cddafae] to PyPi as pre-release! 📦 |
Pre-release👋 Pre-release 0.228.0.dev.1713643365 [cddafae] has been released on PyPi! 🚀 poetry add strawberry-graphql==0.228.0.dev.1713643365 |
Thanks for adding the Here's a preview of the changelog: This release improves our support for generic types, now using the same the same import strawberry
@strawberry.type
class BlockRow[T]:
items: list[T]
@strawberry.type
class Query:
@strawberry.field
def blocks(self) -> list[BlockRow[str] | BlockRow[int]]:
return [
BlockRow(items=["a", "b", "c"]),
BlockRow(items=[1, 2, 3, 4]),
]
schema = strawberry.Schema(query=Query) Here's the tweet text:
|
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 @patrick91 - I've reviewed your changes and they look great!
Here's what I looked at during the review
- 🟡 General issues: 3 issues found
- 🟢 Security: all looks good
- 🟡 Testing: 2 issues found
- 🟢 Complexity: all looks good
- 🟢 Docstrings: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.
@Speedy1991 let me know if you have time to try this! |
€dit: Nvm, I mixed up Interface with Union query. Looks like it works with unions: There is the obvious type collision on the client site (items of type str/int) so you are enforced to use an alias. This is the correct behaviour IMO |
Could this lead to problems on the client site? E.g. Apollo uses cache normalization (not sure about relay - didn't used it for years). I guess this should be ok as long as the return type matches the possible types for this field - just to make sure :) |
Adding the bug introduced as part of the PR |
Still WIP, should fix #3432, but right now it only fixes
the union part 😊