GraphQL GatewayをNode.jsで作ってる話

GraphQL GatewayをNode.jsで作ってる話

704247f4d70f1f25f40331f0f9124eb1?s=128

Haruhiko Kobayashi

December 07, 2018
Tweet

Transcript

  1. GraphQL GatewayΛ Node.jsͰ࡞ͬͯΔ࿩ haruhiko kobayashi 2018/12/6

  2. !2 ࣗݾ঺հ Haruhiko Kobayashi Chief Tech Lead εϖʔεϚʔέοτ yahooͷόοΫΤϯυΤϯδχΞ ग़਎Ͱ͢ɻϑϩϯτΤϯυͱΠϯ

    ϑϥ΋Ұ௨Γ͔ͬͨ͡ͷͪʹεϖʔ εϚʔέοτʹJoin
  3. !3 Agenda

  4. !4 Agenda • GraphQLͷ͝঺հ • Microservicesͱͷ૊Έ߹Θͤ • GraphQL Gateway on

    Node.js
  5. GraphQLͷ͝঺հ

  6. !6 GraphQLͷ͝঺հ • Facebook͕ఏএͨ͠API࢓༷ • ڧ͍ܕγεςϜ • ࢀরܥ͸query • ߋ৽ܥ͸mutation

    • RESTͱରൺͯ͠ޠΒΕΔࣄ͕ଟ͍ جຊతͳ࿩
  7. !7 GraphQLͷ͝঺հ • Partial Response • Batch Request • graphdoc

    • Graphiql σϑΥϧτػೳ
  8. !8 Partial Response ࢦఆͨ͠σʔλͷΈऔಘ

  9. !9 Batch Request 1౓ͷAPIίʔϧͰෳ਺ͷϦιʔεΛऔಘՄೳ

  10. !10 graphdoc GraphQL API͔ΒυΩϡϝϯτࣗಈੜ੒

  11. !11 graphdoc GraphQL API͔ΒυΩϡϝϯτࣗಈੜ੒ confidential

  12. !12 GraphiQL GraphQLͷΫΤϦ࣮ߦ؀ڥ

  13. !13 ಋೖ࣌ظ 2017೥ࠒ͔Β෦෼తʹಋೖ • Client: Apollo Client • Server: Rails

    RESTͱൺ΂ͨ։ൃମݧ • FEɾΞϓϦ։ൃऀ͔Β૬౰ָʹͳͬͨͱ͍͏੠ • BEͱͯ͠΋ແବͳϖΠϩʔυ࡟ݮͳͲϝϦοτ͸ଟ͍
  14. Microservicesͱͷ૊Έ߹Θͤ

  15. !15 Microservicesͱͷ૊Έ߹Θͤ • ݕࡧαʔϏε • ΞΧ΢ϯταʔϏε • ϦίϝϯυαʔϏε • etc..

    ڊେͳREST API͔ΒGraphQLαʔϏεΛ੾Γग़͠த
  16. !16 Microservicesͱͷ૊Έ߹Θͤ API͕ଟ͗ͯ͢frontendͷਏΈ͕༧૝͞ΕΔ ݕࡧ (GraphQL) Ϩίϝϯυ (REST) ΞΧ΢ϯτ (GraphQL) ༧໿

    (REST) FE
  17. !17 Microservicesͱͷ૊Έ߹Θͤ GraphQL GatewayΛrubyͰ࡞ͬͨ ݕࡧ (GraphQL) Ϩίϝϯυ (REST) ΞΧ΢ϯτ (GraphQL)

    ༧໿ (REST) FE gateway
  18. !18 Microservicesͱͷ૊Έ߹Θͤ Gateway͸remoteͷAPIʹϦΫΤετͯ݁͠ՌΛฦ͢

  19. !19 Microservicesͱͷ૊Έ߹Θͤ resolverͰผAPIΛୟ͘ confidential

  20. !20 Microservicesͱͷ૊Έ߹Θͤ resolverͰผAPIΛୟ͘

  21. !21 Microservicesͱͷ૊Έ߹Θͤ ՝୊1: GraphQLͷܕΤϥʔʹͳΔ confidential • GraphQL͸ఆٛ͞Ε͍ͯͳ͍ܕ͕ΫΤϦʹؚ·ΕΔͱΤϥʔ ʹͳΔ

  22. !22 Microservicesͱͷ૊Έ߹Θͤ ՝୊1: GraphQLͷܕΤϥʔʹͳΔ • GraphQLͷΫΤϦΛղੳͯ͠༨ܭͳ΋ͷΛফ͢ॲཧΛॻ͍ͯ ରԠ

  23. !23 Microservicesͱͷ૊Έ߹Θͤ ՝୊2: Blocking IO confidential • ruby͸Blocking IO͕ඪ४ͷͨΊΫΤϦ͕૿͑ΔͱͲΜͲΜ஗ ͘ͳΔ

  24. !24 Microservicesͱͷ૊Έ߹Θͤ ՝୊2: Blocking IO • ΫΤϦͷ࣮ߦΛ஗ԆධՁͯ͠1ͭͷΫΤϦʹ·ͱΊ࣮ͯߦ • graphql-batchͱ͍͏ϥΠϒϥϦͰରԠ͸Մೳ

  25. !25 Microservicesͱͷ૊Έ߹Θͤ ՝୊2: Blocking IO • ̎ͭͷϦΫΤετΛ஗ԆධՁͤͯ͞1ͭͷϦΫΤετʹ߹੒

  26. !26 Microservicesͱͷ૊Έ߹Θͤ ՝୊2: Blocking IO confidential • ̎ͭͷϦΫΤετΛ஗ԆධՁͤͯ͞1ͭͷϦΫΤετʹ߹੒

  27. !27 Microservicesͱͷ૊Έ߹Θͤ ͜͜·Ͱͷ·ͱΊ • ৭ʑ͕Μ͹͕ͬͨෳ਺APIΤϯυϙΠϯτͱͳΔͱॲཧ͕ṫ ࡶʹͳΔ • rubyͷಛੑ͸GraphQL Gatewayʹ͸޲͍ͯͳͦ͞͏ •

    Node.js΁ͷҠ২Λݕ౼͠͸͡ΊΔ
  28. GraphQL Gateway on Node.js

  29. !29 Apollo Server Node.jsͷGraphQL Server࣮૷ • jsͰGraphQL API࡞Δʹ͸σϑΝΫτελϯμʔυ • Gatewayͱͯ͠ಈ͘ػೳ΋ఏڙ͍ͯ͠Δ

    • (ਖ਼֬ʹ͸graphql-toolsύοέʔδʹ)
  30. !30 ՝୊1: GraphQLͷܕΤϥʔʹͳΔ ղܾࡦ: Schema Stitching • remoteͷGraphQL APIΛ͔͋ͨ΋localͷGraphQL APIͱͯ͠

    ѻ͏ػೳͷ͜ͱ
  31. !31 Schema Stitching ͭ·Γ͜Εͷ͜ͱͰ͢ ݕࡧ (GraphQL) Ϩίϝϯυ (REST) ΞΧ΢ϯτ (GraphQL)

    ༧໿ (REST) FE gateway
  32. !32 ՝୊1: GraphQLͷܕΤϥʔʹͳΔ ղܾ: Schema Stitching confidential • remoteͷGraphQL APIΛlocalͷGraphQL

    APIͱͯ͠ѻ͏
  33. !33 ՝୊1: GraphQLͷܕΤϥʔʹͳΔ ղܾ: Schema Stitching • 1ͭͷqueryΛผͷAPI͔ΒऔಘͰ͖ΔΑ͏ʹͳΔ

  34. !34 ՝୊1: GraphQLͷܕΤϥʔʹͳΔ ղܾ: Schema Stitching • rubyͰؤுͬͯ࡞࣮ͬͨ૷͕20ߦ΄Ͳͷ࣮૷ͰղܾͰ͖ͨ • ׬શʹٕज़࠾୒ͷࣦഊ..

  35. !35 ՝୊2: Blocking IO ղܾ:NodeͷಛੑΛੜ͔ͯ͠Non-Blocking IOͰ௨৴ͯ͘͠ΕΔ confidential

  36. !36 ՝୊2: Blocking IO ղܾ:NodeͷಛੑΛੜ͔ͯ͠Non-Blocking IOͰ௨৴ͯ͘͠ΕΔ

  37. ·ͱΊ

  38. !38 • ݴޠͷಛੑΛݟۃΊͯϛυϧ΢ΣΞ͸ઃܭ͢΂͖ • GraphQL GatewayελοΫ΋javascriptͰ࣮૷

  39. None