From 99f0103e37ab5846c3d8678ff5ae17a04572266f Mon Sep 17 00:00:00 2001 From: Ransom Williams <3261168+ransomw@users.noreply.github.com> Date: Wed, 19 Jul 2023 02:00:30 -0500 Subject: [PATCH 1/2] test: print schema with InputObjectType with DateTime field with default_value (#1293) (#1513) * test [1293]: regression test print schema with InputObjectType with DateTime field with default_value * chore: clarify test title and assertion --------- Co-authored-by: Erik Wrede --- graphene/tests/issues/test_1293.py | 41 ++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 graphene/tests/issues/test_1293.py diff --git a/graphene/tests/issues/test_1293.py b/graphene/tests/issues/test_1293.py new file mode 100644 index 00000000..20bcde95 --- /dev/null +++ b/graphene/tests/issues/test_1293.py @@ -0,0 +1,41 @@ +# https://github.com/graphql-python/graphene/issues/1293 + +import datetime + +import graphene +from graphql.utilities import print_schema + + +class Filters(graphene.InputObjectType): + datetime_after = graphene.DateTime( + required=False, + default_value=datetime.datetime.utcfromtimestamp(1434549820776 / 1000), + ) + datetime_before = graphene.DateTime( + required=False, + default_value=datetime.datetime.utcfromtimestamp(1444549820776 / 1000), + ) + + +class SetDatetime(graphene.Mutation): + class Arguments: + filters = Filters(required=True) + + ok = graphene.Boolean() + + def mutate(root, info, filters): + return SetDatetime(ok=True) + + +class Query(graphene.ObjectType): + goodbye = graphene.String() + + +class Mutations(graphene.ObjectType): + set_datetime = SetDatetime.Field() + + +def test_schema_printable_with_default_datetime_value(): + schema = graphene.Schema(query=Query, mutation=Mutations) + schema_str = print_schema(schema.graphql_schema) + assert schema_str, "empty schema printed" From 74db349da4fb72268b309b674361ffbd9e8885e0 Mon Sep 17 00:00:00 2001 From: Naoya Yamashita Date: Wed, 19 Jul 2023 16:01:00 +0900 Subject: [PATCH 2/2] docs: add get_human function (#1380) Co-authored-by: Erik Wrede --- docs/types/objecttypes.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/types/objecttypes.rst b/docs/types/objecttypes.rst index 3cc8d830..f142d4a6 100644 --- a/docs/types/objecttypes.rst +++ b/docs/types/objecttypes.rst @@ -80,6 +80,10 @@ If we have a schema with Person type and one field on the root query. from graphene import ObjectType, String, Field + def get_human(name): + first_name, last_name = name.split() + return Person(first_name, last_name) + class Person(ObjectType): full_name = String()