Repository: mirumee/ariadne
Pull request #1006 (2023-01-17 15:12:49)

Port enums fix from 0.17.1 release
Cherry-pick fix for enums as default values from Ariadne 0.17.1

codecov[bot]: # [Codecov](https://codecov.io/gh/mirumee/ariadne/pull/1006?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mirumee) Report
> Merging [#1006](https://codecov.io/gh/mirumee/ariadne/pull/1006?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mirumee) (c060036) into [master](https://codecov.io/gh/mirumee/ariadne/commit/9a6cd62c9172b5e43cc62cccdec9f28294d7238d?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mirumee) (9a6cd62) will **decrease** coverage by `0.02%`.
> The diff coverage is `100.00%`.

```diff
@@            Coverage Diff             @@
##           master    #1006      +/-   ##
==========================================
- Coverage   98.09%   98.08%   -0.02%     
==========================================
  Files         110      110              
  Lines        7031     7034       +3     
==========================================
+ Hits         6897     6899       +2     
- Misses        134      135       +1     
```


| [Impacted Files](https://codecov.io/gh/mirumee/ariadne/pull/1006?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mirumee) | Coverage Δ | |
|---|---|---|
| [ariadne/enums.py](https://codecov.io/gh/mirumee/ariadne/pull/1006?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mirumee#diff-YXJpYWRuZS9lbnVtcy5weQ==) | `98.27% <100.00%> (+0.01%)` | :arrow_up: |
| [tests/test\_enums.py](https://codecov.io/gh/mirumee/ariadne/pull/1006?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mirumee#diff-dGVzdHMvdGVzdF9lbnVtcy5weQ==) | `100.00% <100.00%> (ø)` | |
| [ariadne/asgi/handlers/graphql\_transport\_ws.py](https://codecov.io/gh/mirumee/ariadne/pull/1006?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mirumee#diff-YXJpYWRuZS9hc2dpL2hhbmRsZXJzL2dyYXBocWxfdHJhbnNwb3J0X3dzLnB5) | `99.46% <0.00%> (-0.54%)` | :arrow_down: |

:mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mirumee)


Patch:
diff --git a/ariadne/enums.py b/ariadne/enums.py
index 9a2e753..50f42ee 100644
--- a/ariadne/enums.py
+++ b/ariadne/enums.py
@@ -27,6 +27,7 @@ from graphql.type.definition import (
     GraphQLInputField,
     GraphQLInputObjectType,
     GraphQLInputType,
+    GraphQLInterfaceType,
     GraphQLNonNull,
     GraphQLObjectType,
     GraphQLScalarType,
@@ -144,8 +145,9 @@ def enum_values_in_types(
 
 
 @enum_values_in_types.register(GraphQLObjectType)
+@enum_values_in_types.register(GraphQLInterfaceType)
 def enum_values_in_object_type(
-    type_: GraphQLObjectType,
+    type_: Union[GraphQLObjectType, GraphQLInterfaceType],
     field_name: str,
 ) -> Generator[ArgumentWithKeys, None, None]:
     for field in type_.fields.values():


Test patch:
diff --git a/tests/test_enums.py b/tests/test_enums.py
index b85b790..32b8047 100644
--- a/tests/test_enums.py
+++ b/tests/test_enums.py
@@ -372,9 +372,11 @@ def test_input_exc_schema_raises_exception_for_undefined_enum_value_in_nested_fi
 def test_find_enum_values_in_schema_for_undefined_and_invalid_values():
     input_schema = """
         type Query {
-            complex(hello: Episode = EMPIRE,
-                    hi: Test = { role: JEDI,  next_role: ENTERPRISE, ignore: "HI"}, 
-                    bonjour: BetterTest = {newIgnore: "Witam", test: { role: NEWHOPE }}): String
+            complex(
+                hello: Episode = EMPIRE,
+                hi: Test = { role: JEDI,  next_role: ENTERPRISE, ignore: "HI"}, 
+                bonjour: BetterTest = {newIgnore: "Witam", test: { role: NEWHOPE }}
+            ): String
         }
     
         input Test {
@@ -387,13 +389,17 @@ def test_find_enum_values_in_schema_for_undefined_and_invalid_values():
             newIgnore: String
             test: Test = { role: NEWHOPE }
         }
+
+        interface Result {
+            hello(r: Episode = ENTERPRISE): String
+        }
     """
     query_complex_keys = [["next_role"], ["role"], ["test", "role"]]
     better_test_complex_keys = [["role"]]
-    number_of_defined_enum_values = 7
+    number_of_defined_enum_values = 8
 
     # 2 Undefined because of "ENTERPRISE" invalid value, and next_role in Test input
-    number_of_undefined_default_enum_values = 3
+    number_of_undefined_default_enum_values = 4
 
     ast_document = parse(join_type_defs([enum_definition, input_schema]))
     schema = build_ast_schema(ast_document)
@@ -413,6 +419,7 @@ def test_find_enum_values_in_schema_for_undefined_and_invalid_values():
 
 def test_enum_type_is_able_to_represent_enum_default_value_in_schema():
     #  regression test for: https://github.com/mirumee/ariadne/issues/293
+    #  regression test for: https://github.com/mirumee/ariadne/issues/995
 
     type_defs = """
         enum Role {
@@ -422,6 +429,15 @@ def test_enum_type_is_able_to_represent_enum_default_value_in_schema():
 
         type Query {
             hello(r: Role = USER): String
+            results: [Result!]!
+        }
+
+        interface Result {
+            hello(r: Role = USER): String
+        }
+
+        type User implements Result {
+            hello(r: Role = USER): String
         }
     """
 
@@ -445,6 +461,8 @@ def test_enum_type_is_able_to_represent_enum_default_value_in_schema():
 
     query = "{__schema{types{name,fields{name,args{name,defaultValue}}}}}"
     _, result = ariadne_graphql_sync(schema, {"query": query}, debug=True)
+    assert not result.get("errors")
+
     types_map = {
         result_type["name"]: result_type
         for result_type in result["data"]["__schema"]["types"]
@@ -453,5 +471,6 @@ def test_enum_type_is_able_to_represent_enum_default_value_in_schema():
 
     result_hello_query = graphql_sync(schema, "{hello}")
     assert types_map["Query"]["fields"][0]["args"][0]["defaultValue"] == "USER"
+    assert types_map["User"]["fields"][0]["args"][0]["defaultValue"] == "USER"
     assert result_hello_query.data["hello"]
     assert result_hello_query.errors is None