Published at
Updated at
Reading time
1min
This post is part of my Today I learned series in which I share all my web development learnings.

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!

Was this TIL post helpful?
Yes? Cool! You might want to check out Web Weekly for more quick learnings. The last edition went out 7 days ago.
Stefan standing in the park in front of a green background

About Stefan Judis

Frontend nerd with over ten years of experience, freelance dev, "Today I Learned" blogger, conference speaker, and Open Source maintainer.

Related Topics

Related Articles