From ed1e1ae93938d33bca74f996f04e4def111d29f0 Mon Sep 17 00:00:00 2001 From: Arthur Date: Wed, 7 Feb 2024 09:03:22 -0800 Subject: [PATCH] 9856 extras schema --- netbox/extras/graphql/schema.py | 93 ++++++++++----------------------- netbox/extras/graphql/types.py | 3 +- netbox/netbox/graphql/schema.py | 3 +- 3 files changed, 33 insertions(+), 66 deletions(-) diff --git a/netbox/extras/graphql/schema.py b/netbox/extras/graphql/schema.py index 09e399e37..14069021b 100644 --- a/netbox/extras/graphql/schema.py +++ b/netbox/extras/graphql/schema.py @@ -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() diff --git a/netbox/extras/graphql/types.py b/netbox/extras/graphql/types.py index 5e69afa9d..e89802b85 100644 --- a/netbox/extras/graphql/types.py +++ b/netbox/extras/graphql/types.py @@ -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): diff --git a/netbox/netbox/graphql/schema.py b/netbox/netbox/graphql/schema.py index 43f1a5eb0..9ccc0b8a7 100644 --- a/netbox/netbox/graphql/schema.py +++ b/netbox/netbox/graphql/schema.py @@ -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,