Closed easherma closed 1 year 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
@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 thanks for the checkin! I wasn't able to get it set up and working at the time, would love to revisit it soon.
@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.
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
Note that with #132 in, you could add additional Query mixins to the schema.
Not using Subscription
s anywhere yet, so didn't sort that out yet. Plus we need to update it for Django 3.x
@easherma did the example from @IAmNatch, https://github.com/torchbox/wagtail-grapple/issues/33#issuecomment-597954453, help your resolve your issue?
Closing as stale since OP is not responding and another user has seeming successfully done what the OP was requesting.
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!