strawberry icon indicating copy to clipboard operation
strawberry copied to clipboard

Cannot add headers to default graphiql playground

Open sarink opened this issue 1 year ago • 3 comments

Is strawberry using an outdated version of the graphiql playground? There is no option to add headers. Is there a way to swap out the graphiql playground with another one?

strawberry version 0.123.3

Screen Shot 2022-08-04 at 12 34 48 AM

sarink avatar Aug 04 '22 05:08 sarink

Is strawberry using an outdated version of the graphiql playground?

Unfortunately we do. The main reason is/was that we want to keep the graphql-explorer extension which we currently integrate using the graphiql-with-extensions package which unfortunately did not get an update in ages.

Is there a way to swap out the graphiql playground with another one?

Yes, you can subclass your integrations view class and provide a different graphiql template path.

In case you use the ASGI integration it would work like this:

from strawberry.asgi import GraphQL
from strawberry.asgi.handlers import HTTPHandler
from starlette.responses import HTMLResponse
from pathlib import Path

from api.schema import schema  # import your schema here

class CustomHTTPHandler(HTTPHandler):
    def get_graphiql_response(self):
        html = Path("path/to/your/graphiql.html").read_text()
        return HTMLResponse(html)

class CustomGraphQL(GraphQL):
    http_handler_class = CustomHTTPHandler
 
app = CustomGraphQL(schema)

DoctorJohn avatar Aug 04 '22 09:08 DoctorJohn

I also need this feature and am already waiting for https://github.com/strawberry-graphql/strawberry/pull/1889

ryou90 avatar Aug 04 '22 09:08 ryou90

maybe we can add a flag to enable the preview of GraphiQL 2, since it is taking more time than I expected

patrick91 avatar Aug 04 '22 09:08 patrick91

Should be closed @patrick91 ?

hepi avatar Oct 10 '22 13:10 hepi

yes! thanks for checking!

patrick91 avatar Oct 10 '22 13:10 patrick91