Skip to content

Commit 625ccc1

Browse files
committed
Merge branch 'codegen-oneof' of https://github.com/enoua5/strawberry-3393 into codegen-oneof
2 parents 0b1386a + 5497709 commit 625ccc1

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

RELEASE.md

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
Release type: minor
2+
3+
The Query Codegen system now supports the `@oneOf` directive.
4+
5+
When writing plugins, you can now access `GraphQLObjectType.is_one_of` to determine if the object being worked with has a `@oneOf` directive.
6+
7+
The default plugins have been updated to take advantage of the new attribute.
8+
9+
For example, given this schema:
10+
11+
```python
12+
@strawberry.input(one_of=True)
13+
class OneOfInput:
14+
a: Optional[str] = strawberry.UNSET
15+
b: Optional[str] = strawberry.UNSET
16+
17+
18+
@strawberry.type
19+
class Query:
20+
@strawberry.field
21+
def one_of(self, value: OneOfInput) -> str: ...
22+
23+
24+
schema = strawberry.Schema(Query)
25+
```
26+
27+
And this query:
28+
29+
```graphql
30+
query OneOfTest($value: OneOfInput!) {
31+
oneOf(value: $value)
32+
}
33+
```
34+
35+
The query codegen can now generate this Typescript file:
36+
37+
```typescript
38+
type OneOfTestResult = {
39+
one_of: string
40+
}
41+
42+
type OneOfInput = {
43+
a: string,
44+
b: never
45+
} | {
46+
a: never,
47+
b: string
48+
}
49+
50+
type OneOfTestVariables = {
51+
value: OneOfInput
52+
}
53+
```

0 commit comments

Comments
 (0)