-
-
Notifications
You must be signed in to change notification settings - Fork 542
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
Add support for federation in schema codegen #3417
Conversation
/pre-release |
Thanks for adding the Here's a preview of the changelog: This release adds support for Apollo Federation in the schema codegen. Now you extend schema
@link(url: "https://specs.apollo.dev/federation/v2.3",
import: ["@key", "@shareable"])
type Query {
me: User
}
type User @key(fields: "id") {
id: ID!
username: String! @shareable
} to a Strawberry powered schema like this: import strawberry
@strawberry.type
class Query:
me: User | None
@strawberry.federation.type(keys=["id"])
class User:
id: strawberry.ID
username: str = strawberry.federation.field(shareable=True)
schema = strawberry.federation.Schema(query=Query, enable_federation_2=True) By running the following command: strawberry schema-codegen example.graphql Here's the tweet text:
|
for more information, see https://pre-commit.ci
Pre-release👋 Pre-release 0.221.0.dev.1710955937 [dbe6b25] has been released on PyPi! 🚀 poetry add strawberry-graphql==0.221.0.dev.1710955937 |
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #3417 +/- ##
==========================================
+ Coverage 96.40% 96.41% +0.01%
==========================================
Files 498 507 +9
Lines 31137 32178 +1041
Branches 3815 5325 +1510
==========================================
+ Hits 30018 31026 +1008
- Misses 913 941 +28
- Partials 206 211 +5 |
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!
General suggestions:
- Consider extending the
_sanitize_argument
function to handle additional data types beyond strings and booleans for future-proofing. - Ensure that the code correctly handles non-federation fields and provides a way to opt-out of federation features explicitly if needed.
- Validate the assumption that federation schema extensions are always declared at the top of the document.
- Expand testing to cover negative scenarios, mixed federation and non-federation schemas, recursive types, and the application of multiple federation directives on the same type or field.
Here's what I looked at during the review
- 🟡 General issues: 4 issues found
- 🟢 Security: all looks good
- 🟡 Testing: 5 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.
@@ -0,0 +1,157 @@ | |||
import textwrap |
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.
suggestion (testing): Consider adding negative test cases for federation features.
While the provided tests cover the positive scenarios well, adding negative test cases (e.g., when directives are malformed or missing expected arguments) would ensure robust error handling and validation.
CodSpeed Performance ReportMerging #3417 will not alter performanceComparing Summary
|
Apollo Federation Subgraph Compatibility Results
Learn more: |
2bdb135
to
8ebbe25
Compare
cf9e13b
to
7d50896
Compare
d7c4554
to
df461db
Compare
Pretty much the title, it could be made more solid, but I think
it is pretty good for most use cases