Skip to main content

A Wagtail package that speeds up and simplifies implementing a GraphQL endpoint!

Project description

A red g with a grapple hook

Wagtail Grapple

Build status PyPi black pre-commit.ci status

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

Explore the docs » · Report Bug · Request Feature

About The Project

GraphQL Preview Demo

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
  • Middleware 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.

Getting Started

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

Prerequisites

Django  >= 3.2, <4.0
Wagtail >= 2.15, <5.0

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 = [
    # ...
    path("api/", 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/api/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 learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the project
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Local development

  • In the Python environment of your choice, navigate to /example
  • Run pip install -r requirements.txt
  • Run ./manage.py migrate
  • Run server ./manage.py runserver
  • Run tests ./manage.py test

Compatibility

Wagtail Grapple supports:

  • Django >= 3.2, < 4.0
  • Python 3.7, 3.8, 3.9, and 3.10
  • Wagtail >= 2.15, < 5.0

License

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

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.18.1.tar.gz (41.0 kB view details)

Uploaded Source

Built Distribution

wagtail_grapple-0.18.1-py2.py3-none-any.whl (43.5 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

  • Download URL: wagtail-grapple-0.18.1.tar.gz
  • Upload date:
  • Size: 41.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.15

File hashes

Hashes for wagtail-grapple-0.18.1.tar.gz
Algorithm Hash digest
SHA256 7343f7a05e67a4422e5798d6138c50dc1c177b6cdba2347baad2a9b0c12db22f
MD5 10c0fe4919fc16fa66efefa023a11439
BLAKE2b-256 4461029c1e3538d09b551e66575b492c8de1f16f9ae102185b8890b7ed2c8373

See more details on using hashes here.

Provenance

File details

Details for the file wagtail_grapple-0.18.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for wagtail_grapple-0.18.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 81df64e53616318b6a667d713f9db3661de59d86f67cf8f7bdf797639ac18bff
MD5 5d591939bcee1f6d4f4f2e98ff80414e
BLAKE2b-256 437ed122eff96af6f900e1bf113e90d1a926cfb8923826e52733167248138e1a

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