-
-
Notifications
You must be signed in to change notification settings - Fork 535
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,53 @@ | ||
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 | ||
} | ||
``` |