graphql-python / graphql-python/graphene-django

GraphQLLocatedError at schema dump for date values

Open
#1,319 0 comments 0 reactions 0 assignees View on GitHub
🐛bug
Dominant language
Python
Stars
4.4k
Forks
760
PR merge metrics
No merged PRs in 30d

Description

* **What is the current behavior?**

When trying to dump a schema using the `graphql_schema` command that contains the following default date value:

```
class MyQuery(graphene.ObjectType):
field = graphene.ConnectionField(
type=MyQueryConnectionType,
start_date=graphene.Argument(
graphene.Date,
default_value=date.min,
description="Earliest `date` value my query",
),
```

An error is raised from `site-packages/graphql/utils/ast_from_value.py", line 53, in ast_from_value`

Adding the following above the error line:

```
if isinstance(value, datetime.date):
return ast.StringValue(value.isoformat())
```
solves the issue. Is this the appropriate solution to this problem ?

* **What is the expected behavior?**

The schema to generate without error. Using the above fix the following entry is generated:

``` {
"defaultValue": "\"0001-01-01\"",
"description": "Earliest `date` value for my query",
"name": "startDate",
"type": {
"kind": "SCALAR",
"name": "Date",
"ofType": null
}
},
```

* **What is the motivation / use case for changing the behavior?**

Be able to generate a schema with date values as default parameters to arguments.

* **Please tell us about your environment:**

graphene==2.1.9
graphene-django==2.15.0
Python 3.10

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.