Repository: mirumee/ariadne

Issue:
Unbound enum values are None when used in arguments
When used as a mutation input, enum parameter should be `str`, but actually is `None`.

```python
def test_executing_mutation_takes_enum():
    type_defs = """
        type Query {
            _: String
        }

        type Mutation {
            eat(meal: Meal!): Int!
        }

        enum Meal {
            SPAM
        }
    """

    mutation = MutationType()

    @mutation.field("eat")
    def resolve_eat(*_, meal):  # pylint: disable=unused-variable
        assert meal == "SPAM"
        return 42

    schema = make_executable_schema(type_defs, mutation)

    result = graphql_sync(schema, 'mutation { eat(meal: SPAM) }')
    assert result.errors is None
    assert result.data == {"eat": 42}
```


Discussion:
Thanks for heads-up. Can you please confirm this issue is specific only to mutations?
> Thanks for heads-up. Can you please confirm this issue is specific only to mutations?

Yes, `pytest tests/test_enums.py` is green for me at bc224eadf416471934f070d3567e1af804faa506 (the current master).
This issue may be caused by `graphql-core-next` upstream:

```python
import graphql


type_defs = """
    type Query {
        _: String
    }

    type Mutation {
        eat(meal: Meal!): Int!
    }

    enum Meal {
        SPAM
    }
"""


schema = graphql.build_schema(type_defs)
meal_type = schema.type_map["Meal"]
assert meal_type.values["SPAM"].value is None
```

Resolving patch:
diff --git a/ariadne/enums.py b/ariadne/enums.py
--- a/ariadne/enums.py
+++ b/ariadne/enums.py
@@ -37,3 +37,15 @@ def validate_graphql_type(self, graphql_type: Optional[GraphQLNamedType]) -> Non
                 "%s is defined in the schema, but it is instance of %s (expected %s)"
                 % (self.name, type(graphql_type).__name__, GraphQLEnumType.__name__)
             )
+
+
+def set_default_enum_values_on_schema(schema: GraphQLSchema):
+    for type_object in schema.type_map.values():
+        if isinstance(type_object, GraphQLEnumType):
+            set_default_enum_values(type_object)
+
+
+def set_default_enum_values(graphql_type: GraphQLEnumType):
+    for key in graphql_type.values:
+        if graphql_type.values[key].value is None:
+            graphql_type.values[key].value = key
diff --git a/ariadne/executable_schema.py b/ariadne/executable_schema.py
--- a/ariadne/executable_schema.py
+++ b/ariadne/executable_schema.py
@@ -2,6 +2,7 @@
 
 from graphql import DocumentNode, GraphQLSchema, build_ast_schema, extend_schema, parse
 
+from .enums import set_default_enum_values_on_schema
 from .types import SchemaBindable
 
 
@@ -21,6 +22,8 @@ def make_executable_schema(
     elif bindables:
         bindables.bind_to_schema(schema)
 
+    set_default_enum_values_on_schema(schema)
+
     return schema
 
 


Test patch:
diff --git a/tests/test_enums.py b/tests/test_enums.py
--- a/tests/test_enums.py
+++ b/tests/test_enums.py
@@ -30,6 +30,7 @@ def test_succesfull_enum_typed_field():
     schema = make_executable_schema([enum_definition, enum_field], query)
     result = graphql_sync(schema, "{ testEnum }")
     assert result.errors is None
+    assert result.data == {"testEnum": TEST_VALUE}
 
 
 def test_unsuccesfull_invalid_enum_value_evaluation():
@@ -57,6 +58,18 @@ def test_successful_enum_value_passed_as_argument():
     assert result.errors is None, result.errors
 
 
+def test_unbound_enum_arg_is_transformed_to_string():
+    query = QueryType()
+    query.set_field("testEnum", lambda *_, value: value == "NEWHOPE")
+
+    schema = make_executable_schema([enum_definition, enum_param], [query])
+    result = graphql_sync(schema, "{ testEnum(value: NEWHOPE) }")
+    assert result.data["testEnum"] is True
+
+    result = graphql_sync(schema, "{ testEnum(value: EMPIRE) }")
+    assert result.data["testEnum"] is False
+
+
 def test_unsuccessful_invalid_enum_value_passed_as_argument():
     query = QueryType()
     query.set_field("testEnum", lambda *_, value: True)
@@ -137,9 +150,12 @@ def test_enum_arg_is_transformed_to_internal_value():
     query.set_field("testEnum", lambda *_, value: value == PyEnum.NEWHOPE)
 
     schema = make_executable_schema([enum_definition, enum_param], [query, py_enum])
-    result = graphql_sync(schema, "{ testEnum(value: %s) }" % TEST_VALUE)
+    result = graphql_sync(schema, "{ testEnum(value: NEWHOPE) }")
     assert result.data["testEnum"] is True
 
+    result = graphql_sync(schema, "{ testEnum(value: EMPIRE) }")
+    assert result.data["testEnum"] is False
+
 
 class PyIntEnum(IntEnum):
     NEWHOPE = 1977
@@ -164,5 +180,8 @@ def test_int_enum_arg_is_transformed_to_internal_value():
     query.set_field("testEnum", lambda *_, value: value == PyIntEnum.NEWHOPE)
 
     schema = make_executable_schema([enum_definition, enum_param], [query, int_enum])
-    result = graphql_sync(schema, "{ testEnum(value: %s) }" % TEST_VALUE)
+    result = graphql_sync(schema, "{ testEnum(value: NEWHOPE) }")
     assert result.data["testEnum"] is True
+
+    result = graphql_sync(schema, "{ testEnum(value: EMPIRE) }")
+    assert result.data["testEnum"] is False