mirror of
https://github.com/graphql-python/graphene.git
synced 2025-07-18 12:02:19 +03:00
Rename name argument to allow custom name
This commit is contained in:
parent
2bd3e61c6b
commit
847af75fd9
|
@ -20,13 +20,13 @@ class ObjectTypeOptions(BaseOptions):
|
||||||
|
|
||||||
|
|
||||||
class ObjectTypeMeta(BaseTypeMeta):
|
class ObjectTypeMeta(BaseTypeMeta):
|
||||||
def __new__(cls, name, bases, namespace, **kwargs):
|
def __new__(cls, name_, bases, namespace, **kwargs):
|
||||||
# We create this type, to then overload it with the dataclass attrs
|
# We create this type, to then overload it with the dataclass attrs
|
||||||
class InterObjectType:
|
class InterObjectType:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
base_cls = super().__new__(
|
base_cls = super().__new__(
|
||||||
cls, name, (InterObjectType,) + bases, namespace, **kwargs
|
cls, name_, (InterObjectType,) + bases, namespace, **kwargs
|
||||||
)
|
)
|
||||||
if base_cls._meta:
|
if base_cls._meta:
|
||||||
fields = [
|
fields = [
|
||||||
|
@ -41,7 +41,7 @@ class ObjectTypeMeta(BaseTypeMeta):
|
||||||
)
|
)
|
||||||
for key, field_value in base_cls._meta.fields.items()
|
for key, field_value in base_cls._meta.fields.items()
|
||||||
]
|
]
|
||||||
dataclass = make_dataclass(name, fields, bases=())
|
dataclass = make_dataclass(name_, fields, bases=())
|
||||||
InterObjectType.__init__ = dataclass.__init__
|
InterObjectType.__init__ = dataclass.__init__
|
||||||
InterObjectType.__eq__ = dataclass.__eq__
|
InterObjectType.__eq__ = dataclass.__eq__
|
||||||
InterObjectType.__repr__ = dataclass.__repr__
|
InterObjectType.__repr__ = dataclass.__repr__
|
||||||
|
|
|
@ -306,3 +306,10 @@ def test_objecttype_meta_arguments():
|
||||||
|
|
||||||
assert MyType._meta.interfaces == [MyInterface]
|
assert MyType._meta.interfaces == [MyInterface]
|
||||||
assert list(MyType._meta.fields.keys()) == ["foo", "bar"]
|
assert list(MyType._meta.fields.keys()) == ["foo", "bar"]
|
||||||
|
|
||||||
|
|
||||||
|
def test_objecttype_type_name():
|
||||||
|
class MyObjectType(ObjectType, name="FooType"):
|
||||||
|
pass
|
||||||
|
|
||||||
|
assert MyObjectType._meta.name == "FooType"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user