Skip to content

Commit

Permalink
Merge pull request #37 from nautobot/pr-graphql-fix
Browse files Browse the repository at this point in the history
Use DjangoObject from Graphene lib. Remove GQL types for models that already use the decorator.
  • Loading branch information
dgarros committed Dec 8, 2021
2 parents 36826fd + 5948226 commit 830c6ae
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 55 deletions.
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,
]

0 comments on commit 830c6ae

Please sign in to comment.