Skip to content

Commit 2a1953f

Browse files
committed
build_ast_schema should set internal enum values (fixes #111)
1 parent 3359fe6 commit 2a1953f

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/graphql/utilities/extend_schema.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,9 @@ def build_enum_value_map(
481481
# Note: While this could make assertions to get the correctly typed
482482
# value, that would throw immediately while type system validation
483483
# with validate_schema() will produce more actionable results.
484-
enum_value_map[value.name.value] = GraphQLEnumValue(
484+
value_name = value.name.value
485+
enum_value_map[value_name] = GraphQLEnumValue(
486+
value=value_name,
485487
description=value.description.value if value.description else None,
486488
deprecation_reason=get_deprecation_reason(value),
487489
ast_node=value,

tests/utilities/test_build_ast_schema.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from collections import namedtuple
2-
from typing import Union
2+
from typing import cast, Union
33

44
from pytest import raises # type: ignore
55

@@ -16,6 +16,7 @@
1616
GraphQLInt,
1717
GraphQLString,
1818
GraphQLArgument,
19+
GraphQLEnumType,
1920
GraphQLEnumValue,
2021
GraphQLField,
2122
GraphQLInputField,
@@ -403,6 +404,12 @@ def multiple_value_enum():
403404
)
404405
assert cycle_sdl(sdl) == sdl
405406

407+
# check that the internal values are the same as the names
408+
schema = build_schema(sdl)
409+
enum_type = schema.get_type("Hello")
410+
assert isinstance(enum_type, GraphQLEnumType)
411+
assert [value.value for value in enum_type.values.values()] == ["WO", "RLD"]
412+
406413
def empty_union():
407414
sdl = dedent(
408415
"""

0 commit comments

Comments
 (0)