Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update README.md #3679

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
116 changes: 58 additions & 58 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,118 +2,128 @@

# Strawberry GraphQL

> Python GraphQL library based on dataclasses
> Python GraphQL library leveraging modern Python features like dataclasses and type hints to create GraphQL APIs.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is our tagline, I'd prefer to leave it as-is


[![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 )
## Quick Start

The quick start method provides a server and CLI to get going quickly. Install
with:
### Installation

```shell
pip install "strawberry-graphql[debug-server]"
```

## Getting Started
### Basic Example

Create a file called `app.py` with the following code:
Create a new file `app.py`:

```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:
Run the debug server:

```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)
Visit [http://0.0.0.0:8000/graphql](http://0.0.0.0:8000/graphql) to access GraphiQL and explore your API.

This will open GraphiQL where you can test the API.
## Features

### Type-checking
### Type Checking with MyPy
HmbleCreator marked this conversation as resolved.
Show resolved Hide resolved

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:
Enable static type checking by adding to your `mypy.ini`:

```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`.
1. Add to `INSTALLED_APPS`:

```python
INSTALLED_APPS = [
..., # your other apps
"strawberry.django",
"strawberry.django", # Add this line
# ... your other apps
]
```

2. Add the view to your `urls.py` file.
2. Configure URL routing in `urls.py`:

```python
from strawberry.django.views import GraphQLView
from .schema import schema

urlpatterns = [
...,
path("graphql", GraphQLView.as_view(schema=schema)),
# ... your other urls
]
```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: worth mentioning that they can (on a step 3), optionally, use the official strawberry-django integration, which provides type generation from models, query optimization and other useful utilities.


## WebSockets
### WebSocket Support

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:
For GraphQL subscriptions over WebSockets:

```shell
pip install 'strawberry-graphql[debug-server]'
pip install 'uvicorn[standard]'
```

## Examples
## Testing

Strawberry provides built-in testing utilities through `BaseGraphQLTestClient`:

```python
from strawberry.test import BaseGraphQLTestClient

class MyTestClient(BaseGraphQLTestClient):
def request(self, body, headers=None, files=None):
# Implement request logic
pass

def test_query():
client = MyTestClient(http_client)
HmbleCreator marked this conversation as resolved.
Show resolved Hide resolved
response = client.query("""
{
user {
name
age
}
}
""")

assert response.data["user"]["name"] == "Patrick"
assert not response.errors
```

## Examples & Resources

* [Various examples on how to use Strawberry](https://github.com/strawberry-graphql/examples)
* [Full stack example using Starlette, SQLAlchemy, Typescript codegen and Next.js](https://github.com/jokull/python-ts-graphql-demo)
* [Quart + Strawberry tutorial](https://github.com/rockyburt/Ketchup)
- [Official Examples Repository](https://github.com/strawberry-graphql/examples)
- [Full-stack Demo (Starlette + SQLAlchemy + TypeScript + Next.js)](https://github.com/jokull/python-ts-graphql-demo)
- [Quart Integration Tutorial](https://github.com/rockyburt/Ketchup)

## Contributing
## Development

We use [poetry](https://github.com/sdispater/poetry) to manage dependencies, to
get started follow these steps:
### Setting Up Development Environment

```shell
git clone https://github.com/strawberry-graphql/strawberry
Expand All @@ -122,31 +132,21 @@ poetry install --with integrations
poetry run pytest
```

For all further detail, check out the [Contributing Page](CONTRIBUTING.md)


### Pre commit

We have a configuration for
[pre-commit](https://github.com/pre-commit/pre-commit), to add the hook run the
following command:
### Pre-commit Hooks

```shell
pre-commit install
```

## Links
## Community & Support

- 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!
- Documentation: [https://strawberry.rocks](https://strawberry.rocks)
- GitHub Repository: [https://github.com/strawberry-graphql/strawberry](https://github.com/strawberry-graphql/strawberry)
- Issue Tracker: [https://github.com/strawberry-graphql/strawberry/issues](https://github.com/strawberry-graphql/strawberry/issues)
- Security Issues: Contact [email protected] directly
HmbleCreator marked this conversation as resolved.
Show resolved Hide resolved

## Licensing
## License

The code in this project is licensed under MIT license. See [LICENSE](./LICENSE)
for more information.
This project is licensed under the MIT License - see the [LICENSE](./LICENSE) file for details.

![Recent Activity](https://images.repography.com/0/strawberry-graphql/strawberry/recent-activity/d751713988987e9331980363e24189ce.svg)