2022-01-27 14:18:25 -05:00
# 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
``` python
# graphql.py
import graphene
2022-03-11 15:47:52 -05:00
from netbox . graphql . types import NetBoxObjectType
2022-01-27 14:18:25 -05:00
from netbox . graphql . fields import ObjectField , ObjectListField
from . import filtersets , models
2022-03-11 15:47:52 -05:00
class MyModelType ( NetBoxObjectType ) :
2022-01-27 14:18:25 -05:00
class Meta :
model = models . MyModel
fields = ' __all__ '
filterset_class = filtersets . MyModelFilterSet
class MyQuery ( graphene . ObjectType ) :
mymodel = ObjectField ( MyModelType )
mymodel_list = ObjectListField ( MyModelType )
schema = MyQuery
```
2022-02-04 15:07:35 -05:00
## GraphQL Objects
NetBox provides two object type classes for use by plugins.
::: netbox.graphql.types.BaseObjectType
2022-10-12 05:36:02 -07:00
options:
2022-02-04 15:07:35 -05:00
members: false
::: netbox.graphql.types.NetBoxObjectType
2022-10-12 05:36:02 -07:00
options:
2022-02-04 15:07:35 -05:00
members: false
2022-01-27 14:18:25 -05:00
## GraphQL Fields
2022-02-04 15:07:35 -05:00
NetBox provides two field classes for use by plugins.
2022-01-27 14:18:25 -05:00
::: netbox.graphql.fields.ObjectField
2022-10-12 05:36:02 -07:00
options:
2022-01-27 14:18:25 -05:00
members: false
::: netbox.graphql.fields.ObjectListField
2022-10-12 05:36:02 -07:00
options:
2022-01-27 14:18:25 -05:00
members: false