Published at
Updated at
Reading time
1min

This post is part of my Today I learned series in which I share all my learnings regarding web development.

I'm jumping between several GraphQL APIs lately, and I was looking for a way to open the endpoints in GraphQL Playground quickly. So I dug into the source code and found that it registers a protocol handler (graphlql-playground). The cool thing about it is that it handles headers like Authorization, too.

To quickly open any GraphQL API in the playground, you can use the following URL:

graphql-playground://endpoint=ENDPOINT?headers={"Authorization": "Bearer AUTH_TOKEN"}

Because I spend a lot of time in the CLI, I also wrote myself a quick shell function to quickly open GraphQL Playground.

function open-gql-playground() {
  local ENDPOINT=$1
  local AUTH_TOKEN=$2

  open "graphql-playground://endpoint=$ENDPOINT?headers={\"Authorization\": \"Bearer $AUTH_TOKEN\"}"
}

Happy querying!

Related Topics

Related Articles