Skip to content

Commit

Permalink
lotta work on querying
Browse files Browse the repository at this point in the history
  • Loading branch information
ValdemarGr committed Sep 2, 2023
1 parent 517b5d8 commit 417ce01
Show file tree
Hide file tree
Showing 3 changed files with 204 additions and 116 deletions.
6 changes: 3 additions & 3 deletions modules/core/src/main/scala/gql/Arg.scala
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ object Arg {
}

sealed trait EmptyableArg[A] {
def addArg[F[_], B]: Resolver[F, B, B]
def addArg[F[_], B]: Resolver[F, B, (A, B)]
}
object EmptyableArg {
case object Empty extends EmptyableArg[Unit] {
override def addArg[F[_], B]: Resolver[F, B, B] = Resolver.id[F, B]
override def addArg[F[_], B]: Resolver[F, B, (Unit, B)] = Resolver.id[F, B].map(((), _))
}
final case class Lift[A](a: Arg[A]) extends EmptyableArg[A] {
override def addArg[F[_], B]: Resolver[F, B, B] = Resolver.id[F, B].arg(a).map{ case (_, x) => x }
override def addArg[F[_], B]: Resolver[F, B, (A, B)] = Resolver.id[F, B].arg(a)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ object SkunkSchema extends QueryAlgebra with QueryDsl {
def runQuery[F[_]: MonadCancelThrow, G[_], I, B, ArgType](
pool: Resource[F, Session[F]],
toplevelArg: EmptyableArg[ArgType],
q: (I, ArgType) => Query[G, B]
q: (NonEmptyList[I], ArgType) => Query[Lambda[X => List[G[X]]], B]
) = {
resolveQuery[F, G, I, B, ArgType](toplevelArg, q).evalMap { case (qc, d: Interpreter.Done[G, a, QueryResult[B]]) =>
resolveQuery[F, G, I, B, ArgType](toplevelArg, q).evalMap { case (qc, d: Interpreter.Done[Lambda[X => List[G[X]]], a, QueryResult[B]]) =>
val af = Interpreter.renderQuery(qc)
println(af.fragment.sql)
val out: F[List[a]] = pool.use(_.execute(af.fragment.query(d.dec))(af.argument))
Expand Down Expand Up @@ -65,7 +65,8 @@ object SkunkSchema extends QueryAlgebra with QueryDsl {
}
}

def lazyPool[F[_]: Concurrent](pool: Resource[F, Session[F]]): Resource[F, LazyResource[F, Session[F]]] =
type Connection[F[_]] = LazyResource[F, Session[F]]
def lazyPool[F[_]: Concurrent](pool: Resource[F, Session[F]]): Resource[F, Connection[F]] =
LazyResource.fromResource(pool)
}

Expand Down
Loading

0 comments on commit 417ce01

Please sign in to comment.