torchbox / wagtail-grapple

A Wagtail app that makes building GraphQL endpoints a breeze!
https://wagtail-grapple.readthedocs.io/en/latest/
Other
155 stars 58 forks source link

Ability to add alongside existing graphql implementation? #33

Closed easherma closed 1 year ago

easherma commented 5 years ago

Hey,

Love the potential of this project, and we'd like to explore using it. However, we'd need to migrate away from our current graphene implementation, and this could take some time. Is there a way we could start including grapple as an alternate endpoint?

I tried giving it its own namespace in urls.py, but setting the schema as instructed in settings.py also sets the schema for our existing graphql endpoint, which doesn't let them live side by side? Any advice?

If we get this working, I'd be happy to do a PR to the docs as an example, as I'm sure this could be a common enough situation and could help make it easier for others to adopt this library!

zerolab commented 5 years ago

Hey @easherma,

I think you can accomplish that by not explicitly defining SCHEMA, but rather passing a schema kwarg to the endpoint url definition as per http://docs.graphene-python.org/projects/django/en/latest/tutorial-plain/#creating-graphql-and-graphiql-views

the

from cookbook.schema import schema

urlpatterns = [
    url(r'^graphql$', GraphQLView.as_view(graphiql=True, schema=schema)),
]

part and manually doing what https://github.com/torchbox/wagtail-grapple/blob/master/grapple/urls.py does

zerolab commented 4 years ago

@easherma did you have any luck with the above? I am curious as to where you got. Would be a valuable addition to the docs

easherma commented 4 years ago

@zerolab thanks for the checkin! I wasn't able to get it set up and working at the time, would love to revisit it soon.

easherma commented 4 years ago

@zerolab I couldn't get this to work but I'd still like to. Feel free to reach out if you'd like to help.

IAmNatch commented 4 years ago

Hi @easherma,

Following the links above I was able to combine the grapple schema with my own. I'm still trying to get subscriptions to work, but I think that is a completely separate issue. Here's an example of my schema.py

import graphene
from grapple.schema import schema as grapple_schema
from grapple.registry import registry

def create_schema():
    """
    Root schema object that graphene is pointed at.
    It inherits its queries from each of the specific type mixins.
    """

    class Query(
        grapple_schema.Query,
        graphene.ObjectType
    ):
        pass

    class Subscription(
        grapple_schema.Subscription,
        graphene.ObjectType
    ):
        pass

    return graphene.Schema(
        query=Query, types=list(registry.models.values()), subscription=Subscription
    )

schema = create_schema()

In the above snippet I have extracted the Query and Subscription from the grapple_schema function. From there you can use them as mixins, and include your own Query's as well.

In the future, once I start adding in my own types, I'm unsure if I'll have to update the types= definition. Will report back here when I get to that point

zerolab commented 4 years ago

Note that with #132 in, you could add additional Query mixins to the schema. Not using Subscriptions anywhere yet, so didn't sort that out yet. Plus we need to update it for Django 3.x

dopry commented 2 years ago

@easherma did the example from @IAmNatch, https://github.com/torchbox/wagtail-grapple/issues/33#issuecomment-597954453, help your resolve your issue?

dopry commented 1 year ago

Closing as stale since OP is not responding and another user has seeming successfully done what the OP was requesting.