Skip to content

Commit 6969023

Browse files
author
Kristian Uzhca
authored
Add copy function for GrapheneGraphQLType (#1463)
1 parent ee1ff97 commit 6969023

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

graphene/types/definitions.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ def __init__(self, *args, **kwargs):
2020
self.graphene_type = kwargs.pop("graphene_type")
2121
super(GrapheneGraphQLType, self).__init__(*args, **kwargs)
2222

23+
def __copy__(self):
24+
result = GrapheneGraphQLType(graphene_type=self.graphene_type)
25+
result.__dict__.update(self.__dict__)
26+
return result
27+
2328

2429
class GrapheneInterfaceType(GrapheneGraphQLType, GraphQLInterfaceType):
2530
pass

graphene/types/tests/test_definition.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
import copy
2+
13
from ..argument import Argument
4+
from ..definitions import GrapheneGraphQLType
25
from ..enum import Enum
36
from ..field import Field
47
from ..inputfield import InputField
@@ -312,3 +315,16 @@ class TestInputObject2(CommonFields, InputObjectType):
312315
pass
313316

314317
assert TestInputObject1._meta.fields == TestInputObject2._meta.fields
318+
319+
320+
def test_graphene_graphql_type_can_be_copied():
321+
class Query(ObjectType):
322+
field = String()
323+
324+
def resolve_field(self, info):
325+
return ""
326+
327+
schema = Schema(query=Query)
328+
query_type_copy = copy.copy(schema.graphql_schema.query_type)
329+
assert query_type_copy.__dict__ == schema.graphql_schema.query_type.__dict__
330+
assert isinstance(schema.graphql_schema.query_type, GrapheneGraphQLType)

0 commit comments

Comments
 (0)