Skip to main content

A django app that speeds up and simplifies implementing a GraphQL endoint!

Project description


Logo

Wagtail Grapple

A library to easily build GraphQL endpoints so you can grapple your wagtail data from anywhere!

Explore the docs »

View Demo · Report Bug · Request Feature

Table of Contents

About The Project

GraphQL Preview Demo

There is a range of GraphQL packages for Python and sepcifically 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 serliazers 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
    • Settings
    • Search (on all models)
  • Custom Image & Document model support
  • Advanced headless preview functionality buit using GraphQL Subscriptions to enable Page previews on any device!
  • Gatsby Image support (both base64 and SVG tracing)! :fire:

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.

Getting Started

Getting Grapple installed is designed to be as simple as possible!

Prerequisites

Django  >= 2.2, <2.3
wagtail >= 2.5, <2.6

Installation

pip install wagtail_grapple


Add the following to the installed_apps list in your wagtail settings file:

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 stucture :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")),
            ("paraagraph", 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.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature)
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Nathan Horrigan

Project Link: https://github.com/NathHorrigan/wagtail-grapple

Inspired by

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wagtail-grapple-0.1.0.tar.gz (22.1 kB view details)

Uploaded Source

Built Distribution

wagtail_grapple-0.1.0-py3-none-any.whl (25.1 kB view details)

Uploaded Python 3

File details

Details for the file wagtail-grapple-0.1.0.tar.gz.

File metadata

  • Download URL: wagtail-grapple-0.1.0.tar.gz
  • Upload date:
  • Size: 22.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.19.1 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

File hashes

Hashes for wagtail-grapple-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e629a386a96dc20738ded45f196c05ba260dd6ac2cd169699e250b7b43225922
MD5 c02a1fa3dcb31fdf20580f70b266e6a6
BLAKE2b-256 7b973cdd30daa3454f6fcf80efc949b837ccbe510b96a8d6146dbdc251028200

See more details on using hashes here.

Provenance

File details

Details for the file wagtail_grapple-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: wagtail_grapple-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 25.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.19.1 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

File hashes

Hashes for wagtail_grapple-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 53c02367475f137496ce179fa171d50da0c5bce2720e1789dc7d80abbea78296
MD5 02b2749d4abf7b499acab133f17c912b
BLAKE2b-256 c1fe3c77c41e9846bcce5e968b1e26967fd0f0a80d0d4e7221af0a4c5c402fe3

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page