strawberry-graphql 0.277.0__py3-none-any.whl → 0.277.1__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.

Potentially problematic release.


This version of strawberry-graphql might be problematic. Click here for more details.

strawberry/annotation.py CHANGED
@@ -125,16 +125,44 @@ class StrawberryAnnotation:
125
125
 
126
126
  return evaled_type, []
127
127
 
128
- def resolve(self) -> Union[StrawberryType, type]:
128
+ def resolve(
129
+ self,
130
+ *,
131
+ type_definition: Optional[StrawberryObjectDefinition] = None,
132
+ ) -> Union[StrawberryType, type]:
129
133
  """Return resolved (transformed) annotation."""
130
- if self.__resolve_cache__ is None:
131
- self.__resolve_cache__ = self._resolve()
134
+ if (resolved := self.__resolve_cache__) is None:
135
+ resolved = self._resolve()
136
+ self.__resolve_cache__ = resolved
137
+
138
+ # If this is a generic field, try to resolve it using its origin's
139
+ # specialized type_var_map
140
+ if self._is_type_generic(resolved) and type_definition is not None:
141
+ from strawberry.types.base import StrawberryType
142
+
143
+ specialized_type_var_map = type_definition.specialized_type_var_map
144
+ if specialized_type_var_map and isinstance(resolved, StrawberryType):
145
+ resolved = resolved.copy_with(specialized_type_var_map)
146
+
147
+ # If the field is still generic, try to resolve it from the type_definition
148
+ # that is asking for it.
149
+ if (
150
+ self._is_type_generic(resolved)
151
+ and type_definition.type_var_map
152
+ and isinstance(resolved, StrawberryType)
153
+ ):
154
+ resolved = resolved.copy_with(type_definition.type_var_map)
155
+
156
+ # Resolve the type again to resolve any `Annotated` types
157
+ resolved = self._resolve_evaled_type(resolved)
132
158
 
133
- return self.__resolve_cache__
159
+ return resolved
134
160
 
135
161
  def _resolve(self) -> Union[StrawberryType, type]:
136
162
  evaled_type = cast("Any", self.evaluate())
163
+ return self._resolve_evaled_type(evaled_type)
137
164
 
165
+ def _resolve_evaled_type(self, evaled_type: Any) -> Union[StrawberryType, type]:
138
166
  if is_private(evaled_type):
139
167
  return evaled_type
140
168
 
@@ -145,7 +173,7 @@ class StrawberryAnnotation:
145
173
  if self._is_lazy_type(evaled_type):
146
174
  return evaled_type
147
175
  if self._is_streamable(evaled_type, args):
148
- return self.create_list(list[evaled_type]) # type: ignore[valid-type]
176
+ return self.create_list(list[evaled_type])
149
177
  if self._is_list(evaled_type):
150
178
  return self.create_list(evaled_type)
151
179
  if self._is_maybe(evaled_type):
@@ -292,6 +320,20 @@ class StrawberryAnnotation:
292
320
  return False
293
321
  return issubclass(annotation, Enum)
294
322
 
323
+ @classmethod
324
+ def _is_type_generic(cls, type_: Union[StrawberryType, type]) -> bool:
325
+ """Returns True if `resolver_type` is generic else False."""
326
+ from strawberry.types.base import StrawberryType
327
+
328
+ if isinstance(type_, StrawberryType):
329
+ return type_.is_graphql_generic
330
+
331
+ # solves the Generic subclass case
332
+ if has_object_definition(type_):
333
+ return type_.__strawberry_definition__.is_graphql_generic
334
+
335
+ return False
336
+
295
337
  @classmethod
296
338
  def _is_graphql_generic(cls, annotation: Any) -> bool:
297
339
  if hasattr(annotation, "__origin__"):
strawberry/types/field.py CHANGED
@@ -13,7 +13,6 @@ from typing import (
13
13
  Optional,
14
14
  TypeVar,
15
15
  Union,
16
- cast,
17
16
  overload,
18
17
  )
19
18
 
@@ -348,7 +347,7 @@ class StrawberryField(dataclasses.Field):
348
347
  with contextlib.suppress(NameError):
349
348
  # Prioritise the field type over the resolver return type
350
349
  if self.type_annotation is not None:
351
- resolved = self.type_annotation.resolve()
350
+ resolved = self.type_annotation.resolve(type_definition=type_definition)
352
351
  elif self.base_resolver is not None and self.base_resolver.type is not None:
353
352
  # Handle unannotated functions (such as lambdas)
354
353
  # Generics will raise MissingTypesForGenericError later
@@ -356,26 +355,6 @@ class StrawberryField(dataclasses.Field):
356
355
  # which is the same behaviour as having no type information.
357
356
  resolved = self.base_resolver.type
358
357
 
359
- # If this is a generic field, try to resolve it using its origin's
360
- # specialized type_var_map
361
- # TODO: should we check arguments here too?
362
- if _is_generic(resolved): # type: ignore
363
- specialized_type_var_map = (
364
- type_definition and type_definition.specialized_type_var_map
365
- )
366
- if specialized_type_var_map and isinstance(resolved, StrawberryType):
367
- resolved = resolved.copy_with(specialized_type_var_map)
368
-
369
- # If the field is still generic, try to resolve it from the type_definition
370
- # that is asking for it.
371
- if (
372
- _is_generic(cast("Union[StrawberryType, type]", resolved))
373
- and type_definition is not None
374
- and type_definition.type_var_map
375
- and isinstance(resolved, StrawberryType)
376
- ):
377
- resolved = resolved.copy_with(type_definition.type_var_map)
378
-
379
358
  return resolved
380
359
 
381
360
  def copy_with(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: strawberry-graphql
3
- Version: 0.277.0
3
+ Version: 0.277.1
4
4
  Summary: A library for creating GraphQL APIs
5
5
  License: MIT
6
6
  Keywords: graphql,api,rest,starlette,async
@@ -4,7 +4,7 @@ strawberry/aiohttp/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuF
4
4
  strawberry/aiohttp/test/__init__.py,sha256=4xxdUZtIISSOwjrcnmox7AvT4WWjowCm5bUuPdQneMg,71
5
5
  strawberry/aiohttp/test/client.py,sha256=8FKZTnvawxYpgEICOri-34O3wHRHLhRpjH_Ktp2EupQ,1801
6
6
  strawberry/aiohttp/views.py,sha256=EhsaD0Ms7qhHxGyS0qDbRPKxz3VUaSdsbEZKTniIjaM,7962
7
- strawberry/annotation.py,sha256=D_12gZSdyges7DMpzsqjGsAbex0M-zffyPa3NWt42bw,14180
7
+ strawberry/annotation.py,sha256=68j7Sku1JT7pUTsUMxekWmQMyFdlV1D0jLFjukmmGpQ,15907
8
8
  strawberry/asgi/__init__.py,sha256=psdKl_52LGkxKKbzZlmwNGZ9jz2FLyLSC7fUhys4FqY,8169
9
9
  strawberry/asgi/test/__init__.py,sha256=4xxdUZtIISSOwjrcnmox7AvT4WWjowCm5bUuPdQneMg,71
10
10
  strawberry/asgi/test/client.py,sha256=kp2O5znHWuAB5VVYO8p4XPSTEDDXBSjNz5WHqW0r6GM,1473
@@ -207,7 +207,7 @@ strawberry/types/base.py,sha256=Bfa-5Wen8qR7m6tlSMRRGlGE-chRGMHjQMopfNdbbrk,1519
207
207
  strawberry/types/cast.py,sha256=fx86MkLW77GIximBAwUk5vZxSGwDqUA6XicXvz8EXwQ,916
208
208
  strawberry/types/enum.py,sha256=7bK7YUzlG117_V9x-f9hx5vogcCRF6UBUFteeKhjDHg,6306
209
209
  strawberry/types/execution.py,sha256=_Rl4akU174P_2mq3x1N1QTj0LgJn3CQ43hPFzN3rs_s,4075
210
- strawberry/types/field.py,sha256=vxb7JvkHfRmDCYsjhDmVnO2lMbtSOteQm3jQUeSFu6g,21605
210
+ strawberry/types/field.py,sha256=8FRKetfwJkRaWDVpKgHQpyBKnDBarcsnZQz5Gs8if0w,20664
211
211
  strawberry/types/fields/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
212
212
  strawberry/types/fields/resolver.py,sha256=b6lxfw6AMOUFWm7vs7a9KzNkpR8b_S110DoIosrrWDQ,14679
213
213
  strawberry/types/graphql.py,sha256=gXKzawwKiow7hvoJhq5ApNJOMUCnKmvTiHaKY5CK1Lw,867
@@ -236,8 +236,8 @@ strawberry/utils/logging.py,sha256=U1cseHGquN09YFhFmRkiphfASKCyK0HUZREImPgVb0c,7
236
236
  strawberry/utils/operation.py,sha256=ZgVOw3K2jQuLjNOYUHauF7itJD0QDNoPw9PBi0IYf6k,1234
237
237
  strawberry/utils/str_converters.py,sha256=-eH1Cl16IO_wrBlsGM-km4IY0IKsjhjnSNGRGOwQjVM,897
238
238
  strawberry/utils/typing.py,sha256=SDvX-Du-9HAV3-XXjqi7Q5f5qPDDFd_gASIITiwBQT4,14073
239
- strawberry_graphql-0.277.0.dist-info/LICENSE,sha256=m-XnIVUKqlG_AWnfi9NReh9JfKhYOB-gJfKE45WM1W8,1072
240
- strawberry_graphql-0.277.0.dist-info/METADATA,sha256=JPt-IK9XsRJrGkO3N4EtmnHqo5HO_ctGLdEYVW8nKlU,7393
241
- strawberry_graphql-0.277.0.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
242
- strawberry_graphql-0.277.0.dist-info/entry_points.txt,sha256=Nk7-aT3_uEwCgyqtHESV9H6Mc31cK-VAvhnQNTzTb4k,49
243
- strawberry_graphql-0.277.0.dist-info/RECORD,,
239
+ strawberry_graphql-0.277.1.dist-info/LICENSE,sha256=m-XnIVUKqlG_AWnfi9NReh9JfKhYOB-gJfKE45WM1W8,1072
240
+ strawberry_graphql-0.277.1.dist-info/METADATA,sha256=pCl_jBS9s2rwDKAcVDwSz04sBR6V0PGmCNAAedv2sR4,7393
241
+ strawberry_graphql-0.277.1.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
242
+ strawberry_graphql-0.277.1.dist-info/entry_points.txt,sha256=Nk7-aT3_uEwCgyqtHESV9H6Mc31cK-VAvhnQNTzTb4k,49
243
+ strawberry_graphql-0.277.1.dist-info/RECORD,,