Skip to main content

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

Project description

A red g with a bifrost hook

Wagtail Bifrost

A library to build GraphQL endpoints easily so you can bifrost 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 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 Bifrost 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
    • 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 Bifrost installed is designed to be as simple as possible!

Prerequisites

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

Installation

pip install wagtail_bifrost


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

installed_apps = [
    ...
    "bifrost",
    "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):

# Bifrost Config:
GRAPHENE = {"SCHEMA": "bifrost.schema.schema"}
BIFROST_APPS = {
    "home": ""
}

Add the GraphQL URLs to your urls.py:

from bifrost import urls as bifrost_urls
...
urlpatterns = [
    ...
    url(r"", include(bifrost_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 bifrost.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

Local development

  • In the python environment of your choice, navigate to /examples
  • Run pip install -r requirements.txt
  • Delete the db.sqlite3 file and run ./manage.py migrate
  • Run server ./manage.py runserver

Compatibility

Wagtail Bifrost supports:

  • Django 2.2.x
  • Python 3.6 and 3.7
  • Wagtail >= 2.5

License

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

Contact

Nathan Horrigan

Project Link: https://github.com/torchbox/wagtail-bifrost

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-bifrost-3.0.1.tar.gz (35.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wagtail_bifrost-3.0.1-py3-none-any.whl (42.5 kB view details)

Uploaded Python 3

File details

Details for the file wagtail-bifrost-3.0.1.tar.gz.

File metadata

  • Download URL: wagtail-bifrost-3.0.1.tar.gz
  • Upload date:
  • Size: 35.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.3.3 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.1

File hashes

Hashes for wagtail-bifrost-3.0.1.tar.gz
Algorithm Hash digest
SHA256 92007bf38db51970ca751514301e9e76b489e3f14d2e505d576c6b5ca30b70a7
MD5 593189cb1cfd9b09dbcc2a8f595b3351
BLAKE2b-256 408992f86641b0a940c5702e333d82fa4392e0f1a3ce7e748cc8f612e096820c

See more details on using hashes here.

File details

Details for the file wagtail_bifrost-3.0.1-py3-none-any.whl.

File metadata

  • Download URL: wagtail_bifrost-3.0.1-py3-none-any.whl
  • Upload date:
  • Size: 42.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.3.3 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.1

File hashes

Hashes for wagtail_bifrost-3.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7c851b1d4af48bffe15c6862e3454fb413a6dd5577763b2deb373a6dea50abf0
MD5 163dab6db5fe19fd713aff81f9c5e2ce
BLAKE2b-256 d137a31d286cebb6c7d9ccd70f6fce6468c88a843bdd627d34d6420ae7352739

See more details on using hashes here.

Supported by

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