Add GraphQL type for ContentType

This commit is contained in:
jeremystretch 2021-06-29 11:36:18 -04:00
parent 7deabfe9cd
commit 79614ed2cf

View File

@ -1,4 +1,5 @@
import graphene
from django.contrib.contenttypes.models import ContentType
from graphene.types.generic import GenericScalar
from graphene_django import DjangoObjectType
@ -9,6 +10,10 @@ __all__ = (
)
#
# Base types
#
class BaseObjectType(DjangoObjectType):
"""
Base GraphQL object type for all NetBox objects
@ -26,13 +31,13 @@ class ObjectType(BaseObjectType):
"""
Extends BaseObjectType with support for custom field data.
"""
# custom_fields = GenericScalar()
custom_fields = GenericScalar()
class Meta:
abstract = True
# def resolve_custom_fields(self, info):
# return self.custom_field_data
def resolve_custom_fields(self, info):
return self.custom_field_data
class TaggedObjectType(ObjectType):
@ -46,3 +51,14 @@ class TaggedObjectType(ObjectType):
def resolve_tags(self, info):
return self.tags.all()
#
# Miscellaneous types
#
class ContentTypeType(DjangoObjectType):
class Meta:
model = ContentType
fields = ('id', 'app_label', 'model')