From 543c03c3f42b5cf004dec9be417a84a3590ed8dd Mon Sep 17 00:00:00 2001 From: Harry Slatyer Date: Thu, 2 Sep 2021 11:04:00 +1000 Subject: [PATCH 1/2] Set enum value values to value names in build_client_schema This makes it consistent with build_ast_schema (see commit 2a1953f8563135b85bd7b0ecf78e7630484ccdb2), and ensures that default enum values are reflected in schemas built from introspection when using `gql`. --- src/graphql/utilities/build_client_schema.py | 1 + tests/utilities/test_build_client_schema.py | 11 ++++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/graphql/utilities/build_client_schema.py b/src/graphql/utilities/build_client_schema.py index 4d4addd4..a4fe8d81 100644 --- a/src/graphql/utilities/build_client_schema.py +++ b/src/graphql/utilities/build_client_schema.py @@ -175,6 +175,7 @@ def build_enum_def(enum_introspection: Dict) -> GraphQLEnumType: description=enum_introspection.get("description"), values={ value_introspect["name"]: GraphQLEnumValue( + value=value_introspect.get("name"), description=value_introspect.get("description"), deprecation_reason=value_introspect.get("deprecationReason"), ) diff --git a/tests/utilities/test_build_client_schema.py b/tests/utilities/test_build_client_schema.py index 48636f1a..0726a52b 100644 --- a/tests/utilities/test_build_client_schema.py +++ b/tests/utilities/test_build_client_schema.py @@ -382,28 +382,29 @@ def builds_a_schema_with_an_enum(): # It's also an Enum type on the client. client_food_enum = assert_enum_type(client_schema.get_type("Food")) - # Client types do not get server-only values, so they are set to None - # rather than using the integers defined in the "server" schema. + # Client types do not get server-only values, so they are set to the + # names of the enum values rather than using the integers defined in + # the "server" schema. values = { name: value.to_kwargs() for name, value in client_food_enum.values.items() } assert values == { "VEGETABLES": { - "value": None, + "value": "VEGETABLES", "description": "Foods that are vegetables.", "deprecation_reason": None, "extensions": None, "ast_node": None, }, "FRUITS": { - "value": None, + "value": "FRUITS", "description": None, "deprecation_reason": None, "extensions": None, "ast_node": None, }, "OILS": { - "value": None, + "value": "OILS", "description": None, "deprecation_reason": "Too fatty.", "extensions": None, From 69af5b9405aa7de75ff9e88668f0816952533c9a Mon Sep 17 00:00:00 2001 From: Harry Slatyer Date: Fri, 3 Sep 2021 20:28:31 +1000 Subject: [PATCH 2/2] Use getitem instead of get for enum value name --- src/graphql/utilities/build_client_schema.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/graphql/utilities/build_client_schema.py b/src/graphql/utilities/build_client_schema.py index a4fe8d81..cdfd5a00 100644 --- a/src/graphql/utilities/build_client_schema.py +++ b/src/graphql/utilities/build_client_schema.py @@ -175,7 +175,7 @@ def build_enum_def(enum_introspection: Dict) -> GraphQLEnumType: description=enum_introspection.get("description"), values={ value_introspect["name"]: GraphQLEnumValue( - value=value_introspect.get("name"), + value=value_introspect["name"], description=value_introspect.get("description"), deprecation_reason=value_introspect.get("deprecationReason"), )