34
loading...
This website collects cookies to deliver better user experience
Note: This tutorial assumes the prerequisite of basic GraphQL knowledge: types and queries. You can read up on them on the official specification site.
"the primary unit of composition in GraphQL."
type Breed {
temperament: String!
origin: String!
name: String
life_span: String
hairless: Int
rare: Int
}
type Query {
BreedById(id: String!): Breed
@rest(
endpoint: "https://api.thecatapi.com/v1/breeds/search?q=$id"
configuration: "cat_config"
)
allBreeds: [Breed]
@rest(
endpoint: "https://api.thecatapi.com/v1/breeds"
configuration: "cat_config"
)
}
breed.graphql
defines our Breed type as well as our two queries, BreedById
and allBreeds
. They retrieve data from Cat API endpoints, specified in StepZen's custom directive, @rest
.To learn more about @rest
, check out our docs.
cat_config
name on both queries' configuration
specification.configurationset:
- configuration:
name: cat_config
Authorization: Apikey {{YOUR_CAT_CONFIG_KEY_HERE}}
config.yaml
contains the information StepZen needs to connect to the Cat API.schema @sdl(files: ["breed.graphql"]) {
query: Query
}
stepzen start
from the command line. If you've never used StepZen before, you might have to run stepzen login
first and provide your credentials.breed.graphql
and write something like:fragment breedFields on Breed {
temperament
origin
name
life_span
hairless
rare
}
...
) on it.allBreeds
and select BreedFragment
.country_code
, then all it takes is one click of a mouse to add it, not just to your fragment definitions, but to all your previous queries in the browser.country_code
:type Breed {
temperament: String!
origin: String!
name: String
life_span: String
hairless: Int
rare: Int
country_code: String
}
query MyQuery {
BreedById(id: "abys") {
temperament
rare
hairless
life_span
name
origin
country_code
}
allBreeds {
temperament
rare
hairless
life_span
name
origin
country_code
}
}
fragment BreedFragment on Breed {
temperament
rare
hairless
life_span
name
origin
country_code
}
country_code
in your Breed fragment and this code:query MyQuery {
BreedById(id: "abys") {
...BreedFragment
rare
}
allBreeds {
...BreedFragment
}
}
fragment BreedFragment on Breed {
temperament
rare
hairless
life_span
name
origin
country_code
}
{
"data": {
"BreedById": {
"country_code": "EG",
"hairless": 0,
"life_span": "14 - 15",
"name": "Abyssinian",
"origin": "Egypt",
"rare": 0,
"temperament": "Active, Energetic, Independent, Intelligent, Gentle"
}, {...} etc