Coder Social home page Coder Social logo

dqcuong93 / wagtail-grapple Goto Github PK

View Code? Open in Web Editor NEW

This project forked from torchbox/wagtail-grapple

0.0 0.0 0.0 1.13 MB

A Wagtail app that makes building GraphQL endpoints a breeze!

Home Page: https://wagtail-grapple.readthedocs.io/en/latest/

License: BSD 3-Clause "New" or "Revised" License

Dockerfile 0.46% Python 93.32% HTML 4.96% CSS 0.94% Makefile 0.31%

wagtail-grapple's Introduction

A red g with a grapple hook

Wagtail Grapple

Build status PyPi black pre-commit

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.0, <4.0
Wagtail >= 2.14, <2.17

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 🎉 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 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/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
  • Delete the db.sqlite3 file and run ./manage.py migrate
  • Run server ./manage.py runserver
  • Run tests ./manage.py test

Compatibility

Wagtail Grapple supports:

  • Django >= 3.0, < 4.0
  • Python 3.7, 3.8, 3.9, and 3.10
  • Wagtail >= 2.14, < 2.17

License

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

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!

wagtail-grapple's People

Contributors

nathhorrigan avatar zerolab avatar fabienheureux avatar ruisaraiva19 avatar kbayliss avatar tbrlpld avatar timmysmalls avatar thibaudcolas avatar tomdyson avatar dopry avatar eltociear avatar kalobtaulien avatar thclark avatar 13hakta avatar leewesleyv avatar protasovse avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.