From a2d94ee6c03b20c7095a8bef4886bc2b8a35ed11 Mon Sep 17 00:00:00 2001 From: Iota Date: Sun, 26 May 2024 13:30:04 -0600 Subject: [PATCH 01/17] Merge unions --- strawberry/schema/schema_converter.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/strawberry/schema/schema_converter.py b/strawberry/schema/schema_converter.py index 332a9bdb5f..a358ceca7b 100644 --- a/strawberry/schema/schema_converter.py +++ b/strawberry/schema/schema_converter.py @@ -870,9 +870,13 @@ def from_union(self, union: StrawberryUnion) -> GraphQLUnionType: if isinstance(graphql_type, GraphQLInputObjectType): raise InvalidTypeInputForUnion(graphql_type) - assert isinstance(graphql_type, GraphQLObjectType) + assert isinstance(graphql_type, GraphQLObjectType | GraphQLUnionType) - graphql_types.append(graphql_type) + if isinstance(graphql_type, GraphQLUnionType): + # merge child types + graphql_types += list(graphql_type.types) + else: + graphql_types.append(graphql_type) graphql_union = GraphQLUnionType( name=union_name, From 12fe63aaae35d32945847f35d24374ef5bd254e7 Mon Sep 17 00:00:00 2001 From: Iota Date: Sun, 26 May 2024 14:02:32 -0600 Subject: [PATCH 02/17] Add RELEASE.md --- RELEASE.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 RELEASE.md diff --git a/RELEASE.md b/RELEASE.md new file mode 100644 index 0000000000..732f56afa3 --- /dev/null +++ b/RELEASE.md @@ -0,0 +1,3 @@ +Release type: patch + +Attempt to merge union types during schema conversion. From 69443e3eb89a69fbc094b4a0e413592e382294f6 Mon Sep 17 00:00:00 2001 From: Jacob Allen Date: Sun, 26 May 2024 13:58:09 -0600 Subject: [PATCH 03/17] Use extend instead of += Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com> --- strawberry/schema/schema_converter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strawberry/schema/schema_converter.py b/strawberry/schema/schema_converter.py index a358ceca7b..34c6df7362 100644 --- a/strawberry/schema/schema_converter.py +++ b/strawberry/schema/schema_converter.py @@ -874,7 +874,7 @@ def from_union(self, union: StrawberryUnion) -> GraphQLUnionType: if isinstance(graphql_type, GraphQLUnionType): # merge child types - graphql_types += list(graphql_type.types) + graphql_types.extend(graphql_type.types) else: graphql_types.append(graphql_type) From ec26443a3751615f11f0e3017e103f4adc27799b Mon Sep 17 00:00:00 2001 From: Jacob Allen Date: Sun, 26 May 2024 13:58:39 -0600 Subject: [PATCH 04/17] Sourcery suggestion Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com> --- strawberry/schema/schema_converter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strawberry/schema/schema_converter.py b/strawberry/schema/schema_converter.py index 34c6df7362..73eb698a64 100644 --- a/strawberry/schema/schema_converter.py +++ b/strawberry/schema/schema_converter.py @@ -873,7 +873,7 @@ def from_union(self, union: StrawberryUnion) -> GraphQLUnionType: assert isinstance(graphql_type, GraphQLObjectType | GraphQLUnionType) if isinstance(graphql_type, GraphQLUnionType): - # merge child types + # Add the child types of the GraphQLUnionType to the list of graphql_types graphql_types.extend(graphql_type.types) else: graphql_types.append(graphql_type) From 4737436b06178407552e68e37362172ee41aba4e Mon Sep 17 00:00:00 2001 From: Jacob Allen Date: Sun, 26 May 2024 13:58:46 -0600 Subject: [PATCH 05/17] Sourcery suggestion Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com> --- strawberry/schema/schema_converter.py | 1 + 1 file changed, 1 insertion(+) diff --git a/strawberry/schema/schema_converter.py b/strawberry/schema/schema_converter.py index 73eb698a64..bba1996960 100644 --- a/strawberry/schema/schema_converter.py +++ b/strawberry/schema/schema_converter.py @@ -872,6 +872,7 @@ def from_union(self, union: StrawberryUnion) -> GraphQLUnionType: raise InvalidTypeInputForUnion(graphql_type) assert isinstance(graphql_type, GraphQLObjectType | GraphQLUnionType) + # If the graphql_type is a GraphQLUnionType, merge its child types if isinstance(graphql_type, GraphQLUnionType): # Add the child types of the GraphQLUnionType to the list of graphql_types graphql_types.extend(graphql_type.types) From e03e12b6d1d0be5a248e65de6d7962e2d55fd488 Mon Sep 17 00:00:00 2001 From: Patrick Arminio Date: Sun, 26 May 2024 21:40:47 +0100 Subject: [PATCH 06/17] Fix check on older python versions --- strawberry/schema/schema_converter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strawberry/schema/schema_converter.py b/strawberry/schema/schema_converter.py index bba1996960..390d2c1e2a 100644 --- a/strawberry/schema/schema_converter.py +++ b/strawberry/schema/schema_converter.py @@ -870,7 +870,7 @@ def from_union(self, union: StrawberryUnion) -> GraphQLUnionType: if isinstance(graphql_type, GraphQLInputObjectType): raise InvalidTypeInputForUnion(graphql_type) - assert isinstance(graphql_type, GraphQLObjectType | GraphQLUnionType) + assert isinstance(graphql_type, (GraphQLObjectType, GraphQLUnionType)) # If the graphql_type is a GraphQLUnionType, merge its child types if isinstance(graphql_type, GraphQLUnionType): From 8abb5b1779c5ebb726bc4ca342e1741d2c859655 Mon Sep 17 00:00:00 2001 From: Patrick Arminio Date: Sun, 26 May 2024 21:57:48 +0100 Subject: [PATCH 07/17] Add test that was already passing --- tests/schema/test_union.py | 56 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/tests/schema/test_union.py b/tests/schema/test_union.py index 71cc92bbf4..44f7b13621 100644 --- a/tests/schema/test_union.py +++ b/tests/schema/test_union.py @@ -840,3 +840,59 @@ class Query: assert not result.errors assert result.data["something"] == {"__typename": "A", "a": 5} + + +def test_generic_union_with_annotated(): + @strawberry.type + class SomeType: + id: strawberry.ID + name: str + + @strawberry.type + class NotFoundError: + id: strawberry.ID + message: str + + T = TypeVar("T") + + @strawberry.type + class ObjectQueries(Generic[T]): + @strawberry.field + def by_id( + self, id: strawberry.ID + ) -> Annotated[Union[T, NotFoundError], strawberry.union("ByIdResult")]: ... + + @strawberry.type + class Query: + @strawberry.field + def some_type_queries(self, id: strawberry.ID) -> ObjectQueries[SomeType]: + raise NotImplementedError() + + schema = strawberry.Schema(Query) + + assert ( + str(schema) + == textwrap.dedent( + """ + type NotFoundError { + id: ID! + message: String! + } + + type Query { + someTypeQueries(id: ID!): SomeTypeObjectQueries! + } + + type SomeType { + id: ID! + name: String! + } + + union SomeTypeNotFoundError = SomeType | NotFoundError + + type SomeTypeObjectQueries { + byId(id: ID!): SomeTypeNotFoundError! + } + """ + ).strip() + ) From eb0eeee212ff0570947d326edfcb3643460aac2a Mon Sep 17 00:00:00 2001 From: Patrick Arminio Date: Sun, 26 May 2024 22:20:53 +0100 Subject: [PATCH 08/17] Add missing test --- tests/schema/test_union.py | 62 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 2 deletions(-) diff --git a/tests/schema/test_union.py b/tests/schema/test_union.py index 44f7b13621..a9a58ce0a9 100644 --- a/tests/schema/test_union.py +++ b/tests/schema/test_union.py @@ -842,6 +842,7 @@ class Query: assert result.data["something"] == {"__typename": "A", "a": 5} +@pytest.mark.xfail(reason="Not supported yet") def test_generic_union_with_annotated(): @strawberry.type class SomeType: @@ -870,6 +871,7 @@ def some_type_queries(self, id: strawberry.ID) -> ObjectQueries[SomeType]: schema = strawberry.Schema(Query) + # TODO: check the name assert ( str(schema) == textwrap.dedent( @@ -880,7 +882,7 @@ def some_type_queries(self, id: strawberry.ID) -> ObjectQueries[SomeType]: } type Query { - someTypeQueries(id: ID!): SomeTypeObjectQueries! + someTypeQueries(id: ID!): SomeTypeByIdResult! } type SomeType { @@ -891,7 +893,63 @@ def some_type_queries(self, id: strawberry.ID) -> ObjectQueries[SomeType]: union SomeTypeNotFoundError = SomeType | NotFoundError type SomeTypeObjectQueries { - byId(id: ID!): SomeTypeNotFoundError! + byId(id: ID!): SomeTypeByIdResult! + } + """ + ).strip() + ) + + +def test_generic_union_with_annotated_inside(): + @strawberry.type + class SomeType: + id: strawberry.ID + name: str + + @strawberry.type + class NotFoundError: + id: strawberry.ID + message: str + + T = TypeVar("T") + + @strawberry.type + class ObjectQueries(Generic[T]): + @strawberry.field + def by_id( + self, id: strawberry.ID + ) -> Union[T, Annotated[NotFoundError, strawberry.union("ByIdResult")]]: ... + + @strawberry.type + class Query: + @strawberry.field + def some_type_queries(self, id: strawberry.ID) -> ObjectQueries[SomeType]: + return ObjectQueries(SomeType) + + schema = strawberry.Schema(Query) + + assert ( + str(schema) + == textwrap.dedent( + """ + type NotFoundError { + id: ID! + message: String! + } + + type Query { + someTypeQueries(id: ID!): SomeTypeObjectQueries! + } + + type SomeType { + id: ID! + name: String! + } + + union SomeTypeByIdResult = SomeType | NotFoundError + + type SomeTypeObjectQueries { + byId(id: ID!): SomeTypeByIdResult! } """ ).strip() From 7f00839c25769b3cba1839a4da4a3e2b1feff0b2 Mon Sep 17 00:00:00 2001 From: Patrick Arminio Date: Sun, 26 May 2024 23:21:18 +0100 Subject: [PATCH 09/17] Add support for generic unions --- strawberry/schema/name_converter.py | 19 ++++++++++++++----- strawberry/schema/schema_converter.py | 1 + strawberry/types/union.py | 7 ++++++- tests/schema/test_union.py | 6 ++---- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/strawberry/schema/name_converter.py b/strawberry/schema/name_converter.py index 94f8331886..3226a8fcb4 100644 --- a/strawberry/schema/name_converter.py +++ b/strawberry/schema/name_converter.py @@ -106,8 +106,14 @@ def from_union(self, union: StrawberryUnion) -> str: return union.graphql_name name = "" + types = union.types - for type_ in union.types: + if union.concrete_of and union.concrete_of.graphql_name: + concrete_of_types = set(union.concrete_of.types) + + types = [type_ for type_ in types if type_ not in concrete_of_types] + + for type_ in types: if isinstance(type_, LazyType): type_ = cast("StrawberryType", type_.resolve_type()) # noqa: PLW2901 @@ -120,6 +126,9 @@ def from_union(self, union: StrawberryUnion) -> str: name += type_name + if union.concrete_of and union.concrete_of.graphql_name: + name += union.concrete_of.graphql_name + return name def from_generic( @@ -132,12 +141,12 @@ def from_generic( names: list[str] = [] for type_ in types: - name = self.get_from_type(type_) + name = self.get_name_from_type(type_) names.append(name) return "".join(names) + generic_type_name - def get_from_type(self, type_: Union[StrawberryType, type]) -> str: + def get_name_from_type(self, type_: Union[StrawberryType, type]) -> str: type_ = eval_type(type_) if isinstance(type_, LazyType): @@ -147,9 +156,9 @@ def get_from_type(self, type_: Union[StrawberryType, type]) -> str: elif isinstance(type_, StrawberryUnion): name = type_.graphql_name if type_.graphql_name else self.from_union(type_) elif isinstance(type_, StrawberryList): - name = self.get_from_type(type_.of_type) + "List" + name = self.get_name_from_type(type_.of_type) + "List" elif isinstance(type_, StrawberryOptional): - name = self.get_from_type(type_.of_type) + "Optional" + name = self.get_name_from_type(type_.of_type) + "Optional" elif hasattr(type_, "_scalar_definition"): strawberry_type = type_._scalar_definition diff --git a/strawberry/schema/schema_converter.py b/strawberry/schema/schema_converter.py index 390d2c1e2a..b1945f3b24 100644 --- a/strawberry/schema/schema_converter.py +++ b/strawberry/schema/schema_converter.py @@ -865,6 +865,7 @@ def from_union(self, union: StrawberryUnion) -> GraphQLUnionType: return graphql_union graphql_types: list[GraphQLObjectType] = [] + for type_ in union.types: graphql_type = self.from_type(type_) diff --git a/strawberry/types/union.py b/strawberry/types/union.py index a61167e80b..170cdaa9c7 100644 --- a/strawberry/types/union.py +++ b/strawberry/types/union.py @@ -64,6 +64,7 @@ def __init__( self.directives = directives self._source_file = None self._source_line = None + self.concrete_of: Optional[StrawberryUnion] = None def __eq__(self, other: object) -> bool: if isinstance(other, StrawberryType): @@ -136,6 +137,7 @@ def copy_with( return self new_types = [] + for type_ in self.types: new_type: Union[StrawberryType, type] @@ -151,10 +153,13 @@ def copy_with( new_types.append(new_type) - return StrawberryUnion( + new_union = StrawberryUnion( type_annotations=tuple(map(StrawberryAnnotation, new_types)), description=self.description, ) + new_union.concrete_of = self + + return new_union def __call__(self, *args: str, **kwargs: Any) -> NoReturn: """Do not use. diff --git a/tests/schema/test_union.py b/tests/schema/test_union.py index a9a58ce0a9..04afcabab2 100644 --- a/tests/schema/test_union.py +++ b/tests/schema/test_union.py @@ -842,7 +842,6 @@ class Query: assert result.data["something"] == {"__typename": "A", "a": 5} -@pytest.mark.xfail(reason="Not supported yet") def test_generic_union_with_annotated(): @strawberry.type class SomeType: @@ -871,7 +870,6 @@ def some_type_queries(self, id: strawberry.ID) -> ObjectQueries[SomeType]: schema = strawberry.Schema(Query) - # TODO: check the name assert ( str(schema) == textwrap.dedent( @@ -882,7 +880,7 @@ def some_type_queries(self, id: strawberry.ID) -> ObjectQueries[SomeType]: } type Query { - someTypeQueries(id: ID!): SomeTypeByIdResult! + someTypeQueries(id: ID!): SomeTypeObjectQueries! } type SomeType { @@ -890,7 +888,7 @@ def some_type_queries(self, id: strawberry.ID) -> ObjectQueries[SomeType]: name: String! } - union SomeTypeNotFoundError = SomeType | NotFoundError + union SomeTypeByIdResult = SomeType | NotFoundError type SomeTypeObjectQueries { byId(id: ID!): SomeTypeByIdResult! From 9f62388606ac7cc304d65da760f5bd6639a8679e Mon Sep 17 00:00:00 2001 From: Patrick Arminio Date: Sun, 26 May 2024 23:32:12 +0100 Subject: [PATCH 10/17] Lint --- strawberry/schema/name_converter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strawberry/schema/name_converter.py b/strawberry/schema/name_converter.py index 3226a8fcb4..449a9e06ad 100644 --- a/strawberry/schema/name_converter.py +++ b/strawberry/schema/name_converter.py @@ -106,7 +106,7 @@ def from_union(self, union: StrawberryUnion) -> str: return union.graphql_name name = "" - types = union.types + types: List[Union[StrawberryType, type]] = union.types if union.concrete_of and union.concrete_of.graphql_name: concrete_of_types = set(union.concrete_of.types) From 32aabf9e6c1276250036bac62b0cba91da1f6a6c Mon Sep 17 00:00:00 2001 From: Patrick Arminio Date: Sun, 26 May 2024 23:33:55 +0100 Subject: [PATCH 11/17] Lint --- strawberry/schema/name_converter.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/strawberry/schema/name_converter.py b/strawberry/schema/name_converter.py index 449a9e06ad..b92794e01b 100644 --- a/strawberry/schema/name_converter.py +++ b/strawberry/schema/name_converter.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Optional, Union, cast +from typing import TYPE_CHECKING, Optional, Tuple, Union, cast from typing_extensions import Protocol from strawberry.directive import StrawberryDirective @@ -106,12 +106,12 @@ def from_union(self, union: StrawberryUnion) -> str: return union.graphql_name name = "" - types: List[Union[StrawberryType, type]] = union.types + types: Tuple[StrawberryType, ...] = union.types if union.concrete_of and union.concrete_of.graphql_name: concrete_of_types = set(union.concrete_of.types) - types = [type_ for type_ in types if type_ not in concrete_of_types] + types = tuple(type_ for type_ in types if type_ not in concrete_of_types) for type_ in types: if isinstance(type_, LazyType): From fde12ebf6dca50a6ebdacc76358196b74808e69c Mon Sep 17 00:00:00 2001 From: Iota Date: Thu, 30 May 2024 21:00:26 -0600 Subject: [PATCH 12/17] Add test for annotated union with two generics --- tests/schema/test_union.py | 63 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/tests/schema/test_union.py b/tests/schema/test_union.py index 04afcabab2..38a9c13236 100644 --- a/tests/schema/test_union.py +++ b/tests/schema/test_union.py @@ -952,3 +952,66 @@ def some_type_queries(self, id: strawberry.ID) -> ObjectQueries[SomeType]: """ ).strip() ) + + +def test_annoted_union_with_two_generics(): + @strawberry.type + class SomeType: + a: str + + @strawberry.type + class OtherType: + b: str + + @strawberry.type + class NotFoundError: + message: str + + T = TypeVar("T") + U = TypeVar("U") + + @strawberry.type + class UnionObjectQueries(Generic[T, U]): + @strawberry.field + def by_id( + self, id: strawberry.ID + ) -> T | Annotated[U | NotFoundError, strawberry.union("ByIdResult")]: ... + + @strawberry.type + class Query: + @strawberry.field + def some_type_queries( + self, id: strawberry.ID + ) -> UnionObjectQueries[SomeType, OtherType]: + return UnionObjectQueries() + + schema = strawberry.Schema(Query) + + assert ( + str(schema) + == textwrap.dedent( + """ + type NotFoundError { + message: String! + } + + type OtherType { + b: String! + } + + type Query { + someTypeQueries(id: ID!): SomeTypeOtherTypeUnionObjectQueries! + } + + type SomeType { + a: String! + } + + union SomeTypeOtherTypeByIdResult = SomeType | OtherType | NotFoundError + + type SomeTypeOtherTypeUnionObjectQueries { + byId(id: ID!): SomeTypeOtherTypeByIdResult! + } + """ + ).strip() + ) From 2bce9f2ac20f46edfb498dd53c0ceddcd8385b13 Mon Sep 17 00:00:00 2001 From: Iota Date: Thu, 30 May 2024 21:08:41 -0600 Subject: [PATCH 13/17] Rewrite test to support python <= 3.9 --- tests/schema/test_union.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/schema/test_union.py b/tests/schema/test_union.py index 38a9c13236..d736caa7a4 100644 --- a/tests/schema/test_union.py +++ b/tests/schema/test_union.py @@ -975,7 +975,9 @@ class UnionObjectQueries(Generic[T, U]): @strawberry.field def by_id( self, id: strawberry.ID - ) -> T | Annotated[U | NotFoundError, strawberry.union("ByIdResult")]: ... + ) -> Union[ + T, Annotated[Union[U, NotFoundError], strawberry.union("ByIdResult")] + ]: ... @strawberry.type class Query: From 0eb6966cf85390a8b272490e94b0025e3010ceb3 Mon Sep 17 00:00:00 2001 From: Jacob Allen Date: Thu, 30 May 2024 22:10:17 -0600 Subject: [PATCH 14/17] Remove unused function bodies from tests --- tests/schema/test_union.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/schema/test_union.py b/tests/schema/test_union.py index d736caa7a4..cfba6150a0 100644 --- a/tests/schema/test_union.py +++ b/tests/schema/test_union.py @@ -921,8 +921,7 @@ def by_id( @strawberry.type class Query: @strawberry.field - def some_type_queries(self, id: strawberry.ID) -> ObjectQueries[SomeType]: - return ObjectQueries(SomeType) + def some_type_queries(self, id: strawberry.ID) -> ObjectQueries[SomeType]: ... schema = strawberry.Schema(Query) @@ -984,8 +983,7 @@ class Query: @strawberry.field def some_type_queries( self, id: strawberry.ID - ) -> UnionObjectQueries[SomeType, OtherType]: - return UnionObjectQueries() + ) -> UnionObjectQueries[SomeType, OtherType]: ... schema = strawberry.Schema(Query) From 5fb86260e56422265b55ece7736954ed4ca16837 Mon Sep 17 00:00:00 2001 From: Jacob Allen Date: Sat, 19 Oct 2024 23:40:54 -0600 Subject: [PATCH 15/17] Update RELEASE.md Co-authored-by: Thiago Bellini Ribeiro --- RELEASE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RELEASE.md b/RELEASE.md index 732f56afa3..e41e9220d4 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -1,3 +1,3 @@ -Release type: patch +Release type: minor Attempt to merge union types during schema conversion. From f18da66134e582a10740a0cab033cb120cf236a2 Mon Sep 17 00:00:00 2001 From: Patrick Arminio Date: Tue, 15 Apr 2025 17:54:50 +0100 Subject: [PATCH 16/17] Update release notes --- RELEASE.md | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/RELEASE.md b/RELEASE.md index e41e9220d4..e885ec299f 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -1,3 +1,20 @@ Release type: minor -Attempt to merge union types during schema conversion. +This release adds support for using strawberry.union with generics, like in this +example: + +```python +@strawberry.type +class ObjectQueries[T]: + @strawberry.field + def by_id( + self, id: strawberry.ID + ) -> Union[T, Annotated[NotFoundError, strawberry.union("ByIdResult")]]: ... + +@strawberry.type +class Query: + @strawberry.field + def some_type_queries(self, id: strawberry.ID) -> ObjectQueries[SomeType]: ... +``` + +which, now, creates a correct union type named `SomeTypeByIdResult` From 70a4758d3d123b492fbcf415e85e3d908383dfeb Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 15 Apr 2025 16:57:02 +0000 Subject: [PATCH 17/17] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- RELEASE.md | 1 + tests/schema/test_union.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/RELEASE.md b/RELEASE.md index e885ec299f..c3b4701ada 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -11,6 +11,7 @@ class ObjectQueries[T]: self, id: strawberry.ID ) -> Union[T, Annotated[NotFoundError, strawberry.union("ByIdResult")]]: ... + @strawberry.type class Query: @strawberry.field diff --git a/tests/schema/test_union.py b/tests/schema/test_union.py index cfba6150a0..78e2657740 100644 --- a/tests/schema/test_union.py +++ b/tests/schema/test_union.py @@ -866,7 +866,7 @@ def by_id( class Query: @strawberry.field def some_type_queries(self, id: strawberry.ID) -> ObjectQueries[SomeType]: - raise NotImplementedError() + raise NotImplementedError schema = strawberry.Schema(Query)