Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support pydantic date types #100

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

edmundhighcock
Copy link

@edmundhighcock edmundhighcock commented Feb 17, 2024

Support the special type hints that pydantic provides to give more control over validating dates.

Enable Pydantic custom datetime type hints

Pydantic has some additional classes that you can use as type hints to give more control over validating dates.

https://docs.pydantic.dev/2.0/usage/types/datetime/#pydantic-date-types

edmundhighcock and others added 2 commits February 17, 2024 23:03
Support the special type hints that pydantic provides to give more control over validating dates.
@dantheman39
Copy link
Contributor

dantheman39 commented Feb 19, 2024

Thanks for this @edmundhighcock !

Could you please add some unit test coverage? This might be a good place to look:

@pytest.mark.parametrize(
"input, expected",
[
((bool, False), graphene.Boolean),
((float, 0.1), graphene.Float),
((int, 6), graphene.Int),
((str, "hi"), graphene.String),
((uuid.UUID, uuid.uuid4()), graphene.UUID),
((datetime.date, datetime.date(2019, 1, 1)), graphene.Date),
((datetime.time, datetime.time(15, 29)), graphene.Time),
((datetime.datetime, datetime.datetime(2019, 1, 1, 1, 37)), graphene.DateTime),
],
)
def test_builtin_scalars(input, expected):

@edmundhighcock
Copy link
Author

Thanks for this @edmundhighcock !

Could you please add some unit test coverage? This might be a good place to look:

@pytest.mark.parametrize(
"input, expected",
[
((bool, False), graphene.Boolean),
((float, 0.1), graphene.Float),
((int, 6), graphene.Int),
((str, "hi"), graphene.String),
((uuid.UUID, uuid.uuid4()), graphene.UUID),
((datetime.date, datetime.date(2019, 1, 1)), graphene.Date),
((datetime.time, datetime.time(15, 29)), graphene.Time),
((datetime.datetime, datetime.datetime(2019, 1, 1, 1, 37)), graphene.DateTime),
],
)
def test_builtin_scalars(input, expected):

Sorry for the slow reply. Yes, will happily do this as soon as I have time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants