GraphQL In Real Life

GraphQL In Real Life

6923bdeb363961b064d2cdb6329982d6?s=128

Roberto Orgiu

April 05, 2019
Tweet

Transcript

  1. film character species homeworld episode

  2. film character species homeworld episode GR APHQL IN REAL L

    IFE ROBERTO ORGIU - @_TIWIZ
  3. the problem

  4. the portrait version I N T R O D U

    C I N G
  5. the landscape version W H I C H B E

    C O M E S
  6. Fun fact GraphQL.replace(REST) usually returns false

  7. Architectural Pattern Query Language

  8. Leverage Protocol Use own Conventions

  9. Versioning Evolution

  10. Full request Client Performances

  11. Ease of Caching DIY Cache

  12. Query Strings Query Language

  13. Multiple Endpoints Single Endpoint

  14. Unified Precise

  15. What is GraphQ What is GraphQL? D E E P

    D I V E I N T O
  16. graphqlbin.com GraphQLBin insomnia.rest/graphql Insomnia altair.sirmuel.design Altair swapi.graph.cool GraphCool graphql.org/swapi-graphql GraphiQL

  17. None
  18. WHY APOLLO? Compile time safety Caching Community Code generation

  19. buildscriptT{ repositoriesT{ google()T }A dependenciesT{ classpathA"com.android.tools.build:gradle:$tools_version" classpathB"org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" }B }C allprojectsT{

    repositoriesB{ google()B }D }E
  20. buildscriptT{ repositoriesT{ google()T jcenter() }A dependenciesT{ classpathA"com.android.tools.build:gradle:$tools_version" classpathB"org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "com.apollographql.apollo:gradle-plugin:$apollo_version"

    }B }C allprojectsT{ repositoriesB{ google()B jcenter() }D }E
  21. buildscriptT{ repositoriesT{ google()T jcenter() }A dependenciesT{ classpathA"com.android.tools.build:gradle:$tools_version" classpathB"org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "com.apollographql.apollo:gradle-plugin:$apollo_version"

    }B }C allprojectsT{ repositoriesB{ google()B jcenter() }D }E
  22. apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' android

    { ... }
  23. apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' apply

    plugin: 'com.apollographql.android' android { ... }
  24. dependencies { ... implementation "com.apollographql.apollo:apollo-runtime:$apollo_version" implementation "com.apollographql.apollo:apollo-rx2-support:$apollo_version" ... }

  25. DOWNSIDES Apollo-plugin schema.json *.graphql X X

  26. testing

  27. testing Compile time safety MockWebServer

  28. > Task :apollo:generateDebugApolloIR FAILED .../android/apollo/Query.graphql: Cannot query field "nam" on

    type "YourType". Did you mean "name"? error: Validation of GraphQL query document failed FAILURE: Build failed with an exception.
  29. @get:Rule val mockWebServer = MockWebServerRule() mockWebServer.enqueueResponse("/response.json") val testApolloClient = ApolloClient.builder()

    .serverUrl(mockWebServer.url) .okHttpClient(client) .build()
  30. WHY?

  31. CDN Android Back end Cache 8 KB limit

  32. Solutions 2 solutions O k H t t p I

    n t e r c e p t o r A u t o m a t i c P e r s i s t e d Q u e r i e s W e f o u n d
  33. query filmById($filmId: ID){ film(filmID :$filmId){ title episodeID characterConnectionT{ charactersT{ name

    homeworldT{ name }A speciesT{ name classification }B filmConnectionT{ filmsT{ title episodeID }C }D }E }F }G }H A u t o m a t i c P e r s i s t e d Q u e r i e s
  34. query filmById($filmId: ID){ film(filmID :$filmId){ title episodeID characterConnectionT{ charactersT{ name

    homeworldT{ name }A speciesT{ name classification }B filmConnectionT{ filmsT{ title episodeID }C }D }E }F }G }H A u t o m a t i c P e r s i s t e d Q u e r i e s variables { "filmId" : 1 }A query: query filmById($filmId: ID) { film(filmId :$filmId) { title episodeID characterConnection { name homeworld{ name }B species { name classification }C filmConnection { films { title episodeID }D }E }F }G }H operationName: filmById
  35. query filmById($filmId: ID){ film(filmID :$filmId){ title episodeID characterConnectionT{ charactersT{ name

    homeworldT{ name }A speciesT{ name classification }B filmConnectionT{ filmsT{ title episodeID }C }D }E }F }G }H A u t o m a t i c P e r s i s t e d Q u e r i e s variables { "filmId" : 1 }A query: query filmById($filmId: ID) { film(filmId :$filmId) { title episodeID characterConnection { name homeworld{ name }B species { name classification }C filmConnection { films { title episodeID }D }E }F }G }H operationName: filmById operationName: filmById variables { "filmId" : 1 }T
  36. query filmById($filmId: ID){ film(filmID :$filmId){ title episodeID characterConnectionT{ charactersT{ name

    homeworldT{ name }A speciesT{ name classification }B filmConnectionT{ filmsT{ title episodeID }C }D }E }F }G }H A u t o m a t i c P e r s i s t e d Q u e r i e s variables { "filmId" : 1 }A query: query filmById($filmId: ID) { film(filmId :$filmId) { title episodeID characterConnection { name homeworld{ name }B species { name classification }C filmConnection { films { title episodeID }D }E }F }G }H operationName: filmById operationName: filmById variables { "filmId" : 1 }T
  37. A u t o m a t i c P

    e r s i s t e d Q u e r i e s operationName: filmById variables { "filmId" : 1 }T extensions: { persistedQuery: { "version": 1, "sha256Hash": "queryHash" } }
  38. Android Back end Query Hash Query Hash Not Found Whole

    Query + Query Hash Response
  39. @get:Rule valTmockWebServerT=TMockWebServerRule() mockWebServer.enqueueResponse(“/response.json") valTurlT=TmockWebServer.url valßapolloClientT= ApolloClient.builder() .serverUrl(url) .okHttpClient(client) .build()

  40. valßapolloClientT= ApolloClient.builder() .serverUrl(url) .okHttpClient(client) .build()

  41. valßapolloClientT= ApolloClient.builder() .serverUrl(url) .okHttpClient(client) .enableAutoPersistedQueries(true) .build()

  42. Tricks Tricks J U S T S O M E

    query SampleQuery { assetID: sourceId fingerprint: modified headlineInfo: headline { __typename headline: default }A lastUpdated: lastModification }B
  43. Tricks Tricks L A B E L F I E

    L D S C A N G O A L O N G D I S T A N C E J U S T S O M E query SampleQuery { assetID: sourceId fingerprint: modified headlineInfo: headline { __typename headline: default }A lastUpdated: lastModification }B
  44. Tricks Tricks A P O L L O A D

    D S T Y P E N A M E E V E R Y W H E R E J U S T S O M E query SampleQuery { assetID: sourceId fingerprint: modified headlineInfo: headline { __typename headline: default }A lastUpdated: lastModification }B
  45. Tricks Tricks S C H E M A A N

    D Q U E R I E S C A N B E M O V E D J U S T S O M E apollo { schemaFilePath = "/path/my-schema.json" outputPackageName = "pkg.graphql.api" }
  46. Tricks Tricks S U P P O R T S

    F O R J A V A B E A N S E M A N T I C S J U S T S O M E class Type { public Another getAnother() { ... } } //build.gradle apollo { useJavaBeansSemanticNaming = true }
  47. Tricks Tricks R E M E M B E R

    T O B E O N L I N E ¯ \ _ ( ツ ) _ / ¯ J U S T S O M E
  48. THANK YOU!