graphql-playground icon indicating copy to clipboard operation
graphql-playground copied to clipboard

Set global variables for HTTP HEADERS

Open DarkLite1 opened this issue 4 years ago • 4 comments

  • [x] GraphQL Playground HTML
  • [x] apollo-server-express: "^2.16.0",

What OS and OS version are you experiencing the issue(s) on?

Windows Server 2016

What version of graphql-playground(-electron/-middleware) are you experiencing the issue(s) on?

We're using apollo-server-express version ^2.16.0 which comes with the Playground build in.

What is the expected behavior?

It would be great if it was possible to store say a token string in a global variable that is then available within the "HTTP HEADERS".

Something like this

{
  "authorization": "Bearer ${token}"
}

What is the actual behavior?

Currently when we test a query we have to copy/paste a string in the "HTTP HEADERS" pane that contains a valid token. This needs to be done for every open tab page. It would be great to able to use a global variable for the token string that can be reused in different tabs.

Another, maybe better, option would be to have a place to set the "HTTP HEADERS" globally, for all tabs. So no more copy/pasting would be required.

Global HTTP Header example used by all tabs:

{
  "authorization": "Bearer xxxMyTokenxxx"
}

image

DarkLite1 avatar Aug 20 '20 09:08 DarkLite1

A bit related, it would be awesome to store the endpoint itself as a variable, allowing to switch between different environments (local / staging - QA etc.)

This is one of the biggest "issue" I have with the GraphQL Playground at the moment, especially when concurrent apps such as Insomnia provide that 😅

flo-sch avatar Jan 20 '21 10:01 flo-sch

The readme says the request.globalHeaders option will accomplish this, but the desktop version doesn't appear to be using them to fetch the schema. Is this expected? Should I install a more up-to-date version?

ckreiling avatar Jan 23 '21 21:01 ckreiling

Just add the token without Bearer.

dancomanlive avatar Mar 04 '21 12:03 dancomanlive

  • added by #992
  • merged at 3b84784

For some reason, this doesn't make it into the jsdelivr.net build I'm using.

playground_global_headers

Where is this 1.7.33 version coming from, anyway? @apollographql/graphql-playground-react in NPM leads to this repository, but the last tag/version here is 1.7.27

rbeer avatar Aug 03 '21 22:08 rbeer