Package: wagtail-grapple
Wagtail GrappleA library to build GraphQL endpoints easily so you can grapple your Wagtail data from anywhere!Explore the docs »·Report Bug·Request FeatureAbout The ProjectThere 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 agraphql_fieldslist
to your model and away you go (although if you want to go deeper you can!).FeaturesEasily create GraphQL types by adding a small annotation in your models.Supports traditional Wagtail models:Pages (including StreamField & Orderables)SnippetsImagesDocumentsMedia (viawagtailmedia)SettingsRedirectsSearch (on all models)Custom Image & Document model supportPagination supportMiddleware supportBuilt WithThis library is an abstraction upon and relies heavily on Graphene & Graphene Django.GrapheneGraphene DjangoGetting StartedGetting Grapple installed is designed to be as simple as possible!PrerequisitesPython >= 3.8
Wagtail >= 4.1InstallationInstall using pippython-mpipinstallwagtail_grappleAdd the following to theINSTALLED_APPSlist in your Wagtail settings file:INSTALLED_APPS=[# ..."grapple","graphene_django",# ...]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 yoururls.py:fromdjango.urlsimportinclude,pathfromgrappleimporturlsasgrapple_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 athttp://localhost:8000/api/graphql/UsageHere is a GraphQL model configuration for the default page from the Wagtail docs:# ...fromgrapple.modelsimportGraphQLString,GraphQLStreamfieldclassBlogPage(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 theDocumentationContributingContributions are what make the open source community such an amazing place to learn, inspire, and create.
Any contributionsyou makearegreatly appreciated.Fork the projectCreate your feature branch (git checkout -b feature/amazing-feature)Commit your changes (git commit -m 'Add some amazing feature')Push to the branch (git push origin feature/amazing-feature)Open a Pull RequestLocal developmentIn the Python environment of your choice, navigate totests/Runpython -m pip install -r requirements.txtRunpython manage.py migrateRun serverpython manage.py runserverRun testspython manage.py testWith PostgresEnsure you have docker and docker composeRundocker compose upRunexport DATABASE_URL="postgres://postgres:postgres@localhost/postgres"In the Python environment of your choice, navigate totests/Runpython -m pip install -r requirements.txtRunpython manage.py migrateRun serverpython manage.py runserverRun testspython manage.py testCompatibilityWagtail Grapple supports:Python 3.8, 3.9, 3.10 and 3.11Wagtail >= 4.1LicenseDistributed under the MIT License. SeeLICENSEfor more information.Inspired by@tr11@tmkn