-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8562 from netbox-community/8405-plugins-graphql
Closes #8405: GraphQL support for plugins
- Loading branch information
Showing
18 changed files
with
201 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# 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 | ||
from netbox.graphql.fields import ObjectField, ObjectListField | ||
from . import filtersets, models | ||
|
||
class MyModelType(graphene.ObjectType): | ||
|
||
class Meta: | ||
model = models.MyModel | ||
fields = '__all__' | ||
filterset_class = filtersets.MyModelFilterSet | ||
|
||
class MyQuery(graphene.ObjectType): | ||
mymodel = ObjectField(MyModelType) | ||
mymodel_list = ObjectListField(MyModelType) | ||
|
||
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 | ||
rendering: | ||
show_source: false | ||
|
||
::: netbox.graphql.fields.ObjectListField | ||
selection: | ||
members: false | ||
rendering: | ||
show_source: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import graphene | ||
from graphene_django import DjangoObjectType | ||
|
||
from netbox.graphql.fields import ObjectField, ObjectListField | ||
|
||
from . import models | ||
|
||
|
||
class DummyModelType(DjangoObjectType): | ||
|
||
class Meta: | ||
model = models.DummyModel | ||
fields = '__all__' | ||
|
||
|
||
class DummyQuery(graphene.ObjectType): | ||
dummymodel = ObjectField(DummyModelType) | ||
dummymodel_list = ObjectListField(DummyModelType) | ||
|
||
|
||
schema = DummyQuery |
Oops, something went wrong.