I know beginnings,
I know endings too,
and life-in-death, and something else
I'd rather not recall just now.
First encounter
We met in an unbelievable year,
When the world's strength was at an ebb
I marvel at everything as if it were new.
Getting to know better
type Poet {
name: String!
nationality: String!
literatureMovement: String!
poems: [Poem]
bornIn: Int!
diedIn: Int!
}
type Query {
poets: [Poet]
}
const resolvers = {
Query: {
poets: () => {
// Here would be the logic for getting all the poets
// But this time we'll just return an object
return [{
name: 'Anna Akhmatova',
nationality: 'Russian / Soviet',
literatureMovement: 'Acmeism',
poems: [/* Here would be the poems */],
bornIn: 1889,
diedIn: 1966
}]
}
}
}
Forgive me that I ignored the sun
And that I lived in sorrow.
The crush
[{
"id": 1,
"name": "Anna Akhmatova",
"nationality": "Russian / Soviet",
"literatureMovement": "Acmeism",
"bornIn": 1889,
"diedIn": 1966
},
...
]
GET /poets/
query {
poets {
name
}
}
{
"data": {
"poets": [
{
"name": "Anna Akhmatova"
},
{
"name": "Marina Tsvetaeva"
},
...
]
}
}
GET /poets/1/
GET /poets/1/poems
{
"id": 1,
"name": "Anna Akhmatova",
"nationality": "Russian / Soviet",
"literatureMovement": "Acmeism",
"bornIn": 1889,
"diedIn": 1966
}
[{
"name": "Requiem",
...
},
...
]
query {
poet(id: 1) {
name
poems {
name
}
}
}
{
"data": {
"poet": {
"name": "Anna Akhmatova",
"poems": [{
"name": "Requiem"
},
...
]
}
}
}
Each of our lives is a Shakespearean drama raised to the thousandth degree.
The conflict
This is only the beginning
You're tender and loyal, we'll be friends.
const query = gql`
query {
poet @rest(type: "Poet", path: "poets/1/") {
name
}
}
`;
{
"data": {
"poet": {
"name": "Anna Akhmatova"
}
}
}