Last active
June 11, 2020 20:07
-
-
Save anotherhale/dc2a56b59e8e3572c18da7e7f28793ec to your computer and use it in GitHub Desktop.
Train App - not sure how to call the `allStations` query
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package client | |
| import client.TrainClient._ | |
| import sttp.client._ | |
| import sttp.client.asynchttpclient.zio.{ AsyncHttpClientZioBackend, SttpClient } | |
| import zio.console.putStrLn | |
| import zio.{ App, ExitCode, ZIO } | |
| object TrainApp extends App { | |
| case class Train(`type`: String, platform: String, trainNumber: String, time: String, stops: List[String]) | |
| override def run(args: List[String]): ZIO[zio.ZEnv, Nothing, ExitCode] = { | |
| val trainInStation = | |
| (TrainInStation.`type` ~ | |
| TrainInStation.platform ~ | |
| TrainInStation.trainNumber ~ | |
| TrainInStation.time ~ | |
| TrainInStation.stops).mapN(Train) | |
| val query = | |
| Query.search(Some("Berlin Ostbahnhof")) { | |
| Searchable.stations { | |
| Station.name ~ | |
| Station.hasWiFi ~ | |
| Station.timetable { | |
| Timetable.nextDepatures { | |
| trainInStation | |
| } ~ | |
| Timetable.nextArrivals { | |
| trainInStation | |
| } | |
| } | |
| } | |
| } | |
| val q = | |
| // fails to compile with the following error: | |
| // [error] ~/caliban-blog-series/src/main/scala/client/TrainApp.scala:38:24: not enough arguments for method allStations: (innerSelection: caliban.client.SelectionBuilder[client.TrainClient.Station,A])caliban.client.SelectionBuilder[caliban.client.Operations.RootQuery,Option[List[Option[A]]]]. | |
| // [error] Unspecified value parameter innerSelection. | |
| // [error] Query.allStations(){ | |
| Query.allStations(){ | |
| Station.name ~ | |
| Station.hasWiFi ~ | |
| Station.timetable { | |
| Timetable.nextDepatures { | |
| trainInStation | |
| } ~ | |
| Timetable.nextArrivals { | |
| trainInStation | |
| } | |
| } | |
| } | |
| val uri = uri"https://bahnql.herokuapp.com/graphql" | |
| SttpClient | |
| .send(query.toRequest(uri)) | |
| .map(_.body) | |
| .absolve | |
| .tap(res => putStrLn(s"Result: $res")) | |
| .provideCustomLayer(AsyncHttpClientZioBackend.layer()) | |
| .foldM(ex => putStrLn(ex.toString).as(ExitCode.failure), _ => ZIO.succeed(ExitCode.success)) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment