strawberry-graphql / strawberry

A GraphQL library for Python that leverages type annotations 🍓
https://strawberry.rocks
MIT License
3.98k stars 531 forks source link

Incorrect template rendering when overriding graphql IDE template #3276

Open msopacua opened 10 months ago

msopacua commented 10 months ago

The GraphQLView and its async version allow overriding the template file. However, the loading of the template is incorrect, resulting in JSON.parse("") // empty string , because the variable is already replaced.

Additional Context

In the view we see the following code:

        try:
            template = Template(render_to_string("graphql/graphiql.html"))
        except TemplateDoesNotExist:
            template = Template(self.graphql_ide_html)

The loading in the try section, erronously calls render_to_string and sticks the result into a Template class. However, render_to_string already renders the entire template, replacing its variables.

Upvote & Fund

Fund with Polar

patrick91 commented 10 months ago

@msopacua would you be interested in sending a PR to fix this?

msopacua commented 10 months ago

Yes, will do.