<img src="https://github.com/strawberry-graphql/strawberry/raw/main/.github/logo.png" width="124" height="150">
# Strawberry GraphQL
> Python GraphQL library based on dataclasses
[![CircleCI](https://img.shields.io/circleci/token/307b40d5e152e074d34f84d30d226376a15667d5/project/github/strawberry-graphql/strawberry/main.svg?style=for-the-badge)](https://circleci.com/gh/strawberry-graphql/strawberry/tree/main)
[![Discord](https://img.shields.io/discord/689806334337482765?label=discord&logo=discord&logoColor=white&style=for-the-badge&color=blue)](https://discord.gg/ZkRTEJQ)
[![PyPI](https://img.shields.io/pypi/v/strawberry-graphql?logo=pypi&logoColor=white&style=for-the-badge)](https://pypi.org/project/strawberry-graphql/)
## Installation ( Quick Start )
The quick start method provides a server and CLI to get going quickly. Install
with:
```shell
pip install strawberry-graphql[debug-server]
```
## Getting Started
Create a file called `app.py` with the following code:
```python
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 `User` type and a single query
field `user` that will return a hardcoded user.
To run the debug server run the following command:
```shell
strawberry server app
```
Open the debug server by clicking on the following link:
[http://0.0.0.0:8000/graphql](http://0.0.0.0:8000/graphql)
This will open GraphiQL where you can test the API.
### Type-checking
Strawberry comes with a [mypy] plugin that enables statically type-checking your
GraphQL schema. To enable it, add the following lines to your `mypy.ini`
configuration:
```ini
[mypy]
plugins = strawberry.ext.mypy_plugin
```
[mypy]: http://www.mypy-lang.org/
### Django Integration
A Django view is provided for adding a GraphQL endpoint to your application.
1. Add the app to your `INSTALLED_APPS`.
```python
INSTALLED_APPS = [
...
'strawberry.django',
]
```
2. Add the view to your `urls.py` file.
```python
from strawberry.django.views import GraphQLView
from .schema import schema
urlpatterns = [
...,
path('graphql', GraphQLView.as_view(schema=schema)),
]
```
## WebSockets
To 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:
```shell
pip install strawberry-graphql[debug-server]
pip install uvicorn[standard]
```
## Contributing
We use [poetry](https://github.com/sdispater/poetry) to manage dependencies, to
get started follow these steps:
```shell
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 commit
We have a configuration for
[pre-commit](https://github.com/pre-commit/pre-commit), to add the hook run the
following command:
```shell
pre-commit install
```
## Links
- Project homepage: https://strawberry.rocks
- Repository: https://github.com/strawberry-graphql/strawberry
- Issue tracker: https://github.com/strawberry-graphql/strawberry/issues
- In case of sensitive bugs like security vulnerabilities, please contact
patrick.arminio@gmail.com directly instead of using the issue tracker. We
value your effort to improve the security and privacy of this project!
## Licensing
The code in this project is licensed under MIT license. See [LICENSE](./LICENSE)
for more information.
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
资源分类:Python库 所属语言:Python 资源全名:strawberry-graphql-0.64.5.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源推荐
资源详情
资源评论
收起资源包目录
strawberry-graphql-0.64.5.tar.gz (95个子文件)
strawberry-graphql-0.64.5
PKG-INFO 5KB
pyproject.toml 3KB
LICENSE 1KB
strawberry
http.py 1KB
py.typed 0B
flask
graphiql.py 359B
__init__.py 0B
views.py 2KB
extensions
runner.py 2KB
__init__.py 666B
tracing
utils.py 1KB
__init__.py 165B
opentelemetry.py 3KB
apollo.py 5KB
sanic
graphiql.py 366B
utils.py 1KB
__init__.py 0B
context.py 211B
views.py 4KB
tools
create_type.py 1KB
__init__.py 72B
lazy_type.py 970B
private.py 658B
mutation.py 256B
schema
__init__.py 117B
schema_converter.py 12KB
schema.py 7KB
execute.py 6KB
types
concrete_type.py 624B
__init__.py 85B
base_scalars.py 935B
scalar.py 2KB
base.py 2KB
experimental
pydantic
conversion.py 1KB
error_type.py 2KB
utils.py 655B
__init__.py 188B
type.py 4KB
fields.py 2KB
exceptions.py 535B
__init__.py 94B
aiohttp
__init__.py 0B
views.py 11KB
resolvers.py 209B
union.py 5KB
dataloader.py 3KB
middleware.py 1KB
arguments.py 7KB
static
graphiql.html 4KB
permission.py 333B
__init__.py 742B
federation.py 5KB
printer.py 3KB
ext
mypy_plugin.py 22KB
LICENSE 1KB
type.py 5KB
graphql.py 0B
directive.py 1KB
scalars.py 538B
field.py 12KB
enum.py 1KB
custom_scalar.py 3KB
types
type_resolver.py 16KB
execution.py 870B
generics.py 5KB
fields
resolver.py 3KB
__init__.py 0B
types.py 1KB
__init__.py 140B
info.py 824B
subscriptions
constants.py 357B
__init__.py 0B
utils
graphql_lexer.py 1KB
typing.py 4KB
debug.py 1012B
str_converters.py 476B
importer.py 592B
__init__.py 0B
inspect.py 399B
file_uploads
__init__.py 51B
scalars.py 132B
data.py 786B
asgi
utils.py 257B
__init__.py 12KB
exceptions.py 5KB
django
apps.py 135B
__init__.py 769B
context.py 494B
views.py 7KB
cli
commands
server.py 2KB
export_schema.py 684B
__init__.py 0B
__init__.py 257B
setup.py 6KB
README.md 4KB
共 95 条
- 1
资源评论
挣扎的蓝藻
- 粉丝: 14w+
- 资源: 15万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- gadget驱动研究论文
- 组装式箱式变电站3款工程图机械结构设计图纸和其它技术资料和技术方案非常好100%好用.zip
- rongxin11111111
- 116395807409340大猫vb登陆器.apk
- Win11操作系统高效快捷键全面指南
- Windows 10快捷键大全:提升工作效率的操作指南
- 2024年最全Nmap扫描技术与案例集锦(15类场景,102种命令)
- DigiShow 教程1 基本概念
- DigiShow 教程2 软件安装使用入门
- DigiShow 教程3 信号映射
- DigiShow 教程4 软件常用操作
- 小戴人工智能PurposeAI-20241205分词字符集识别的程序的详细解释 (第三版)
- SARibbon-qt
- EasyCode-sql server
- brightnessUI-ubuntu
- Pyqt5-pyqt5
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功