Skip to content

Commit

Permalink
Update zio-query to 0.6.0 (#2037)
Browse files Browse the repository at this point in the history
* Update zio-query to 0.6.0

* Fix examples and test compiling
  • Loading branch information
kyri-petrou authored Dec 13, 2023
1 parent 7e005e0 commit 4760c24
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ val zioInteropCats2Version = "22.0.0.0"
val zioInteropCats3Version = "23.0.0.8"
val zioInteropReactiveVersion = "2.0.2"
val zioConfigVersion = "3.0.7"
val zqueryVersion = "0.5.1"
val zqueryVersion = "0.6.0"
val zioJsonVersion = "0.6.2"
val zioHttpVersion = "3.0.0-RC4"
val zioOpenTelemetryVersion = "3.0.0-RC15"
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/caliban/execution/Executor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ object Executor {
ZStream.succeed(resp) ++ makeDeferStream(more, cache)
})

ZStream.mergeAll(1)(defers.map(run): _*)
ZStream.mergeAllUnbounded()(defers.map(run): _*)
}

def runIncrementalQuery(
Expand Down
24 changes: 14 additions & 10 deletions examples/src/main/scala/example/optimizations/OptimizedTest.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package example.optimizations

import caliban.schema.Schema
import caliban.schema.ArgBuilder.auto._
import caliban._
import caliban.schema.ArgBuilder.auto._
import caliban.schema.Schema
import example.optimizations.CommonData._
import zio.Console.printLine
import zio.query.DataSource.fromFunctionBatchedZIO
Expand Down Expand Up @@ -57,44 +57,48 @@ object OptimizedTest extends ZIOAppDefault {
val UserDataSource: DataSource[Any, GetUser] = DataSource.Batched.make("UserDataSource") { requests =>
requests.toList match {
case head :: Nil =>
printLine("getUser").orDie.as(CompletedRequestMap.empty.insert(head)(Exit.succeed(fakeUser(head.id))))
printLine("getUser").orDie.as(CompletedRequestMap.empty.insert(head, Exit.succeed(fakeUser(head.id))))
case list =>
printLine("getUsers").orDie.as(list.foldLeft(CompletedRequestMap.empty) { case (map, req) =>
map.insert(req)(Exit.succeed(fakeUser(req.id)))
map.insert(req, Exit.succeed(fakeUser(req.id)))
})
}
}

case class GetEvent(id: Int) extends Request[Nothing, EventData]
val EventDataSource: DataSource[Any, GetEvent] =
fromFunctionBatchedZIO("EventDataSource")(requests => printLine("getEvents").as(requests.map(r => fakeEvent(r.id))))
fromFunctionBatchedZIO("EventDataSource")(requests =>
printLine("getEvents").orDie.as(requests.map(r => fakeEvent(r.id)))
)

case class GetViewerMetadataForEvents(id: Int) extends Request[Nothing, ViewerMetadata]
val ViewerMetadataDataSource: DataSource[Any, GetViewerMetadataForEvents] =
fromFunctionBatchedZIO("ViewerMetadataDataSource") { requests =>
printLine("getViewerMetadataForEvents").as(requests.map(_ => ViewerMetadata("")))
printLine("getViewerMetadataForEvents").orDie.as(requests.map(_ => ViewerMetadata("")))
}

case class GetVenue(id: Int) extends Request[Nothing, Venue]
val VenueDataSource: DataSource[Any, GetVenue] =
fromFunctionBatchedZIO("VenueDataSource")(requests => printLine("getVenues").as(requests.map(_ => Venue("venue"))))
fromFunctionBatchedZIO("VenueDataSource")(requests =>
printLine("getVenues").orDie.as(requests.map(_ => Venue("venue")))
)

case class GetTags(ids: List[Int]) extends Request[Nothing, List[Tag]]
val TagsDataSource: DataSource[Any, GetTags] =
fromFunctionBatchedZIO("TagsDataSource") { requests =>
printLine("getTags").as(requests.map(_.ids.map(id => Tag(id.toString))))
printLine("getTags").orDie.as(requests.map(_.ids.map(id => Tag(id.toString))))
}

case class GetViewerFriendIdsAttendingEvent(id: Int, first: Int) extends Request[Nothing, List[Int]]
val ViewerFriendDataSource: DataSource[Any, GetViewerFriendIdsAttendingEvent] =
fromFunctionBatchedZIO("ViewerFriendDataSource") { requests =>
printLine("getViewerFriendIdsAttendingEvent").as(requests.map(r => (1 to r.first).toList))
printLine("getViewerFriendIdsAttendingEvent").orDie.as(requests.map(r => (1 to r.first).toList))
}

case class GetUpcomingEventIdsForUser(id: Int, first: Int) extends Request[Nothing, List[Int]]
val UpcomingEventDataSource: DataSource[Any, GetUpcomingEventIdsForUser] =
fromFunctionBatchedZIO("UpcomingEventDataSource") { requests =>
printLine("getUpcomingEventIdsForUser").as(requests.map(r => (1 to r.first).toList))
printLine("getUpcomingEventIdsForUser").orDie.as(requests.map(r => (1 to r.first).toList))
}

def getUser(id: Int): ConsoleQuery[UserData] = ZQuery.fromRequest(GetUser(id))(UserDataSource)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ object TracingWrapperSpec extends ZIOSpecDefault {
override val identifier: String = "NamesDatasource"
override def run(requests: Chunk[GetName])(implicit trace: zio.Trace): ZIO[Any, Nothing, CompletedRequestMap] =
ZIO.succeed(requests.foldLeft(CompletedRequestMap.empty) { case (map, req) =>
map.insert(req)(Exit.succeed(req.name))
map.insert(req, Exit.succeed(req.name))
})
}

Expand Down

0 comments on commit 4760c24

Please sign in to comment.