-
-
Notifications
You must be signed in to change notification settings - Fork 593
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
Open
enoua5
wants to merge
18
commits into
strawberry-graphql:main
Choose a base branch
from
enoua5:codegen-oneof
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
cdc943c
Pass is_one_of into codegen context
enoua5 0d60c8d
Update python plug-in to use is_one_of
enoua5 bd34fca
Fix python codegen
enoua5 93b19c3
More fixes on python plugin
enoua5 b0479b0
Add tests for python plugin
enoua5 6d4c073
Update typescript plugin
enoua5 d926ba4
Fix print operation error
enoua5 b2094c4
Add tests for typenames and aliases
enoua5 db0b0d1
Clean up code coverage
enoua5 5497709
Create RELEASE.md
enoua5 0b1386a
Add comments to potentially confusing sections
enoua5 625ccc1
Merge branch 'codegen-oneof' of https://github.com/enoua5/strawberry-…
enoua5 0434e68
Add spacing around component classes
enoua5 5834355
Remove the "just in case" branches that don't affect anything
enoua5 4e57fbd
Make typescript output optional fields for the `never` types
enoua5 2854ef3
Explain to codecov that we don't need to test Ellipsis
enoua5 a9194bf
Fix spacing in python union generation
enoua5 1347bde
Update release file to make example match actual current output
enoua5 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
Release type: minor | ||
|
||
The Query Codegen system now supports the `@oneOf` directive. | ||
|
||
When writing plugins, you can now access `GraphQLObjectType.is_one_of` to determine if the object being worked with has a `@oneOf` directive. | ||
|
||
The default plugins have been updated to take advantage of the new attribute. | ||
|
||
For example, given this schema: | ||
|
||
```python | ||
@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: | ||
|
||
```graphql | ||
query OneOfTest($value: OneOfInput!) { | ||
oneOf(value: $value) | ||
} | ||
``` | ||
|
||
The query codegen can now generate this Typescript file: | ||
|
||
```typescript | ||
type OneOfTestResult = { | ||
one_of: string | ||
} | ||
|
||
type OneOfInput = { a: string, b?: never } | ||
| { a?: never, b: string } | ||
|
||
type OneOfTestVariables = { | ||
value: OneOfInput | ||
} | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
query OneOfTest($value: OneOfInput!) { | ||
oneOf(value: $value) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
query OneOfTypenameTest($value: OneOfInput!) { | ||
alias: oneOfTypename(value: $value) { | ||
... on Person { | ||
name | ||
age | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from typing import Union | ||
|
||
class OneOfTestResult: | ||
one_of: str | ||
|
||
class OneOfInputA: | ||
a: str | ||
|
||
class OneOfInputB: | ||
b: str | ||
|
||
OneOfInput = Union[OneOfInputA, OneOfInputB] | ||
|
||
class OneOfTestVariables: | ||
value: OneOfInput |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from typing import Union | ||
|
||
class OneOfTypenameTestResultOneOfTypenamePerson: | ||
# typename: Person | ||
name: str | ||
age: int | ||
|
||
class OneOfTypenameTestResult: | ||
# alias for one_of_typename | ||
alias: OneOfTypenameTestResultOneOfTypenamePerson | ||
enoua5 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
class OneOfInputA: | ||
a: str | ||
|
||
class OneOfInputB: | ||
b: str | ||
|
||
OneOfInput = Union[OneOfInputA, OneOfInputB] | ||
|
||
class OneOfTypenameTestVariables: | ||
value: OneOfInput |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
type OneOfTestResult = { | ||
one_of: string | ||
} | ||
enoua5 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
type OneOfInput = { a: string, b?: never } | ||
| { a?: never, b: string } | ||
|
||
type OneOfTestVariables = { | ||
value: OneOfInput | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
type OneOfTypenameTestResultOneOfTypenamePerson = { | ||
name: string | ||
age: number | ||
} | ||
|
||
type OneOfTypenameTestResult = { | ||
// alias for one_of_typename | ||
alias: OneOfTypenameTestResultOneOfTypenamePerson | ||
} | ||
|
||
type OneOfInput = { a: string, b?: never } | ||
| { a?: never, b: string } | ||
|
||
type OneOfTypenameTestVariables = { | ||
value: OneOfInput | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.