Repository: mirumee/ariadne

Issue:
Query filter with default `null` filter causes error
**GraphQL Schema:**

```gql
Query {
    """Get sensors with filtering"""
    sensors(filters: SensorFilters = null): [Sensor!]!
}
```

**Expected Behavior:**

Schema is built with no errors. This happens in Ariadne 0.13.0.

**Actual Behavior:**

In Ariadne >= 0.14.0 (currently running 0.19.1), the following error is raised when running the `make_executable_schema()` method:

```python
ImportError while loading conftest '/Users/*****/Code/mycode/tests/conftest.py'.
tests/conftest.py:21: in <module>
    from src import (
mycode/src/graphql/__init__.py:103: in <module>
    schema = make_executable_schema(type_defs, types)
venv/lib/python3.9/site-packages/ariadne/executable_schema.py:354: in make_executable_schema
    validate_schema_enum_values(schema)
venv/lib/python3.9/site-packages/ariadne/enums.py:239: in validate_schema_enum_values
    for type_name, field_name, arg, _ in find_enum_values_in_schema(schema):
venv/lib/python3.9/site-packages/ariadne/enums.py:260: in find_enum_values_in_schema
    yield from result
venv/lib/python3.9/site-packages/ariadne/enums.py:278: in enum_values_in_object_type
    yield from enum_values_in_field_args(field_name, field)
venv/lib/python3.9/site-packages/ariadne/enums.py:301: in enum_values_in_field_args
    yield from _get_field_with_keys(field_name, args)
venv/lib/python3.9/site-packages/ariadne/enums.py:312: in _get_field_with_keys
    routes = get_enum_keys_from_ast(field.ast_node)
venv/lib/python3.9/site-packages/ariadne/enums.py:320: in get_enum_keys_from_ast
    nodes = [([field.name.value], field) for field in object_node.fields]
E   AttributeError: 'NullValueNode' object has no attribute 'fields'
```

**Workaround:**

If I remove the default `null` value from the query filter, this works as expected, but removing the default value is not desired.

**Solution:**

Checking the `default_value` to ensure it is an instance of `ObjectValueNode` (which is expected by `get_enum_keys_from_ast`) resolves this issue.

```diff
diff --git a/ariadne/enums.py b/ariadne/enums.py
index 05e0ccd..544127a 100644
--- a/ariadne/enums.py
+++ b/ariadne/enums.py
@@ -308,7 +308,11 @@ def _get_field_with_keys(field_name, fields):
             yield field_name, input_name, field, None
 
         if isinstance(resolved_type, GraphQLInputObjectType):
-            if field.ast_node is not None and field.ast_node.default_value is not None:
+            if (
+                field.ast_node is not None
+                and field.ast_node.default_value is not None
+                and isinstance(field.ast_node.default_value, ObjectValueNode)
+            ):
                 routes = get_enum_keys_from_ast(field.ast_node)
                 for route in routes:
                     yield field_name, input_name, field, route
```





Discussion:

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f44f302..5934b6b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,15 +2,16 @@
 
 ## 0.20 (UNRELEASED)
 
+- Dropped support for Python 3.7.
+- Added `OpenTelemetry` and `opentelemetry_extension` extension, importable form `ariadne.tracing.opentelemetry`.
 - Added `query_validator` option to ASGI and WSGI `GraphQL` applications that enables customization of query validation step.
 - Fixed `ERROR` message in GraphQL-WS protocol having invalid payload type.
 - Fixed query cost validator incorrect handling of inline fragments.
+- Fixed `make_executable_schema` error when `null` is used as default value for `input` typed field argument.
+- Updated default GraphiQL2 template to use production build of React.js.
 - Removed `ExtensionSync`. `Extension` now supports both async and sync contexts.
 - Removed `OpenTracingSync` and `opentracing_extension_sync`. `OpenTracing` and `opentracing_extension` now support both async and sync contexts.
 - Removed `ApolloTracingSync`. `ApolloTracing` now supports both async and sync contexts.
-- Added `OpenTelemetry` and `opentelemetry_extension` extension, importable form `ariadne.tracing.opentelemetry`.
-- Updated default GraphiQL2 template to use production build of React.js.
-- Dropped support for Python 3.7.
 
 
 ## 0.19.1 (2023-03-28)
diff --git a/ariadne/enums.py b/ariadne/enums.py
index 05e0ccd..544127a 100644
--- a/ariadne/enums.py
+++ b/ariadne/enums.py
@@ -308,7 +308,11 @@ def _get_field_with_keys(field_name, fields):
             yield field_name, input_name, field, None
 
         if isinstance(resolved_type, GraphQLInputObjectType):
-            if field.ast_node is not None and field.ast_node.default_value is not None:
+            if (
+                field.ast_node is not None
+                and field.ast_node.default_value is not None
+                and isinstance(field.ast_node.default_value, ObjectValueNode)
+            ):
                 routes = get_enum_keys_from_ast(field.ast_node)
                 for route in routes:
                     yield field_name, input_name, field, route


Test patch:
diff --git a/tests/test_enums.py b/tests/test_enums.py
index bde296b..4eeff7b 100644
--- a/tests/test_enums.py
+++ b/tests/test_enums.py
@@ -515,3 +515,18 @@ def test_error_is_raised_for_python_enum_with_name_not_in_schema():
 
     with pytest.raises(ValueError):
         make_executable_schema([enum_definition, enum_field], query, UnknownEnum)
+
+
+def test_schema_enum_values_fixer_handles_null_input_default():
+    #  regression test for: https://github.com/mirumee/ariadne/issues/1074
+    make_executable_schema(
+        """
+        input SearchInput {
+          name: String!
+        }
+    
+        type Query {
+          search(filters: SearchInput = null): String
+        }
+        """
+    )