25. • exactly the data the client needs
• in one request
26. {
p45: product(id: "45") {
name
}
p54: product(id: "54") {
name
canBeCombinedWith {
id
name
}
}
}
• exactly the data the client needs
• in one request
27. {
p45: product(id: "45") {
name
}
p54: product(id: "54") {
name
canBeCombinedWith {
id
name
}
}
}
• exactly the data the client needs
• in one request
28. {
p45: product(id: "45") {
name
}
p54: product(id: "54") {
name
canBeCombinedWith {
id
name
}
}
}
{
"data": {
"p45": {
"name": "running shoes"
},
"p54": {
"name": "basketball shirt",
"canBeCombinedWith": [
{
"id": "46",
"name": "basketball shoes"
},
{
"id": "58",
"name": "basketball T-shirt"
}
]
}
}
}
• exactly the data the client needs
• in one request
29. {
p45: product(id: "45") {
name
}
p54: product(id: "54") {
name
canBeCombinedWith {
id
name
}
}
}
{
"data": {
"p45": {
"name": "running shoes"
},
"p54": {
"name": "basketball shirt",
"canBeCombinedWith": [
{
"id": "46",
"name": "basketball shoes"
},
{
"id": "58",
"name": "basketball T-shirt"
}
]
}
}
}
• exactly the data the client needs
• in one request
m
obile
friendly
30. With GraphQL
• the client has more power
{
product(id: "45") {
variants(master: false, limit: 10, offset: 20) {
price {
centAmount
}
}
}
}
• and the server can be more generic
31. Introspection
{
__type(name: "product") {
fields {
name
}
}
}
{
"data": {
"__type": {
"fields": [
{
"name": "id"
},
{
"name": "name"
},
{
"name": "masterVariant"
},
{
• the schema is used:
• to validate the queries (server & maybe client)
• for introspection
• for documentation
36. With GraphQL
• a field can be deprecated
• still valid for a query
• not in the schema anymore
• the server can track if a field is used
• the field can be removed when not used anymore
37. REST vs GraphQL?
• REST is here to stay
• simple
• widely used
• GraphQL
• different approach
• solve some limits of REST
38. ecosystem
• used in Facebook’s native apps in production since 2012
• open source in July 2015
• specification
• backend agnostic
• implementation in different languages
• nodejs, java, scala, ruby, php and many more
• front-end frameworks based on GraphQL like relay
39. So you want to try it?
• https://learngraphql.com/
• create an account on https://admin.sphere.io/
• you can create a project with sample data
• try GraphQL with this account on https://
impex.sphere.io/graphiql