question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Set default options for GraphQLPlayground

See original GitHub issue

There was a PR to pass extra options to GraphQLPlayground but it was closed https://github.com/mirumee/ariadne/pull/315/files

Is there an option to support it? We have a problem with authentication and every single person that wants to use playground needs to remember to set

"request.credentials": "include",

on every user agent.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:6
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
rafalpcommented, Oct 7, 2022

We are moving to GraphiQL 2 but we’ll keep playground support as an opt-in, and part of this support is support for setting default options for Playground from python code:

class APIExplorerPlayground(APIExplorer):
    def __init__(
        self,
        title: str = "Ariadne GraphQL",
        editor_cursor_shape: Optional[str] = None,
        editor_font_family: Optional[str] = None,
        editor_font_size: Optional[int] = None,
        editor_reuse_headers: Optional[bool] = None,
        editor_theme: Optional[str] = None,
        general_beta_updates: Optional[bool] = None,
        prettier_print_width: Optional[int] = None,
        prettier_tab_width: Optional[int] = None,
        prettier_use_tabs: Optional[bool] = None,
        request_credentials: Optional[str] = None,
        request_global_headers: Optional[Dict[str, str]] = None,
        schema_polling_enable: Optional[bool] = None,
        schema_polling_endpoint_filter: Optional[str] = None,
        schema_polling_interval: Optional[int] = None,
        schema_disable_comments: Optional[bool] = None,
        tracing_hide_tracing_response: Optional[bool] = None,
        tracing_tracing_supported: Optional[bool] = None,
        query_plan_hide_query_plan_response: Optional[bool] = None,
    ):
        ...
1reaction
cons0l3commented, Apr 15, 2021

Hi,

first of all, good work. Thanks!

I was facing the same issue and found a solution by deriving my own GraphQL class:

from ariadne.asgi import GraphQL
[...]
class MyGraphQL(GraphQL):
  
    def __init__(self, schema:GraphQLSchema, **kwargs):
        super(AppGraphQL, self).__init__(schema, **kwargs)

    async def render_playground(self, request: Request) -> Response:
        return FileResponse('app/static/playground.html')

I added a “playground.html” to my static content folder and modified it:

  <script>window.addEventListener('load', function (event) {
      GraphQLPlayground.init(document.getElementById('root'), {
        "settings": { ...GraphQLPlayground.ISettings, "request.credentials": "include" }
      })
    })</script>

and then used that derived MyGraphQL class to do all the normal stuff:

[...]
routes=[Mount("/", MyGraphQL(make_schema(), debug=DEBUG, introspection=INTROSPECT))]
middleware=[Middleware(CORSMiddleware, allow_origins=[ALLOWED_ORIGINS], allow_methods=("GET", "POST", "OPTIONS"))]
app = Starlette(routes=routes, middleware=middleware, debug=DEBUG, on_startup=[startup])
[...]
Read more comments on GitHub >

github_iconTop Results From Across the Web

GraphQL Playground - Apollo GraphQL Docs
The Apollo Server constructor contains the ability to configure GraphQL Playground with the playground configuration option. The options can be found on ...
Read more >
Complete guide to GraphQL Playground - LogRocket Blog
In this guide, I'll introduce you to GraphQL Playground and walk you through some basic concepts to help you make the most of...
Read more >
GraphQL + TypeScript - A progressive Node.js framework
For Express and Apollo (default) $ npm i @nestjs/graphql @nestjs/apollo graphql ... make sure to enable the disableHealthCheck setting in the GraphQLModule ...
Read more >
GraphQL | RedwoodJS Docs
On the web side, Redwood uses Apollo Client by default though you can swap it ... to the GraphQL response headers which you...
Read more >
GraphQL Playground - Apollo Server
When NODE_ENV is set to production , GraphQL Playground (as well as ... ability to configure GraphQL Playground with the playground configuration option....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found