GraphQL,

you're intuitive and flexible,

we'll be friends

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

Query

Mutation

Subscription

Schema

type Poet {
  name: String!
  nationality: String!
  literatureMovement: String!
  poems: [Poem]
  bornIn: Int!
  diedIn: Int!
}

type Query {
  poets: [Poet]
}

Resolvers

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

Get what you actually need

[{
  "id": 1,
  "name": "Anna Akhmatova",
  "nationality": "Russian / Soviet",
  "literatureMovement": "Acmeism",
  "bornIn": 1889,
  "diedIn": 1966
},
...
]
GET /poets/

Get what you actually need

query {
  poets {
    name
  }
}
{
  "data": {
    "poets": [
      {
        "name": "Anna Akhmatova"
      },
      {
        "name": "Marina Tsvetaeva"
      },
      ...
    ]
  }
}

Get what you actually need

GET /poets/1/
GET /poets/1/poems
{
  "id": 1,
  "name": "Anna Akhmatova",
  "nationality": "Russian / Soviet",
  "literatureMovement": "Acmeism",
  "bornIn": 1889,
  "diedIn": 1966
}
[{
  "name": "Requiem",
  ...
},
  ...
]

Get what you actually need

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

ERRor Handling

N+1 problem

This is only the beginning

You're tender and loyal, we'll be friends.

State management with

Apollo client

directives

directives

const query = gql`
  query {
    poet @rest(type: "Poet", path: "poets/1/") {
      name
    }
  }
`;
{
  "data": {
    "poet": {
      "name": "Anna Akhmatova"
    }
  }
}

Links

GraphQL, you're intuitive and flexible, we'll be friends

By Eevis Panula

GraphQL, you're intuitive and flexible, we'll be friends

All the quotes are from Anna Akhmatova

  • 1,404