Skip to content

Commit

Permalink
#9856 base types
Browse files Browse the repository at this point in the history
  • Loading branch information
arthanson committed Sep 8, 2022
1 parent 8ffb278 commit b11b6b8
Show file tree
Hide file tree
Showing 6 changed files with 197 additions and 107 deletions.
26 changes: 10 additions & 16 deletions netbox/circuits/graphql/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,17 @@

@strawberry.type
class CircuitsQuery:
circuit_list: List[CircuitTerminationType] = strawberry.django.field()
circuit: CircuitType = strawberry.django.field()
circuit_list: List[CircuitType] = strawberry.django.field()

circuit_termination: CircuitTerminationType = strawberry.django.field()
circuit_termination_list: List[CircuitTerminationType] = strawberry.django.field()

"""
class CircuitsQuery(graphene.ObjectType):
circuit = ObjectField(CircuitType)
circuit_list = ObjectListField(CircuitType)
circuit_type: CircuitTypeType = strawberry.django.field()
circuit_type_list: List[CircuitTypeType] = strawberry.django.field()

circuit_termination = ObjectField(CircuitTerminationType)
circuit_termination_list = ObjectListField(CircuitTerminationType)
provider: ProviderType = strawberry.django.field()
provider_list: List[ProviderType] = strawberry.django.field()

circuit_type = ObjectField(CircuitTypeType)
circuit_type_list = ObjectListField(CircuitTypeType)
provider = ObjectField(ProviderType)
provider_list = ObjectListField(ProviderType)
provider_network = ObjectField(ProviderNetworkType)
provider_network_list = ObjectListField(ProviderNetworkType)
"""
provider_network: ProviderNetworkType = strawberry.django.field()
provider_network_list: List[ProviderNetworkType] = strawberry.django.field()
57 changes: 30 additions & 27 deletions netbox/circuits/graphql/types.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
from circuits import filtersets, models
from typing import List

import strawberry
from circuits import filtersets, models
from dcim.graphql.mixins import CabledObjectMixin
from extras.graphql.mixins import CustomFieldsMixin, TagsMixin
from strawberry import auto
from typing import List

__all__ = ("CircuitTerminationType",)
from netbox.graphql.types import NetBoxObjectType, ObjectType, OrganizationalObjectType

__all__ = (
"CircuitTerminationType",
"CircuitType",
"CircuitTypeType",
"ProviderType",
"ProviderNetworkType",
)


@strawberry.django.type(models.CircuitTermination)
class CircuitTerminationType:
id: auto
class CircuitTerminationType(
CustomFieldsMixin, TagsMixin, CabledObjectMixin, ObjectType
):
# filterset_class = filtersets.CircuitTerminationFilterSet
created: auto
last_updated: auto
# custom_field_data
Expand All @@ -29,35 +42,25 @@ class CircuitTerminationType:
# custom_fields:


"""
@strawberry.django.type(models.Circuit)
class CircuitType(NetBoxObjectType):
class Meta:
model = models.Circuit
fields = '__all__'
filterset_class = filtersets.CircuitFilterSet
# filterset_class = filtersets.CircuitFilterSet
pass


@strawberry.django.type(models.CircuitType)
class CircuitTypeType(OrganizationalObjectType):
class Meta:
model = models.CircuitType
fields = '__all__'
filterset_class = filtersets.CircuitTypeFilterSet
# filterset_class = filtersets.CircuitTypeFilterSet
pass


@strawberry.django.type(models.Provider)
class ProviderType(NetBoxObjectType):
class Meta:
model = models.Provider
fields = '__all__'
filterset_class = filtersets.ProviderFilterSet
# filterset_class = filtersets.ProviderFilterSet
pass


@strawberry.django.type(models.ProviderNetwork)
class ProviderNetworkType(NetBoxObjectType):
class Meta:
model = models.ProviderNetwork
fields = '__all__'
filterset_class = filtersets.ProviderNetworkFilterSet
"""
# filterset_class = filtersets.ProviderNetworkFilterSet
pass
40 changes: 32 additions & 8 deletions netbox/extras/graphql/mixins.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import graphene
import strawberry
from strawberry import auto
from django.contrib.contenttypes.models import ContentType
from graphene.types.generic import GenericScalar

from extras.models import ObjectChange

__all__ = (
'ChangelogMixin',
'ConfigContextMixin',
'CustomFieldsMixin',
'ImageAttachmentsMixin',
'JournalEntriesMixin',
'TagsMixin',
"ChangelogMixin",
"ConfigContextMixin",
"CustomFieldsMixin",
"ImageAttachmentsMixin",
"JournalEntriesMixin",
"TagsMixin",
)


class ChangelogMixin:
"""
changelog = graphene.List('extras.graphql.types.ObjectChangeType')
def resolve_changelog(self, info):
Expand All @@ -24,38 +25,61 @@ def resolve_changelog(self, info):
changed_object_id=self.pk
)
return object_changes.restrict(info.context.user, 'view')
"""

pass


class ConfigContextMixin:
"""
config_context = GenericScalar()
def resolve_config_context(self, info):
return self.get_config_context()
"""

pass


class CustomFieldsMixin:
"""
custom_fields = GenericScalar()
def resolve_custom_fields(self, info):
return self.custom_field_data
"""

pass


class ImageAttachmentsMixin:
"""
image_attachments = graphene.List('extras.graphql.types.ImageAttachmentType')
def resolve_image_attachments(self, info):
return self.images.restrict(info.context.user, 'view')
"""

pass


class JournalEntriesMixin:
"""
journal_entries = graphene.List('extras.graphql.types.JournalEntryType')
def resolve_journal_entries(self, info):
return self.journal_entries.restrict(info.context.user, 'view')
"""

pass


class TagsMixin:
"""
tags = graphene.List('extras.graphql.types.TagType')
def resolve_tags(self, info):
return self.tags.all()
"""

pass
92 changes: 38 additions & 54 deletions netbox/extras/graphql/types.py
Original file line number Diff line number Diff line change
@@ -1,87 +1,71 @@
import strawberry
from strawberry import auto
from extras import filtersets, models
from extras.graphql.mixins import CustomFieldsMixin, TagsMixin
from netbox.graphql.types import BaseObjectType, ObjectType

__all__ = (
'ConfigContextType',
'CustomFieldType',
'CustomLinkType',
'ExportTemplateType',
'ImageAttachmentType',
'JournalEntryType',
'ObjectChangeType',
'TagType',
'WebhookType',
"ConfigContextType",
"CustomFieldType",
"CustomLinkType",
"ExportTemplateType",
"ImageAttachmentType",
"JournalEntryType",
"ObjectChangeType",
"TagType",
"WebhookType",
)


@strawberry.django.type(models.ConfigContext)
class ConfigContextType(ObjectType):

class Meta:
model = models.ConfigContext
fields = '__all__'
filterset_class = filtersets.ConfigContextFilterSet
# filterset_class = filtersets.ConfigContextFilterSet
pass


@strawberry.django.type(models.CustomField)
class CustomFieldType(ObjectType):

class Meta:
model = models.CustomField
fields = '__all__'
filterset_class = filtersets.CustomFieldFilterSet
# filterset_class = filtersets.CustomFieldFilterSet
pass


@strawberry.django.type(models.CustomLink)
class CustomLinkType(ObjectType):

class Meta:
model = models.CustomLink
fields = '__all__'
filterset_class = filtersets.CustomLinkFilterSet
# filterset_class = filtersets.CustomLinkFilterSet
pass


@strawberry.django.type(models.ExportTemplate)
class ExportTemplateType(ObjectType):

class Meta:
model = models.ExportTemplate
fields = '__all__'
filterset_class = filtersets.ExportTemplateFilterSet
# filterset_class = filtersets.ExportTemplateFilterSet
pass


@strawberry.django.type(models.ImageAttachment)
class ImageAttachmentType(BaseObjectType):

class Meta:
model = models.ImageAttachment
fields = '__all__'
filterset_class = filtersets.ImageAttachmentFilterSet
# filterset_class = filtersets.ImageAttachmentFilterSet
pass


@strawberry.django.type(models.JournalEntry)
class JournalEntryType(CustomFieldsMixin, TagsMixin, ObjectType):

class Meta:
model = models.JournalEntry
fields = '__all__'
filterset_class = filtersets.JournalEntryFilterSet
# filterset_class = filtersets.JournalEntryFilterSet
pass


@strawberry.django.type(models.ObjectChange)
class ObjectChangeType(BaseObjectType):

class Meta:
model = models.ObjectChange
fields = '__all__'
filterset_class = filtersets.ObjectChangeFilterSet
# filterset_class = filtersets.ObjectChangeFilterSet
pass


@strawberry.django.type(models.Tag)
class TagType(ObjectType):

class Meta:
model = models.Tag
exclude = ('extras_taggeditem_items',)
filterset_class = filtersets.TagFilterSet
# filterset_class = filtersets.TagFilterSet
pass


@strawberry.django.type(models.Webhook)
class WebhookType(ObjectType):

class Meta:
model = models.Webhook
fields = '__all__'
filterset_class = filtersets.WebhookFilterSet
# filterset_class = filtersets.WebhookFilterSet
pass
22 changes: 20 additions & 2 deletions netbox/netbox/graphql/schema.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import strawberry
from typing import List

import strawberry
from circuits.graphql.schema import CircuitsQuery
# from dcim.graphql.schema import DCIMQuery
# from extras.graphql.schema import ExtrasQuery
# from extras.registry import registry
# from ipam.graphql.schema import IPAMQuery
# from tenancy.graphql.schema import TenancyQuery
# from users.graphql.schema import UsersQuery
# from virtualization.graphql.schema import VirtualizationQuery
# from wireless.graphql.schema import WirelessQuery


@strawberry.type
Expand All @@ -10,7 +19,16 @@ class User:


@strawberry.type
class Query(CircuitsQuery):
class Query(
CircuitsQuery,
# DCIMQuery,
# ExtrasQuery,
# IPAMQuery,
# TenancyQuery,
# UsersQuery,
# VirtualizationQuery,
# WirelessQuery,
):
pass


Expand Down
Loading

0 comments on commit b11b6b8

Please sign in to comment.