1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Refactor base Graphene object types

This commit is contained in:
jeremystretch
2021-08-03 13:49:12 -04:00
parent 735286d3b0
commit c416fce400
2 changed files with 23 additions and 16 deletions

View File

@@ -1,8 +1,8 @@
import graphene
from django.contrib.contenttypes.models import ContentType
from graphene.types.generic import GenericScalar
from graphene_django import DjangoObjectType
from extras.graphql.mixins import CustomFieldsMixin, TagsMixin
__all__ = (
'BaseObjectType',
'ObjectType',
@@ -27,31 +27,21 @@ class BaseObjectType(DjangoObjectType):
return queryset.restrict(info.context.user, 'view')
class ObjectType(BaseObjectType):
class ObjectType(CustomFieldsMixin, BaseObjectType):
"""
Extends BaseObjectType with support for custom field data.
Extends BaseObjectType with support for custom fields.
"""
custom_fields = GenericScalar()
class Meta:
abstract = True
def resolve_custom_fields(self, info):
return self.custom_field_data
class TaggedObjectType(ObjectType):
class TaggedObjectType(CustomFieldsMixin, TagsMixin, BaseObjectType):
"""
Extends ObjectType with support for Tags
Extends BaseObjectType with support for custom fields and tags
"""
tags = graphene.List(graphene.String)
class Meta:
abstract = True
def resolve_tags(self, info):
return self.tags.all()
#
# Miscellaneous types