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

Add GraphQL for extras

This commit is contained in:
jeremystretch
2021-06-25 14:12:09 -04:00
parent 7a2a25c13a
commit 7256c7050a
6 changed files with 121 additions and 11 deletions

View File

View File

@ -0,0 +1,30 @@
import graphene
from netbox.graphql.fields import ObjectField, ObjectListField
from .types import *
class ExtrasQuery(graphene.ObjectType):
config_context = ObjectField(ConfigContextType)
config_contexts = ObjectListField(ConfigContextType)
custom_field = ObjectField(CustomFieldType)
custom_fields = ObjectListField(CustomFieldType)
custom_link = ObjectField(CustomLinkType)
custom_links = ObjectListField(CustomLinkType)
export_template = ObjectField(ExportTemplateType)
export_templates = ObjectListField(ExportTemplateType)
image_attachment = ObjectField(ImageAttachmentType)
image_attachments = ObjectListField(ImageAttachmentType)
journal_entry = ObjectField(JournalEntryType)
journal_entries = ObjectListField(JournalEntryType)
tag = ObjectField(TagType)
tags = ObjectListField(TagType)
webhook = ObjectField(WebhookType)
webhooks = ObjectListField(WebhookType)

View File

@ -0,0 +1,77 @@
from extras import filtersets, models
from netbox.graphql.types import BaseObjectType
__all__ = (
'ConfigContextType',
'CustomFieldType',
'CustomLinkType',
'ExportTemplateType',
'ImageAttachmentType',
'JournalEntryType',
'TagType',
'WebhookType',
)
class ConfigContextType(BaseObjectType):
class Meta:
model = models.ConfigContext
fields = '__all__'
filterset_class = filtersets.ConfigContextFilterSet
class CustomFieldType(BaseObjectType):
class Meta:
model = models.CustomField
fields = '__all__'
filterset_class = filtersets.CustomFieldFilterSet
class CustomLinkType(BaseObjectType):
class Meta:
model = models.CustomLink
fields = '__all__'
filterset_class = filtersets.CustomLinkFilterSet
class ExportTemplateType(BaseObjectType):
class Meta:
model = models.ExportTemplate
fields = '__all__'
filterset_class = filtersets.ExportTemplateFilterSet
class ImageAttachmentType(BaseObjectType):
class Meta:
model = models.ImageAttachment
fields = '__all__'
filterset_class = filtersets.ImageAttachmentFilterSet
class JournalEntryType(BaseObjectType):
class Meta:
model = models.JournalEntry
fields = '__all__'
filterset_class = filtersets.JournalEntryFilterSet
class TagType(BaseObjectType):
class Meta:
model = models.Tag
fields = '__all__'
filterset_class = filtersets.TagFilterSet
class WebhookType(BaseObjectType):
class Meta:
model = models.Webhook
fields = '__all__'
filterset_class = filtersets.WebhookFilterSet

View File

@ -31,7 +31,7 @@ class AppTest(APITestCase):
self.assertEqual(response.status_code, 200)
class WebhookTest(APIViewTestCases.APIViewTestCase):
class WebhookTest(APIViewTestCases.GraphQLTestCase, APIViewTestCases.APIViewTestCase):
model = Webhook
brief_fields = ['display', 'id', 'name', 'url']
create_data = [
@ -85,7 +85,7 @@ class WebhookTest(APIViewTestCases.APIViewTestCase):
webhook.content_types.add(site_ct, rack_ct)
class CustomFieldTest(APIViewTestCases.APIViewTestCase):
class CustomFieldTest(APIViewTestCases.GraphQLTestCase, APIViewTestCases.APIViewTestCase):
model = CustomField
brief_fields = ['display', 'id', 'name', 'url']
create_data = [
@ -132,7 +132,7 @@ class CustomFieldTest(APIViewTestCases.APIViewTestCase):
cf.content_types.add(site_ct)
class CustomLinkTest(APIViewTestCases.APIViewTestCase):
class CustomLinkTest(APIViewTestCases.GraphQLTestCase, APIViewTestCases.APIViewTestCase):
model = CustomLink
brief_fields = ['display', 'id', 'name', 'url']
create_data = [
@ -186,7 +186,7 @@ class CustomLinkTest(APIViewTestCases.APIViewTestCase):
CustomLink.objects.bulk_create(custom_links)
class ExportTemplateTest(APIViewTestCases.APIViewTestCase):
class ExportTemplateTest(APIViewTestCases.GraphQLTestCase, APIViewTestCases.APIViewTestCase):
model = ExportTemplate
brief_fields = ['display', 'id', 'name', 'url']
create_data = [
@ -234,7 +234,7 @@ class ExportTemplateTest(APIViewTestCases.APIViewTestCase):
ExportTemplate.objects.bulk_create(export_templates)
class TagTest(APIViewTestCases.APIViewTestCase):
class TagTest(APIViewTestCases.GraphQLTestCase, APIViewTestCases.APIViewTestCase):
model = Tag
brief_fields = ['color', 'display', 'id', 'name', 'slug', 'url']
create_data = [
@ -270,7 +270,8 @@ class TagTest(APIViewTestCases.APIViewTestCase):
class ImageAttachmentTest(
APIViewTestCases.GetObjectViewTestCase,
APIViewTestCases.ListObjectsViewTestCase,
APIViewTestCases.DeleteObjectViewTestCase
APIViewTestCases.DeleteObjectViewTestCase,
APIViewTestCases.GraphQLTestCase
):
model = ImageAttachment
brief_fields = ['display', 'id', 'image', 'name', 'url']
@ -310,7 +311,7 @@ class ImageAttachmentTest(
ImageAttachment.objects.bulk_create(image_attachments)
class JournalEntryTest(APIViewTestCases.APIViewTestCase):
class JournalEntryTest(APIViewTestCases.GraphQLTestCase, APIViewTestCases.APIViewTestCase):
model = JournalEntry
brief_fields = ['created', 'display', 'id', 'url']
bulk_update_data = {
@ -360,7 +361,7 @@ class JournalEntryTest(APIViewTestCases.APIViewTestCase):
]
class ConfigContextTest(APIViewTestCases.APIViewTestCase):
class ConfigContextTest(APIViewTestCases.GraphQLTestCase, APIViewTestCases.APIViewTestCase):
model = ConfigContext
brief_fields = ['display', 'id', 'name', 'url']
create_data = [

View File

@ -1,11 +1,13 @@
import graphene
from circuits.graphql.schema import CircuitsQuery
from extras.graphql.schema import ExtrasQuery
from ipam.graphql.schema import IPAMQuery
class Query(
CircuitsQuery,
ExtrasQuery,
IPAMQuery,
graphene.ObjectType
):

View File

@ -26,13 +26,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):