Skip to content
Snippets Groups Projects
Commit 6872af68 authored by Tomás Fox's avatar Tomás Fox
Browse files

Add example queries to the readme

parent c4dfc733
No related branches found
No related tags found
No related merge requests found
......@@ -3,13 +3,15 @@
## Install
```py
```bash
pip install graphene-django-optimizer
```
## Usage
Having the following schema based on [the tutorial of graphene-django](http://docs.graphene-python.org/projects/django/en/latest/tutorial-plain/#hello-graphql-schema-and-object-types) (notice the use of `gql_optimizer`)
```py
# cookbook/ingredients/schema.py
import graphene
......@@ -42,6 +44,58 @@ class Query(object):
```
We will show some graphql queries and the queryset that will be executed.
Fetching all the ingredients with the related category:
```graphql
{
all_ingredients {
id
name
category {
id
name
}
}
}
```
```py
ingredients = (
Ingredient.objects
.select_related('category')
.only('id', 'name', 'category__id', 'category__name')
)
```
Fetching all the categories with the related ingredients:
```graphql
{
all_categories {
id
name
ingredients {
id
name
}
}
}
```
```py
categories = (
Category.objects
.only('id', 'name')
.prefetch_related(Prefetch(
'ingredients',
queryset=Ingredient.objects.only('id', 'name'),
))
)
```
## Contribute
The system must have installed:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment