在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):strawberry-graphql/strawberry-graphql-django开源软件地址(OpenSource Url):https://github.com/strawberry-graphql/strawberry-graphql-django开源编程语言(OpenSource Language):Python 100.0%开源软件介绍(OpenSource Introduction):Strawberry GraphQL Django extensionThis package provides powerful tools to generate GraphQL types, queries, mutations and resolvers from Django models. Installing pip install strawberry-graphql-django Full documentation is available under docs github folder. Supported features
Basic Usage# models.py
from django.db import models
class Fruit(models.Model):
name = models.CharField(max_length=20)
color = models.ForeignKey('Color', blank=True, null=True,
related_name='fruits', on_delete=models.CASCADE)
class Color(models.Model):
name = models.CharField(max_length=20) # types.py
import strawberry
from strawberry import auto
from typing import List
from . import models
@strawberry.django.type(models.Fruit)
class Fruit:
id: auto
name: auto
color: 'Color'
@strawberry.django.type(models.Color)
class Color:
id: auto
name: auto
fruits: List[Fruit] # schema.py
import strawberry
from typing import List
from .types import Fruit
@strawberry.type
class Query:
fruits: List[Fruit] = strawberry.django.field()
schema = strawberry.Schema(query=Query) Code above generates following schema.
# urls.py
from django.urls import include, path
from strawberry.django.views import AsyncGraphQLView
from .schema import schema
urlpatterns = [
path('graphql', AsyncGraphQLView.as_view(schema=schema)),
] See complete Django project from github repository folder examples/django. Autocompletion with editorsSome editors like VSCode may not be able to resolve symbols and types without explicit import strawberry.django Running unit testspoetry install
poetry run pytest Pre commit hooksWe have a configuration for pre-commit, to add the hook run the following command: pre-commit install ContributingWe are happy to get pull requests and feedback from you. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论