Skip to content

Commit 4bb11c2

Browse files
authored
Set enum value values to value names in build_client_schema (#138)
This makes it consistent with build_ast_schema, and ensures that default enum values are reflected in schemas built from introspection when using gql.
1 parent 64a8021 commit 4bb11c2

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/graphql/utilities/build_client_schema.py

+1
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ def build_enum_def(enum_introspection: Dict) -> GraphQLEnumType:
175175
description=enum_introspection.get("description"),
176176
values={
177177
value_introspect["name"]: GraphQLEnumValue(
178+
value=value_introspect["name"],
178179
description=value_introspect.get("description"),
179180
deprecation_reason=value_introspect.get("deprecationReason"),
180181
)

tests/utilities/test_build_client_schema.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -382,28 +382,29 @@ def builds_a_schema_with_an_enum():
382382
# It's also an Enum type on the client.
383383
client_food_enum = assert_enum_type(client_schema.get_type("Food"))
384384

385-
# Client types do not get server-only values, so they are set to None
386-
# rather than using the integers defined in the "server" schema.
385+
# Client types do not get server-only values, so they are set to the
386+
# names of the enum values rather than using the integers defined in
387+
# the "server" schema.
387388
values = {
388389
name: value.to_kwargs() for name, value in client_food_enum.values.items()
389390
}
390391
assert values == {
391392
"VEGETABLES": {
392-
"value": None,
393+
"value": "VEGETABLES",
393394
"description": "Foods that are vegetables.",
394395
"deprecation_reason": None,
395396
"extensions": None,
396397
"ast_node": None,
397398
},
398399
"FRUITS": {
399-
"value": None,
400+
"value": "FRUITS",
400401
"description": None,
401402
"deprecation_reason": None,
402403
"extensions": None,
403404
"ast_node": None,
404405
},
405406
"OILS": {
406-
"value": None,
407+
"value": "OILS",
407408
"description": None,
408409
"deprecation_reason": "Too fatty.",
409410
"extensions": None,

0 commit comments

Comments
 (0)