strawberry-graphql 0.262.6__py3-none-any.whl → 0.263.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.
@@ -12,7 +12,7 @@ from pydantic.version import VERSION as PYDANTIC_VERSION
12
12
  from strawberry.experimental.pydantic.exceptions import UnsupportedTypeError
13
13
 
14
14
  if TYPE_CHECKING:
15
- from pydantic.fields import FieldInfo
15
+ from pydantic.fields import ComputedFieldInfo, FieldInfo
16
16
 
17
17
  IS_PYDANTIC_V2: bool = PYDANTIC_VERSION.startswith("2.")
18
18
  IS_PYDANTIC_V1: bool = not IS_PYDANTIC_V2
@@ -128,7 +128,33 @@ class PydanticV2Compat:
128
128
 
129
129
  return PydanticUndefined
130
130
 
131
- def get_model_fields(self, model: type[BaseModel]) -> dict[str, CompatModelField]:
131
+ def get_model_computed_fields(
132
+ self, model: type[BaseModel]
133
+ ) -> dict[str, CompatModelField]:
134
+ computed_field_info: dict[str, ComputedFieldInfo] = model.model_computed_fields
135
+ new_fields = {}
136
+ # Convert it into CompatModelField
137
+ for name, field in computed_field_info.items():
138
+ new_fields[name] = CompatModelField(
139
+ name=name,
140
+ type_=field.return_type,
141
+ outer_type_=field.return_type,
142
+ default=None,
143
+ default_factory=None,
144
+ required=False,
145
+ alias=field.alias,
146
+ # v2 doesn't have allow_none
147
+ allow_none=False,
148
+ has_alias=field is not None,
149
+ description=field.description,
150
+ _missing_type=self.PYDANTIC_MISSING_TYPE,
151
+ is_v1=False,
152
+ )
153
+ return new_fields
154
+
155
+ def get_model_fields(
156
+ self, model: type[BaseModel], include_computed: bool = False
157
+ ) -> dict[str, CompatModelField]:
132
158
  field_info: dict[str, FieldInfo] = model.model_fields
133
159
  new_fields = {}
134
160
  # Convert it into CompatModelField
@@ -148,6 +174,8 @@ class PydanticV2Compat:
148
174
  _missing_type=self.PYDANTIC_MISSING_TYPE,
149
175
  is_v1=False,
150
176
  )
177
+ if include_computed:
178
+ new_fields |= self.get_model_computed_fields(model)
151
179
  return new_fields
152
180
 
153
181
  @cached_property
@@ -175,7 +203,10 @@ class PydanticV1Compat:
175
203
  def PYDANTIC_MISSING_TYPE(self) -> Any: # noqa: N802
176
204
  return dataclasses.MISSING
177
205
 
178
- def get_model_fields(self, model: type[BaseModel]) -> dict[str, CompatModelField]:
206
+ def get_model_fields(
207
+ self, model: type[BaseModel], include_computed: bool = False
208
+ ) -> dict[str, CompatModelField]:
209
+ """`include_computed` is a noop for PydanticV1Compat."""
179
210
  new_fields = {}
180
211
  # Convert it into CompatModelField
181
212
  for name, field in model.__fields__.items(): # type: ignore[attr-defined]
@@ -284,7 +315,6 @@ else:
284
315
  smart_deepcopy,
285
316
  )
286
317
 
287
-
288
318
  __all__ = [
289
319
  "PydanticCompat",
290
320
  "get_args",
@@ -126,11 +126,12 @@ def type( # noqa: PLR0915
126
126
  description: Optional[str] = None,
127
127
  directives: Optional[Sequence[object]] = (),
128
128
  all_fields: bool = False,
129
+ include_computed: bool = False,
129
130
  use_pydantic_alias: bool = True,
130
131
  ) -> Callable[..., builtins.type[StrawberryTypeFromPydantic[PydanticModel]]]:
131
132
  def wrap(cls: Any) -> builtins.type[StrawberryTypeFromPydantic[PydanticModel]]: # noqa: PLR0915
132
133
  compat = PydanticCompat.from_model(model)
133
- model_fields = compat.get_model_fields(model)
134
+ model_fields = compat.get_model_fields(model, include_computed=include_computed)
134
135
  original_fields_set = set(fields) if fields else set()
135
136
 
136
137
  if fields:
@@ -171,7 +172,10 @@ def type( # noqa: PLR0915
171
172
  raise MissingFieldsListError(cls)
172
173
 
173
174
  ensure_all_auto_fields_in_pydantic(
174
- model=model, auto_fields=auto_fields_set, cls_name=cls.__name__
175
+ model=model,
176
+ auto_fields=auto_fields_set,
177
+ cls_name=cls.__name__,
178
+ include_computed=include_computed,
175
179
  )
176
180
 
177
181
  wrapped = _wrap_dataclass(cls)
@@ -117,11 +117,17 @@ def get_default_factory_for_field(
117
117
 
118
118
 
119
119
  def ensure_all_auto_fields_in_pydantic(
120
- model: type[BaseModel], auto_fields: set[str], cls_name: str
120
+ model: type[BaseModel],
121
+ auto_fields: set[str],
122
+ cls_name: str,
123
+ include_computed: bool = False,
121
124
  ) -> None:
122
125
  compat = PydanticCompat.from_model(model)
123
126
  # Raise error if user defined a strawberry.auto field not present in the model
124
- non_existing_fields = list(auto_fields - compat.get_model_fields(model).keys())
127
+ non_existing_fields = list(
128
+ auto_fields
129
+ - compat.get_model_fields(model, include_computed=include_computed).keys()
130
+ )
125
131
 
126
132
  if non_existing_fields:
127
133
  raise AutoFieldsNotInBaseModelError(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: strawberry-graphql
3
- Version: 0.262.6
3
+ Version: 0.263.0
4
4
  Summary: A library for creating GraphQL APIs
5
5
  License: MIT
6
6
  Keywords: graphql,api,rest,starlette,async
@@ -73,14 +73,14 @@ strawberry/exceptions/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMp
73
73
  strawberry/exceptions/utils/source_finder.py,sha256=kqSjCGIlnkD0DuCBYElqConp9wAvAyQ8kIHKgnmupjY,20123
74
74
  strawberry/experimental/__init__.py,sha256=2HP5XtxL8ZKsPp4EDRAbMCqiP7p2V4Cca278JUGxnt0,102
75
75
  strawberry/experimental/pydantic/__init__.py,sha256=UpO8wHNXGpoCYp34YStViInO1tsrGsMyhTVubTpJY7Y,255
76
- strawberry/experimental/pydantic/_compat.py,sha256=GN_EQK_Pa3tlzTH3iVEvjerauFOJDNnpDHk7jrD5Dt0,8523
76
+ strawberry/experimental/pydantic/_compat.py,sha256=CUc7SmGA-viYoBgD4L8X483yTGyDKaKMjX3WYWkiohg,9710
77
77
  strawberry/experimental/pydantic/conversion.py,sha256=210v83ttSVhBlNM52to-x8s80V9WuOPez94qd5yDOD4,4224
78
78
  strawberry/experimental/pydantic/conversion_types.py,sha256=jf7PR5Q7hgo4J_AuxBK-BVj-8MC6vIg1k1pUfGfGTL8,925
79
79
  strawberry/experimental/pydantic/error_type.py,sha256=NdiaAv2zlaNKfzw0vGgG0lOLTfXAM8gQMk2LsfE7bI4,4555
80
80
  strawberry/experimental/pydantic/exceptions.py,sha256=pDMPL94ojuSGHxk8H8mI2pfWReG8BhqZ5T2eSxfOi9w,1486
81
81
  strawberry/experimental/pydantic/fields.py,sha256=NcB38JYk29fPwJWtoHkIvwTfqD2Ekf7fJ57GjvvK6mQ,2265
82
- strawberry/experimental/pydantic/object_type.py,sha256=cL0zzme1iJL_M4LTLA8r_VnL9IcgV9jur0AfuS12tCM,12752
83
- strawberry/experimental/pydantic/utils.py,sha256=anIFiMip_s4JZgFdsd98pSv-Y6NYiP9idRxbpsVZ9pk,3933
82
+ strawberry/experimental/pydantic/object_type.py,sha256=O7b5LgQuzmE9EdmX4HPea5ul9lmM-08GS3R4HWf-dEk,12895
83
+ strawberry/experimental/pydantic/utils.py,sha256=URSzmcK2KzNGsLv4RyFdFfJnr-ARNLkkM0D4CjijVQU,4035
84
84
  strawberry/ext/LICENSE,sha256=_oY0TZg0b_sW0--0T44aMTpy2e2zF1Kiyn8E1qDiivo,1249
85
85
  strawberry/ext/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
86
86
  strawberry/ext/dataclasses/LICENSE,sha256=WZgm35K_3NJwLqxpEHJJi7CWxVrwTumEz5D3Dtd7WnA,13925
@@ -228,8 +228,8 @@ strawberry/utils/logging.py,sha256=U1cseHGquN09YFhFmRkiphfASKCyK0HUZREImPgVb0c,7
228
228
  strawberry/utils/operation.py,sha256=SSXxN-vMqdHO6W2OZtip-1z7y4_A-eTVFdhDvhKeLCk,1193
229
229
  strawberry/utils/str_converters.py,sha256=-eH1Cl16IO_wrBlsGM-km4IY0IKsjhjnSNGRGOwQjVM,897
230
230
  strawberry/utils/typing.py,sha256=Ux0Hl46lhuXvOKK-C5hj6nlz3zDn8P4CUGH2nUVD2vU,13373
231
- strawberry_graphql-0.262.6.dist-info/LICENSE,sha256=m-XnIVUKqlG_AWnfi9NReh9JfKhYOB-gJfKE45WM1W8,1072
232
- strawberry_graphql-0.262.6.dist-info/METADATA,sha256=7nqosxgnwdquqIsxQb_9MR_f6c_Tsbt21wdMmZTzQyc,7679
233
- strawberry_graphql-0.262.6.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
234
- strawberry_graphql-0.262.6.dist-info/entry_points.txt,sha256=Nk7-aT3_uEwCgyqtHESV9H6Mc31cK-VAvhnQNTzTb4k,49
235
- strawberry_graphql-0.262.6.dist-info/RECORD,,
231
+ strawberry_graphql-0.263.0.dist-info/LICENSE,sha256=m-XnIVUKqlG_AWnfi9NReh9JfKhYOB-gJfKE45WM1W8,1072
232
+ strawberry_graphql-0.263.0.dist-info/METADATA,sha256=DSR0TZpTt5adk8Ont_WYmUZydMtQ1GDgK46H3YPlEZ0,7679
233
+ strawberry_graphql-0.263.0.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
234
+ strawberry_graphql-0.263.0.dist-info/entry_points.txt,sha256=Nk7-aT3_uEwCgyqtHESV9H6Mc31cK-VAvhnQNTzTb4k,49
235
+ strawberry_graphql-0.263.0.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 2.1.1
2
+ Generator: poetry-core 2.1.2
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any