strawberry-graphql 0.234.2__py3-none-any.whl → 0.235.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/experimental/pydantic/_compat.py +6 -0
- strawberry/experimental/pydantic/object_type.py +1 -1
- strawberry/experimental/pydantic/utils.py +10 -3
- strawberry/schema/base.py +19 -0
- strawberry/schema/config.py +1 -0
- strawberry/schema/schema.py +2 -2
- {strawberry_graphql-0.234.2.dist-info → strawberry_graphql-0.235.0.dist-info}/METADATA +1 -1
- {strawberry_graphql-0.234.2.dist-info → strawberry_graphql-0.235.0.dist-info}/RECORD +11 -11
- {strawberry_graphql-0.234.2.dist-info → strawberry_graphql-0.235.0.dist-info}/LICENSE +0 -0
- {strawberry_graphql-0.234.2.dist-info → strawberry_graphql-0.235.0.dist-info}/WHEEL +0 -0
- {strawberry_graphql-0.234.2.dist-info → strawberry_graphql-0.235.0.dist-info}/entry_points.txt +0 -0
@@ -162,6 +162,9 @@ class PydanticV2Compat:
|
|
162
162
|
|
163
163
|
return type_
|
164
164
|
|
165
|
+
def model_dump(self, model_instance: BaseModel) -> Dict[Any, Any]:
|
166
|
+
return model_instance.model_dump()
|
167
|
+
|
165
168
|
|
166
169
|
class PydanticV1Compat:
|
167
170
|
@property
|
@@ -235,6 +238,9 @@ class PydanticV1Compat:
|
|
235
238
|
|
236
239
|
return type_
|
237
240
|
|
241
|
+
def model_dump(self, model_instance: BaseModel) -> Dict[Any, Any]:
|
242
|
+
return model_instance.dict()
|
243
|
+
|
238
244
|
|
239
245
|
class PydanticCompat:
|
240
246
|
def __init__(self, is_v2: bool) -> None:
|
@@ -91,7 +91,7 @@ def _build_dataclass_creation_fields(
|
|
91
91
|
graphql_name=graphql_name,
|
92
92
|
# always unset because we use default_factory instead
|
93
93
|
default=dataclasses.MISSING,
|
94
|
-
default_factory=get_default_factory_for_field(field),
|
94
|
+
default_factory=get_default_factory_for_field(field, compat=compat),
|
95
95
|
type_annotation=StrawberryAnnotation.from_annotation(field_type),
|
96
96
|
description=field.description,
|
97
97
|
deprecation_reason=(
|
@@ -13,6 +13,8 @@ from typing import (
|
|
13
13
|
cast,
|
14
14
|
)
|
15
15
|
|
16
|
+
from pydantic import BaseModel
|
17
|
+
|
16
18
|
from strawberry.experimental.pydantic._compat import (
|
17
19
|
CompatModelField,
|
18
20
|
PydanticCompat,
|
@@ -33,7 +35,6 @@ from strawberry.utils.typing import (
|
|
33
35
|
)
|
34
36
|
|
35
37
|
if TYPE_CHECKING:
|
36
|
-
from pydantic import BaseModel
|
37
38
|
from pydantic.typing import NoArgAnyCallable
|
38
39
|
|
39
40
|
|
@@ -72,6 +73,7 @@ class DataclassCreationFields(NamedTuple):
|
|
72
73
|
|
73
74
|
def get_default_factory_for_field(
|
74
75
|
field: CompatModelField,
|
76
|
+
compat: PydanticCompat,
|
75
77
|
) -> Union[NoArgAnyCallable, dataclasses._MISSING_TYPE]:
|
76
78
|
"""
|
77
79
|
Gets the default factory for a pydantic field.
|
@@ -105,9 +107,14 @@ def get_default_factory_for_field(
|
|
105
107
|
return default_factory
|
106
108
|
|
107
109
|
# if we have a default, we should return it
|
108
|
-
|
109
110
|
if has_default:
|
110
|
-
|
111
|
+
# if the default value is a pydantic base model
|
112
|
+
# we should return the serialized version of that default for
|
113
|
+
# printing the value.
|
114
|
+
if isinstance(default, BaseModel):
|
115
|
+
return lambda: compat.model_dump(default)
|
116
|
+
else:
|
117
|
+
return lambda: smart_deepcopy(default)
|
111
118
|
|
112
119
|
# if we don't have default or default_factory, but the field is not required,
|
113
120
|
# we should return a factory that returns None
|
strawberry/schema/base.py
CHANGED
@@ -87,6 +87,25 @@ class BaseSchema(Protocol):
|
|
87
87
|
def as_str(self) -> str:
|
88
88
|
raise NotImplementedError
|
89
89
|
|
90
|
+
@staticmethod
|
91
|
+
def remove_field_suggestion(error: GraphQLError) -> None:
|
92
|
+
if (
|
93
|
+
error.message.startswith("Cannot query field")
|
94
|
+
and "Did you mean" in error.message
|
95
|
+
):
|
96
|
+
error.message = error.message.split("Did you mean")[0].strip()
|
97
|
+
|
98
|
+
def _process_errors(
|
99
|
+
self,
|
100
|
+
errors: List[GraphQLError],
|
101
|
+
execution_context: Optional[ExecutionContext] = None,
|
102
|
+
) -> None:
|
103
|
+
if self.config.disable_field_suggestions:
|
104
|
+
for error in errors:
|
105
|
+
self.remove_field_suggestion(error)
|
106
|
+
|
107
|
+
self.process_errors(errors, execution_context)
|
108
|
+
|
90
109
|
def process_errors(
|
91
110
|
self,
|
92
111
|
errors: List[GraphQLError],
|
strawberry/schema/config.py
CHANGED
@@ -12,6 +12,7 @@ class StrawberryConfig:
|
|
12
12
|
name_converter: NameConverter = field(default_factory=NameConverter)
|
13
13
|
default_resolver: Callable[[Any, str], object] = getattr
|
14
14
|
relay_max_results: int = 100
|
15
|
+
disable_field_suggestions: bool = False
|
15
16
|
|
16
17
|
def __post_init__(
|
17
18
|
self,
|
strawberry/schema/schema.py
CHANGED
@@ -269,7 +269,7 @@ class Schema(BaseSchema):
|
|
269
269
|
execution_context_class=self.execution_context_class,
|
270
270
|
execution_context=execution_context,
|
271
271
|
allowed_operation_types=allowed_operation_types,
|
272
|
-
process_errors=self.
|
272
|
+
process_errors=self._process_errors,
|
273
273
|
)
|
274
274
|
|
275
275
|
return result
|
@@ -301,7 +301,7 @@ class Schema(BaseSchema):
|
|
301
301
|
execution_context_class=self.execution_context_class,
|
302
302
|
execution_context=execution_context,
|
303
303
|
allowed_operation_types=allowed_operation_types,
|
304
|
-
process_errors=self.
|
304
|
+
process_errors=self._process_errors,
|
305
305
|
)
|
306
306
|
|
307
307
|
return result
|
@@ -84,14 +84,14 @@ strawberry/exceptions/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMp
|
|
84
84
|
strawberry/exceptions/utils/source_finder.py,sha256=AcuevLgWwOSOR5zBDJbVyXMGRUxsTzrr07XUB0UqNiI,20044
|
85
85
|
strawberry/experimental/__init__.py,sha256=2HP5XtxL8ZKsPp4EDRAbMCqiP7p2V4Cca278JUGxnt0,102
|
86
86
|
strawberry/experimental/pydantic/__init__.py,sha256=jlsYH1j_9W4ieRpUKgt5zQPERDL7nc1ZBNQ3dAhJs8w,241
|
87
|
-
strawberry/experimental/pydantic/_compat.py,sha256
|
87
|
+
strawberry/experimental/pydantic/_compat.py,sha256=-qJvpNzsDuY5E2NF87FL7QiakrhJXWqiCjCoS0tr1_g,8371
|
88
88
|
strawberry/experimental/pydantic/conversion.py,sha256=nS79s_-nVDvJJgazE84pIgPx2u4g4r-ouOOzRGMuwlU,4220
|
89
89
|
strawberry/experimental/pydantic/conversion_types.py,sha256=VuuBULz2v6cz_N1fa51ayJMA5_bQkqZmxaCumDsTGRM,931
|
90
90
|
strawberry/experimental/pydantic/error_type.py,sha256=iSDNlbsRYZyU5zrg3mzU3ntREUPnU1f2waGmY_kiXLU,4370
|
91
91
|
strawberry/experimental/pydantic/exceptions.py,sha256=Q8Deq3bNkMgc8fwvIYdcfxHSONXVMu-ZB6jcsh1NQYo,1498
|
92
92
|
strawberry/experimental/pydantic/fields.py,sha256=QP5vYb8vKf7vOC69cjUPGOdlO_j4kZRdxalWgeqJ5Hk,2588
|
93
|
-
strawberry/experimental/pydantic/object_type.py,sha256=
|
94
|
-
strawberry/experimental/pydantic/utils.py,sha256=
|
93
|
+
strawberry/experimental/pydantic/object_type.py,sha256=ySqKs2_lwwoJiskAn-yLIUaHY2XKUrZMvEFTwKKKzZs,12391
|
94
|
+
strawberry/experimental/pydantic/utils.py,sha256=sNVhVXrXHgqZnCma8zrifyffMx34SQwIfuSfWahW-3Y,4065
|
95
95
|
strawberry/ext/LICENSE,sha256=_oY0TZg0b_sW0--0T44aMTpy2e2zF1Kiyn8E1qDiivo,1249
|
96
96
|
strawberry/ext/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
97
97
|
strawberry/ext/dataclasses/LICENSE,sha256=WZgm35K_3NJwLqxpEHJJi7CWxVrwTumEz5D3Dtd7WnA,13925
|
@@ -183,13 +183,13 @@ strawberry/sanic/utils.py,sha256=eDiJPJYpELj4hFsx8CCAHomqe7dDEpStDPm6OfkstJ0,998
|
|
183
183
|
strawberry/sanic/views.py,sha256=CyhR9RCS4atekEorOH6wAOqfJgmi-h-hAfHA1rq8sA8,5584
|
184
184
|
strawberry/scalars.py,sha256=usENRKCwl60KstV9sBGYhk2dqW5zw2wGX5eTpOWQiqg,2106
|
185
185
|
strawberry/schema/__init__.py,sha256=u1QCyDVQExUVDA20kyosKPz3TS5HMCN2NrXclhiFAL4,92
|
186
|
-
strawberry/schema/base.py,sha256=
|
186
|
+
strawberry/schema/base.py,sha256=RNacxV0AdRSG2kFDitiB2G59mUjp-tFBf2mU3ZkcBbc,3607
|
187
187
|
strawberry/schema/compat.py,sha256=n0r3UPUcGemMqK8vklgtCkkuCA1p6tWAYbc6Vl4iNOw,1684
|
188
|
-
strawberry/schema/config.py,sha256=
|
188
|
+
strawberry/schema/config.py,sha256=X83kbrNUCocueAwkDWuwq0GZD2Spgfjo4-zqR5b_r_E,684
|
189
189
|
strawberry/schema/exceptions.py,sha256=T-DsvBtjx9svkegIm1YrVPGPswpVEpMTFc0_7flLEkM,542
|
190
190
|
strawberry/schema/execute.py,sha256=dwxMrJrR2Qdd1nPGcIS9-Viq7h5qtPfsD6qdujALoMw,11153
|
191
191
|
strawberry/schema/name_converter.py,sha256=UdNyd-QtqF2HsDCQK-nsOcLGxDTj4hJwYFNvMtZnpq4,6533
|
192
|
-
strawberry/schema/schema.py,sha256=
|
192
|
+
strawberry/schema/schema.py,sha256=RWR28Nu8RpFxr5vFaswnp-0sWkO6-ZZcbfJVq2mgVEQ,14370
|
193
193
|
strawberry/schema/schema_converter.py,sha256=_kufIUo71mWCAC7QaXcW8KxKXa86vdvh75mBdjbJE7Y,36795
|
194
194
|
strawberry/schema/types/__init__.py,sha256=oHO3COWhL3L1KLYCJNY1XFf5xt2GGtHiMC-UaYbFfnA,68
|
195
195
|
strawberry/schema/types/base_scalars.py,sha256=NzGQmDtHdCcBeJpRpyeZQ6EgYRpQBTd8fUf1p9cMWlQ,1847
|
@@ -245,8 +245,8 @@ strawberry/utils/logging.py,sha256=flS7hV0JiIOEdXcrIjda4WyIWix86cpHHFNJL8gl1y4,7
|
|
245
245
|
strawberry/utils/operation.py,sha256=Um-tBCPl3_bVFN2Ph7o1mnrxfxBes4HFCj6T0x4kZxE,1135
|
246
246
|
strawberry/utils/str_converters.py,sha256=avIgPVLg98vZH9mA2lhzVdyyjqzLsK2NdBw9mJQ02Xk,813
|
247
247
|
strawberry/utils/typing.py,sha256=G92wuT2WhEGQrwjek_On2K8l0nyVFtBW3P7I_cfjG-8,13870
|
248
|
-
strawberry_graphql-0.
|
249
|
-
strawberry_graphql-0.
|
250
|
-
strawberry_graphql-0.
|
251
|
-
strawberry_graphql-0.
|
252
|
-
strawberry_graphql-0.
|
248
|
+
strawberry_graphql-0.235.0.dist-info/LICENSE,sha256=m-XnIVUKqlG_AWnfi9NReh9JfKhYOB-gJfKE45WM1W8,1072
|
249
|
+
strawberry_graphql-0.235.0.dist-info/METADATA,sha256=pbG-KszzQKU30_gF1B2tUWz0f9OCMXLoXdlhsiUr-bM,7821
|
250
|
+
strawberry_graphql-0.235.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
251
|
+
strawberry_graphql-0.235.0.dist-info/entry_points.txt,sha256=Nk7-aT3_uEwCgyqtHESV9H6Mc31cK-VAvhnQNTzTb4k,49
|
252
|
+
strawberry_graphql-0.235.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|
{strawberry_graphql-0.234.2.dist-info → strawberry_graphql-0.235.0.dist-info}/entry_points.txt
RENAMED
File without changes
|