Upgrade to Pro — share decks privately, control downloads, hide ads and more …

It Depends - Examining GraphQL Myths & Assumptions

It Depends - Examining GraphQL Myths & Assumptions

Marc-Andre Giroux

December 07, 2020
Tweet

More Decks by Marc-Andre Giroux

Other Decks in Programming

Transcript

  1. Marc-Andre Giroux - GraphQL Galaxy 2020
    It Depends
    Examining GraphQL Myths & Assumptions

    View Slide

  2. Marc-Andre Giroux
    GitHub

    Montreal, Canada

    View Slide

  3. It Depends

    View Slide

  4. Caching
    We’re thinking of using GraphQL

    as our API
    Terrible mistake! Say bye to
    caching.

    View Slide

  5. View Slide

  6. View Slide

  7. https://tools.ietf.org/html/rfc7234

    View Slide

  8. View Slide

  9. View Slide

  10. Solutions must be looked at from a
    specific context

    View Slide

  11. There’s some truth to it

    View Slide

  12. Conventions

    View Slide

  13. Flexibility vs Cache Hits

    View Slide

  14. Performance
    We’re thinking of using
    GraphQL as our API
    Cool! Why are you
    choosing GraphQL over
    other API styles?
    Because… performance!

    View Slide

  15. Is GraphQL faster than ____?

    View Slide

  16. GET /user
    {

    viewer {

    name

    age

    }

    }

    View Slide

  17. The trade-off, though, is that a uniform interface degrades efficiency, since information is transferred in a
    standardized form rather than one which is specific to an application's needs. The REST interface is
    designed to be efficient for large-grain hypermedia data transfer, optimizing for the common case of the
    Web, but resulting in an interface that is not optimal for other forms of architectural interaction.
    https://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm

    View Slide

  18. One Query to Rule them All

    View Slide

  19. viewer {

    contributionsCollection {

    commitContributionsByRepository {

    contributions {

    nodes {

    commitCount

    }

    }

    }

    }

    repositories(first: 100) {

    nodes {

    name

    issues(first: 100) {

    nodes {

    body

    }

    }

    }

    }

    issues(first: 100) {

    edges {

    node {

    author {

    login

    }

    }

    }

    }

    View Slide

  20. @defer & @stream

    View Slide

  21. viewer {

    contributionsCollection {

    commitContributionsByRepository {

    contributions {

    nodes {

    commitCount

    }

    }

    }

    }

    repositories(first: 100) @defer {

    nodes {

    name

    issues(first: 100) {

    nodes {

    body

    }

    }

    }

    }

    issues(first: 100) @defer {

    edges {

    node {

    author {

    login

    }

    }

    }

    }

    View Slide

  22. Full Circle?

    View Slide

  23. Make Tradeoffs, Mitigate Downsides

    View Slide

  24. Predictability

    View Slide

  25. BFF
    The Backend-For-Frontend Pattern

    View Slide

  26. https://samnewman.io/patterns/architectural/bff/

    View Slide

  27. BFFs are not only about
    representation

    View Slide

  28. Autonomy

    View Slide

  29. type User {

    name: String!

    age: Int!

    Friends: [User!]!

    }

    View Slide

  30. type User {

    name: String!

    nameForAndroid: String!

    age: Int!

    ageForThisOneClient: Int!

    friends: [User!]!

    friendsForXBOX: [XBOXFriend!]!

    }

    View Slide

  31. Complete Separation

    View Slide

  32. “One Graph”

    View Slide

  33. type User {

    name: String!

    nameForAndroid: String!

    age: Int!

    ageForThisOneClient: Int!

    friends: [User!]!

    friendsForXBOX: [XBOXFriend!]!

    }

    View Slide

  34. It Depends

    View Slide

  35. Why this is important

    View Slide

  36. We want GraphQL to succeed

    View Slide

  37. We want developers using GraphQL
    to succeed.

    View Slide

  38. In which context?

    View Slide

  39. Compared to what?

    View Slide

  40. What are the trade-offs?

    View Slide

  41. Thank You!
    @__xuorig__
    book.productionreadygraphql.com
    twitch.tv/graphqlfm - youtube.com/c/GraphQLFM/
    (30% OFF GRAPHQLGALAXY30)

    View Slide