Skip to content

Commit

Permalink
Merge pull request #34 from DanSheps/develop
Browse files Browse the repository at this point in the history
Add GraphQL support
  • Loading branch information
DanSheps authored Sep 16, 2024
2 parents dc6b952 + 4664e2a commit 7a12079
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 2 deletions.
5 changes: 3 additions & 2 deletions netbox_routing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

class NetboxRouting(PluginConfig):
name = plugin.get('Name').replace('-', '_')
verbose_name = plugin.get('Summary')
description = plugin.get('Description')
verbose_name = plugin.get('Name').replace('-', ' ').title()
description = plugin.get('Summary')
version = plugin.get('Version')
author = plugin.get('Author')
author_email = plugin.get('Author-email')
Expand All @@ -17,6 +17,7 @@ class NetboxRouting(PluginConfig):
required_settings = []
caching_config = {}
default_settings = {}
graphql_schema = 'graphql.schema.schema'


config = NetboxRouting
Empty file.
16 changes: 16 additions & 0 deletions netbox_routing/graphql/filters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import strawberry_django

from netbox_routing import filtersets, models

from netbox.graphql.filter_mixins import autotype_decorator, BaseFilterMixin

__all__ = (
'StaticRouteFilter',
)


@strawberry_django.filter(models.StaticRoute, lookups=True)
@autotype_decorator(filtersets.StaticRouteFilterSet)
class StaticRouteFilter(BaseFilterMixin):
prefix: str
next_hop: str
17 changes: 17 additions & 0 deletions netbox_routing/graphql/schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from typing import List

import strawberry
import strawberry_django

from .types import *


@strawberry.type(name="Query")
class StaticRouteQuery:
static_route: StaticRouteType = strawberry_django.field()
static_route_list: List[StaticRouteType] = strawberry_django.field()


schema = [
StaticRouteQuery,
]
30 changes: 30 additions & 0 deletions netbox_routing/graphql/types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from typing import Annotated, List

import strawberry
import strawberry_django

from netbox.graphql.types import NetBoxObjectType
from .filters import *

from netbox_routing import models

__all__ = (
'StaticRouteType',
)


@strawberry_django.type(
models.StaticRoute,
fields='__all__',
filters=StaticRouteFilter
)
class StaticRouteType(NetBoxObjectType):

name: str
devices: List[Annotated["DeviceType", strawberry.lazy('dcim.graphql.types')]] | None
vrf: Annotated["VRFType", strawberry.lazy('ipam.graphql.types')] | None
prefix: str | None
next_hop: str | None
metric: int | None
permanent: bool | None

0 comments on commit 7a12079

Please sign in to comment.