strawberry-graphql / strawberry-django

Strawberry GraphQL Django extension
https://strawberry.rocks/docs/django
MIT License
415 stars 120 forks source link

Enable custom graphiql templates #177

Open pauloteixeirajr opened 2 years ago

pauloteixeirajr commented 2 years ago

Feature Request Type

Description

Can we allow custom graphiql templates? We're migrating to strawberry, but our team have a custom playground template which contains tabs and other site settings like schema polling, tracing and etc.

I was able to workaround it by creating a custom BaseView and overriding the _render_graphiql method, but it would be great to have a property for that. I just want to reduce the efforts should you ever update the render method.

Can I introduce a graphiql_template attribute to the BaseView?

class BaseView(View):
    ...
    graphiql_template = "graphql/graphiql.html"
    ...

    def _render_graphiql(self, request: HttpRequest, context=None):
       ...
       template = Template(render_to_string(self.graphiql_template))
       ...

Thanks for the awesome library, by the way :)

Upvote & Fund

Fund with Polar

patrick91 commented 2 years ago

hi @pauloteixeirajr! good suggestion, I was thinking the same a couple of days ago, I want to merge this PR: https://github.com/strawberry-graphql/strawberry/pull/1840 before adding this feature 😊 I'd love to have this option for all frameworks :)

btw I think you could technically already do this with django if you add strawberry django to the installed apps and use the same path for the template :)

pauloteixeirajr commented 2 years ago

@patrick91 that's great to hear! We did try changing the path, but because other projects also use the template from our internal library, it caused lots of issues for other teams, so we went with the custom view for now.

Like I said, we have a workaround for it, so there is no rush. I'm more than happy to help with PRs if you need πŸ˜„

humphrey commented 2 years ago

If this also allows me to easily have a separate url for subscriptions/websockets, then I'm all for it πŸ‘