mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
* Fix typos in migration-v4.md * Replace typing.List with list typing.List is deprecated since Python 3.9 * Also replace typing.List with list in graphql-api.md
This commit is contained in:
@ -8,7 +8,6 @@ A plugin can extend NetBox's GraphQL API by registering its own schema class. By
|
|||||||
|
|
||||||
```python
|
```python
|
||||||
# graphql.py
|
# graphql.py
|
||||||
from typing import List
|
|
||||||
import strawberry
|
import strawberry
|
||||||
import strawberry_django
|
import strawberry_django
|
||||||
|
|
||||||
@ -28,7 +27,7 @@ class MyQuery:
|
|||||||
@strawberry.field
|
@strawberry.field
|
||||||
def dummymodel(self, id: int) -> DummyModelType:
|
def dummymodel(self, id: int) -> DummyModelType:
|
||||||
return None
|
return None
|
||||||
dummymodel_list: List[DummyModelType] = strawberry_django.field()
|
dummymodel_list: list[DummyModelType] = strawberry_django.field()
|
||||||
|
|
||||||
|
|
||||||
schema = [
|
schema = [
|
||||||
|
@ -85,7 +85,7 @@ from django import forms
|
|||||||
class MyForm(forms.Form):
|
class MyForm(forms.Form):
|
||||||
```
|
```
|
||||||
|
|
||||||
### Update Fieldset Definitions
|
### Update Fieldset definitions
|
||||||
|
|
||||||
NetBox v4.0 introduces [several new classes](./forms.md#form-rendering) for advanced form rendering, including FieldSet. Fieldset definitions on forms should use this new class instead of a tuple or list.
|
NetBox v4.0 introduces [several new classes](./forms.md#form-rendering) for advanced form rendering, including FieldSet. Fieldset definitions on forms should use this new class instead of a tuple or list.
|
||||||
|
|
||||||
@ -252,7 +252,7 @@ class SiteSerializer(NetBoxModelSerializer):
|
|||||||
|
|
||||||
### Include description fields in brief mode
|
### Include description fields in brief mode
|
||||||
|
|
||||||
NetBox now includes the `description` the field in "brief" mode for all models which have one. This is not required for plugins, but you may opt to do the same for consistency.
|
NetBox now includes the `description` field in "brief" mode for all models which have one. This is not required for plugins, but you may opt to do the same for consistency.
|
||||||
|
|
||||||
## GraphQL
|
## GraphQL
|
||||||
|
|
||||||
@ -260,7 +260,7 @@ NetBox has replaced [Graphene-Django](https://github.com/graphql-python/graphene
|
|||||||
|
|
||||||
### Change schema.py
|
### Change schema.py
|
||||||
|
|
||||||
Strawberry uses [python typing](https://docs.python.org/3/library/typing.html) and generally only requires a small refactoring of the schema definition to update:
|
Strawberry uses [Python typing](https://docs.python.org/3/library/typing.html) and generally only requires a small refactoring of the schema definition to update:
|
||||||
|
|
||||||
```python title="Old"
|
```python title="Old"
|
||||||
import graphene
|
import graphene
|
||||||
@ -276,8 +276,6 @@ class CircuitsQuery(graphene.ObjectType):
|
|||||||
```
|
```
|
||||||
|
|
||||||
```python title="New"
|
```python title="New"
|
||||||
from typing import List
|
|
||||||
|
|
||||||
import strawberry
|
import strawberry
|
||||||
import strawberry_django
|
import strawberry_django
|
||||||
|
|
||||||
@ -286,7 +284,7 @@ class CircuitsQuery:
|
|||||||
@strawberry.field
|
@strawberry.field
|
||||||
def circuit(self, id: int) -> CircuitType:
|
def circuit(self, id: int) -> CircuitType:
|
||||||
return models.Circuit.objects.get(pk=id)
|
return models.Circuit.objects.get(pk=id)
|
||||||
circuit_list: List[CircuitType] = strawberry_django.field()
|
circuit_list: list[CircuitType] = strawberry_django.field()
|
||||||
```
|
```
|
||||||
|
|
||||||
### Change types.py
|
### Change types.py
|
||||||
@ -307,7 +305,7 @@ class CircuitType(NetBoxObjectType, ContactsMixin):
|
|||||||
```
|
```
|
||||||
|
|
||||||
```python title="New"
|
```python title="New"
|
||||||
from typing import Annotated, List
|
from typing import Annotated
|
||||||
|
|
||||||
import strawberry
|
import strawberry
|
||||||
import strawberry_django
|
import strawberry_django
|
||||||
@ -321,7 +319,7 @@ class CircuitTypeType(OrganizationalObjectType):
|
|||||||
color: str
|
color: str
|
||||||
|
|
||||||
@strawberry_django.field
|
@strawberry_django.field
|
||||||
def circuits(self) -> List[Annotated["CircuitType", strawberry.lazy('circuits.graphql.types')]]:
|
def circuits(self) -> list[Annotated["CircuitType", strawberry.lazy('circuits.graphql.types')]]:
|
||||||
return self.circuits.all()
|
return self.circuits.all()
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user