From 916722780cca2d1e0b07e61448fc7e57b78969f9 Mon Sep 17 00:00:00 2001 From: Arthur Date: Mon, 11 Mar 2024 08:50:56 -0700 Subject: [PATCH] 9856 fix docs --- docs/plugins/development/graphql-api.md | 35 +++++++++++++-------- netbox/netbox/tests/dummy_plugin/graphql.py | 1 - 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/docs/plugins/development/graphql-api.md b/docs/plugins/development/graphql-api.md index f802e8025..decbe485c 100644 --- a/docs/plugins/development/graphql-api.md +++ b/docs/plugins/development/graphql-api.md @@ -8,23 +8,32 @@ A plugin can extend NetBox's GraphQL API by registering its own schema class. By ```python # graphql.py -import graphene -from netbox.graphql.types import NetBoxObjectType -from netbox.graphql.fields import ObjectField, ObjectListField -from . import filtersets, models +from typing import List +import strawberry +import strawberry_django -class MyModelType(NetBoxObjectType): +from . import models - class Meta: - model = models.MyModel - fields = '__all__' - filterset_class = filtersets.MyModelFilterSet -class MyQuery(graphene.ObjectType): - mymodel = ObjectField(MyModelType) - mymodel_list = ObjectListField(MyModelType) +@strawberry_django.type( + models.MyModel, + 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 diff --git a/netbox/netbox/tests/dummy_plugin/graphql.py b/netbox/netbox/tests/dummy_plugin/graphql.py index a4e6a1fdc..2651f4e9e 100644 --- a/netbox/netbox/tests/dummy_plugin/graphql.py +++ b/netbox/netbox/tests/dummy_plugin/graphql.py @@ -1,7 +1,6 @@ from typing import List import strawberry import strawberry_django -from strawberry.schema.config import StrawberryConfig from . import models