-
-
Notifications
You must be signed in to change notification settings - Fork 543
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
HmbleCreator
wants to merge
10
commits into
strawberry-graphql:main
Choose a base branch
from
HmbleCreator:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Update README.md #3679
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
323ab87
Update README.md
HmbleCreator b318f59
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 42339c2
Update README.md
HmbleCreator 7fc7fc4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] f8100ab
Update README.md
HmbleCreator 545bf1f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] b57ed59
Update README.md
HmbleCreator acc42b6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 32c08b1
Update README.md
HmbleCreator 351e8eb
Update README.md
HmbleCreator File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
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 | ||
] | ||
``` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
@@ -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) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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