strawberry-graphql 0.228.0__py3-none-any.whl → 0.229.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.
@@ -31,8 +31,10 @@ from graphql import (
31
31
  GraphQLInputObjectType,
32
32
  GraphQLInterfaceType,
33
33
  GraphQLList,
34
+ GraphQLNamedType,
34
35
  GraphQLNonNull,
35
36
  GraphQLObjectType,
37
+ GraphQLType,
36
38
  GraphQLUnionType,
37
39
  Undefined,
38
40
  ValueNode,
@@ -429,7 +431,7 @@ class GraphQLCoreConverter:
429
431
  ) -> GraphQLInterfaceType:
430
432
  interface_name = self.config.name_converter.from_type(interface)
431
433
 
432
- # Don't reevaluate known types
434
+ # Don't re-evaluate known types
433
435
  cached_type = self.type_map.get(interface_name, None)
434
436
  if cached_type:
435
437
  self.validate_same_type_definition(interface_name, interface, cached_type)
@@ -450,7 +452,32 @@ class GraphQLCoreConverter:
450
452
  # TODO: we should find the correct type here from the
451
453
  # generic
452
454
  if not type_definition.is_graphql_generic:
453
- return obj.__strawberry_definition__.name
455
+ return type_definition.name
456
+
457
+ # here we don't all the implementations of the generic
458
+ # we need to find a way to find them, for now maybe
459
+ # we can follow the union's approach and iterate over
460
+ # all the types in the schema, but we should probably
461
+ # optimize this
462
+
463
+ return_type: Optional[GraphQLType] = None
464
+
465
+ for possible_concrete_type in self.type_map.values():
466
+ possible_type = possible_concrete_type.definition
467
+
468
+ if not isinstance(
469
+ possible_type, StrawberryObjectDefinition
470
+ ): # pragma: no cover
471
+ continue
472
+
473
+ if possible_type.is_implemented_by(obj):
474
+ return_type = possible_concrete_type.implementation
475
+ break
476
+
477
+ if return_type:
478
+ assert isinstance(return_type, GraphQLNamedType)
479
+
480
+ return return_type.name
454
481
 
455
482
  # Revert to calling is_type_of for cases where a direct subclass
456
483
  # of the interface is not returned (i.e. an ORM object)
@@ -794,7 +821,7 @@ class GraphQLCoreConverter:
794
821
  if not StrawberryUnion.is_valid_union_type(type_):
795
822
  raise InvalidUnionTypeError(union_name, type_, union_definition=union)
796
823
 
797
- # Don't reevaluate known types
824
+ # Don't re-evaluate known types
798
825
  if union_name in self.type_map:
799
826
  graphql_union = self.type_map[union_name].implementation
800
827
  assert isinstance(graphql_union, GraphQLUnionType) # For mypy
strawberry/types/types.py CHANGED
@@ -17,6 +17,7 @@ from typing import (
17
17
  from typing_extensions import Self, deprecated
18
18
 
19
19
  from strawberry.type import (
20
+ StrawberryList,
20
21
  StrawberryType,
21
22
  StrawberryTypeVar,
22
23
  WithStrawberryObjectDefinition,
@@ -169,21 +170,43 @@ class StrawberryObjectDefinition(StrawberryType):
169
170
  return False
170
171
 
171
172
  # Check the mapping of all fields' TypeVars
172
- for generic_field in type_definition.fields:
173
- generic_field_type = generic_field.type
174
- if not isinstance(generic_field_type, StrawberryTypeVar):
173
+ for field in type_definition.fields:
174
+ if not field.is_graphql_generic:
175
+ continue
176
+
177
+ value = getattr(root, field.name)
178
+ generic_field_type = field.type
179
+
180
+ while isinstance(generic_field_type, StrawberryList):
181
+ generic_field_type = generic_field_type.of_type
182
+
183
+ assert isinstance(value, (list, tuple))
184
+
185
+ if len(value) == 0:
186
+ # We can't infer the type of an empty list, so we just
187
+ # return the first one we find
188
+ return True
189
+
190
+ value = value[0]
191
+
192
+ if isinstance(generic_field_type, StrawberryTypeVar):
193
+ type_var = generic_field_type.type_var
194
+ # TODO: I don't think we support nested types properly
195
+ # if there's a union that has two nested types that
196
+ # are have the same field with different types, we might
197
+ # not be able to differentiate them
198
+ else:
175
199
  continue
176
200
 
177
201
  # For each TypeVar found, get the expected type from the copy's type map
178
- expected_concrete_type = self.type_var_map.get(
179
- generic_field_type.type_var.__name__
180
- )
202
+ expected_concrete_type = self.type_var_map.get(type_var.__name__)
203
+
204
+ # this shouldn't happen, but we do a defensive check just in case
181
205
  if expected_concrete_type is None:
182
- # TODO: Should this return False?
183
206
  continue
184
207
 
185
208
  # Check if the expected type matches the type found on the type_map
186
- real_concrete_type = type(getattr(root, generic_field.name))
209
+ real_concrete_type = type(value)
187
210
 
188
211
  # TODO: uniform type var map, at the moment we map object types
189
212
  # to their class (not to TypeDefinition) while we map enum to
strawberry/union.py CHANGED
@@ -194,7 +194,6 @@ class StrawberryUnion(StrawberryType):
194
194
  # Union in case a nested generic object matches against more than one type.
195
195
  concrete_types_for_union = (type_map[x.name] for x in type_.types)
196
196
 
197
- # TODO: do we still need to iterate over all types in `type_map`?
198
197
  for possible_concrete_type in chain(
199
198
  concrete_types_for_union, type_map.values()
200
199
  ):
@@ -213,13 +212,9 @@ class StrawberryUnion(StrawberryType):
213
212
  info.field_name, str(type(root)), set(type_.types)
214
213
  )
215
214
 
216
- # Return the name of the type. Returning the actual type is now deprecated
217
- if isinstance(return_type, GraphQLNamedType):
218
- # TODO: Can return_type ever _not_ be a GraphQLNamedType?
219
- return return_type.name
220
- else:
221
- # TODO: check if this is correct
222
- return return_type.__name__ # type: ignore
215
+ assert isinstance(return_type, GraphQLNamedType)
216
+
217
+ return return_type.name
223
218
 
224
219
  return _resolve_union_type
225
220
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: strawberry-graphql
3
- Version: 0.228.0
3
+ Version: 0.229.0
4
4
  Summary: A library for creating GraphQL APIs
5
5
  Home-page: https://strawberry.rocks/
6
6
  License: MIT
@@ -189,7 +189,7 @@ strawberry/schema/exceptions.py,sha256=T-DsvBtjx9svkegIm1YrVPGPswpVEpMTFc0_7flLE
189
189
  strawberry/schema/execute.py,sha256=6OE7_5v4G3t_wxp1_mfwu8TTiIkTJNBQaeGCVAljUYw,10982
190
190
  strawberry/schema/name_converter.py,sha256=UdNyd-QtqF2HsDCQK-nsOcLGxDTj4hJwYFNvMtZnpq4,6533
191
191
  strawberry/schema/schema.py,sha256=MOC8k6NHolFGrCyqrungv0ciCImLdXTlbmo7y7rLRas,13734
192
- strawberry/schema/schema_converter.py,sha256=8uLOK8C7g9V7Zn8UpDlOMdFtVryK5bXPyLtzNtTZKxA,34777
192
+ strawberry/schema/schema_converter.py,sha256=_pVXXDoswZPhUGqwXK7oB68XZ4Lf6gkHehR-X_-GqCI,35885
193
193
  strawberry/schema/types/__init__.py,sha256=oHO3COWhL3L1KLYCJNY1XFf5xt2GGtHiMC-UaYbFfnA,68
194
194
  strawberry/schema/types/base_scalars.py,sha256=Z_BmgwLicNexLipGyw6MmZ7OBnkGJU3ySgaY9SwBWrw,1837
195
195
  strawberry/schema/types/concrete_type.py,sha256=HB30G1hMUuuvjAvfSe6ADS35iI_T_wKO-EprVOWTMSs,746
@@ -225,8 +225,8 @@ strawberry/types/graphql.py,sha256=3SWZEsa0Zy1eVW6vy75BnB7t9_lJVi6TBV3_1j3RNBs,6
225
225
  strawberry/types/info.py,sha256=b1ZWW_wUop6XrGNcGHKBQeUYjlX-y8u3s2Wm_XhKPYI,3412
226
226
  strawberry/types/nodes.py,sha256=5tTYmxGpVDshbydicHTTBWEiUe8A7p7mdiaSV8Ry80Y,5027
227
227
  strawberry/types/type_resolver.py,sha256=wuAYCbEjdov0IrnTvkFMNtSwb3lruQsbYI11x35ADeU,6542
228
- strawberry/types/types.py,sha256=hzfixwwwk6du1dWxjc90YytMVn8Ejzj90Pg2vSW8cqY,7139
229
- strawberry/union.py,sha256=IyC1emthtgoEGDOrEOpicC7QyQ0sUexXMx4BT6tFIF8,9951
228
+ strawberry/types/types.py,sha256=X6XwzDoboQkJjCfzi85Lw-pjTRzEYWi-uAUR8yDkstA,7947
229
+ strawberry/union.py,sha256=bQ3QBOLLugGvN434vHTZRuelgJdblfy8aJMrUpLgG_g,9585
230
230
  strawberry/unset.py,sha256=4zYRN8vUD7lHQLLpulBFqEPfyvzpx8fl7ZDBUyfMqqk,1112
231
231
  strawberry/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
232
232
  strawberry/utils/aio.py,sha256=nRu0VYg9RLpkY90t6UfUlCJhIS1qpmqLdQHlwTOK89g,1608
@@ -241,8 +241,8 @@ strawberry/utils/logging.py,sha256=flS7hV0JiIOEdXcrIjda4WyIWix86cpHHFNJL8gl1y4,7
241
241
  strawberry/utils/operation.py,sha256=Um-tBCPl3_bVFN2Ph7o1mnrxfxBes4HFCj6T0x4kZxE,1135
242
242
  strawberry/utils/str_converters.py,sha256=avIgPVLg98vZH9mA2lhzVdyyjqzLsK2NdBw9mJQ02Xk,813
243
243
  strawberry/utils/typing.py,sha256=SQVOw1nuFZk2Pe3iz0o8ebzpoyvBVoGSQZVZj6-8k7I,13483
244
- strawberry_graphql-0.228.0.dist-info/LICENSE,sha256=m-XnIVUKqlG_AWnfi9NReh9JfKhYOB-gJfKE45WM1W8,1072
245
- strawberry_graphql-0.228.0.dist-info/METADATA,sha256=U-Gu5DUkkLA2tapjewc98ESfX0ldUuztC0csHrp5Jfc,7821
246
- strawberry_graphql-0.228.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
247
- strawberry_graphql-0.228.0.dist-info/entry_points.txt,sha256=Nk7-aT3_uEwCgyqtHESV9H6Mc31cK-VAvhnQNTzTb4k,49
248
- strawberry_graphql-0.228.0.dist-info/RECORD,,
244
+ strawberry_graphql-0.229.0.dist-info/LICENSE,sha256=m-XnIVUKqlG_AWnfi9NReh9JfKhYOB-gJfKE45WM1W8,1072
245
+ strawberry_graphql-0.229.0.dist-info/METADATA,sha256=78joN5IOTLml1cPshc9NuDoJAnJ9zdE-lufGTeULi9o,7821
246
+ strawberry_graphql-0.229.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
247
+ strawberry_graphql-0.229.0.dist-info/entry_points.txt,sha256=Nk7-aT3_uEwCgyqtHESV9H6Mc31cK-VAvhnQNTzTb4k,49
248
+ strawberry_graphql-0.229.0.dist-info/RECORD,,