strawberry-graphql 0.266.1__py3-none-any.whl → 0.267.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.
strawberry/parent.py CHANGED
@@ -1,4 +1,7 @@
1
- from typing import Annotated, TypeVar
1
+ import re
2
+ from typing import Annotated, Any, ForwardRef, TypeVar
3
+
4
+ _parent_re = re.compile(r"^(?:strawberry\.)?Parent\[(.*)\]$")
2
5
 
3
6
 
4
7
  class StrawberryParent: ...
@@ -40,4 +43,20 @@ class Query:
40
43
  ```
41
44
  """
42
45
 
43
- __all__ = ["Parent"]
46
+
47
+ def resolve_parent_forward_arg(annotation: Any) -> Any:
48
+ if isinstance(annotation, str):
49
+ str_annotation = annotation
50
+ elif isinstance(annotation, ForwardRef):
51
+ str_annotation = annotation.__forward_arg__
52
+ else:
53
+ # If neither, return the annotation as is
54
+ return annotation
55
+
56
+ if parent_match := _parent_re.match(str_annotation):
57
+ annotation = Parent[ForwardRef(parent_match.group(1))] # type: ignore[misc]
58
+
59
+ return annotation
60
+
61
+
62
+ __all__ = ["Parent", "StrawberryParent", "resolve_parent_forward_arg"]
@@ -25,7 +25,7 @@ from strawberry.exceptions import (
25
25
  ConflictingArgumentsError,
26
26
  MissingArgumentsAnnotationsError,
27
27
  )
28
- from strawberry.parent import StrawberryParent
28
+ from strawberry.parent import StrawberryParent, resolve_parent_forward_arg
29
29
  from strawberry.types.arguments import StrawberryArgument
30
30
  from strawberry.types.base import StrawberryType, has_object_definition
31
31
  from strawberry.types.info import Info
@@ -118,10 +118,17 @@ class ReservedType(NamedTuple):
118
118
  try:
119
119
  evaled_annotation = annotation.evaluate()
120
120
  except NameError:
121
- continue
122
- else:
123
- if self.is_reserved_type(evaled_annotation):
124
- type_parameters.append(parameter)
121
+ # If this is a strawberry.Parent using ForwardRef, we will fail to
122
+ # evaluate at this moment, but at least knowing that it is a reserved
123
+ # type is enough for now
124
+ # We might want to revisit this in the future, maybe by postponing
125
+ # this check to when the schema is actually being created
126
+ evaled_annotation = resolve_parent_forward_arg(
127
+ annotation.annotation
128
+ )
129
+
130
+ if self.is_reserved_type(evaled_annotation):
131
+ type_parameters.append(parameter)
125
132
 
126
133
  if len(type_parameters) > 1:
127
134
  raise ConflictingArgumentsError(
@@ -304,11 +304,13 @@ def eval_type(
304
304
  localns: Optional[dict] = None,
305
305
  ) -> type:
306
306
  """Evaluates a type, resolving forward references."""
307
+ from strawberry.parent import StrawberryParent
307
308
  from strawberry.types.auto import StrawberryAuto
308
309
  from strawberry.types.lazy_type import StrawberryLazyReference
309
310
  from strawberry.types.private import StrawberryPrivate
310
311
 
311
312
  globalns = globalns or {}
313
+
312
314
  # If this is not a string, maybe its args are (e.g. list["Foo"])
313
315
  if isinstance(type_, ForwardRef):
314
316
  ast_obj = cast("ast.Expr", ast.parse(type_.__forward_arg__).body[0])
@@ -355,6 +357,7 @@ def eval_type(
355
357
  )
356
358
  args = (type_arg, *remaining_args)
357
359
  break
360
+
358
361
  if isinstance(arg, StrawberryAuto):
359
362
  remaining_args = [
360
363
  a for a in args[1:] if not isinstance(a, StrawberryAuto)
@@ -362,6 +365,21 @@ def eval_type(
362
365
  args = (args[0], arg, *remaining_args)
363
366
  break
364
367
 
368
+ if isinstance(arg, StrawberryParent):
369
+ remaining_args = [
370
+ a for a in args[1:] if not isinstance(a, StrawberryParent)
371
+ ]
372
+ try:
373
+ type_arg = (
374
+ eval_type(args[0], globalns, localns)
375
+ if isinstance(args[0], ForwardRef)
376
+ else args[0]
377
+ )
378
+ except (NameError, TypeError):
379
+ type_arg = args[0]
380
+ args = (type_arg, arg, *remaining_args)
381
+ break
382
+
365
383
  # If we have only a StrawberryLazyReference and no more annotations,
366
384
  # we need to return the argument directly because Annotated
367
385
  # will raise an error if trying to instantiate it with only
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: strawberry-graphql
3
- Version: 0.266.1
3
+ Version: 0.267.0
4
4
  Summary: A library for creating GraphQL APIs
5
5
  License: MIT
6
6
  Keywords: graphql,api,rest,starlette,async
@@ -142,7 +142,7 @@ strawberry/http/types.py,sha256=H0wGOdCO-5tNKZM_6cAtNRwZAjoEXnAC5N0Q7b70AtU,398
142
142
  strawberry/http/typevars.py,sha256=Uu6NkKe3h7o29ZWwldq6sJy4ioSSeXODTCDRvY2hUpE,489
143
143
  strawberry/litestar/__init__.py,sha256=zsXzg-mglCGUVO9iNXLm-yadoDSCK7k-zuyRqyvAh1w,237
144
144
  strawberry/litestar/controller.py,sha256=DSbjl7QGCY_TX77EomqDvtH8-ZK6wfhL81IUEFa-JJs,14124
145
- strawberry/parent.py,sha256=wViSVYl5ADuyy2EGaS98by_iT1ep9xTP2od8NB_EIuw,742
145
+ strawberry/parent.py,sha256=JYFp-HGCgwbH2oB4uLSiIO4cVsoPaxX6lfYmxOKPkSg,1362
146
146
  strawberry/permission.py,sha256=dSRJMjSCmTlXfvfC24kCSrAk0txTjYKTJ5ZVU5IW91Y,7537
147
147
  strawberry/printer/__init__.py,sha256=DmepjmgtkdF5RxK_7yC6qUyRWn56U-9qeZMbkztYB9w,62
148
148
  strawberry/printer/ast_from_value.py,sha256=Tkme60qlykbN2m3dNPNMOe65X-wj6EmcDQwgQv7gUkc,4987
@@ -203,7 +203,7 @@ strawberry/types/enum.py,sha256=IcCz0FLswJtDC_bU8aG1cjreawcqHywAzzVRBZUSAqs,6229
203
203
  strawberry/types/execution.py,sha256=Ylc0lH0nyHyQW509mVqBh2sIN5qpf4cJtt8QhVmWGgI,3749
204
204
  strawberry/types/field.py,sha256=vxb7JvkHfRmDCYsjhDmVnO2lMbtSOteQm3jQUeSFu6g,21605
205
205
  strawberry/types/fields/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
206
- strawberry/types/fields/resolver.py,sha256=iYYVUVpm-JM3AFQHuQFeOooftiQWFw3kg64pqSNIe_0,14186
206
+ strawberry/types/fields/resolver.py,sha256=b6lxfw6AMOUFWm7vs7a9KzNkpR8b_S110DoIosrrWDQ,14679
207
207
  strawberry/types/graphql.py,sha256=gXKzawwKiow7hvoJhq5ApNJOMUCnKmvTiHaKY5CK1Lw,867
208
208
  strawberry/types/info.py,sha256=bPP7XTQQScmskJcmVv36iqLAWpdGmF2nhYjI1pJ-csI,4709
209
209
  strawberry/types/lazy_type.py,sha256=dlP9VcMjZc9sdgriiQGzOZa0TToB6Ee7zpIP8h7TLC0,5079
@@ -228,9 +228,9 @@ strawberry/utils/inspect.py,sha256=-aFT65PkQ9KXo5w8Q2uveBJ8jEpi40sTqRipRQVdYR8,3
228
228
  strawberry/utils/logging.py,sha256=U1cseHGquN09YFhFmRkiphfASKCyK0HUZREImPgVb0c,746
229
229
  strawberry/utils/operation.py,sha256=s7ajvLg_q6v2mg47kEMQPjO_J-XluMKTCwo4d47mGvE,1195
230
230
  strawberry/utils/str_converters.py,sha256=-eH1Cl16IO_wrBlsGM-km4IY0IKsjhjnSNGRGOwQjVM,897
231
- strawberry/utils/typing.py,sha256=Xmnhwvnw8RIQVIc5D5iI4_9qM4Thpk7tWx8xf-RW_So,13383
232
- strawberry_graphql-0.266.1.dist-info/LICENSE,sha256=m-XnIVUKqlG_AWnfi9NReh9JfKhYOB-gJfKE45WM1W8,1072
233
- strawberry_graphql-0.266.1.dist-info/METADATA,sha256=_RqVVXjFJ7svPPZ9xGPZHsBg5fjlnPAue2seThG3Tjo,7679
234
- strawberry_graphql-0.266.1.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
235
- strawberry_graphql-0.266.1.dist-info/entry_points.txt,sha256=Nk7-aT3_uEwCgyqtHESV9H6Mc31cK-VAvhnQNTzTb4k,49
236
- strawberry_graphql-0.266.1.dist-info/RECORD,,
231
+ strawberry/utils/typing.py,sha256=SDvX-Du-9HAV3-XXjqi7Q5f5qPDDFd_gASIITiwBQT4,14073
232
+ strawberry_graphql-0.267.0.dist-info/LICENSE,sha256=m-XnIVUKqlG_AWnfi9NReh9JfKhYOB-gJfKE45WM1W8,1072
233
+ strawberry_graphql-0.267.0.dist-info/METADATA,sha256=U6UycYRIH28R4jOQQO9BfGiciKuLEBUl_Doas8LahO0,7679
234
+ strawberry_graphql-0.267.0.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
235
+ strawberry_graphql-0.267.0.dist-info/entry_points.txt,sha256=Nk7-aT3_uEwCgyqtHESV9H6Mc31cK-VAvhnQNTzTb4k,49
236
+ strawberry_graphql-0.267.0.dist-info/RECORD,,