From 12af7cbca6cc8491147198553a1ef1f734dfbb99 Mon Sep 17 00:00:00 2001 From: Valdemar Grange Date: Mon, 5 Feb 2024 18:55:51 +0100 Subject: [PATCH] fix: parse arg in parallel --- .../core/src/main/scala/gql/preparation/ArgParsing.scala | 2 +- modules/core/src/main/scala/gql/std/FreeApply.scala | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/modules/core/src/main/scala/gql/preparation/ArgParsing.scala b/modules/core/src/main/scala/gql/preparation/ArgParsing.scala index 43bf9d5d2..833863902 100644 --- a/modules/core/src/main/scala/gql/preparation/ArgParsing.scala +++ b/modules/core/src/main/scala/gql/preparation/ArgParsing.scala @@ -192,7 +192,7 @@ class ArgParsing[C](variables: VariableMap[C]) { if (tooMuch.isEmpty) G.unit else G.raise(s"Too many fields provided, unknown fields are ${tooMuch.toList.map(x => s"'$x'").mkString_(", ")}.", context) - val fv = arg.impl.foldMap[G, ValidatedNec[String, A]](new (Arg.Impl ~> G) { + val fv = arg.impl.parFoldMap[G, ValidatedNec[String, A]](new (Arg.Impl ~> G) { def apply[B](fa: Arg.Impl[B]): G[B] = fa match { case fa: ArgDecoder[a, B] => G.ambientField(fa.av.name) { diff --git a/modules/core/src/main/scala/gql/std/FreeApply.scala b/modules/core/src/main/scala/gql/std/FreeApply.scala index 88d0dd757..1e54f08db 100644 --- a/modules/core/src/main/scala/gql/std/FreeApply.scala +++ b/modules/core/src/main/scala/gql/std/FreeApply.scala @@ -23,6 +23,12 @@ import scala.annotation.nowarn /** FreeApply is a Free Applicative, but witout pure. It has an Apply instance. */ sealed abstract class FreeApply[F[_], +A] extends Product with Serializable { + def parFoldMap[G[_], B >: A](fk: F ~> G)(implicit G: Parallel[G]): G[B] = { + implicit val H: Apply[G.F] = G.apply + val fk2: F ~> G.F = fk.andThen(G.parallel) + G.sequential(foldMap[G.F, B](fk2)) + } + def foldMap[G[_], B >: A](fk: F ~> G)(implicit G: Apply[G]): G[B] = FreeApply.foldMap[F, G, B](this)(fk)