wagtail-grapple icon indicating copy to clipboard operation
wagtail-grapple copied to clipboard

Ability to add alongside existing graphql implementation?

Open easherma opened this issue 6 years ago • 7 comments

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!

easherma avatar Nov 15 '19 21:11 easherma

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 avatar Nov 16 '19 09:11 zerolab

@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

zerolab avatar Dec 13 '19 09:12 zerolab

@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 avatar Dec 20 '19 18:12 easherma

@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.

easherma avatar Feb 05 '20 21:02 easherma

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

IAmNatch avatar Mar 12 '20 01:03 IAmNatch

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

zerolab avatar Oct 20 '20 19:10 zerolab

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

dopry avatar Aug 08 '22 01:08 dopry

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

dopry avatar May 12 '23 17:05 dopry