2. GRAPHQL QUERY
Public GraphQL APIs:
SWAPI : http://graphql.org/swapi-graphql
GitHub API : https://developer.github.com/v4/explorer
Yelp : https://www.yelp.com/developer/graphql
SWAPI : http://graphql.org/swapi-graphql
GitHub API : https://developer.github.com/v4/explorer
Yelp : https://www.yelp.com/developer/graphql
below examples will be run on : http://snowtooth.moonhighway.com < visit the url and type in queries
You can add multiple queries to a query document but you can only run 1 query at a time.
for example,
# Try to write your query here
query lifts{
allLifts{
name
status
}
}
query trails{
allTrails{
name
difficulty
}
}
if you run the query document above, GraphQL playgound will ask you to choose one query to run.
To run both queries at once, you need to wrap them into 1 query.
To run both queries at once, you need to wrap them into 1 query.
query liftsAndTrails { // query : root type. fields that are availabled will be in the documentation.
liftCount(status: OPEN) // liftCount : fields chosen from GraphQL documentation
allLifts{ // allLifts : fields chosen from GraphQL documentation
name
status //selection sets
}
allTrails {
name
difficulty
}
}
Specifying the return field name
query liftsAndTrails {
open: liftCount(status: OPEN)
chairlifts: allLifts {
liftName : name // Like this!
status
}
skiSlopes: allTrails {
name
difficulty
}
}
result is:
{
"data": {
"open": 0,
"chairlifts": [
{
"liftName": "Astra Express", // name field has been returned with the name "liftName"
"status": "CLOSED"
}
],
"skiSlopes": [
{
"name": "Blue Bird", // if not specified, returned by the name of the query's field name
"difficulty": "intermediate"
},
]
}
}
Using arguments to select data
query jazzCatStatus {
Lift(id: "jazz-cat") { // argument
name
status
night
elevationGain
}
}
Built-In GraphQL Scalar Types:
- Int
- Float
- String
- Boolean
- ID
댓글
댓글 쓰기