We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Incorrect typing for values on EnumType.__init__()
Ariadne 0.18.0 has updated the `EnumType` class in a way that causes the `values` argument of `__init__()` to become typed, but the typing is incorrect:

```
    def __init__(
        self, name: str, values: Union[Dict[str, Any], enum.Enum, enum.IntEnum]
    ) -> None:
```

should be:

```
    def __init__(
        self, name: str, values: Union[Dict[str, Any], Type[enum.Enum], Type[enum.IntEnum]]
    ) -> None:
```

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `ariadne/enums.py`
Content:
```
1 import enum
2 from typing import (
3     Any,
4     Dict,
5     Generator,
6     List,
7     Mapping,
8     Optional,
9     Tuple,
10     TypeVar,
11     Union,
12     cast,
13 )
14 from functools import reduce, singledispatch
15 import operator
16 
17 from graphql.type import GraphQLEnumType, GraphQLNamedType, GraphQLSchema
18 from graphql.language.ast import (
19     EnumValueNode,
20     InputValueDefinitionNode,
21     ObjectValueNode,
22 )
23 from graphql.pyutils.undefined import Undefined
24 from graphql.type.definition import (
25     GraphQLArgument,
26     GraphQLField,
27     GraphQLInputField,
28     GraphQLInputObjectType,
29     GraphQLInputType,
30     GraphQLInterfaceType,
31     GraphQLNonNull,
32     GraphQLObjectType,
33     GraphQLScalarType,
34 )
35 
36 from .types import SchemaBindable
37 
38 
39 T = TypeVar("T")
40 ArgumentWithKeys = Tuple[str, str, GraphQLArgument, Optional[List["str"]]]
41 InputFieldWithKeys = Tuple[str, str, GraphQLInputField, Optional[List["str"]]]
42 GraphQLNamedInputType = Union[
43     GraphQLScalarType, GraphQLEnumType, GraphQLInputObjectType
44 ]
45 
46 
47 class EnumType(SchemaBindable):
48     """Bindable mapping Python values to enumeration members in a GraphQL schema.
49 
50     # Example
51 
52     Given following GraphQL enum:
53 
54     ```graphql
55     enum UserRole {
56         MEMBER
57         MODERATOR
58         ADMIN
59     }
60     ```
61 
62     You can use `EnumType` to map it's members to Python `Enum`:
63 
64     ```python
65     user_role_type = EnumType(
66         "UserRole",
67         {
68             "MEMBER": 0,
69             "MODERATOR": 1,
70             "ADMIN": 2,
71         }
72     )
73     ```
74 
75     `EnumType` also works with dictionaries:
76 
77     ```python
78     user_role_type = EnumType(
79         "UserRole",
80         {
81             "MEMBER": 0,
82             "MODERATOR": 1,
83             "ADMIN": 2,
84         }
85     )
86     ```
87     """
88 
89     def __init__(
90         self, name: str, values: Union[Dict[str, Any], enum.Enum, enum.IntEnum]
91     ) -> None:
92         """Initializes the `EnumType` with `name` and `values` mapping.
93 
94         # Required arguments
95 
96         `name`: a `str` with the name of GraphQL enum type in GraphQL schema to
97         bind to.
98 
99         `values`: a `dict` or `enums.Enum` with values to use to represent GraphQL
100         enum's in Python logic.
101         """
102         self.name = name
103         self.values = cast(Dict[str, Any], getattr(values, "__members__", values))
104 
105     def bind_to_schema(self, schema: GraphQLSchema) -> None:
106         """Binds this `EnumType` instance to the instance of GraphQL schema."""
107         graphql_type = schema.type_map.get(self.name)
108         self.validate_graphql_type(graphql_type)
109         graphql_type = cast(GraphQLEnumType, graphql_type)
110 
111         for key, value in self.values.items():
112             if key not in graphql_type.values:
113                 raise ValueError(
114                     "Value %s is not defined on enum %s" % (key, self.name)
115                 )
116             graphql_type.values[key].value = value
117 
118     def bind_to_default_values(self, schema: GraphQLSchema) -> None:
119         """Populates default values of input fields and args in the GraphQL schema.
120 
121         This step is required because GraphQL query executor doesn't perform a
122         lookup for default values defined in schema. Instead it simply pulls the
123         value from fields and arguments `default_value` attribute, which is
124         `None` by default.
125         """
126         for _, _, arg, key_list in find_enum_values_in_schema(schema):
127             type_ = resolve_null_type(arg.type)
128             type_ = cast(GraphQLNamedInputType, type_)
129 
130             if (
131                 key_list is None
132                 and arg.default_value in self.values
133                 and type_.name == self.name
134             ):
135                 type_ = resolve_null_type(arg.type)
136                 arg.default_value = self.values[arg.default_value]
137 
138             elif key_list is not None:
139                 enum_value = get_value_from_mapping_value(arg.default_value, key_list)
140                 type_ = cast(GraphQLEnumType, track_type_for_nested(arg, key_list))
141 
142                 if enum_value in self.values and type_.name == self.name:
143                     set_leaf_value_in_mapping(
144                         arg.default_value, key_list, self.values[enum_value]
145                     )
146 
147     def validate_graphql_type(self, graphql_type: Optional[GraphQLNamedType]) -> None:
148         """Validates that schema's GraphQL type associated with this `EnumType`
149         is an `enum`."""
150         if not graphql_type:
151             raise ValueError("Enum %s is not defined in the schema" % self.name)
152         if not isinstance(graphql_type, GraphQLEnumType):
153             raise ValueError(
154                 "%s is defined in the schema, but it is instance of %s (expected %s)"
155                 % (self.name, type(graphql_type).__name__, GraphQLEnumType.__name__)
156             )
157 
158 
159 def set_default_enum_values_on_schema(schema: GraphQLSchema):
160     """Sets missing Python values for GraphQL enums in schema.
161 
162     Recursively scans GraphQL schema for enums and their values. If `value`
163     attribute is empty, its populated with with a string of its GraphQL name.
164 
165     This string is then used to represent enum's value in Python instead of `None`.
166 
167     # Requires arguments
168 
169     `schema`: a GraphQL schema to set enums default values in.
170     """
171     for type_object in schema.type_map.values():
172         if isinstance(type_object, GraphQLEnumType):
173             set_default_enum_values(type_object)
174 
175 
176 def set_default_enum_values(graphql_type: GraphQLEnumType):
177     for key in graphql_type.values:
178         if graphql_type.values[key].value is None:
179             graphql_type.values[key].value = key
180 
181 
182 def validate_schema_enum_values(schema: GraphQLSchema) -> None:
183     """Raises `ValueError` if GraphQL schema has input fields or arguments with
184     default values that are undefined enum values.
185 
186     # Example schema with invalid field argument
187 
188     This schema fails to validate because argument `role` on field `users`
189     specifies `REVIEWER` as default value and `REVIEWER` is not a member of
190     the `UserRole` enum:
191 
192     ```graphql
193     type Query {
194         users(role: UserRole = REVIEWER): [User!]!
195     }
196 
197     enum UserRole {
198         MEMBER
199         MODERATOR
200         ADMIN
201     }
202 
203     type User {
204         id: ID!
205     }
206     ```
207 
208     # Example schema with invalid input field
209 
210     This schema fails to validate because field `role` on input `UserFilters`
211     specifies `REVIEWER` as default value and `REVIEWER` is not a member of
212     the `UserRole` enum:
213 
214     ```graphql
215     type Query {
216         users(filter: UserFilters): [User!]!
217     }
218 
219     input UserFilters {
220         name: String
221         role: UserRole = REVIEWER
222     }
223 
224     enum UserRole {
225         MEMBER
226         MODERATOR
227         ADMIN
228     }
229 
230     type User {
231         id: ID!
232     }
233     ```
234     """
235 
236     for type_name, field_name, arg, _ in find_enum_values_in_schema(schema):
237         if is_invalid_enum_value(arg):
238             raise ValueError(
239                 f"Value for type: <{arg.type}> is invalid. "
240                 f"Check InputField/Arguments for <{field_name}> in <{type_name}> "
241                 "(Undefined enum value)."
242             )
243 
244 
245 def is_invalid_enum_value(field: Union[GraphQLInputField, GraphQLArgument]) -> bool:
246     if field.ast_node is None:
247         return False
248     return field.default_value is Undefined and field.ast_node.default_value is not None
249 
250 
251 def find_enum_values_in_schema(
252     schema: GraphQLSchema,
253 ) -> Generator[Union[ArgumentWithKeys, InputFieldWithKeys], None, None]:
254     for name, type_ in schema.type_map.items():
255         result = enum_values_in_types(type_, name)
256         if result is not None:
257             yield from result
258 
259 
260 @singledispatch
261 def enum_values_in_types(
262     type_: GraphQLNamedType,  # pylint: disable=unused-argument
263     name: str,  # pylint: disable=unused-argument
264 ) -> Optional[Generator[Union[ArgumentWithKeys, InputFieldWithKeys], None, None]]:
265     pass
266 
267 
268 @enum_values_in_types.register(GraphQLObjectType)
269 @enum_values_in_types.register(GraphQLInterfaceType)
270 def enum_values_in_object_type(
271     type_: Union[GraphQLObjectType, GraphQLInterfaceType],
272     field_name: str,
273 ) -> Generator[ArgumentWithKeys, None, None]:
274     for field in type_.fields.values():
275         yield from enum_values_in_field_args(field_name, field)
276 
277 
278 @enum_values_in_types.register(GraphQLInputObjectType)
279 def enum_values_in_input_type(
280     type_: GraphQLInputObjectType,
281     field_name,
282 ) -> Generator[InputFieldWithKeys, None, None]:
283     yield from _get_field_with_keys(field_name, type_.fields.items())
284 
285 
286 def enum_values_in_field_args(
287     field_name: str,
288     field: GraphQLField,
289 ) -> Generator[ArgumentWithKeys, None, None]:
290     args = [
291         (name, arg)
292         for name, arg in field.args.items()
293         if isinstance(
294             arg.type, (GraphQLInputObjectType, GraphQLEnumType, GraphQLNonNull)
295         )
296     ]
297 
298     yield from _get_field_with_keys(field_name, args)
299 
300 
301 def _get_field_with_keys(field_name, fields):
302     for input_name, field in fields:
303         resolved_type = resolve_null_type(field.type)
304         if isinstance(resolved_type, GraphQLEnumType):
305             yield field_name, input_name, field, None
306 
307         if isinstance(resolved_type, GraphQLInputObjectType):
308             if field.ast_node is not None and field.ast_node.default_value is not None:
309                 routes = get_enum_keys_from_ast(field.ast_node)
310                 for route in routes:
311                     yield field_name, input_name, field, route
312 
313 
314 def get_enum_keys_from_ast(ast_node: InputValueDefinitionNode) -> List[List["str"]]:
315     routes = []
316     object_node = cast(ObjectValueNode, ast_node.default_value)
317     nodes = [([field.name.value], field) for field in object_node.fields]
318 
319     while nodes:
320         key_list, field = nodes.pop()
321         if isinstance(field.value, EnumValueNode):
322             routes.append(key_list)
323 
324         if isinstance(field.value, ObjectValueNode):
325             for new_field in field.value.fields:
326                 new_route = key_list[:]
327                 new_route.append(new_field.name.value)
328                 nodes.append((new_route, new_field))
329 
330     return routes
331 
332 
333 def get_value_from_mapping_value(mapping: Mapping[T, Any], key_list: List[T]) -> Any:
334     return reduce(operator.getitem, key_list, mapping)
335 
336 
337 def set_leaf_value_in_mapping(
338     mapping: Mapping[T, Any], key_list: List[T], value: Any
339 ) -> None:
340     get_value_from_mapping_value(mapping, key_list[:-1])[key_list[-1]] = value
341 
342 
343 def track_type_for_nested(
344     arg: Union[GraphQLArgument, GraphQLInputField], key_list: List[str]
345 ) -> GraphQLInputType:
346     type_ = resolve_null_type(arg.type)
347 
348     for elem in key_list:
349         if isinstance(type_, GraphQLInputObjectType):
350             type_ = type_.fields[elem].type
351     return type_
352 
353 
354 def resolve_null_type(type_: GraphQLInputType) -> GraphQLInputType:
355     return type_.of_type if isinstance(type_, GraphQLNonNull) else type_
356
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/ariadne/enums.py b/ariadne/enums.py
--- a/ariadne/enums.py
+++ b/ariadne/enums.py
@@ -7,6 +7,7 @@
     Mapping,
     Optional,
     Tuple,
+    Type,
     TypeVar,
     Union,
     cast,
@@ -87,7 +88,9 @@
     """
 
     def __init__(
-        self, name: str, values: Union[Dict[str, Any], enum.Enum, enum.IntEnum]
+        self,
+        name: str,
+        values: Union[Dict[str, Any], Type[enum.Enum], Type[enum.IntEnum]],
     ) -> None:
         """Initializes the `EnumType` with `name` and `values` mapping.

{"golden_diff": "diff --git a/ariadne/enums.py b/ariadne/enums.py\n--- a/ariadne/enums.py\n+++ b/ariadne/enums.py\n@@ -7,6 +7,7 @@\n     Mapping,\n     Optional,\n     Tuple,\n+    Type,\n     TypeVar,\n     Union,\n     cast,\n@@ -87,7 +88,9 @@\n     \"\"\"\n \n     def __init__(\n-        self, name: str, values: Union[Dict[str, Any], enum.Enum, enum.IntEnum]\n+        self,\n+        name: str,\n+        values: Union[Dict[str, Any], Type[enum.Enum], Type[enum.IntEnum]],\n     ) -> None:\n         \"\"\"Initializes the `EnumType` with `name` and `values` mapping.\n", "issue": "Incorrect typing for values on EnumType.__init__()\nAriadne 0.18.0 has updated the `EnumType` class in a way that causes the `values` argument of `__init__()` to become typed, but the typing is incorrect:\r\n\r\n```\r\n    def __init__(\r\n        self, name: str, values: Union[Dict[str, Any], enum.Enum, enum.IntEnum]\r\n    ) -> None:\r\n```\r\n\r\nshould be:\r\n\r\n```\r\n    def __init__(\r\n        self, name: str, values: Union[Dict[str, Any], Type[enum.Enum], Type[enum.IntEnum]]\r\n    ) -> None:\r\n```\n", "before_files": [{"content": "import enum\nfrom typing import (\n    Any,\n    Dict,\n    Generator,\n    List,\n    Mapping,\n    Optional,\n    Tuple,\n    TypeVar,\n    Union,\n    cast,\n)\nfrom functools import reduce, singledispatch\nimport operator\n\nfrom graphql.type import GraphQLEnumType, GraphQLNamedType, GraphQLSchema\nfrom graphql.language.ast import (\n    EnumValueNode,\n    InputValueDefinitionNode,\n    ObjectValueNode,\n)\nfrom graphql.pyutils.undefined import Undefined\nfrom graphql.type.definition import (\n    GraphQLArgument,\n    GraphQLField,\n    GraphQLInputField,\n    GraphQLInputObjectType,\n    GraphQLInputType,\n    GraphQLInterfaceType,\n    GraphQLNonNull,\n    GraphQLObjectType,\n    GraphQLScalarType,\n)\n\nfrom .types import SchemaBindable\n\n\nT = TypeVar(\"T\")\nArgumentWithKeys = Tuple[str, str, GraphQLArgument, Optional[List[\"str\"]]]\nInputFieldWithKeys = Tuple[str, str, GraphQLInputField, Optional[List[\"str\"]]]\nGraphQLNamedInputType = Union[\n    GraphQLScalarType, GraphQLEnumType, GraphQLInputObjectType\n]\n\n\nclass EnumType(SchemaBindable):\n    \"\"\"Bindable mapping Python values to enumeration members in a GraphQL schema.\n\n    # Example\n\n    Given following GraphQL enum:\n\n    ```graphql\n    enum UserRole {\n        MEMBER\n        MODERATOR\n        ADMIN\n    }\n    ```\n\n    You can use `EnumType` to map it's members to Python `Enum`:\n\n    ```python\n    user_role_type = EnumType(\n        \"UserRole\",\n        {\n            \"MEMBER\": 0,\n            \"MODERATOR\": 1,\n            \"ADMIN\": 2,\n        }\n    )\n    ```\n\n    `EnumType` also works with dictionaries:\n\n    ```python\n    user_role_type = EnumType(\n        \"UserRole\",\n        {\n            \"MEMBER\": 0,\n            \"MODERATOR\": 1,\n            \"ADMIN\": 2,\n        }\n    )\n    ```\n    \"\"\"\n\n    def __init__(\n        self, name: str, values: Union[Dict[str, Any], enum.Enum, enum.IntEnum]\n    ) -> None:\n        \"\"\"Initializes the `EnumType` with `name` and `values` mapping.\n\n        # Required arguments\n\n        `name`: a `str` with the name of GraphQL enum type in GraphQL schema to\n        bind to.\n\n        `values`: a `dict` or `enums.Enum` with values to use to represent GraphQL\n        enum's in Python logic.\n        \"\"\"\n        self.name = name\n        self.values = cast(Dict[str, Any], getattr(values, \"__members__\", values))\n\n    def bind_to_schema(self, schema: GraphQLSchema) -> None:\n        \"\"\"Binds this `EnumType` instance to the instance of GraphQL schema.\"\"\"\n        graphql_type = schema.type_map.get(self.name)\n        self.validate_graphql_type(graphql_type)\n        graphql_type = cast(GraphQLEnumType, graphql_type)\n\n        for key, value in self.values.items():\n            if key not in graphql_type.values:\n                raise ValueError(\n                    \"Value %s is not defined on enum %s\" % (key, self.name)\n                )\n            graphql_type.values[key].value = value\n\n    def bind_to_default_values(self, schema: GraphQLSchema) -> None:\n        \"\"\"Populates default values of input fields and args in the GraphQL schema.\n\n        This step is required because GraphQL query executor doesn't perform a\n        lookup for default values defined in schema. Instead it simply pulls the\n        value from fields and arguments `default_value` attribute, which is\n        `None` by default.\n        \"\"\"\n        for _, _, arg, key_list in find_enum_values_in_schema(schema):\n            type_ = resolve_null_type(arg.type)\n            type_ = cast(GraphQLNamedInputType, type_)\n\n            if (\n                key_list is None\n                and arg.default_value in self.values\n                and type_.name == self.name\n            ):\n                type_ = resolve_null_type(arg.type)\n                arg.default_value = self.values[arg.default_value]\n\n            elif key_list is not None:\n                enum_value = get_value_from_mapping_value(arg.default_value, key_list)\n                type_ = cast(GraphQLEnumType, track_type_for_nested(arg, key_list))\n\n                if enum_value in self.values and type_.name == self.name:\n                    set_leaf_value_in_mapping(\n                        arg.default_value, key_list, self.values[enum_value]\n                    )\n\n    def validate_graphql_type(self, graphql_type: Optional[GraphQLNamedType]) -> None:\n        \"\"\"Validates that schema's GraphQL type associated with this `EnumType`\n        is an `enum`.\"\"\"\n        if not graphql_type:\n            raise ValueError(\"Enum %s is not defined in the schema\" % self.name)\n        if not isinstance(graphql_type, GraphQLEnumType):\n            raise ValueError(\n                \"%s is defined in the schema, but it is instance of %s (expected %s)\"\n                % (self.name, type(graphql_type).__name__, GraphQLEnumType.__name__)\n            )\n\n\ndef set_default_enum_values_on_schema(schema: GraphQLSchema):\n    \"\"\"Sets missing Python values for GraphQL enums in schema.\n\n    Recursively scans GraphQL schema for enums and their values. If `value`\n    attribute is empty, its populated with with a string of its GraphQL name.\n\n    This string is then used to represent enum's value in Python instead of `None`.\n\n    # Requires arguments\n\n    `schema`: a GraphQL schema to set enums default values in.\n    \"\"\"\n    for type_object in schema.type_map.values():\n        if isinstance(type_object, GraphQLEnumType):\n            set_default_enum_values(type_object)\n\n\ndef set_default_enum_values(graphql_type: GraphQLEnumType):\n    for key in graphql_type.values:\n        if graphql_type.values[key].value is None:\n            graphql_type.values[key].value = key\n\n\ndef validate_schema_enum_values(schema: GraphQLSchema) -> None:\n    \"\"\"Raises `ValueError` if GraphQL schema has input fields or arguments with\n    default values that are undefined enum values.\n\n    # Example schema with invalid field argument\n\n    This schema fails to validate because argument `role` on field `users`\n    specifies `REVIEWER` as default value and `REVIEWER` is not a member of\n    the `UserRole` enum:\n\n    ```graphql\n    type Query {\n        users(role: UserRole = REVIEWER): [User!]!\n    }\n\n    enum UserRole {\n        MEMBER\n        MODERATOR\n        ADMIN\n    }\n\n    type User {\n        id: ID!\n    }\n    ```\n\n    # Example schema with invalid input field\n\n    This schema fails to validate because field `role` on input `UserFilters`\n    specifies `REVIEWER` as default value and `REVIEWER` is not a member of\n    the `UserRole` enum:\n\n    ```graphql\n    type Query {\n        users(filter: UserFilters): [User!]!\n    }\n\n    input UserFilters {\n        name: String\n        role: UserRole = REVIEWER\n    }\n\n    enum UserRole {\n        MEMBER\n        MODERATOR\n        ADMIN\n    }\n\n    type User {\n        id: ID!\n    }\n    ```\n    \"\"\"\n\n    for type_name, field_name, arg, _ in find_enum_values_in_schema(schema):\n        if is_invalid_enum_value(arg):\n            raise ValueError(\n                f\"Value for type: <{arg.type}> is invalid. \"\n                f\"Check InputField/Arguments for <{field_name}> in <{type_name}> \"\n                \"(Undefined enum value).\"\n            )\n\n\ndef is_invalid_enum_value(field: Union[GraphQLInputField, GraphQLArgument]) -> bool:\n    if field.ast_node is None:\n        return False\n    return field.default_value is Undefined and field.ast_node.default_value is not None\n\n\ndef find_enum_values_in_schema(\n    schema: GraphQLSchema,\n) -> Generator[Union[ArgumentWithKeys, InputFieldWithKeys], None, None]:\n    for name, type_ in schema.type_map.items():\n        result = enum_values_in_types(type_, name)\n        if result is not None:\n            yield from result\n\n\n@singledispatch\ndef enum_values_in_types(\n    type_: GraphQLNamedType,  # pylint: disable=unused-argument\n    name: str,  # pylint: disable=unused-argument\n) -> Optional[Generator[Union[ArgumentWithKeys, InputFieldWithKeys], None, None]]:\n    pass\n\n\n@enum_values_in_types.register(GraphQLObjectType)\n@enum_values_in_types.register(GraphQLInterfaceType)\ndef enum_values_in_object_type(\n    type_: Union[GraphQLObjectType, GraphQLInterfaceType],\n    field_name: str,\n) -> Generator[ArgumentWithKeys, None, None]:\n    for field in type_.fields.values():\n        yield from enum_values_in_field_args(field_name, field)\n\n\n@enum_values_in_types.register(GraphQLInputObjectType)\ndef enum_values_in_input_type(\n    type_: GraphQLInputObjectType,\n    field_name,\n) -> Generator[InputFieldWithKeys, None, None]:\n    yield from _get_field_with_keys(field_name, type_.fields.items())\n\n\ndef enum_values_in_field_args(\n    field_name: str,\n    field: GraphQLField,\n) -> Generator[ArgumentWithKeys, None, None]:\n    args = [\n        (name, arg)\n        for name, arg in field.args.items()\n        if isinstance(\n            arg.type, (GraphQLInputObjectType, GraphQLEnumType, GraphQLNonNull)\n        )\n    ]\n\n    yield from _get_field_with_keys(field_name, args)\n\n\ndef _get_field_with_keys(field_name, fields):\n    for input_name, field in fields:\n        resolved_type = resolve_null_type(field.type)\n        if isinstance(resolved_type, GraphQLEnumType):\n            yield field_name, input_name, field, None\n\n        if isinstance(resolved_type, GraphQLInputObjectType):\n            if field.ast_node is not None and field.ast_node.default_value is not None:\n                routes = get_enum_keys_from_ast(field.ast_node)\n                for route in routes:\n                    yield field_name, input_name, field, route\n\n\ndef get_enum_keys_from_ast(ast_node: InputValueDefinitionNode) -> List[List[\"str\"]]:\n    routes = []\n    object_node = cast(ObjectValueNode, ast_node.default_value)\n    nodes = [([field.name.value], field) for field in object_node.fields]\n\n    while nodes:\n        key_list, field = nodes.pop()\n        if isinstance(field.value, EnumValueNode):\n            routes.append(key_list)\n\n        if isinstance(field.value, ObjectValueNode):\n            for new_field in field.value.fields:\n                new_route = key_list[:]\n                new_route.append(new_field.name.value)\n                nodes.append((new_route, new_field))\n\n    return routes\n\n\ndef get_value_from_mapping_value(mapping: Mapping[T, Any], key_list: List[T]) -> Any:\n    return reduce(operator.getitem, key_list, mapping)\n\n\ndef set_leaf_value_in_mapping(\n    mapping: Mapping[T, Any], key_list: List[T], value: Any\n) -> None:\n    get_value_from_mapping_value(mapping, key_list[:-1])[key_list[-1]] = value\n\n\ndef track_type_for_nested(\n    arg: Union[GraphQLArgument, GraphQLInputField], key_list: List[str]\n) -> GraphQLInputType:\n    type_ = resolve_null_type(arg.type)\n\n    for elem in key_list:\n        if isinstance(type_, GraphQLInputObjectType):\n            type_ = type_.fields[elem].type\n    return type_\n\n\ndef resolve_null_type(type_: GraphQLInputType) -> GraphQLInputType:\n    return type_.of_type if isinstance(type_, GraphQLNonNull) else type_\n", "path": "ariadne/enums.py"}], "after_files": [{"content": "import enum\nfrom typing import (\n    Any,\n    Dict,\n    Generator,\n    List,\n    Mapping,\n    Optional,\n    Tuple,\n    Type,\n    TypeVar,\n    Union,\n    cast,\n)\nfrom functools import reduce, singledispatch\nimport operator\n\nfrom graphql.type import GraphQLEnumType, GraphQLNamedType, GraphQLSchema\nfrom graphql.language.ast import (\n    EnumValueNode,\n    InputValueDefinitionNode,\n    ObjectValueNode,\n)\nfrom graphql.pyutils.undefined import Undefined\nfrom graphql.type.definition import (\n    GraphQLArgument,\n    GraphQLField,\n    GraphQLInputField,\n    GraphQLInputObjectType,\n    GraphQLInputType,\n    GraphQLInterfaceType,\n    GraphQLNonNull,\n    GraphQLObjectType,\n    GraphQLScalarType,\n)\n\nfrom .types import SchemaBindable\n\n\nT = TypeVar(\"T\")\nArgumentWithKeys = Tuple[str, str, GraphQLArgument, Optional[List[\"str\"]]]\nInputFieldWithKeys = Tuple[str, str, GraphQLInputField, Optional[List[\"str\"]]]\nGraphQLNamedInputType = Union[\n    GraphQLScalarType, GraphQLEnumType, GraphQLInputObjectType\n]\n\n\nclass EnumType(SchemaBindable):\n    \"\"\"Bindable mapping Python values to enumeration members in a GraphQL schema.\n\n    # Example\n\n    Given following GraphQL enum:\n\n    ```graphql\n    enum UserRole {\n        MEMBER\n        MODERATOR\n        ADMIN\n    }\n    ```\n\n    You can use `EnumType` to map it's members to Python `Enum`:\n\n    ```python\n    user_role_type = EnumType(\n        \"UserRole\",\n        {\n            \"MEMBER\": 0,\n            \"MODERATOR\": 1,\n            \"ADMIN\": 2,\n        }\n    )\n    ```\n\n    `EnumType` also works with dictionaries:\n\n    ```python\n    user_role_type = EnumType(\n        \"UserRole\",\n        {\n            \"MEMBER\": 0,\n            \"MODERATOR\": 1,\n            \"ADMIN\": 2,\n        }\n    )\n    ```\n    \"\"\"\n\n    def __init__(\n        self,\n        name: str,\n        values: Union[Dict[str, Any], Type[enum.Enum], Type[enum.IntEnum]],\n    ) -> None:\n        \"\"\"Initializes the `EnumType` with `name` and `values` mapping.\n\n        # Required arguments\n\n        `name`: a `str` with the name of GraphQL enum type in GraphQL schema to\n        bind to.\n\n        `values`: a `dict` or `enums.Enum` with values to use to represent GraphQL\n        enum's in Python logic.\n        \"\"\"\n        self.name = name\n        self.values = cast(Dict[str, Any], getattr(values, \"__members__\", values))\n\n    def bind_to_schema(self, schema: GraphQLSchema) -> None:\n        \"\"\"Binds this `EnumType` instance to the instance of GraphQL schema.\"\"\"\n        graphql_type = schema.type_map.get(self.name)\n        self.validate_graphql_type(graphql_type)\n        graphql_type = cast(GraphQLEnumType, graphql_type)\n\n        for key, value in self.values.items():\n            if key not in graphql_type.values:\n                raise ValueError(\n                    \"Value %s is not defined on enum %s\" % (key, self.name)\n                )\n            graphql_type.values[key].value = value\n\n    def bind_to_default_values(self, schema: GraphQLSchema) -> None:\n        \"\"\"Populates default values of input fields and args in the GraphQL schema.\n\n        This step is required because GraphQL query executor doesn't perform a\n        lookup for default values defined in schema. Instead it simply pulls the\n        value from fields and arguments `default_value` attribute, which is\n        `None` by default.\n        \"\"\"\n        for _, _, arg, key_list in find_enum_values_in_schema(schema):\n            type_ = resolve_null_type(arg.type)\n            type_ = cast(GraphQLNamedInputType, type_)\n\n            if (\n                key_list is None\n                and arg.default_value in self.values\n                and type_.name == self.name\n            ):\n                type_ = resolve_null_type(arg.type)\n                arg.default_value = self.values[arg.default_value]\n\n            elif key_list is not None:\n                enum_value = get_value_from_mapping_value(arg.default_value, key_list)\n                type_ = cast(GraphQLEnumType, track_type_for_nested(arg, key_list))\n\n                if enum_value in self.values and type_.name == self.name:\n                    set_leaf_value_in_mapping(\n                        arg.default_value, key_list, self.values[enum_value]\n                    )\n\n    def validate_graphql_type(self, graphql_type: Optional[GraphQLNamedType]) -> None:\n        \"\"\"Validates that schema's GraphQL type associated with this `EnumType`\n        is an `enum`.\"\"\"\n        if not graphql_type:\n            raise ValueError(\"Enum %s is not defined in the schema\" % self.name)\n        if not isinstance(graphql_type, GraphQLEnumType):\n            raise ValueError(\n                \"%s is defined in the schema, but it is instance of %s (expected %s)\"\n                % (self.name, type(graphql_type).__name__, GraphQLEnumType.__name__)\n            )\n\n\ndef set_default_enum_values_on_schema(schema: GraphQLSchema):\n    \"\"\"Sets missing Python values for GraphQL enums in schema.\n\n    Recursively scans GraphQL schema for enums and their values. If `value`\n    attribute is empty, its populated with with a string of its GraphQL name.\n\n    This string is then used to represent enum's value in Python instead of `None`.\n\n    # Requires arguments\n\n    `schema`: a GraphQL schema to set enums default values in.\n    \"\"\"\n    for type_object in schema.type_map.values():\n        if isinstance(type_object, GraphQLEnumType):\n            set_default_enum_values(type_object)\n\n\ndef set_default_enum_values(graphql_type: GraphQLEnumType):\n    for key in graphql_type.values:\n        if graphql_type.values[key].value is None:\n            graphql_type.values[key].value = key\n\n\ndef validate_schema_enum_values(schema: GraphQLSchema) -> None:\n    \"\"\"Raises `ValueError` if GraphQL schema has input fields or arguments with\n    default values that are undefined enum values.\n\n    # Example schema with invalid field argument\n\n    This schema fails to validate because argument `role` on field `users`\n    specifies `REVIEWER` as default value and `REVIEWER` is not a member of\n    the `UserRole` enum:\n\n    ```graphql\n    type Query {\n        users(role: UserRole = REVIEWER): [User!]!\n    }\n\n    enum UserRole {\n        MEMBER\n        MODERATOR\n        ADMIN\n    }\n\n    type User {\n        id: ID!\n    }\n    ```\n\n    # Example schema with invalid input field\n\n    This schema fails to validate because field `role` on input `UserFilters`\n    specifies `REVIEWER` as default value and `REVIEWER` is not a member of\n    the `UserRole` enum:\n\n    ```graphql\n    type Query {\n        users(filter: UserFilters): [User!]!\n    }\n\n    input UserFilters {\n        name: String\n        role: UserRole = REVIEWER\n    }\n\n    enum UserRole {\n        MEMBER\n        MODERATOR\n        ADMIN\n    }\n\n    type User {\n        id: ID!\n    }\n    ```\n    \"\"\"\n\n    for type_name, field_name, arg, _ in find_enum_values_in_schema(schema):\n        if is_invalid_enum_value(arg):\n            raise ValueError(\n                f\"Value for type: <{arg.type}> is invalid. \"\n                f\"Check InputField/Arguments for <{field_name}> in <{type_name}> \"\n                \"(Undefined enum value).\"\n            )\n\n\ndef is_invalid_enum_value(field: Union[GraphQLInputField, GraphQLArgument]) -> bool:\n    if field.ast_node is None:\n        return False\n    return field.default_value is Undefined and field.ast_node.default_value is not None\n\n\ndef find_enum_values_in_schema(\n    schema: GraphQLSchema,\n) -> Generator[Union[ArgumentWithKeys, InputFieldWithKeys], None, None]:\n    for name, type_ in schema.type_map.items():\n        result = enum_values_in_types(type_, name)\n        if result is not None:\n            yield from result\n\n\n@singledispatch\ndef enum_values_in_types(\n    type_: GraphQLNamedType,  # pylint: disable=unused-argument\n    name: str,  # pylint: disable=unused-argument\n) -> Optional[Generator[Union[ArgumentWithKeys, InputFieldWithKeys], None, None]]:\n    pass\n\n\n@enum_values_in_types.register(GraphQLObjectType)\n@enum_values_in_types.register(GraphQLInterfaceType)\ndef enum_values_in_object_type(\n    type_: Union[GraphQLObjectType, GraphQLInterfaceType],\n    field_name: str,\n) -> Generator[ArgumentWithKeys, None, None]:\n    for field in type_.fields.values():\n        yield from enum_values_in_field_args(field_name, field)\n\n\n@enum_values_in_types.register(GraphQLInputObjectType)\ndef enum_values_in_input_type(\n    type_: GraphQLInputObjectType,\n    field_name,\n) -> Generator[InputFieldWithKeys, None, None]:\n    yield from _get_field_with_keys(field_name, type_.fields.items())\n\n\ndef enum_values_in_field_args(\n    field_name: str,\n    field: GraphQLField,\n) -> Generator[ArgumentWithKeys, None, None]:\n    args = [\n        (name, arg)\n        for name, arg in field.args.items()\n        if isinstance(\n            arg.type, (GraphQLInputObjectType, GraphQLEnumType, GraphQLNonNull)\n        )\n    ]\n\n    yield from _get_field_with_keys(field_name, args)\n\n\ndef _get_field_with_keys(field_name, fields):\n    for input_name, field in fields:\n        resolved_type = resolve_null_type(field.type)\n        if isinstance(resolved_type, GraphQLEnumType):\n            yield field_name, input_name, field, None\n\n        if isinstance(resolved_type, GraphQLInputObjectType):\n            if field.ast_node is not None and field.ast_node.default_value is not None:\n                routes = get_enum_keys_from_ast(field.ast_node)\n                for route in routes:\n                    yield field_name, input_name, field, route\n\n\ndef get_enum_keys_from_ast(ast_node: InputValueDefinitionNode) -> List[List[\"str\"]]:\n    routes = []\n    object_node = cast(ObjectValueNode, ast_node.default_value)\n    nodes = [([field.name.value], field) for field in object_node.fields]\n\n    while nodes:\n        key_list, field = nodes.pop()\n        if isinstance(field.value, EnumValueNode):\n            routes.append(key_list)\n\n        if isinstance(field.value, ObjectValueNode):\n            for new_field in field.value.fields:\n                new_route = key_list[:]\n                new_route.append(new_field.name.value)\n                nodes.append((new_route, new_field))\n\n    return routes\n\n\ndef get_value_from_mapping_value(mapping: Mapping[T, Any], key_list: List[T]) -> Any:\n    return reduce(operator.getitem, key_list, mapping)\n\n\ndef set_leaf_value_in_mapping(\n    mapping: Mapping[T, Any], key_list: List[T], value: Any\n) -> None:\n    get_value_from_mapping_value(mapping, key_list[:-1])[key_list[-1]] = value\n\n\ndef track_type_for_nested(\n    arg: Union[GraphQLArgument, GraphQLInputField], key_list: List[str]\n) -> GraphQLInputType:\n    type_ = resolve_null_type(arg.type)\n\n    for elem in key_list:\n        if isinstance(type_, GraphQLInputObjectType):\n            type_ = type_.fields[elem].type\n    return type_\n\n\ndef resolve_null_type(type_: GraphQLInputType) -> GraphQLInputType:\n    return type_.of_type if isinstance(type_, GraphQLNonNull) else type_\n", "path": "ariadne/enums.py"}]}