graphql-python / graphql-core

A Python 3.6+ port of the GraphQL.js reference implementation of GraphQL.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

menma1234 opened this issue · comments

commented

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.