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.

Proposal: Default headers for GraphQLPlayground.init

See original GitHub issue

I’m building a Ruby on Rails integration for GraphQL Playground - here.

In a lot of Ruby on Rails application, developers use the GraphQL with the build in CSRF protection.

For the gem to work, I have to be able to set default headers for the GraphQL endpoint. I imagining the following would do the trick:

window.addEventListener('load', function (event) {
  GraphQLPlayground.init(document.getElementById('root'), {
    endpoint: '<%= graphql_endpoint_path %>',
    headers: {
      'X-CSRF-Token': '<%= form_authenticity_token %>',
    },
  });
});
 

This would also be useful, for default authentication headers and similar.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:10
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
robertopedrosocommented, May 13, 2018

Seconding this – I was working on a PR to add graphql-playground as an optional interface to graphene-django, but the inability to set headers through the playground’s init function makes this impossible.

The <Playground /> component accepts headers as an optional prop. I’m pretty sure the prop would simply have to be added to <PlaygroundWrapper /> and <GraphQLBinApp />.

I lack React expertise, but if someone can confirm my thoughts on passing this prop down, I’d be happy to make a PR.

2reactions
huv1kcommented, Oct 15, 2018

Thanks to @wilsongp its done in #825 and will be released in the new version of the playground.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Proposal: Default headers for GraphQLPlayground.init #636
I'm building a Ruby on Rails integration for GraphQL Playground - here. ... Proposal: Default headers for GraphQLPlayground.init #636.
Read more >
Setting Up Authentication and Authorization with Apollo ...
If we try running the viewer query from GraphQL Playground without an Authorization header, then we'll see an error of Not Authorised! now...
Read more >
Spring for GraphQL Documentation
A GraphQL Java application can register a DataFetcherExceptionHandler to decide how to represent exceptions from the data layer in the "errors" ...
Read more >
Using the GraphQL Playground - WellLine
After the headers area is configured, the "error": "Unexpected token < in JSON at position 0" message will be removed, indicating the playground...
Read more >
GraphQL - Strapi Developer Docs
The GraphQL Playground is enabled by default for both the development and staging environments, but disabled in production environments.
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