Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
HmbleCreator authored Oct 24, 2024
1 parent 8859ad3 commit 323ab87
Showing 1 changed file with 58 additions and 58 deletions.
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.
[![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

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
]
```

## 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)
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
patrick.arminio@gmail.com 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 patrick.arminio@gmail.com directly

## 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)

0 comments on commit 323ab87

Please sign in to comment.