GraphQL API
Defining the Schema Class
A plugin can extend NetBox's GraphQL API by registering its own schema class. By default, NetBox will attempt to import graphql.schema from the plugin, if it exists. This path can be overridden by defining graphql_schema on the PluginConfig instance as the dotted path to the desired Python class. This class must be a subclass of graphene.ObjectType.
Example
# graphql.py
import graphene
from netbox.graphql.types import NetBoxObjectType
from netbox.graphql.fields import ObjectField, ObjectListField
from . import filtersets, models
class MyModelType(NetBoxObjectType):
class Meta:
model = models.MyModel
fields = '__all__'
filterset_class = filtersets.MyModelFilterSet
class MyQuery(graphene.ObjectType):
mymodel = ObjectField(MyModelType)
mymodel_list = ObjectListField(MyModelType)
schema = MyQueryGraphQL Objects
NetBox provides two object type classes for use by plugins.
BaseObjectType
Bases: DjangoObjectType
Base GraphQL object type for all NetBox objects. Restricts the model queryset to enforce object permissions.
NetBoxObjectType
Bases: ChangelogMixin, CustomFieldsMixin, JournalEntriesMixin, TagsMixin, BaseObjectType
GraphQL type for most NetBox models. Includes support for custom fields, change logging, journaling, and tags.
GraphQL Fields
NetBox provides two field classes for use by plugins.
ObjectField
Bases: Field
Retrieve a single object, identified by its numeric ID.
object_resolver(django_object_type, root, info, **args)
Return an object given its numeric ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
| django_object_type | Any | No description available | - |
| root | Any | No description available | - |
| info | Any | No description available | - |
ObjectListField
Bases: DjangoListField
Retrieve a list of objects, optionally filtered by one or more FilterSet filters.
REST API
Plugins can declare custom endpoints on NetBox's REST API to retrieve or manipulate models or other data. These behave very similarly to views, except that i...
Background Tasks
NetBox supports the queuing of tasks that need to be performed in the background, decoupled from the request-response cycle, using the Python RQ library. Thr...