Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use DjangoObject from Graphene lib. Remove GQL types for models that already use the decorator. #37

Merged
merged 2 commits into from Dec 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 13 additions & 2 deletions nautobot_device_lifecycle_mgmt/__init__.py
Expand Up @@ -7,11 +7,18 @@

__version__ = metadata.version(__name__)

from packaging import version

from django.conf import settings
from django.db.models.signals import post_migrate

from nautobot.extras.plugins import PluginConfig


current_nautobot_version = version.parse(settings.VERSION)
NAUTOBOT_GRAPHQL_FIX = version.parse("1.2.0b1")


class DeviceLifeCycleConfig(PluginConfig):
"""Plugin configuration for the Device Lifecycle Management plugin."""

Expand All @@ -30,14 +37,18 @@ class DeviceLifeCycleConfig(PluginConfig):

def ready(self):
"""Register custom signals."""
super().ready()
import nautobot_device_lifecycle_mgmt.signals # pylint: disable=C0415,W0611 # noqa: F401

from .signals import ( # pylint: disable=import-outside-toplevel
post_migrate_create_relationships,
)

# Workaround for https://github.com/nautobot/nautobot/issues/567 for Nautobot < 1.2.0b1
if current_nautobot_version < NAUTOBOT_GRAPHQL_FIX:
import nautobot.extras.graphql.types # pylint: disable=import-outside-toplevel, unused-import # noqa: F401

post_migrate.connect(post_migrate_create_relationships, sender=self)

super().ready()


config = DeviceLifeCycleConfig # pylint:disable=invalid-name
55 changes: 2 additions & 53 deletions nautobot_device_lifecycle_mgmt/graphql/types.py
@@ -1,63 +1,16 @@
"""GraphQL implementation for the Device LifeCycle Management plugin."""
import graphene

from nautobot.extras.graphql.types import DjangoObjectType
from graphene_django import DjangoObjectType

from nautobot_device_lifecycle_mgmt.models import (
HardwareLCM,
ContractLCM,
ProviderLCM,
ContactLCM,
ValidatedSoftwareLCM,
)
from nautobot_device_lifecycle_mgmt.filters import (
HardwareLCMFilterSet,
ContractLCMFilterSet,
ProviderLCMFilterSet,
ContactLCMFilterSet,
ValidatedSoftwareLCMFilterSet,
)


class HardwareLCMType(DjangoObjectType):
"""Graphql Type Object for the Device Lifecycle model."""

class Meta:
"""Metadata magic method for the HardwareLCMType."""

model = HardwareLCM
filterset_class = HardwareLCMFilterSet


class ContractLCMType(DjangoObjectType):
"""Graphql Type Object for the Device Lifecycle model."""

class Meta:
"""Metadata magic method for the ContractLCMType."""

model = ContractLCM
filterset_class = ContractLCMFilterSet


class ProviderLCMType(DjangoObjectType):
"""Graphql Type Object for the Device Lifecycle model."""

class Meta:
"""Metadata magic method for the ProviderLCMType."""

model = ProviderLCM
filterset_class = ProviderLCMFilterSet


class ContactLCMType(DjangoObjectType):
"""Graphql Type Object for the Device Lifecycle model."""

class Meta:
"""Metadata magic method for the ContactLCMType."""

model = ContactLCM
filterset_class = ContactLCMFilterSet


class ValidatedSoftwareLCMType(DjangoObjectType):
"""Graphql Type Object for the ValidatedSoftwareLCM model."""

Expand All @@ -71,9 +24,5 @@ class Meta:


graphql_types = [
HardwareLCMType,
ContractLCMType,
ProviderLCMType,
ContactLCMType,
ValidatedSoftwareLCMType,
]