Example Application with graphene_django and relay with reformatting structure. This repo is the walkthrough in the docs of graphene_django with relay. Its also have filtering capacities. There are some typos on docs and some deprecated codes. All these things fixed in this repo. So please follow the docs and this repo to make your code error free.
- git clone https://github.com/kamranhossain/graphene_cookbook_relay.git
- cd graphene_cookbook
- virtualenv venv
- source venv/bin/activate
- pip install -Ur requirments/base.txt
- python manage.py makemigrations
- python manage.py migrate
- python manage.py createsuperuser
- python manage.py runserver
- Go to localhost:8000/graphql and type your first query!
query {
allIngredients {
edges {
node {
id,
name
}
}
}
}
- The above will return the names & IDs for all ingredients. But perhaps you want a specific ingredient:
query {
# Graphene creates globally unique IDs for all objects.
# You may need to copy this value from the results of the first query
ingredient(id: "SW5ncmVkaWVudE5vZGU6MQ==") {
name
}
}
- You can also get each ingredient for each category:
query {
allCategories {
edges {
node {
name,
ingredients {
edges {
node {
name
}
}
}
}
}
}
}
- Or you can get only ‘meat’ ingredients containing the letter ‘e’:
query {
# You can also use `category: "CATEGORY GLOBAL ID"`
allIngredients(name_Icontains: "e", category_Name: "Meat") {
edges {
node {
name
}
}
}
}