Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
107 commits
Select commit Hold shift + click to select a range
3f2c21f
9856 base strawberry integration
arthanson Aug 22, 2023
eceac90
9856 user and group
arthanson Aug 24, 2023
700f015
9856 user and circuits base
arthanson Aug 24, 2023
46b0df4
9856 extras and mixins
arthanson Aug 25, 2023
36f57f8
9856 fk
arthanson Aug 25, 2023
34d9b78
9856 merge feature
arthanson Jan 3, 2024
dbe4097
Merge branch 'feature' into 9856-strawberry-2
arthanson Jan 3, 2024
de2d9ed
9856 update strawberry version
arthanson Jan 3, 2024
7a222a6
9856 update imports
arthanson Jan 4, 2024
28c48b3
9856 compatability fixes
arthanson Jan 9, 2024
2d4fbea
9856 compatability fixes
arthanson Jan 10, 2024
5e40ebd
9856 merge feature
arthanson Feb 6, 2024
663af64
9856 update strawberry types
arthanson Feb 6, 2024
fb4d63f
9856 update strawberry types
arthanson Feb 6, 2024
cdcaa90
9856 core schema
arthanson Feb 6, 2024
460b57d
9856 dcim schema
arthanson Feb 7, 2024
ed1e1ae
9856 extras schema
arthanson Feb 7, 2024
d3fc026
9856 ipam and tenant schema
arthanson Feb 7, 2024
48b0cdd
9856 virtualization, vpn, wireless schema
arthanson Feb 8, 2024
6d7678f
9856 fix old decorator
arthanson Feb 8, 2024
a171a02
Merge branch 'feature' into 9856-strawberry-2
arthanson Feb 12, 2024
7779e87
9856 cleanup
arthanson Feb 12, 2024
eca0966
9856 cleanup
arthanson Feb 12, 2024
99b0198
9856 fixes to circuits type specifiers
arthanson Feb 13, 2024
4fab68a
9856 fixes to circuits type specifiers
arthanson Feb 13, 2024
cc5703c
Merge branch 'feature' into 9856-strawberry-2
arthanson Feb 14, 2024
d37414d
9856 update types
arthanson Feb 15, 2024
1aa5b0d
9856 GFK working
arthanson Feb 15, 2024
c3cbefc
9856 GFK working
arthanson Feb 15, 2024
ff03abf
9856 _name
arthanson Feb 15, 2024
a0d0ab1
9856 misc fixes
arthanson Feb 16, 2024
3c24cf9
Merge branch 'feature' into 9856-strawberry-2
arthanson Feb 16, 2024
d4812b2
9856 type updates
arthanson Feb 23, 2024
a5445bb
9856 _name to types
arthanson Feb 23, 2024
69134db
9856 update types
arthanson Feb 23, 2024
6bb9d68
9856 update types
arthanson Feb 23, 2024
ce003b2
9856 update types
arthanson Feb 26, 2024
82c08d9
9856 update types
arthanson Feb 26, 2024
0387cb0
9856 update types
arthanson Feb 26, 2024
4d0d19b
9856 update types
arthanson Feb 26, 2024
3e284c5
9856 update types
arthanson Feb 26, 2024
44f4d60
9856 update types
arthanson Feb 26, 2024
497de46
9856 update types
arthanson Feb 26, 2024
13bf2c1
9856 merge feature
arthanson Mar 4, 2024
14f0445
9856 GraphQLView
arthanson Mar 5, 2024
f874801
9856 GraphQLView
arthanson Mar 6, 2024
0312ec3
Merge branch 'feature' into 9856-strawberry-2
arthanson Mar 6, 2024
7c289ae
9856 fix OrganizationalObjectType
arthanson Mar 6, 2024
2f71926
9856 single item query for schema
arthanson Mar 6, 2024
aa7c00e
9856 circuits graphql tests working
arthanson Mar 6, 2024
a5aad53
9856 test fixes
arthanson Mar 6, 2024
888d9ec
9856 test fixes
arthanson Mar 6, 2024
0ca46e3
9856 test fixes
arthanson Mar 6, 2024
1052ea5
9856 test fix vpn
arthanson Mar 6, 2024
5ff2c18
9856 test fixes
arthanson Mar 6, 2024
77eb101
9856 test fixes
arthanson Mar 6, 2024
7c66a6a
9856 test fixes
arthanson Mar 6, 2024
28ac66b
9856 circuits test sans DjangoModelType
arthanson Mar 6, 2024
4784829
9856 core test sans DjangoModelType
arthanson Mar 6, 2024
005a339
9856 temp checkin
arthanson Mar 7, 2024
12cca5d
9856 fix extas FK
arthanson Mar 7, 2024
4b56f0b
9856 fix tenancy FK
arthanson Mar 7, 2024
26c8ee3
9856 fix virtualization FK
arthanson Mar 7, 2024
38c7d76
9856 fix vpn FK
arthanson Mar 7, 2024
5f56e2d
9856 fix wireless FK
arthanson Mar 7, 2024
e53475a
9856 fix ipam FK
arthanson Mar 7, 2024
676764a
9856 fix partial dcim FK
arthanson Mar 7, 2024
a32f4b8
9856 fix dcim FK
arthanson Mar 7, 2024
133d6bf
9856 fix virtualization FK
arthanson Mar 7, 2024
7b6a603
9856 fix tests / remove debug code
arthanson Mar 7, 2024
7fa36ca
9856 fix test imagefield
arthanson Mar 7, 2024
ccc81e7
9856 cleanup graphene
arthanson Mar 11, 2024
f960d5a
9856 fix plugin schema
arthanson Mar 11, 2024
ba79078
9856 fix requirements
arthanson Mar 11, 2024
36e6f0d
9856 fix requirements
arthanson Mar 11, 2024
9167227
9856 fix docs
arthanson Mar 11, 2024
02fbea5
9856 fix docs
arthanson Mar 11, 2024
be2a814
9856 temp fix tests
arthanson Mar 11, 2024
a36cc0a
9856 first filterset
arthanson Mar 12, 2024
8aca8f8
9856 first filterset
arthanson Mar 12, 2024
c2a3275
9856 merge feature
arthanson Mar 12, 2024
d6fd0b8
9856 fix tests
arthanson Mar 12, 2024
960f340
9856 fix tests
arthanson Mar 12, 2024
fe3f2c8
9856 working auto filter generation
arthanson Mar 12, 2024
2c9bea9
9856 filter types
arthanson Mar 13, 2024
21b585e
9856 filter types
arthanson Mar 13, 2024
347e453
9856 filter types
arthanson Mar 13, 2024
634f35a
9856 fix graphiql test
arthanson Mar 13, 2024
2b7c1d1
Merge branch 'feature' into 9856-strawberry-2
arthanson Mar 13, 2024
1da5219
9856 fix counter fields and merge feature
arthanson Mar 13, 2024
1517175
9856 temp fix tests
arthanson Mar 13, 2024
b47c5ee
9856 fix tests
arthanson Mar 13, 2024
9c53f76
9856 fix tenancy, ipam filter definitions
arthanson Mar 13, 2024
da0c23b
9856 cleanup
arthanson Mar 13, 2024
6090d41
9856 cleanup
arthanson Mar 13, 2024
3b30aa9
9856 cleanup
arthanson Mar 13, 2024
9c29f45
Merge branch 'feature' into 9856-strawberry-2
jeremystretch Mar 18, 2024
b75b9e0
9856 review changes
arthanson Mar 19, 2024
908150f
9856 review changes
arthanson Mar 19, 2024
783c4f2
9856 review changes
arthanson Mar 19, 2024
371a2a2
9856 fix base-requirements
arthanson Mar 19, 2024
f456731
9856 add wrapper to graphiql
arthanson Mar 20, 2024
bbccb87
9856 remove old graphiql debug toolbar
arthanson Mar 20, 2024
be52246
Merge branch 'feature' into 9856-strawberry-2
arthanson Mar 22, 2024
d027a1c
9856 review changes
arthanson Mar 22, 2024
d40bf63
9856 update strawberry
arthanson Mar 22, 2024
55725ee
9856 remove superfluous check
arthanson Mar 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions base_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ django-debug-toolbar
# https://github.com/carltongibson/django-filter/blob/main/CHANGES.rst
django-filter

# Django debug toolbar extension with support for GraphiQL
# https://github.com/flavors/django-graphiql-debug-toolbar/blob/main/CHANGES.rst
django-graphiql-debug-toolbar

# HTMX utilities for Django
# https://django-htmx.readthedocs.io/en/latest/changelog.html
django-htmx
Expand Down Expand Up @@ -75,11 +71,6 @@ drf-spectacular-sidecar
# https://github.com/kurtmckee/feedparser/blob/develop/CHANGELOG.rst
feedparser

# Django wrapper for Graphene (GraphQL support)
# https://github.com/graphql-python/graphene-django/releases
# Pinned to v3.0.0 for GraphiQL UI issue (see #12762)
graphene_django==3.0.0

# WSGI HTTP server
# https://docs.gunicorn.org/en/latest/news.html
gunicorn
Expand Down Expand Up @@ -136,8 +127,16 @@ social-auth-core
# https://github.com/python-social-auth/social-app-django/blob/master/CHANGELOG.md
social-auth-app-django

# Strawberry GraphQL
# https://github.com/strawberry-graphql/strawberry/blob/main/CHANGELOG.md
strawberry-graphql

# Strawberry GraphQL Django extension
# https://github.com/strawberry-graphql/strawberry-django/blob/main/CHANGELOG.md
strawberry-graphql-django

# SVG image rendering (used for rack elevations)
# hhttps://github.com/mozman/svgwrite/blob/master/NEWS.rst
# https://github.com/mozman/svgwrite/blob/master/NEWS.rst
svgwrite

# Tabular dataset library (for table-based exports)
Expand Down
47 changes: 22 additions & 25 deletions docs/plugins/development/graphql-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,32 @@ A plugin can extend NetBox's GraphQL API by registering its own schema class. By

```python
# graphql.py
import graphene
from netbox.graphql.types import NetBoxObjectType
from netbox.graphql.fields import ObjectField, ObjectListField
from . import filtersets, models
from typing import List
import strawberry
import strawberry_django

class MyModelType(NetBoxObjectType):
from . import models

class Meta:
model = models.MyModel
fields = '__all__'
filterset_class = filtersets.MyModelFilterSet

class MyQuery(graphene.ObjectType):
mymodel = ObjectField(MyModelType)
mymodel_list = ObjectListField(MyModelType)
@strawberry_django.type(
models.MyModel,
fields='__all__',
)
class MyModelType:
pass

schema = MyQuery

@strawberry.type
class MyQuery:
@strawberry.field
def dummymodel(self, id: int) -> DummyModelType:
return None
dummymodel_list: List[DummyModelType] = strawberry_django.field()


schema = [
MyQuery,
]
```

## GraphQL Objects
Expand All @@ -38,15 +47,3 @@ NetBox provides two object type classes for use by plugins.
::: netbox.graphql.types.NetBoxObjectType
options:
members: false

## GraphQL Fields

NetBox provides two field classes for use by plugins.

::: netbox.graphql.fields.ObjectField
options:
members: false

::: netbox.graphql.fields.ObjectListField
options:
members: false
50 changes: 50 additions & 0 deletions netbox/circuits/graphql/filters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import strawberry
import strawberry_django
from circuits import filtersets, models

from netbox.graphql.filter_mixins import autotype_decorator, BaseFilterMixin

__all__ = (
'CircuitTerminationFilter',
'CircuitFilter',
'CircuitTypeFilter',
'ProviderFilter',
'ProviderAccountFilter',
'ProviderNetworkFilter',
)


@strawberry_django.filter(models.CircuitTermination, lookups=True)
@autotype_decorator(filtersets.CircuitTerminationFilterSet)
class CircuitTerminationFilter(BaseFilterMixin):
pass


@strawberry_django.filter(models.Circuit, lookups=True)
@autotype_decorator(filtersets.CircuitFilterSet)
class CircuitFilter(BaseFilterMixin):
pass


@strawberry_django.filter(models.CircuitType, lookups=True)
@autotype_decorator(filtersets.CircuitTypeFilterSet)
class CircuitTypeFilter(BaseFilterMixin):
pass


@strawberry_django.filter(models.Provider, lookups=True)
@autotype_decorator(filtersets.ProviderFilterSet)
class ProviderFilter(BaseFilterMixin):
pass


@strawberry_django.filter(models.ProviderAccount, lookups=True)
@autotype_decorator(filtersets.ProviderAccountFilterSet)
class ProviderAccountFilter(BaseFilterMixin):
pass


@strawberry_django.filter(models.ProviderNetwork, lookups=True)
@autotype_decorator(filtersets.ProviderNetworkFilterSet)
class ProviderNetworkFilter(BaseFilterMixin):
pass
71 changes: 35 additions & 36 deletions netbox/circuits/graphql/schema.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,40 @@
import graphene
from typing import List

import strawberry
import strawberry_django

from circuits import models
from netbox.graphql.fields import ObjectField, ObjectListField
from .types import *
from utilities.graphql_optimizer import gql_query_optimizer


class CircuitsQuery(graphene.ObjectType):
circuit = ObjectField(CircuitType)
circuit_list = ObjectListField(CircuitType)

def resolve_circuit_list(root, info, **kwargs):
return gql_query_optimizer(models.Circuit.objects.all(), info)

circuit_termination = ObjectField(CircuitTerminationType)
circuit_termination_list = ObjectListField(CircuitTerminationType)

def resolve_circuit_termination_list(root, info, **kwargs):
return gql_query_optimizer(models.CircuitTermination.objects.all(), info)

circuit_type = ObjectField(CircuitTypeType)
circuit_type_list = ObjectListField(CircuitTypeType)

def resolve_circuit_type_list(root, info, **kwargs):
return gql_query_optimizer(models.CircuitType.objects.all(), info)

provider = ObjectField(ProviderType)
provider_list = ObjectListField(ProviderType)

def resolve_provider_list(root, info, **kwargs):
return gql_query_optimizer(models.Provider.objects.all(), info)

provider_account = ObjectField(ProviderAccountType)
provider_account_list = ObjectListField(ProviderAccountType)

provider_network = ObjectField(ProviderNetworkType)
provider_network_list = ObjectListField(ProviderNetworkType)

def resolve_provider_network_list(root, info, **kwargs):
return gql_query_optimizer(models.ProviderNetwork.objects.all(), info)
@strawberry.type
class CircuitsQuery:
@strawberry.field
def circuit(self, id: int) -> CircuitType:
return models.Circuit.objects.get(pk=id)
circuit_list: List[CircuitType] = strawberry_django.field()

@strawberry.field
def circuit_termination(self, id: int) -> CircuitTerminationType:
return models.CircuitTermination.objects.get(pk=id)
circuit_termination_list: List[CircuitTerminationType] = strawberry_django.field()

@strawberry.field
def circuit_type(self, id: int) -> CircuitTypeType:
return models.CircuitType.objects.get(pk=id)
circuit_type_list: List[CircuitTypeType] = strawberry_django.field()

@strawberry.field
def provider(self, id: int) -> ProviderType:
return models.Provider.objects.get(pk=id)
provider_list: List[ProviderType] = strawberry_django.field()

@strawberry.field
def provider_account(self, id: int) -> ProviderAccountType:
return models.ProviderAccount.objects.get(pk=id)
provider_account_list: List[ProviderAccountType] = strawberry_django.field()

@strawberry.field
def provider_network(self, id: int) -> ProviderNetworkType:
return models.ProviderNetwork.objects.get(pk=id)
provider_network_list: List[ProviderNetworkType] = strawberry_django.field()
118 changes: 84 additions & 34 deletions netbox/circuits/graphql/types.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import graphene
from typing import Annotated, List

from circuits import filtersets, models
import strawberry
import strawberry_django

from circuits import models
from dcim.graphql.mixins import CabledObjectMixin
from extras.graphql.mixins import CustomFieldsMixin, TagsMixin, ContactsMixin
from netbox.graphql.types import ObjectType, OrganizationalObjectType, NetBoxObjectType
from extras.graphql.mixins import ContactsMixin, CustomFieldsMixin, TagsMixin
from netbox.graphql.types import NetBoxObjectType, ObjectType, OrganizationalObjectType
from tenancy.graphql.types import TenantType
from .filters import *

__all__ = (
'CircuitTerminationType',
Expand All @@ -15,48 +20,93 @@
)


class CircuitTerminationType(CustomFieldsMixin, TagsMixin, CabledObjectMixin, ObjectType):
@strawberry_django.type(
models.Provider,
fields='__all__',
filters=ProviderFilter
)
class ProviderType(NetBoxObjectType, ContactsMixin):

class Meta:
model = models.CircuitTermination
fields = '__all__'
filterset_class = filtersets.CircuitTerminationFilterSet
@strawberry_django.field
def networks(self) -> List[Annotated["ProviderNetworkType", strawberry.lazy('circuits.graphql.types')]]:
return self.networks.all()

@strawberry_django.field
def circuits(self) -> List[Annotated["CircuitType", strawberry.lazy('circuits.graphql.types')]]:
return self.circuits.all()

class CircuitType(NetBoxObjectType, ContactsMixin):
class Meta:
model = models.Circuit
fields = '__all__'
filterset_class = filtersets.CircuitFilterSet
@strawberry_django.field
def asns(self) -> List[Annotated["ASNType", strawberry.lazy('ipam.graphql.types')]]:
return self.asns.all()

@strawberry_django.field
def accounts(self) -> List[Annotated["ProviderAccountType", strawberry.lazy('circuits.graphql.types')]]:
return self.accounts.all()

class CircuitTypeType(OrganizationalObjectType):

class Meta:
model = models.CircuitType
fields = '__all__'
filterset_class = filtersets.CircuitTypeFilterSet
@strawberry_django.type(
models.ProviderAccount,
fields='__all__',
filters=ProviderAccountFilter
)
class ProviderAccountType(NetBoxObjectType):
provider: Annotated["ProviderType", strawberry.lazy('circuits.graphql.types')]

@strawberry_django.field
def circuits(self) -> List[Annotated["CircuitType", strawberry.lazy('circuits.graphql.types')]]:
return self.circuits.all()

class ProviderType(NetBoxObjectType, ContactsMixin):

class Meta:
model = models.Provider
fields = '__all__'
filterset_class = filtersets.ProviderFilterSet
@strawberry_django.type(
models.ProviderNetwork,
fields='__all__',
filters=ProviderNetworkFilter
)
class ProviderNetworkType(NetBoxObjectType):
provider: Annotated["ProviderType", strawberry.lazy('circuits.graphql.types')]

@strawberry_django.field
def circuit_terminations(self) -> List[Annotated["CircuitTerminationType", strawberry.lazy('circuits.graphql.types')]]:
return self.circuit_terminations.all()

class ProviderAccountType(NetBoxObjectType):

class Meta:
model = models.ProviderAccount
fields = '__all__'
filterset_class = filtersets.ProviderAccountFilterSet
@strawberry_django.type(
models.CircuitTermination,
fields='__all__',
filters=CircuitTerminationFilter
)
class CircuitTerminationType(CustomFieldsMixin, TagsMixin, CabledObjectMixin, ObjectType):
circuit: Annotated["CircuitType", strawberry.lazy('circuits.graphql.types')]
provider_network: Annotated["ProviderNetworkType", strawberry.lazy('circuits.graphql.types')] | None
site: Annotated["SiteType", strawberry.lazy('dcim.graphql.types')] | None


class ProviderNetworkType(NetBoxObjectType):
@strawberry_django.type(
models.CircuitType,
fields='__all__',
filters=CircuitTypeFilter
)
class CircuitTypeType(OrganizationalObjectType):
color: str

@strawberry_django.field
def circuits(self) -> List[Annotated["CircuitType", strawberry.lazy('circuits.graphql.types')]]:
return self.circuits.all()


class Meta:
model = models.ProviderNetwork
fields = '__all__'
filterset_class = filtersets.ProviderNetworkFilterSet
@strawberry_django.type(
models.Circuit,
fields='__all__',
filters=CircuitFilter
)
class CircuitType(NetBoxObjectType, ContactsMixin):
provider: ProviderType
provider_account: ProviderAccountType | None
termination_a: CircuitTerminationType | None
termination_z: CircuitTerminationType | None
type: CircuitTypeType
tenant: TenantType | None

@strawberry_django.field
def terminations(self) -> List[CircuitTerminationType]:
return self.terminations.all()
21 changes: 21 additions & 0 deletions netbox/core/graphql/filters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import strawberry_django

from core import filtersets, models
from netbox.graphql.filter_mixins import autotype_decorator, BaseFilterMixin

__all__ = (
'DataFileFilter',
'DataSourceFilter',
)


@strawberry_django.filter(models.DataFile, lookups=True)
@autotype_decorator(filtersets.DataFileFilterSet)
class DataFileFilter(BaseFilterMixin):
pass


@strawberry_django.filter(models.DataSource, lookups=True)
@autotype_decorator(filtersets.DataSourceFilterSet)
class DataSourceFilter(BaseFilterMixin):
pass
Loading