GraphQL

GraphQL is a query language for APIs and a runtime for fulfilling those queries with your existing data. GraphQL provides a complete and understandable description of the data in your API, gives clients the power to ask for exactly what they need and nothing more, makes it easier to evolve APIs over time, and enables powerful developer tools.

Petr Šnobelt / @petrsnobelt

Agenda

  • GraphQL introduction
  • Ipex journey
  • Samples
  • Advanced features
  • Discussion

GraphQL facts

Základní charakteristika

  • NewAge API 😀
  • StrongTyped
  • DB/Data source independent
  • GraphQL servers are available for all major languages

Allows clients to dictate what data is needed

RestAPI problems

  1. multiple requests
  2. overfetching
  3. documentation
  4. realtime (websockets)

#1 multiple requests

Je možné skládat více dotazů do jednoho

Je možné se zeptat na objednávku, její řádky i odběratele najednou

#2 overfetching

Klient si může vybrat které data chce

#3 documentation

Api je dokumentované pomocí typů a komentářů

Protože si klient vybírá, jaké data chce není tak velká potřeba api verzovat

#4 realtime
subscriptions

Je možné se přihlásit k odběru dat pomocí websockets

Firmy využívající graphQL

IPEX way to graphQL

  1. Internal workshop
  2. Basic skeleton tested using GraphiQL
  3. Subscriptions
  4. Use storybook for components
  5. Win 😄

Live coding, samples

Server

  • Basic query and mutation
  • More query samples
  • Add subscription

Live coding, samples

Client

  • Basic react component
  • React component with subscription
  • Show end result
  • devtools

Our Troubles

  • Caching
  • Authorizations
  • Apollo client internals
    • Data “normalization”
    • Set correct keys
  • Subscriptions monitoring

Problémy graphQL

  • relativně "mladá" technologie
  • problémy(nevyužití) s http cachováním
    (používá POST)
  • Query N+1 problém
    řešením je dataloader
  • LoadBalancing subscriptions
    stejné jako u websocketů

Hidden features

  • Different schemas
  • Input validation
  • Declarativní zápis jaké data komponenta potřebuje
  • “Remove complexity while building frontend clients”

Advanced features of

Apollo client 2.0

Sample of advanced features

If time permits

  • Using graphQL for rest
  • Using graphql for local storage
  • Custom resolvers

Stojí to za to?

  • as always - it depend on project
  • in our case yes
  • ...but you should try it

Resources I/II

Articles

Resources II/II

Tools

Děkuji za pozornost

Otázky?


Petr Šnobelt
petr.snobelt@gmail.com
@petrsnobelt