Skip to content

Set enum value values to value names in build_client_schema #138

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

Merged
merged 2 commits into from
Sep 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/graphql/utilities/build_client_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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["name"],
description=value_introspect.get("description"),
deprecation_reason=value_introspect.get("deprecationReason"),
)
Expand Down
11 changes: 6 additions & 5 deletions tests/utilities/test_build_client_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down