/* Code-Comments */

August 31, 2019

Passing Test Variables To GraphiQL

Previously, I wrote about writing a GraphQL query that takes variables.

I was using this to programmatically create posts.

In returning to that post later, however, I noticed that I actually forgot a relevant detail: how to test it in GraphiQL, the playground Gatsby provides.

Continuing with the same example we used last time, you can see at the bottom left of the screen a “Query Variables” option.

Clicking on it exposes an input window.

example query variables

In my case, my only variable is a string for the argument $slug. To pass an option, I create an object with slug as the key and whatever value I want.

For example:

{"slug": "hello-world"}

Note: It’s important to put quotes around Slug or it will error.

error expected string


Stephen Weiss

Thanks for reading! My name's Stephen Weiss. I live in Chicago with my wife, Kate, and dog, Finn.
Click here to see the archives of my weeks in review and sign up yourself!