-
-
Notifications
You must be signed in to change notification settings - Fork 599
Take oneOf directive into account in codegen module #3652
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
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3652 +/- ##
==========================================
+ Coverage 96.76% 96.83% +0.06%
==========================================
Files 522 503 -19
Lines 33824 33457 -367
Branches 5635 5596 -39
==========================================
- Hits 32731 32397 -334
+ Misses 863 830 -33
Partials 230 230 |
CodSpeed Performance ReportMerging #3652 will not alter performanceComparing Summary
|
Reviewer's Guide by SourceryThis pull request adds support for the Sequence DiagramsequenceDiagram
participant CG as Codegen Manager
participant PY as Python Plugin
participant TS as TypeScript Plugin
CG->>CG: Set is_one_of flag in GraphQLObjectType
CG->>PY: Process oneOf type
PY->>PY: Generate union of classes
CG->>TS: Process oneOf type
TS->>TS: Generate union of objects
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 @enoua5 - 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: 4 issues found
- 🟢 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.
|
Thanks for adding the Here's a preview of the changelog: The Query Codegen system now supports the When writing plugins, you can now access The default plugins have been updated to take advantage of the new attribute. For example, given this schema: @strawberry.input(one_of=True)
class OneOfInput:
a: Optional[str] = strawberry.UNSET
b: Optional[str] = strawberry.UNSET
@strawberry.type
class Query:
@strawberry.field
def one_of(self, value: OneOfInput) -> str: ...
schema = strawberry.Schema(Query)And this query: query OneOfTest($value: OneOfInput!) {
oneOf(value: $value)
}The query codegen can now generate this Typescript file: type OneOfTestResult = {
one_of: string
}
type OneOfInput = { a: string, b?: never }
| { a?: never, b: string }
type OneOfTestVariables = {
value: OneOfInput
}Here's the tweet text: |
|
I unchecked "My change requires a change to the documentation". I would add a note about this to the documentation on codegen plugins, but the docs already don't go over any of the other types that are passed into the plugin. |
|
If anyone has opinions on how those Typescript unions should be formatted, I'd be happy to take the feedback 😄 |
|
@enoua5 I'll check this on the weekend! thank you so much 😊 |
Looking at type OneOfInput =
{ a: string, b?: never }
| { a?: never, b: string };I'm not a big fan of the hanging |
|
@enoua5 I think that's fine, we could maybe in future run prettier/biome to the output if the user has one of them installed :) |
|
@patrick91 That's a fair point. Do you think its not worth changing it from how it is now, then? |

Description
Adds support for
oneOfto thecodegenmoduleis_one_oftoGraphQLObjectTypemaking it part of the codegen plugin apineverTypes of Changes
Issues Fixed or Closed by This PR
Checklist
Summary by Sourcery
Implement support for the
oneOfdirective in the code generation module, enhancing the Python and TypeScript plugins to handleoneOftypes as unions. Add corresponding tests and snapshots to verify the new functionality.New Features:
oneOfdirective in the code generation module, allowing the generation of union types foroneOffields in both Python and TypeScript plugins.Enhancements:
oneOftypes as a union of classes, each with one field.oneOftypes as a union of objects, where each object has all but one field typed asnever.Tests:
oneOfdirective in both Python and TypeScript code generation to ensure correct functionality.