(HTTP)
{
user(id: 1) {
name
age
friends {
name,
age
}
}
}
{
"user": {
"name": John,
"age": 25,
"friends": [
{
"name": "Jina",
"age": 23
}
]
}
}
Response
Query
{
user(id: 1) {
name
age
friends {
name
}
}
}
GET /users/1
GET /users/1/friends
.
.
.
GraphQL
REST
"{
user(id: 1) {
name
age
}
}"
A Factory in the SF-SM
class Product {
constructor(private GraphQlQueryBuilder: gql.GraphQlQueryFactory) {
}
}
1. Injecting the factory
let productQuery = new this.GraphQlQueryBuilder('product', {productId: 1});
productQuery.select('pageUrl');
console.log(productQuery.toString());
// 'product (productId:1) { pageUrl}'
function name
arguments
fields
2. building the query
class ProductApi {
...
this.HttpFacade.doHTTPQl(url, productQuery, operationName);
}
3. send Http request with the query
GraphiQl is an interactive in-browser GraphQL IDE