<img src="https://github.com/strawberry-graphql/strawberry/raw/master/.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/master.svg?style=for-the-badge)](https://circleci.com/gh/strawberry-graphql/strawberry/tree/master)
[![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
Install with:
```shell
pip install strawberry-graphql
```
## 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, info) -> 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)),
]
```
## 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
[email protected] 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.
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
共67个文件
py:61个
typed:1个
license:1个
资源分类:Python库 所属语言:Python 资源全名:strawberry-graphql-0.32.4.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源推荐
资源详情
资源评论
收起资源包目录
strawberry-graphql-0.32.4.tar.gz (67个子文件)
strawberry-graphql-0.32.4
PKG-INFO 4KB
pyproject.toml 2KB
LICENSE 1KB
strawberry
http.py 557B
py.typed 0B
flask
graphiql.py 359B
__init__.py 0B
views.py 2KB
lazy_type.py 950B
mutation.py 256B
schema
__init__.py 89B
schema.py 4KB
types
directives.py 1KB
types.py 498B
union.py 3KB
arguments.py 1KB
__init__.py 140B
object_type.py 2KB
base_scalars.py 810B
type.py 2KB
fields.py 1KB
enum.py 791B
scalar.py 2KB
base.py 2KB
resolvers.py 2KB
union.py 1KB
middleware.py 1KB
arguments.py 4KB
static
graphiql.html 3KB
permission.py 249B
__init__.py 493B
federation.py 5KB
printer.py 3KB
ext
mypy_plugin.py 1KB
type.py 3KB
graphql.py 2KB
directive.py 707B
scalars.py 538B
field.py 4KB
enum.py 1KB
custom_scalar.py 2KB
types
type_resolver.py 14KB
generics.py 3KB
types.py 3KB
__init__.py 0B
utils
graphql_lexer.py 1KB
typing.py 4KB
debug.py 870B
str_converters.py 476B
__init__.py 0B
inspect.py 399B
file_uploads
__init__.py 36B
scalars.py 132B
data.py 765B
asgi
constants.py 357B
http.py 2KB
utils.py 257B
__init__.py 6KB
exceptions.py 3KB
django
apps.py 135B
__init__.py 0B
views.py 4KB
cli
commands
server.py 1KB
__init__.py 0B
__init__.py 151B
setup.py 5KB
README.md 3KB
共 67 条
- 1
资源评论
挣扎的蓝藻
- 粉丝: 13w+
- 资源: 15万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功