@@ -49,9 +49,7 @@ def parse_date_str(value: str) -> date:
49
49
# Parse "YYYY-MM-DD" string into date
50
50
return datetime.strptime(value, "%Y-%m-%d").date()
51
51
except (ValueError, TypeError):
52
- raise ValueError(
53
- f'"{value}" is not a date string in YYYY-MM-DD format.'
54
- )
52
+ raise ValueError(f'"{value}" is not a date string in YYYY-MM-DD format.')
55
53
```
56
54
57
55
# Literal parsing
@@ -63,19 +61,15 @@ def parse_date_str(value: str) -> date:
63
61
query's variables and returns Python value:
64
62
65
63
```python
66
- def parse_date_literal(
67
- value: str, variable_values: dict[str, Any] = None
68
- ) -> date:
64
+ def parse_date_literal(value: str, variable_values: dict[str, Any] = None) -> date:
69
65
if not isinstance(ast, StringValueNode):
70
66
raise ValueError()
71
67
72
68
try:
73
69
# Parse "YYYY-MM-DD" string into date
74
70
return datetime.strptime(ast.value, "%Y-%m-%d").date()
75
71
except (ValueError, TypeError):
76
- raise ValueError(
77
- f'"{value}" is not a date string in YYYY-MM-DD format.'
78
- )
72
+ raise ValueError(f'"{value}" is not a date string in YYYY-MM-DD format.')
79
73
```
80
74
81
75
When scalar has custom value parser set, but not the literal parser, the
@@ -225,6 +219,7 @@ def set_serializer(self, f: GraphQLScalarSerializer) -> GraphQLScalarSerializer:
225
219
```python
226
220
date_scalar = ScalarType("Date")
227
221
222
+
228
223
@date_scalar.serializer
229
224
def serialize_date(value: date) -> str:
230
225
# Serialize dates as "YYYY-MM-DD" string
@@ -242,15 +237,14 @@ def set_value_parser(self, f: GraphQLScalarValueParser) -> GraphQLScalarValuePar
242
237
```python
243
238
date_scalar = ScalarType("Date")
244
239
240
+
245
241
@date_scalar.value_parser
246
242
def parse_date_str(value: str) -> date:
247
243
try:
248
244
# Parse "YYYY-MM-DD" string into date
249
245
return datetime.strptime(value, "%Y-%m-%d").date()
250
246
except (ValueError, TypeError):
251
- raise ValueError(
252
- f'"{value}" is not a date string in YYYY-MM-DD format.'
253
- )
247
+ raise ValueError(f'"{value}" is not a date string in YYYY-MM-DD format.')
254
248
```
255
249
"""
256
250
self ._parse_value = f
@@ -266,20 +260,17 @@ def set_literal_parser(
266
260
```python
267
261
date_scalar = ScalarType("Date")
268
262
263
+
269
264
@date_scalar.literal_parser
270
- def parse_date_literal(
271
- value: str, variable_values: Optional[dict[str, Any]] = None
272
- ) -> date:
265
+ def parse_date_literal(value: str, variable_values: Optional[dict[str, Any]] = None) -> date:
273
266
if not isinstance(ast, StringValueNode):
274
267
raise ValueError()
275
268
276
269
try:
277
270
# Parse "YYYY-MM-DD" string into date
278
271
return datetime.strptime(ast.value, "%Y-%m-%d").date()
279
272
except (ValueError, TypeError):
280
- raise ValueError(
281
- f'"{value}" is not a date string in YYYY-MM-DD format.'
282
- )
273
+ raise ValueError(f'"{value}" is not a date string in YYYY-MM-DD format.')
283
274
```
284
275
"""
285
276
self ._parse_literal = f
@@ -316,5 +307,7 @@ def validate_graphql_type(self, graphql_type: Optional[GraphQLNamedType]) -> Non
316
307
raise ValueError (f"Scalar { self .name } is not defined in the schema" )
317
308
if not isinstance (graphql_type , GraphQLScalarType ):
318
309
raise ValueError (
319
- f"{ self .name } is defined in the schema, but it is instance of { type (graphql_type ).__name__ } (expected { GraphQLScalarType .__name__ } )"
310
+ f"{ self .name } is defined in the schema, "
311
+ f"but it is instance of { type (graphql_type ).__name__ } "
312
+ f"(expected { GraphQLScalarType .__name__ } )"
320
313
)
0 commit comments