strawberry-graphql 0.226.0__py3-none-any.whl → 0.226.2__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.
@@ -11,6 +11,7 @@ from typing import (
11
11
  List,
12
12
  Optional,
13
13
  Set,
14
+ Tuple,
14
15
  Union,
15
16
  cast,
16
17
  )
@@ -59,11 +60,16 @@ try:
59
60
  except ImportError:
60
61
  TypeVarDef = TypeVarType
61
62
 
63
+ PYDANTIC_VERSION: Optional[Tuple[int, ...]] = None
64
+
62
65
  # To be compatible with user who don't use pydantic
63
66
  try:
67
+ import pydantic
64
68
  from pydantic.mypy import METADATA_KEY as PYDANTIC_METADATA_KEY
65
69
  from pydantic.mypy import PydanticModelField
66
70
 
71
+ PYDANTIC_VERSION = tuple(map(int, pydantic.__version__.split(".")))
72
+
67
73
  from strawberry.experimental.pydantic._compat import IS_PYDANTIC_V1
68
74
  except ImportError:
69
75
  PYDANTIC_METADATA_KEY = ""
@@ -464,6 +470,11 @@ def strawberry_pydantic_class_callback(ctx: ClassDefContext) -> None:
464
470
  return_type=model_type,
465
471
  )
466
472
  else:
473
+ extra = {}
474
+
475
+ if PYDANTIC_VERSION and PYDANTIC_VERSION >= (2, 7, 0):
476
+ extra["api"] = ctx.api
477
+
467
478
  add_method(
468
479
  ctx,
469
480
  "to_pydantic",
@@ -474,6 +485,7 @@ def strawberry_pydantic_class_callback(ctx: ClassDefContext) -> None:
474
485
  typed=True,
475
486
  force_optional=False,
476
487
  use_alias=True,
488
+ **extra,
477
489
  )
478
490
  for f in missing_pydantic_fields
479
491
  ],
@@ -487,12 +499,23 @@ def strawberry_pydantic_class_callback(ctx: ClassDefContext) -> None:
487
499
  initializer=None,
488
500
  kind=ARG_OPT,
489
501
  )
502
+ extra_type = ctx.api.named_type(
503
+ "builtins.dict",
504
+ [ctx.api.named_type("builtins.str"), AnyType(TypeOfAny.explicit)],
505
+ )
506
+
507
+ extra_argument = Argument(
508
+ variable=Var(name="extra", type=UnionType([NoneType(), extra_type])),
509
+ type_annotation=UnionType([NoneType(), extra_type]),
510
+ initializer=None,
511
+ kind=ARG_OPT,
512
+ )
490
513
 
491
514
  add_static_method_to_class(
492
515
  ctx.api,
493
516
  ctx.cls,
494
517
  name="from_pydantic",
495
- args=[model_argument],
518
+ args=[model_argument, extra_argument],
496
519
  return_type=fill_typevars(ctx.cls.info),
497
520
  )
498
521
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: strawberry-graphql
3
- Version: 0.226.0
3
+ Version: 0.226.2
4
4
  Summary: A library for creating GraphQL APIs
5
5
  Home-page: https://strawberry.rocks/
6
6
  License: MIT
@@ -96,7 +96,7 @@ strawberry/ext/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
96
96
  strawberry/ext/dataclasses/LICENSE,sha256=WZgm35K_3NJwLqxpEHJJi7CWxVrwTumEz5D3Dtd7WnA,13925
97
97
  strawberry/ext/dataclasses/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
98
98
  strawberry/ext/dataclasses/dataclasses.py,sha256=Le32f96qmahuenVsMW5xjIr-EPnO7WKljbOPLpU800Q,2254
99
- strawberry/ext/mypy_plugin.py,sha256=AGWu3xTguWMetqQP7bnaLRJBdLplPOtZ_eRGYt0Gfg8,18956
99
+ strawberry/ext/mypy_plugin.py,sha256=iqqRtJk3YRt1-rxDDl7aa9QtxZ0QYcu9-o6OWaczkqo,19716
100
100
  strawberry/extensions/__init__.py,sha256=SZ-YEMnxAzoDZFo-uHXMHOaY_PPkYm1muPpK4ccJ3Xk,1248
101
101
  strawberry/extensions/add_validation_rules.py,sha256=l1cCl6VGQ8c2EELK3cIjmn6RftonHD1jKoWQ5-hMTf0,1366
102
102
  strawberry/extensions/base_extension.py,sha256=XvYKIsSaxfTCVWdphOFll-Fo0wJd5Ib4QdKuYule6S0,2000
@@ -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=Qxz1LwyVsNGV7LQW1dFsaUbsswj5LHBOdKLMom5eyEA,13491
244
- strawberry_graphql-0.226.0.dist-info/LICENSE,sha256=m-XnIVUKqlG_AWnfi9NReh9JfKhYOB-gJfKE45WM1W8,1072
245
- strawberry_graphql-0.226.0.dist-info/METADATA,sha256=IsdKlusyjcwHbGq9o1obCi9IjY0UXYtFJ3m0XSSEqV4,7740
246
- strawberry_graphql-0.226.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
247
- strawberry_graphql-0.226.0.dist-info/entry_points.txt,sha256=Nk7-aT3_uEwCgyqtHESV9H6Mc31cK-VAvhnQNTzTb4k,49
248
- strawberry_graphql-0.226.0.dist-info/RECORD,,
244
+ strawberry_graphql-0.226.2.dist-info/LICENSE,sha256=m-XnIVUKqlG_AWnfi9NReh9JfKhYOB-gJfKE45WM1W8,1072
245
+ strawberry_graphql-0.226.2.dist-info/METADATA,sha256=j56ccpQGKWttSAIkUjsog3QlUzi3Tceumtonk8f3AWs,7740
246
+ strawberry_graphql-0.226.2.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
247
+ strawberry_graphql-0.226.2.dist-info/entry_points.txt,sha256=Nk7-aT3_uEwCgyqtHESV9H6Mc31cK-VAvhnQNTzTb4k,49
248
+ strawberry_graphql-0.226.2.dist-info/RECORD,,