9856 extras schema

This commit is contained in:
Arthur 2024-02-07 09:03:22 -08:00
parent 460b57dbf7
commit ed1e1ae939
3 changed files with 33 additions and 66 deletions

View File

@ -1,80 +1,45 @@
import graphene
from typing import List
import strawberry
import strawberry_django
from extras import models
from netbox.graphql.fields import ObjectField, ObjectListField
from .types import *
from utilities.graphql_optimizer import gql_query_optimizer
class ExtrasQuery(graphene.ObjectType):
config_context = ObjectField(ConfigContextType)
config_context_list = ObjectListField(ConfigContextType)
@strawberry.type
class ExtrasQuery:
config_context: ConfigContextType = strawberry_django.field()
config_context_list: List[ConfigContextType] = strawberry_django.field()
def resolve_config_context_list(root, info, **kwargs):
return gql_query_optimizer(models.ConfigContext.objects.all(), info)
config_template: ConfigTemplateType = strawberry_django.field()
config_template_list: List[ConfigTemplateType] = strawberry_django.field()
config_template = ObjectField(ConfigTemplateType)
config_template_list = ObjectListField(ConfigTemplateType)
custom_field: CustomFieldType = strawberry_django.field()
custom_field_list: List[CustomFieldType] = strawberry_django.field()
def resolve_config_template_list(root, info, **kwargs):
return gql_query_optimizer(models.ConfigTemplate.objects.all(), info)
custom_field_choice_set: CustomFieldChoiceSetType = strawberry_django.field()
custom_field_choice_set_list: List[CustomFieldChoiceSetType] = strawberry_django.field()
custom_field = ObjectField(CustomFieldType)
custom_field_list = ObjectListField(CustomFieldType)
custom_link: CustomLinkType = strawberry_django.field()
custom_link_list: List[CustomLinkType] = strawberry_django.field()
def resolve_custom_field_list(root, info, **kwargs):
return gql_query_optimizer(models.CustomField.objects.all(), info)
export_template: ExportTemplateType = strawberry_django.field()
export_template_list: List[ExportTemplateType] = strawberry_django.field()
custom_field_choice_set = ObjectField(CustomFieldChoiceSetType)
custom_field_choice_set_list = ObjectListField(CustomFieldChoiceSetType)
image_attachment: ImageAttachmentType = strawberry_django.field()
image_attachment_list: List[ImageAttachmentType] = strawberry_django.field()
def resolve_custom_field_choices_list(root, info, **kwargs):
return gql_query_optimizer(models.CustomFieldChoiceSet.objects.all(), info)
saved_filter: SavedFilterType = strawberry_django.field()
saved_filter_list: List[SavedFilterType] = strawberry_django.field()
custom_link = ObjectField(CustomLinkType)
custom_link_list = ObjectListField(CustomLinkType)
journal_entry: JournalEntryType = strawberry_django.field()
journal_entry_list: List[JournalEntryType] = strawberry_django.field()
def resolve_custom_link_list(root, info, **kwargs):
return gql_query_optimizer(models.CustomLink.objects.all(), info)
tag: TagType = strawberry_django.field()
tag_list: List[TagType] = strawberry_django.field()
export_template = ObjectField(ExportTemplateType)
export_template_list = ObjectListField(ExportTemplateType)
webhook: WebhookType = strawberry_django.field()
webhook_list: List[WebhookType] = strawberry_django.field()
def resolve_export_template_list(root, info, **kwargs):
return gql_query_optimizer(models.ExportTemplate.objects.all(), info)
image_attachment = ObjectField(ImageAttachmentType)
image_attachment_list = ObjectListField(ImageAttachmentType)
def resolve_image_attachment_list(root, info, **kwargs):
return gql_query_optimizer(models.ImageAttachment.objects.all(), info)
saved_filter = ObjectField(SavedFilterType)
saved_filter_list = ObjectListField(SavedFilterType)
def resolve_saved_filter_list(root, info, **kwargs):
return gql_query_optimizer(models.SavedFilter.objects.all(), info)
journal_entry = ObjectField(JournalEntryType)
journal_entry_list = ObjectListField(JournalEntryType)
def resolve_journal_entry_list(root, info, **kwargs):
return gql_query_optimizer(models.JournalEntry.objects.all(), info)
tag = ObjectField(TagType)
tag_list = ObjectListField(TagType)
def resolve_tag_list(root, info, **kwargs):
return gql_query_optimizer(models.Tag.objects.all(), info)
webhook = ObjectField(WebhookType)
webhook_list = ObjectListField(WebhookType)
def resolve_webhook_list(root, info, **kwargs):
return gql_query_optimizer(models.Webhook.objects.all(), info)
event_rule = ObjectField(EventRuleType)
event_rule_list = ObjectListField(EventRuleType)
def resolve_eventrule_list(root, info, **kwargs):
return gql_query_optimizer(models.EventRule.objects.all(), info)
event_rule: EventRuleType = strawberry_django.field()
event_rule_list: List[EventRuleType] = strawberry_django.field()

View File

@ -56,7 +56,8 @@ class CustomFieldType(ObjectType):
@strawberry_django.type(
models.CustomFieldChoiceSet,
fields='__all__',
# fields='__all__',
exclude=('extra_choices', ), # bug - temp
filters=CustomFieldChoiceSetFilter
)
class CustomFieldChoiceSetType(ObjectType):

View File

@ -4,6 +4,7 @@ from strawberry.schema.config import StrawberryConfig
from circuits.graphql.schema import CircuitsQuery
from core.graphql.schema import CoreQuery
from dcim.graphql.schema import DCIMQuery
from extras.graphql.schema import ExtrasQuery
from users.graphql.schema import UsersQuery
# from virtualization.graphql.schema import VirtualizationQuery
# from vpn.graphql.schema import VPNQuery
@ -16,7 +17,7 @@ class Query(
CircuitsQuery,
CoreQuery,
DCIMQuery,
# ExtrasQuery,
ExtrasQuery,
# IPAMQuery,
# TenancyQuery,
# VirtualizationQuery,