在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):strawberry-graphql/strawberry开源软件地址(OpenSource Url):https://github.com/strawberry-graphql/strawberry开源编程语言(OpenSource Language):Python 99.4%开源软件介绍(OpenSource Introduction):Strawberry GraphQL
Installation ( Quick Start )The quick start method provides a server and CLI to get going quickly. Install with: pip install 'strawberry-graphql[debug-server]' Getting StartedCreate a file called import strawberry
@strawberry.type
class User:
name: str
age: int
@strawberry.type
class Query:
@strawberry.field
def user(self) -> User:
return User(name="Patrick", age=100)
schema = strawberry.Schema(query=Query) This will create a GraphQL schema defining a To run the debug server run the following command: strawberry server app Open the debug server by clicking on the following link: http://0.0.0.0:8000/graphql This will open GraphiQL where you can test the API. Type-checkingStrawberry comes with a mypy plugin that enables statically type-checking your
GraphQL schema. To enable it, add the following lines to your [mypy]
plugins = strawberry.ext.mypy_plugin Django IntegrationA Django view is provided for adding a GraphQL endpoint to your application.
INSTALLED_APPS = [
...
'strawberry.django',
]
from strawberry.django.views import GraphQLView
from .schema import schema
urlpatterns = [
...,
path('graphql', GraphQLView.as_view(schema=schema)),
] WebSocketsTo support graphql Subscriptions over WebSockets you need to provide a WebSocket enabled server. The debug server can be made to support WebSockets with these commands: pip install 'strawberry-graphql[debug-server]'
pip install 'uvicorn[standard]' Examples
ContributingWe use poetry to manage dependencies, to get started follow these steps: git clone https://github.com/strawberry-graphql/strawberry
cd strawberry
poetry install
poetry run pytest This will install all the dependencies (including dev ones) and run the tests. Pre commitWe have a configuration for pre-commit, to add the hook run the following command: pre-commit install Links
LicensingThe code in this project is licensed under MIT license. See LICENSE for more information. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论