Skip to content

Commit

Permalink
query wrok
Browse files Browse the repository at this point in the history
  • Loading branch information
ValdemarGr committed Sep 3, 2023
1 parent 6a3a3d7 commit efe9741
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,20 @@ trait QueryAlgebra {
fa: Query[G, A],
f: A => Query[H, B]
) extends Query[Lambda[X => G[H[X]]], B]
case class ToList[G[_], A](fa: Query[G, A]) extends Query[List, A]
case class MapK[G[_], H[_], A](
fa: Query[G, A],
f: G ~> H
) extends Query[H, A]
case class Select[A](cols: Chain[Frag], decoder: Decoder[A]) extends Query[Lambda[X => X], Select[A]]
implicit lazy val applicativeForSelect: Applicative[Select] = new Applicative[Select] {
override def pure[A](x: A): Select[A] =
Select(Chain.empty, Applicative[Decoder].pure(x))
object Select {
implicit lazy val applicativeForSelect: Applicative[Select] = new Applicative[Select] {
override def pure[A](x: A): Select[A] =
Select(Chain.empty, Applicative[Decoder].pure(x))

override def ap[A, B](ff: Select[A => B])(fa: Select[A]): Select[B] =
Select(ff.cols ++ fa.cols, ff.decoder ap fa.decoder)
override def ap[A, B](ff: Select[A => B])(fa: Select[A]): Select[B] =
Select(ff.cols ++ fa.cols, ff.decoder ap fa.decoder)
}
}
}

Expand Down Expand Up @@ -446,6 +449,16 @@ trait QueryAlgebra {
case p: Query.Pure[a] => Effect.pure(QueryStateImpl(JoinType.One.reassoc[Unit], ().pure[Decoder], p.a, FunctionK.id[G]))
case s: Query.Select[a] => Effect.pure(QueryStateImpl(JoinType.One.reassoc[Unit], ().pure[Decoder], s, FunctionK.id[G]))
case fm: Query.FlatMap[g, h, a, b] => handleFlatMap(fm)
case toList: Query.ToList[g, a] =>
collapseQuery(toList.fa).map{ qs =>
QueryStateImpl(
JoinType.joinTypeList.reassoc[Unit],
().pure[Decoder],
qs.value,
FunctionK.id[List]
)
}
???
case j: Query.Join[g, t] =>
for {
n <- nextId
Expand Down
24 changes: 14 additions & 10 deletions modules/relational/src/main/scala/gql/relational/QueryDsl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,20 @@ trait QueryDsl extends QueryAlgebra { self =>
)(f: (A, C) => Query[G, Query.Select[B]])(g: Resolver[F, G[B], G[B]] => Resolver[F, G[B], D])(implicit
tpe: => Out[F, D]
): Field[F, QueryResult[A], D] =
/* queryFull(EmptyableArg.Lift(a))((a, c) => f(a, c), g(Resolver.id[F, G[B]]))(tpe)
def contBoundary[G[_], B, C, D](connection: Connection[F])(f: A => Query[G, Query.Select[B]])(
continue: NonEmptyList[B] => Query[G, C]
)(implicit F: Applicative[F], Q: Queryable[F], tpe: => Out[F, G[QueryResult[B]]]) =
Field(
queryFull(EmptyableArg.Empty)((i, _) => q(a), Resolver.id[F, G[B]])(tpe)
)
Field(queryAndThen(f)(_.andThen(resolveQuery(EmptyableArg.Empty, (i, _) => q(i), connection))), Eval.later(tpe))
*/
queryFull(EmptyableArg.Lift(a))((a, c) => f(a, c), g(Resolver.id[F, G[B]]))(tpe)

def contBoundary[G[_], H[_], B, C, D](connection: Connection[F])(f: A => Query[G, Query.Select[B]])(
continue: NonEmptyList[List[B]] => Query[H, (Query.Select[List[B]], C)]
)(implicit F: Applicative[F], Q: Queryable[F], tpe: => Out[F, H[QueryResult[C]]]) =
queryFull[F, List, A, B, Unit, H[QueryResult[C]]](EmptyableArg.Empty)((i, _) => Query.ToList(f(i)), Resolver.id[F, List[B]].andThen(
resolveQuery[F, H, List[B], C, Unit](
EmptyableArg.Empty,
(i, _) => continue(i),
connection
)
)
)(tpe)

def query[G[_], B](f: A => Query[G, Query.Select[B]])(implicit
tpe: => Out[F, G[B]]
): Field[F, QueryResult[A], G[B]] =
Expand Down

0 comments on commit efe9741

Please sign in to comment.