A Django app that speeds up and simplifies implementing a GraphQL endpoint!
Project description
Wagtail Grapple
A library to build GraphQL endpoints easily so you can grapple your Wagtail data from anywhere!
Explore the docs »
View Demo
·
Report Bug
·
Request Feature
Table of Contents
About The Project
There is a range of GraphQL packages for Python and specifically Django. However, getting these packages to work out of the box with an existing infrastructure without errors isn't as easy to come by.
The purpose of Grapple is to be able to build GraphQL endpoints on a model by model
basis as quickly as possible. The setup and configuration have been designed
to be as simple but also provide the best features;
No complex serializers need to be written - just add a graphql_fields
list
to your model and away you go (although if you want to go deeper you can!).
Features:
- Easily create GraphQL types by adding a small annotation in your models.
- Supports traditional Wagtail models:
- Pages (including Streamfield & Orderables)
- Snippets
- Images
- Documents
- Media
- Settings
- Redirects
- Search (on all models)
- Custom Image & Document model support
- Pagination support
- Advanced headless preview functionality built using GraphQL Subscriptions to enable Page previews on any device!
Built With
This library is an abstraction upon and relies heavily on Graphene & Graphene Django. We also use Django Channels and the Potrace image library.
- Graphene
- Graphene Django
- Potrace
- Django Channels when installed with
wagtail_grapple[channels]
Getting Started
Getting Grapple installed is designed to be as simple as possible!
Prerequisites
Django >= 2.2, <3.1 (<2.3 if using channels)
wagtail >= 2.5, <2.12
Installation
pip install wagtail_grapple
Add the following to the installed_apps
list in your Wagtail settings file:
installed_apps = [
...
"grapple",
"graphene_django",
...
]
For GraphQL Subscriptions with Django Channels, run pip install wagtail_grapple[channels]
and add
channels
to installed apps:
installed_apps = [
...
"grapple",
"graphene_django",
"channels",
...
]
Add the following to the bottom of the same settings file, where each key is the app you want to this library to scan and the value is the prefix you want to give to GraphQL types (you can usually leave this blank):
# Grapple Config:
GRAPHENE = {"SCHEMA": "grapple.schema.schema"}
GRAPPLE_APPS = {
"home": ""
}
Add the GraphQL URLs to your urls.py
:
from grapple import urls as grapple_urls
...
urlpatterns = [
...
url(r"", include(grapple_urls)),
...
]
Done! Now you can proceed onto configuring your models to generate GraphQL types that adopt their structure :tada: Your GraphQL endpoint is available at http://localhost:8000/graphql/
Usage
Here is a GraphQL model configuration for the default page from the Wagtail docs:
...
from grapple.models import (
GraphQLString,
GraphQLStreamfield,
)
class BlogPage(Page):
author = models.CharField(max_length=255)
date = models.DateField("Post date")
body = StreamField(
[
("heading", blocks.CharBlock(classname="full title")),
("paragraph", blocks.RichTextBlock()),
("image", ImageChooserBlock()),
]
)
content_panels = Page.content_panels + [
FieldPanel("author"),
FieldPanel("date"),
StreamFieldPanel("body"),
]
# Note these fields below:
graphql_fields = [
GraphQLString("heading"),
GraphQLString("date"),
GraphQLString("author"),
GraphQLStreamfield("body"),
]
For more examples, please refer to the Documentation
Contributing
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Local development
- In the python environment of your choice, navigate to
/example
- Run
pip install -r requirements.txt
- Delete the
db.sqlite3
file and run./manage.py migrate
- Run server
./manage.py runserver
Compatibility
Wagtail Grapple supports:
- Django 2.2.x, 3.0.x
- Python 3.6, 3.7, 3.8 and 3.9
- Wagtail >= 2.5, < 2.12
License
Distributed under the MIT License. See LICENSE
for more information.
Contact
Nathan Horrigan
Project Link: https://github.com/GrappleGQL/wagtail-grapple
Inspired by
Contributors ✨
Thanks goes to these wonderful people (emoji key):
Nathan Horrigan 💻 🐛 📖 🚇 🚧 |
Cameron Lamb 💻 🐛 📖 🚇 🚧 |
Dan Braghis 💻 🐛 📖 🚇 🚧 |
Rui Saraiva 💻 🐛 📖 🚇 🚧 |
Tibor 💻 🐛 📖 |
timmysmalls 💻 🐛 |
Tom Dyson 💻 📖 |
fabienheureux 💻 🐛 📖 |
This project follows the all-contributors specification. Contributions of any kind welcome!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file wagtail-grapple-0.10.2.tar.gz
.
File metadata
- Download URL: wagtail-grapple-0.10.2.tar.gz
- Upload date:
- Size: 34.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 63252e7455e11f8d87a261dde793dc02ee8a137c0a538d6a2b45e04fdf425068 |
|
MD5 | debcffbc357bea410d2b414ff8bb620b |
|
BLAKE2b-256 | c2e357b182959080d38585861eb48785742a6f77b0f197498afbd82ff033906d |
Provenance
File details
Details for the file wagtail_grapple-0.10.2-py2.py3-none-any.whl
.
File metadata
- Download URL: wagtail_grapple-0.10.2-py2.py3-none-any.whl
- Upload date:
- Size: 38.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d1d07c5fbd73914213c996e61d665bb99573bd542c8bf14649e03f7509664c87 |
|
MD5 | 95961b5779e29128bf1dbcc331254f83 |
|
BLAKE2b-256 | 7d5f8a4a9dedafb8e9230a01cb0b6ac302422a0a41b13d6bbafb6bbee2cfb25d |