mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-24 17:38:37 -06:00
9856 fix docs
This commit is contained in:
parent
36e6f0d28e
commit
916722780c
@ -8,23 +8,32 @@ A plugin can extend NetBox's GraphQL API by registering its own schema class. By
|
|||||||
|
|
||||||
```python
|
```python
|
||||||
# graphql.py
|
# graphql.py
|
||||||
import graphene
|
from typing import List
|
||||||
from netbox.graphql.types import NetBoxObjectType
|
import strawberry
|
||||||
from netbox.graphql.fields import ObjectField, ObjectListField
|
import strawberry_django
|
||||||
from . import filtersets, models
|
|
||||||
|
|
||||||
class MyModelType(NetBoxObjectType):
|
from . import models
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = models.MyModel
|
|
||||||
fields = '__all__'
|
|
||||||
filterset_class = filtersets.MyModelFilterSet
|
|
||||||
|
|
||||||
class MyQuery(graphene.ObjectType):
|
@strawberry_django.type(
|
||||||
mymodel = ObjectField(MyModelType)
|
models.MyModel,
|
||||||
mymodel_list = ObjectListField(MyModelType)
|
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
|
## GraphQL Objects
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
from typing import List
|
from typing import List
|
||||||
import strawberry
|
import strawberry
|
||||||
import strawberry_django
|
import strawberry_django
|
||||||
from strawberry.schema.config import StrawberryConfig
|
|
||||||
|
|
||||||
from . import models
|
from . import models
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user