Skip to content

Commit

Permalink
#9856 cleanup circular imports
Browse files Browse the repository at this point in the history
  • Loading branch information
arthanson committed Sep 8, 2022
1 parent b11b6b8 commit 8fdfae0
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 120 deletions.
17 changes: 10 additions & 7 deletions netbox/circuits/graphql/schema.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
from .types import *
import typing

# schema.py
import strawberry
from typing import List

from .types import *


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

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

circuit_type: CircuitTypeType = strawberry.django.field()
circuit_type_list: List[CircuitTypeType] = strawberry.django.field()
circuit_type_list: typing.List[CircuitTypeType] = strawberry.django.field()

provider: ProviderType = strawberry.django.field()
provider_list: List[ProviderType] = strawberry.django.field()
provider_list: typing.List[ProviderType] = strawberry.django.field()

provider_network: ProviderNetworkType = strawberry.django.field()
provider_network_list: List[ProviderNetworkType] = strawberry.django.field()
provider_network_list: typing.List[ProviderNetworkType] = strawberry.django.field()
2 changes: 1 addition & 1 deletion netbox/circuits/graphql/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import strawberry
from circuits import filtersets, models
from dcim.graphql.mixins import CabledObjectMixin
from extras.graphql.mixins import CustomFieldsMixin, TagsMixin
from extras.graphql.types import CustomFieldsMixin, TagsMixin
from strawberry import auto

from netbox.graphql.types import NetBoxObjectType, ObjectType, OrganizationalObjectType
Expand Down
85 changes: 0 additions & 85 deletions netbox/extras/graphql/mixins.py

This file was deleted.

111 changes: 95 additions & 16 deletions netbox/extras/graphql/types.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import typing

import strawberry
from strawberry import auto
import strawberry_django
from extras import filtersets, models
from extras.graphql.mixins import CustomFieldsMixin, TagsMixin
from netbox.graphql.types import BaseObjectType, ObjectType

from netbox.graphql.base_types import BaseObjectType

__all__ = (
"ConfigContextType",
Expand All @@ -14,29 +16,112 @@
"ObjectChangeType",
"TagType",
"WebhookType",
"ChangelogMixin",
"ConfigContextMixin",
"CustomFieldsMixin",
"ImageAttachmentsMixin",
"JournalEntriesMixin",
"TagsMixin",
)


class ConfigContextMixin:

"""
config_context = GenericScalar()
"""

@strawberry_django.field
def config_context(self, info) -> typing.Dict:
return self.get_config_context()


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


@strawberry.django.type(models.ObjectChange)
class ObjectChangeType(BaseObjectType):
# filterset_class = filtersets.ObjectChangeFilterSet
pass


class ChangelogMixin:
"""
changelog = graphene.List('extras.graphql.types.ObjectChangeType')
"""

@strawberry_django.field
def changelog(self) -> typing.List[ObjectChangeType]:
content_type = ContentType.objects.get_for_model(self)
object_changes = ObjectChange.objects.filter(
changed_object_type=content_type, changed_object_id=self.pk
)
return object_changes.restrict(info.context.user, "view")


@strawberry.django.type(models.ConfigContext)
class ConfigContextType(ObjectType):
class ConfigContextType(ChangelogMixin, BaseObjectType):
# filterset_class = filtersets.ConfigContextFilterSet
pass


@strawberry.django.type(models.CustomField)
class CustomFieldType(ObjectType):
class CustomFieldType(ChangelogMixin, BaseObjectType):
# filterset_class = filtersets.CustomFieldFilterSet
pass


@strawberry.django.type(models.CustomLink)
class CustomLinkType(ObjectType):
class CustomLinkType(ChangelogMixin, BaseObjectType):
# filterset_class = filtersets.CustomLinkFilterSet
pass


@strawberry.django.type(models.ExportTemplate)
class ExportTemplateType(ObjectType):
class ExportTemplateType(ChangelogMixin, BaseObjectType):
# filterset_class = filtersets.ExportTemplateFilterSet
pass

Expand All @@ -48,24 +133,18 @@ class ImageAttachmentType(BaseObjectType):


@strawberry.django.type(models.JournalEntry)
class JournalEntryType(CustomFieldsMixin, TagsMixin, ObjectType):
class JournalEntryType(ChangelogMixin, CustomFieldsMixin, TagsMixin, BaseObjectType):
# filterset_class = filtersets.JournalEntryFilterSet
pass


@strawberry.django.type(models.ObjectChange)
class ObjectChangeType(BaseObjectType):
# filterset_class = filtersets.ObjectChangeFilterSet
pass


@strawberry.django.type(models.Tag)
class TagType(ObjectType):
class TagType(ChangelogMixin, BaseObjectType):
# filterset_class = filtersets.TagFilterSet
pass


@strawberry.django.type(models.Webhook)
class WebhookType(ObjectType):
class WebhookType(ChangelogMixin, BaseObjectType):
# filterset_class = filtersets.WebhookFilterSet
pass
16 changes: 16 additions & 0 deletions netbox/netbox/graphql/base_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import strawberry
from strawberry import auto

__all__ = ("BaseObjectType",)

#
# Base types
#


class BaseObjectType:
"""
Base GraphQL object type for all NetBox objects. Restricts the model queryset to enforce object permissions.
"""

id: auto
15 changes: 4 additions & 11 deletions netbox/netbox/graphql/types.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import strawberry
from strawberry import auto
from django.contrib.contenttypes.models import ContentType
from extras.graphql.mixins import (
from extras.graphql.types import (
ChangelogMixin,
CustomFieldsMixin,
JournalEntriesMixin,
TagsMixin,
)
from strawberry import auto

from netbox.graphql.base_types import BaseObjectType

__all__ = (
"BaseObjectType",
"ObjectType",
"OrganizationalObjectType",
"NetBoxObjectType",
Expand All @@ -20,14 +21,6 @@
#


class BaseObjectType:
"""
Base GraphQL object type for all NetBox objects. Restricts the model queryset to enforce object permissions.
"""

id: auto


class ObjectType(ChangelogMixin, BaseObjectType):
"""
Base GraphQL object type for unclassified models which support change logging
Expand Down

0 comments on commit 8fdfae0

Please sign in to comment.