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

GraphQL on Scala

GraphQL on Scala

Introduction for GraphQL and implementing GraphQL API using Scala.

petitviolet

June 28, 2018
Tweet

More Decks by petitviolet

Other Decks in Programming

Transcript

  1. งғؾ case class MyObject(id: Long, name: String) val myObjectType: ObjectType[Unit,

    MyObject] = derive.deriveObjectType() val myQuery: ObjectType[MyObjectRepository, Unit] = { ObjectType.apply( "MyQuery", fields[MyObjectRepository, Unit]( { val idArg = Argument("id", LongType) Field( "findById", OptionType(myObjectType), arguments = idArg :: Nil, resolve = ctx => ctx.ctx.findById(ctx.arg(idArg))) }, Field("all", ListType(myObjectType), resolve = ctx => Future { ctx.ctx.findAll }) ) ) } 13
  2. งғؾ case class MyObject(id: Long, name: String) val myObjectType: ObjectType[Unit,

    MyObject] = derive.deriveObjectType() val myQuery: ObjectType[MyObjectRepository, Unit] = { ObjectType.apply( "MyQuery", fields[MyObjectRepository, Unit]( { val idArg = Argument("id", LongType) Field( "findById", OptionType(myObjectType), arguments = idArg :: Nil, resolve = ctx => ctx.ctx.findById(ctx.arg(idArg))) }, Field("all", ListType(myObjectType), resolve = ctx => Future { ctx.ctx.findAll }) ) ) } (SBQI2-ͷUZQF 14
  3. งғؾ case class MyObject(id: Long, name: String) val myObjectType: ObjectType[Unit,

    MyObject] = derive.deriveObjectType() val myQuery: ObjectType[MyObjectRepository, Unit] = { ObjectType.apply( "MyQuery", fields[MyObjectRepository, Unit]( { val idArg = Argument("id", LongType) Field( "findById", OptionType(myObjectType), arguments = idArg :: Nil, resolve = ctx => ctx.ctx.findById(ctx.arg(idArg))) }, Field("all", ListType(myObjectType), resolve = ctx => Future { ctx.ctx.findAll }) ) ) } ܕͷࣗಈಋग़ 15
  4. งғؾ case class MyObject(id: Long, name: String) val myObjectType: ObjectType[Unit,

    MyObject] = derive.deriveObjectType() val myQuery: ObjectType[MyObjectRepository, Unit] = { ObjectType.apply( "MyQuery", fields[MyObjectRepository, Unit]( { val idArg = Argument("id", LongType) Field( "findById", OptionType(myObjectType), arguments = idArg :: Nil, resolve = ctx => ctx.ctx.findById(ctx.arg(idArg))) }, Field("all", ListType(myObjectType), resolve = ctx => Future { ctx.ctx.findAll }) ) ) } DPOUFYUͱͯ͠ 3FQPTJUPSZΛ࢖༻ 16
  5. งғؾ case class MyObject(id: Long, name: String) val myObjectType: ObjectType[Unit,

    MyObject] = derive.deriveObjectType() val myQuery: ObjectType[MyObjectRepository, Unit] = { ObjectType.apply( "MyQuery", fields[MyObjectRepository, Unit]( { val idArg = Argument("id", LongType) Field( "findById", OptionType(myObjectType), arguments = idArg :: Nil, resolve = ctx => ctx.ctx.findById(ctx.arg(idArg))) }, Field("all", ListType(myObjectType), resolve = ctx => Future { ctx.ctx.findAll }) ) ) } OVMMBCMF͸0QUJPOͰදݱ 17
  6. งғؾ case class MyObject(id: Long, name: String) val myObjectType: ObjectType[Unit,

    MyObject] = derive.deriveObjectType() val myQuery: ObjectType[MyObjectRepository, Unit] = { ObjectType.apply( "MyQuery", fields[MyObjectRepository, Unit]( { val idArg = Argument("id", LongType) Field( "findById", OptionType(myObjectType), arguments = idArg :: Nil, resolve = ctx => ctx.ctx.findById(ctx.arg(idArg))) }, Field("all", ListType(myObjectType), resolve = ctx => Future { ctx.ctx.findAll }) ) ) } ඇಉظॲཧ 'VUVSF ͕؆୯ 18
  7. 4DBMBͰ(SBQI2-͢Δ w 4BOHSJB͸ػೳ͕े෼ʹଗ͍ͬͯΔ w ඇಉظॲཧ w ϚΫϩʹΑΔUZQFͷࣗಈಋग़ w +40/ͱͷ૬ޓม׵ w

    DBTFDMBTTͱ(SBQI2-Λ+40/͕ܨ͙ w / ໰୊ղܾ w 'FUDIFS%FGFSSFE3FTPMWFS w 3FMBZαϙʔτ w TBOHSJBHSBQIRMTBOHSJBSFMBZ 19
  8. (SBQI2-Λ࢖ͬͯΈͯͲ͏͔ w ײ૝ͱͯ͠ɺ(SBQI2-ʹͯ͠ྑ͔ͬͨ w ͍ΖΜͳ͜ͱ͔Βղ์͞Εͨ w ʮͱΓ͋͑ͣશ෦ฦ͔͢Β͋ͱΑΖ͘͠ʯͷָ͞ w ؔ࿈ΦϒδΣΫτ͸SFTPMWFͰؤு࣮ͬͯ૷ w

    ͿͬͪΌ͚Ͳ͏࢖ͬͯΔ͔Α͘஌Βͳ͍ w 4DBMBͱ(SBQI2-ܕ࢓༷ͷ૬ੑͷྑ͞ w ૉ௚ʹදݱͰ͖Δ҆͠શʹָʹ։ൃͰ͖Δ w OPOOVMMΛίϯύΠϥͰڧ੍Ͱ͖Δ 21