strawberry-graphql 0.264.0__py3-none-any.whl → 0.265.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -83,14 +83,14 @@ def convert_pydantic_model_to_strawberry_class(
83
83
  field = cast("StrawberryField", field_)
84
84
  python_name = field.python_name
85
85
 
86
- data_from_extra = extra.get(python_name, None)
87
- data_from_model = (
88
- getattr(model_instance, python_name, None) if model_instance else None
89
- )
90
-
91
86
  # only convert and add fields to kwargs if they are present in the `__init__`
92
87
  # method of the class
93
88
  if field.init:
89
+ data_from_extra = extra.get(python_name, None)
90
+ data_from_model = (
91
+ getattr(model_instance, python_name, None) if model_instance else None
92
+ )
93
+
94
94
  kwargs[python_name] = _convert_from_pydantic_to_strawberry_type(
95
95
  field.type, data_from_model, extra=data_from_extra
96
96
  )
@@ -1,6 +1,6 @@
1
1
  from __future__ import annotations
2
2
 
3
- from typing import TYPE_CHECKING, Optional, Union, cast
3
+ from typing import TYPE_CHECKING, Optional, Tuple, Union, cast
4
4
  from typing_extensions import Protocol
5
5
 
6
6
  from strawberry.directive import StrawberryDirective
@@ -106,8 +106,14 @@ class NameConverter:
106
106
  return union.graphql_name
107
107
 
108
108
  name = ""
109
+ types: Tuple[StrawberryType, ...] = union.types
109
110
 
110
- for type_ in union.types:
111
+ if union.concrete_of and union.concrete_of.graphql_name:
112
+ concrete_of_types = set(union.concrete_of.types)
113
+
114
+ types = tuple(type_ for type_ in types if type_ not in concrete_of_types)
115
+
116
+ for type_ in types:
111
117
  if isinstance(type_, LazyType):
112
118
  type_ = cast("StrawberryType", type_.resolve_type()) # noqa: PLW2901
113
119
 
@@ -120,6 +126,9 @@ class NameConverter:
120
126
 
121
127
  name += type_name
122
128
 
129
+ if union.concrete_of and union.concrete_of.graphql_name:
130
+ name += union.concrete_of.graphql_name
131
+
123
132
  return name
124
133
 
125
134
  def from_generic(
@@ -132,12 +141,12 @@ class NameConverter:
132
141
  names: list[str] = []
133
142
 
134
143
  for type_ in types:
135
- name = self.get_from_type(type_)
144
+ name = self.get_name_from_type(type_)
136
145
  names.append(name)
137
146
 
138
147
  return "".join(names) + generic_type_name
139
148
 
140
- def get_from_type(self, type_: Union[StrawberryType, type]) -> str:
149
+ def get_name_from_type(self, type_: Union[StrawberryType, type]) -> str:
141
150
  type_ = eval_type(type_)
142
151
 
143
152
  if isinstance(type_, LazyType):
@@ -147,9 +156,9 @@ class NameConverter:
147
156
  elif isinstance(type_, StrawberryUnion):
148
157
  name = type_.graphql_name if type_.graphql_name else self.from_union(type_)
149
158
  elif isinstance(type_, StrawberryList):
150
- name = self.get_from_type(type_.of_type) + "List"
159
+ name = self.get_name_from_type(type_.of_type) + "List"
151
160
  elif isinstance(type_, StrawberryOptional):
152
- name = self.get_from_type(type_.of_type) + "Optional"
161
+ name = self.get_name_from_type(type_.of_type) + "Optional"
153
162
  elif hasattr(type_, "_scalar_definition"):
154
163
  strawberry_type = type_._scalar_definition
155
164
 
@@ -865,14 +865,20 @@ class GraphQLCoreConverter:
865
865
  return graphql_union
866
866
 
867
867
  graphql_types: list[GraphQLObjectType] = []
868
+
868
869
  for type_ in union.types:
869
870
  graphql_type = self.from_type(type_)
870
871
 
871
872
  if isinstance(graphql_type, GraphQLInputObjectType):
872
873
  raise InvalidTypeInputForUnion(graphql_type)
873
- assert isinstance(graphql_type, GraphQLObjectType)
874
+ assert isinstance(graphql_type, (GraphQLObjectType, GraphQLUnionType))
874
875
 
875
- graphql_types.append(graphql_type)
876
+ # If the graphql_type is a GraphQLUnionType, merge its child types
877
+ if isinstance(graphql_type, GraphQLUnionType):
878
+ # Add the child types of the GraphQLUnionType to the list of graphql_types
879
+ graphql_types.extend(graphql_type.types)
880
+ else:
881
+ graphql_types.append(graphql_type)
876
882
 
877
883
  graphql_union = GraphQLUnionType(
878
884
  name=union_name,
strawberry/types/union.py CHANGED
@@ -64,6 +64,7 @@ class StrawberryUnion(StrawberryType):
64
64
  self.directives = directives
65
65
  self._source_file = None
66
66
  self._source_line = None
67
+ self.concrete_of: Optional[StrawberryUnion] = None
67
68
 
68
69
  def __eq__(self, other: object) -> bool:
69
70
  if isinstance(other, StrawberryType):
@@ -136,6 +137,7 @@ class StrawberryUnion(StrawberryType):
136
137
  return self
137
138
 
138
139
  new_types = []
140
+
139
141
  for type_ in self.types:
140
142
  new_type: Union[StrawberryType, type]
141
143
 
@@ -151,10 +153,13 @@ class StrawberryUnion(StrawberryType):
151
153
 
152
154
  new_types.append(new_type)
153
155
 
154
- return StrawberryUnion(
156
+ new_union = StrawberryUnion(
155
157
  type_annotations=tuple(map(StrawberryAnnotation, new_types)),
156
158
  description=self.description,
157
159
  )
160
+ new_union.concrete_of = self
161
+
162
+ return new_union
158
163
 
159
164
  def __call__(self, *args: str, **kwargs: Any) -> NoReturn:
160
165
  """Do not use.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: strawberry-graphql
3
- Version: 0.264.0
3
+ Version: 0.265.0
4
4
  Summary: A library for creating GraphQL APIs
5
5
  License: MIT
6
6
  Keywords: graphql,api,rest,starlette,async
@@ -74,7 +74,7 @@ strawberry/exceptions/utils/source_finder.py,sha256=kqSjCGIlnkD0DuCBYElqConp9wAv
74
74
  strawberry/experimental/__init__.py,sha256=2HP5XtxL8ZKsPp4EDRAbMCqiP7p2V4Cca278JUGxnt0,102
75
75
  strawberry/experimental/pydantic/__init__.py,sha256=UpO8wHNXGpoCYp34YStViInO1tsrGsMyhTVubTpJY7Y,255
76
76
  strawberry/experimental/pydantic/_compat.py,sha256=CUc7SmGA-viYoBgD4L8X483yTGyDKaKMjX3WYWkiohg,9710
77
- strawberry/experimental/pydantic/conversion.py,sha256=LBkR3CukdZx9LLvmDyK75YhoOrl0AlF3UD7x8HYr7us,4226
77
+ strawberry/experimental/pydantic/conversion.py,sha256=xspWZtbCuhLeStf12X60c5cOrKp4ilVDlnW-tRU0_YY,4242
78
78
  strawberry/experimental/pydantic/conversion_types.py,sha256=jf7PR5Q7hgo4J_AuxBK-BVj-8MC6vIg1k1pUfGfGTL8,925
79
79
  strawberry/experimental/pydantic/error_type.py,sha256=RdmiUY4V0baXCAk80ST-XtCiZbndZaaUSEajQplDAzw,4557
80
80
  strawberry/experimental/pydantic/exceptions.py,sha256=pDMPL94ojuSGHxk8H8mI2pfWReG8BhqZ5T2eSxfOi9w,1486
@@ -166,9 +166,9 @@ strawberry/schema/base.py,sha256=q5UAw6do4Ele5Cf8dNAouiPjNmZoCBNFqh5Vl05caCI,386
166
166
  strawberry/schema/compat.py,sha256=9qJ0lhYJeaN43ayFgVz708ZMvedBhofiTSw9kpFqmjU,1830
167
167
  strawberry/schema/config.py,sha256=6BpCbNNCuekGgiKEPt2mliMqLH_wIjJmSW0tLbnJwk4,924
168
168
  strawberry/schema/exceptions.py,sha256=rqVNb_oYrKM0dHPgvAemqCG6Um282LPPu4zwQ5cZqs4,584
169
- strawberry/schema/name_converter.py,sha256=1rrpch-wBidlWfZ7hVouvIIhJpdxWfB5tWnO6PqYug8,6544
169
+ strawberry/schema/name_converter.py,sha256=MK4CqCtboyWnjIwit0tx9VCoS75LYTz4O5YAL3HBpiA,6952
170
170
  strawberry/schema/schema.py,sha256=qthZttzb9a0GEcwh7trqBKHmuPXOgQlnceqiCRPj4_s,34566
171
- strawberry/schema/schema_converter.py,sha256=-_QZCcmHWIEjRPqEChtPMPbFtgz6YmLn8V6KXvZJMOk,37192
171
+ strawberry/schema/schema_converter.py,sha256=OkJaYrWKGqcxdhoTeuf0aGqiTnWtDuZwYddY5uBlf8Q,37521
172
172
  strawberry/schema/types/__init__.py,sha256=oHO3COWhL3L1KLYCJNY1XFf5xt2GGtHiMC-UaYbFfnA,68
173
173
  strawberry/schema/types/base_scalars.py,sha256=JRUq0WjEkR9dFewstZnqnZKp0uOEipo4UXNF5dzRf4M,1971
174
174
  strawberry/schema/types/concrete_type.py,sha256=axIyFZgdwNv-XYkiqX67464wuFX6Vp0jYATwnBZSUvM,750
@@ -213,7 +213,7 @@ strawberry/types/object_type.py,sha256=CW-detiYjGmk4kHJP-vUK9sBkBuDic4nswDub4zUy
213
213
  strawberry/types/private.py,sha256=DhJs50XVGtOXlxWZFkRpMxQ5_6oki0-x_WQsV1bGUxk,518
214
214
  strawberry/types/scalar.py,sha256=CM24Ixg4DKxxI1C6hTNGYVitohJibs8BpGtntRZvMXw,6284
215
215
  strawberry/types/type_resolver.py,sha256=fH2ZOK4dAGgu8AMPi-JAXe_kEAbvvw2MCYXqbpx-kTc,6529
216
- strawberry/types/union.py,sha256=jlIQwIZdvvD78ybYEy0CB4P7xnr07rb3VuK0SfCUvPk,9962
216
+ strawberry/types/union.py,sha256=rwZoJcMdUxJBlYMwx3ONByv6BylhvXT0Bflem6xzMM4,10090
217
217
  strawberry/types/unset.py,sha256=7DVK-WWxVLo41agvavTvIbphE42BmY8UpGolXfasIvw,1682
218
218
  strawberry/utils/__init__.py,sha256=wuuNvKjcMfE0l4lqrlC-cc0_SR4hV19gNBJ3Mcn7l3A,141
219
219
  strawberry/utils/aio.py,sha256=Nry5jxFHvipGS1CwX5VvFS2YQ6_bp-_cewnI6v9A7-A,2226
@@ -228,8 +228,8 @@ strawberry/utils/logging.py,sha256=U1cseHGquN09YFhFmRkiphfASKCyK0HUZREImPgVb0c,7
228
228
  strawberry/utils/operation.py,sha256=s7ajvLg_q6v2mg47kEMQPjO_J-XluMKTCwo4d47mGvE,1195
229
229
  strawberry/utils/str_converters.py,sha256=-eH1Cl16IO_wrBlsGM-km4IY0IKsjhjnSNGRGOwQjVM,897
230
230
  strawberry/utils/typing.py,sha256=Xmnhwvnw8RIQVIc5D5iI4_9qM4Thpk7tWx8xf-RW_So,13383
231
- strawberry_graphql-0.264.0.dist-info/LICENSE,sha256=m-XnIVUKqlG_AWnfi9NReh9JfKhYOB-gJfKE45WM1W8,1072
232
- strawberry_graphql-0.264.0.dist-info/METADATA,sha256=Z4gLrc-diDadDxYz17PQW1OIjVnLJ-qwQjIJQSkLYO0,7679
233
- strawberry_graphql-0.264.0.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
234
- strawberry_graphql-0.264.0.dist-info/entry_points.txt,sha256=Nk7-aT3_uEwCgyqtHESV9H6Mc31cK-VAvhnQNTzTb4k,49
235
- strawberry_graphql-0.264.0.dist-info/RECORD,,
231
+ strawberry_graphql-0.265.0.dist-info/LICENSE,sha256=m-XnIVUKqlG_AWnfi9NReh9JfKhYOB-gJfKE45WM1W8,1072
232
+ strawberry_graphql-0.265.0.dist-info/METADATA,sha256=Ds08QsahrOH09gzBALiyESIbKiVn8CHMnsf-OLW_kLk,7679
233
+ strawberry_graphql-0.265.0.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
234
+ strawberry_graphql-0.265.0.dist-info/entry_points.txt,sha256=Nk7-aT3_uEwCgyqtHESV9H6Mc31cK-VAvhnQNTzTb4k,49
235
+ strawberry_graphql-0.265.0.dist-info/RECORD,,