4. Querying with Apollo Sandbox
1m

To access Sandbox, go to http://studio.apollographql.com/sandbox.

Demo: Sandbox with the Countries API

  1. Go to Sandbox.

  2. Under Connection Settings, set the endpoint to the Countries API URL below:

    https://countries.trevorblades.com/

We'll show you how to build queries using Sandbox for the following data:

Fetch the code, name, and emoji for all countries

query AllCountries {
countries {
code
name
emoji
}
}

Fetch the name, capital, currency, emoji and continent name for a specific country with the code "CA".

query SpecificCountry($code: ID!) {
country(code: $code) {
name
capital
currency
emoji
continent {
name
}
}
}

In the Variables panel:

{"code": "CA"}

Important things from Sandbox Demo

Convention: Give your operation a helpful and descriptive name, using PascalCase.

Schema Definition Language: countries: [Country!]!

  • The countries field returns a list of Country types.
  • The list is non-nullable (it cannot be null).
  • The objects inside of the list must be of type Country, and is also non-nullable.

Response: After running the query, we can see the response as a JSON object, shaped in the same way as our query, under the data key. We can also see this response in table view.

Variables:

  • Variables are denoted with a $ symbol.
  • We can add variables in the Variables panel in the bottom middle section of Sandbox.
Previous
Next