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:

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8064549..4e2c0e0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,7 +12,7 @@
 - Added support for `extend type` in schema definitions.
 - Removed unused `format_errors` utility function and renamed `ariadne.format_errors` module to `ariadne.format_error`.
 - Removed explicit `typing` dependency.
-- Added Flask integration example.
+- Fixed default ENUM values not being set.
 
 
 ## 0.3.0 (2019-04-08)
diff --git a/ariadne/enums.py b/ariadne/enums.py
index bba2fa8..68ce512 100644
--- a/ariadne/enums.py
+++ b/ariadne/enums.py
@@ -37,3 +37,15 @@ class EnumType(SchemaBindable):
                 "%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
index a498316..f3f151a 100644
--- a/ariadne/executable_schema.py
+++ b/ariadne/executable_schema.py
@@ -2,6 +2,7 @@ from typing import List, Union
 
 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
index ee3e2bc..bd2fb15 100644
--- 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