Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add copy function for GrapheneGraphQLType #1463

Merged
merged 2 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions graphene/types/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ def __init__(self, *args, **kwargs):
self.graphene_type = kwargs.pop("graphene_type")
super(GrapheneGraphQLType, self).__init__(*args, **kwargs)

def __copy__(self):
result = GrapheneGraphQLType(graphene_type=self.graphene_type)
result.__dict__.update(self.__dict__)
return result


class GrapheneInterfaceType(GrapheneGraphQLType, GraphQLInterfaceType):
pass
Expand Down
16 changes: 16 additions & 0 deletions graphene/types/tests/test_definition.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import copy

from ..argument import Argument
from ..definitions import GrapheneGraphQLType
from ..enum import Enum
from ..field import Field
from ..inputfield import InputField
Expand Down Expand Up @@ -312,3 +315,16 @@ class TestInputObject2(CommonFields, InputObjectType):
pass

assert TestInputObject1._meta.fields == TestInputObject2._meta.fields


def test_graphene_graphql_type_can_be_copied():
class Query(ObjectType):
field = String()

def resolve_field(self, info):
return ""

schema = Schema(query=Query)
query_type_copy = copy.copy(schema.graphql_schema.query_type)
assert query_type_copy.__dict__ == schema.graphql_schema.query_type.__dict__
assert isinstance(schema.graphql_schema.query_type, GrapheneGraphQLType)