Skip to content

deepcopy fails if the schema has a directive with an enum argument #210

Closed
@menma1234

Description

@menma1234

It seems like if you have a GraphQLSchema containing a directive definition that has an argument that is an enum, trying to deepcopy it results in a TypeError:

Python 3.10.5 (tags/v3.10.5:f377153, Jun  6 2022, 16:14:13) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from copy import deepcopy
>>> from graphql import build_schema
>>> schema_text = """
... directive @testDirective(enumArg: TestEnum) on FIELD_DEFINITION
...
... enum TestEnum {
...     FIRST
...     SECOND
... }
...
... type TestType {
...     field: String @testDirective(enumArg: FIRST)
... }
... """
>>> schema = build_schema(schema_text)
>>> deepcopy(schema)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Program Files\Python310\lib\copy.py", line 153, in deepcopy
    y = copier(memo)
  File "C:\test\.venv\lib\site-packages\graphql\type\schema.py", line 329, in __deepcopy__
    return self.__class__(
  File "C:\test\.venv\lib\site-packages\graphql\type\schema.py", line 258, in __init__
    raise TypeError(
TypeError: Schema must contain uniquely named types but contains multiple types named 'TestEnum'.

Using graphql-core version 3.2.3.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions