diff --git a/docs/plugins/development/graphql.md b/docs/plugins/development/graphql.md index 372498516..411b16936 100644 --- a/docs/plugins/development/graphql.md +++ b/docs/plugins/development/graphql.md @@ -26,8 +26,26 @@ class MyQuery(graphene.ObjectType): schema = MyQuery ``` +## GraphQL Objects + +NetBox provides two object type classes for use by plugins. + +::: netbox.graphql.types.BaseObjectType + selection: + members: false + rendering: + show_source: false + +::: netbox.graphql.types.NetBoxObjectType + selection: + members: false + rendering: + show_source: false + ## GraphQL Fields +NetBox provides two field classes for use by plugins. + ::: netbox.graphql.fields.ObjectField selection: members: false diff --git a/netbox/circuits/graphql/types.py b/netbox/circuits/graphql/types.py index a6c28c4cd..027b53203 100644 --- a/netbox/circuits/graphql/types.py +++ b/netbox/circuits/graphql/types.py @@ -1,5 +1,5 @@ from circuits import filtersets, models -from netbox.graphql.types import ObjectType, OrganizationalObjectType, PrimaryObjectType +from netbox.graphql.types import ObjectType, OrganizationalObjectType, NetBoxObjectType __all__ = ( 'CircuitTerminationType', @@ -18,7 +18,7 @@ class CircuitTerminationType(ObjectType): filterset_class = filtersets.CircuitTerminationFilterSet -class CircuitType(PrimaryObjectType): +class CircuitType(NetBoxObjectType): class Meta: model = models.Circuit @@ -34,7 +34,7 @@ class CircuitTypeType(OrganizationalObjectType): filterset_class = filtersets.CircuitTypeFilterSet -class ProviderType(PrimaryObjectType): +class ProviderType(NetBoxObjectType): class Meta: model = models.Provider @@ -42,7 +42,7 @@ class ProviderType(PrimaryObjectType): filterset_class = filtersets.ProviderFilterSet -class ProviderNetworkType(PrimaryObjectType): +class ProviderNetworkType(NetBoxObjectType): class Meta: model = models.ProviderNetwork diff --git a/netbox/dcim/graphql/types.py b/netbox/dcim/graphql/types.py index a47ca40ca..d25a6bba6 100644 --- a/netbox/dcim/graphql/types.py +++ b/netbox/dcim/graphql/types.py @@ -6,7 +6,7 @@ from extras.graphql.mixins import ( ) from ipam.graphql.mixins import IPAddressesMixin, VLANGroupsMixin from netbox.graphql.scalars import BigInt -from netbox.graphql.types import BaseObjectType, OrganizationalObjectType, PrimaryObjectType +from netbox.graphql.types import BaseObjectType, OrganizationalObjectType, NetBoxObjectType __all__ = ( 'CableType', @@ -85,7 +85,7 @@ class ComponentTemplateObjectType( # Model types # -class CableType(PrimaryObjectType): +class CableType(NetBoxObjectType): class Meta: model = models.Cable @@ -143,7 +143,7 @@ class ConsoleServerPortTemplateType(ComponentTemplateObjectType): return self.type or None -class DeviceType(ConfigContextMixin, ImageAttachmentsMixin, PrimaryObjectType): +class DeviceType(ConfigContextMixin, ImageAttachmentsMixin, NetBoxObjectType): class Meta: model = models.Device @@ -189,7 +189,7 @@ class DeviceRoleType(OrganizationalObjectType): filterset_class = filtersets.DeviceRoleFilterSet -class DeviceTypeType(PrimaryObjectType): +class DeviceTypeType(NetBoxObjectType): class Meta: model = models.DeviceType @@ -300,7 +300,7 @@ class ModuleBayTemplateType(ComponentTemplateObjectType): filterset_class = filtersets.ModuleBayTemplateFilterSet -class ModuleTypeType(PrimaryObjectType): +class ModuleTypeType(NetBoxObjectType): class Meta: model = models.ModuleType @@ -316,7 +316,7 @@ class PlatformType(OrganizationalObjectType): filterset_class = filtersets.PlatformFilterSet -class PowerFeedType(PrimaryObjectType): +class PowerFeedType(NetBoxObjectType): class Meta: model = models.PowerFeed @@ -352,7 +352,7 @@ class PowerOutletTemplateType(ComponentTemplateObjectType): return self.type or None -class PowerPanelType(PrimaryObjectType): +class PowerPanelType(NetBoxObjectType): class Meta: model = models.PowerPanel @@ -382,7 +382,7 @@ class PowerPortTemplateType(ComponentTemplateObjectType): return self.type or None -class RackType(VLANGroupsMixin, ImageAttachmentsMixin, PrimaryObjectType): +class RackType(VLANGroupsMixin, ImageAttachmentsMixin, NetBoxObjectType): class Meta: model = models.Rack @@ -396,7 +396,7 @@ class RackType(VLANGroupsMixin, ImageAttachmentsMixin, PrimaryObjectType): return self.outer_unit or None -class RackReservationType(PrimaryObjectType): +class RackReservationType(NetBoxObjectType): class Meta: model = models.RackReservation @@ -436,7 +436,7 @@ class RegionType(VLANGroupsMixin, OrganizationalObjectType): filterset_class = filtersets.RegionFilterSet -class SiteType(VLANGroupsMixin, ImageAttachmentsMixin, PrimaryObjectType): +class SiteType(VLANGroupsMixin, ImageAttachmentsMixin, NetBoxObjectType): asn = graphene.Field(BigInt) class Meta: @@ -453,7 +453,7 @@ class SiteGroupType(VLANGroupsMixin, OrganizationalObjectType): filterset_class = filtersets.SiteGroupFilterSet -class VirtualChassisType(PrimaryObjectType): +class VirtualChassisType(NetBoxObjectType): class Meta: model = models.VirtualChassis diff --git a/netbox/ipam/graphql/types.py b/netbox/ipam/graphql/types.py index 8dd122a0c..ca206b4b8 100644 --- a/netbox/ipam/graphql/types.py +++ b/netbox/ipam/graphql/types.py @@ -2,7 +2,7 @@ import graphene from ipam import filtersets, models from netbox.graphql.scalars import BigInt -from netbox.graphql.types import BaseObjectType, OrganizationalObjectType, PrimaryObjectType +from netbox.graphql.types import BaseObjectType, OrganizationalObjectType, NetBoxObjectType __all__ = ( 'ASNType', @@ -23,7 +23,7 @@ __all__ = ( ) -class ASNType(PrimaryObjectType): +class ASNType(NetBoxObjectType): asn = graphene.Field(BigInt) class Meta: @@ -32,7 +32,7 @@ class ASNType(PrimaryObjectType): filterset_class = filtersets.ASNFilterSet -class AggregateType(PrimaryObjectType): +class AggregateType(NetBoxObjectType): class Meta: model = models.Aggregate @@ -40,7 +40,7 @@ class AggregateType(PrimaryObjectType): filterset_class = filtersets.AggregateFilterSet -class FHRPGroupType(PrimaryObjectType): +class FHRPGroupType(NetBoxObjectType): class Meta: model = models.FHRPGroup @@ -59,7 +59,7 @@ class FHRPGroupAssignmentType(BaseObjectType): filterset_class = filtersets.FHRPGroupAssignmentFilterSet -class IPAddressType(PrimaryObjectType): +class IPAddressType(NetBoxObjectType): class Meta: model = models.IPAddress @@ -70,7 +70,7 @@ class IPAddressType(PrimaryObjectType): return self.role or None -class IPRangeType(PrimaryObjectType): +class IPRangeType(NetBoxObjectType): class Meta: model = models.IPRange @@ -81,7 +81,7 @@ class IPRangeType(PrimaryObjectType): return self.role or None -class PrefixType(PrimaryObjectType): +class PrefixType(NetBoxObjectType): class Meta: model = models.Prefix @@ -105,7 +105,7 @@ class RoleType(OrganizationalObjectType): filterset_class = filtersets.RoleFilterSet -class RouteTargetType(PrimaryObjectType): +class RouteTargetType(NetBoxObjectType): class Meta: model = models.RouteTarget @@ -113,7 +113,7 @@ class RouteTargetType(PrimaryObjectType): filterset_class = filtersets.RouteTargetFilterSet -class ServiceType(PrimaryObjectType): +class ServiceType(NetBoxObjectType): class Meta: model = models.Service @@ -121,7 +121,7 @@ class ServiceType(PrimaryObjectType): filterset_class = filtersets.ServiceFilterSet -class ServiceTemplateType(PrimaryObjectType): +class ServiceTemplateType(NetBoxObjectType): class Meta: model = models.ServiceTemplate @@ -129,7 +129,7 @@ class ServiceTemplateType(PrimaryObjectType): filterset_class = filtersets.ServiceTemplateFilterSet -class VLANType(PrimaryObjectType): +class VLANType(NetBoxObjectType): class Meta: model = models.VLAN @@ -145,7 +145,7 @@ class VLANGroupType(OrganizationalObjectType): filterset_class = filtersets.VLANGroupFilterSet -class VRFType(PrimaryObjectType): +class VRFType(NetBoxObjectType): class Meta: model = models.VRF diff --git a/netbox/netbox/graphql/types.py b/netbox/netbox/graphql/types.py index 7d71bd1fb..7d1b26f84 100644 --- a/netbox/netbox/graphql/types.py +++ b/netbox/netbox/graphql/types.py @@ -5,8 +5,9 @@ from extras.graphql.mixins import ChangelogMixin, CustomFieldsMixin, JournalEntr __all__ = ( 'BaseObjectType', + 'ObjectType', 'OrganizationalObjectType', - 'PrimaryObjectType', + 'NetBoxObjectType', ) @@ -16,7 +17,7 @@ __all__ = ( class BaseObjectType(DjangoObjectType): """ - Base GraphQL object type for all NetBox objects + Base GraphQL object type for all NetBox objects. Restricts the model queryset to enforce object permissions. """ class Meta: abstract = True @@ -51,7 +52,7 @@ class OrganizationalObjectType( abstract = True -class PrimaryObjectType( +class NetBoxObjectType( ChangelogMixin, CustomFieldsMixin, JournalEntriesMixin, @@ -59,7 +60,7 @@ class PrimaryObjectType( BaseObjectType ): """ - Base type for primary models + GraphQL type for most NetBox models. Includes support for custom fields, change logging, journaling, and tags. """ class Meta: abstract = True diff --git a/netbox/tenancy/graphql/types.py b/netbox/tenancy/graphql/types.py index ce00eafa3..e0b99c2eb 100644 --- a/netbox/tenancy/graphql/types.py +++ b/netbox/tenancy/graphql/types.py @@ -1,7 +1,7 @@ import graphene from tenancy import filtersets, models -from netbox.graphql.types import BaseObjectType, OrganizationalObjectType, PrimaryObjectType +from netbox.graphql.types import BaseObjectType, OrganizationalObjectType, NetBoxObjectType __all__ = ( 'ContactAssignmentType', @@ -24,7 +24,7 @@ class ContactAssignmentsMixin: # Tenants # -class TenantType(PrimaryObjectType): +class TenantType(NetBoxObjectType): class Meta: model = models.Tenant @@ -44,7 +44,7 @@ class TenantGroupType(OrganizationalObjectType): # Contacts # -class ContactType(ContactAssignmentsMixin, PrimaryObjectType): +class ContactType(ContactAssignmentsMixin, NetBoxObjectType): class Meta: model = models.Contact diff --git a/netbox/virtualization/graphql/types.py b/netbox/virtualization/graphql/types.py index c21b6f9a1..96b0fc875 100644 --- a/netbox/virtualization/graphql/types.py +++ b/netbox/virtualization/graphql/types.py @@ -1,7 +1,7 @@ from dcim.graphql.types import ComponentObjectType from extras.graphql.mixins import ConfigContextMixin from ipam.graphql.mixins import IPAddressesMixin, VLANGroupsMixin -from netbox.graphql.types import OrganizationalObjectType, PrimaryObjectType +from netbox.graphql.types import OrganizationalObjectType, NetBoxObjectType from virtualization import filtersets, models __all__ = ( @@ -13,7 +13,7 @@ __all__ = ( ) -class ClusterType(VLANGroupsMixin, PrimaryObjectType): +class ClusterType(VLANGroupsMixin, NetBoxObjectType): class Meta: model = models.Cluster @@ -37,7 +37,7 @@ class ClusterTypeType(OrganizationalObjectType): filterset_class = filtersets.ClusterTypeFilterSet -class VirtualMachineType(ConfigContextMixin, PrimaryObjectType): +class VirtualMachineType(ConfigContextMixin, NetBoxObjectType): class Meta: model = models.VirtualMachine diff --git a/netbox/wireless/graphql/types.py b/netbox/wireless/graphql/types.py index c3235e72e..2fc477dfa 100644 --- a/netbox/wireless/graphql/types.py +++ b/netbox/wireless/graphql/types.py @@ -1,5 +1,5 @@ from wireless import filtersets, models -from netbox.graphql.types import OrganizationalObjectType, PrimaryObjectType +from netbox.graphql.types import OrganizationalObjectType, NetBoxObjectType __all__ = ( 'WirelessLANType', @@ -16,7 +16,7 @@ class WirelessLANGroupType(OrganizationalObjectType): filterset_class = filtersets.WirelessLANGroupFilterSet -class WirelessLANType(PrimaryObjectType): +class WirelessLANType(NetBoxObjectType): class Meta: model = models.WirelessLAN @@ -30,7 +30,7 @@ class WirelessLANType(PrimaryObjectType): return self.auth_cipher or None -class WirelessLinkType(PrimaryObjectType): +class WirelessLinkType(NetBoxObjectType): class Meta: model = models.WirelessLink