From 35c67a82bcbcdb31737e58efa237b256795358d2 Mon Sep 17 00:00:00 2001 From: ubaldop Date: Thu, 20 Apr 2023 11:24:09 +0200 Subject: [PATCH 1/2] add Iterable context bound to FromInput --- .../scala/sangria/marshalling/FromInput.scala | 25 +++++++++++-------- .../marshalling/ResultMarshaller.scala | 2 +- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/main/scala/sangria/marshalling/FromInput.scala b/src/main/scala/sangria/marshalling/FromInput.scala index 4791b72..ee5c7f5 100644 --- a/src/main/scala/sangria/marshalling/FromInput.scala +++ b/src/main/scala/sangria/marshalling/FromInput.scala @@ -16,19 +16,21 @@ object FromInput { def fromResult(node: marshaller.Node): marshaller.Node = node } - class SeqFromInput[T](delegate: FromInput[T]) extends FromInput[Seq[T]] { + class IterableFromInput[T, I[_] <: Iterable[_]](delegate: FromInput[T]) extends FromInput[I[T]] { val marshaller: ResultMarshaller = delegate.marshaller - def fromResult(node: marshaller.Node): Seq[T] = + def fromResult(node: marshaller.Node): I[T] = node - .asInstanceOf[Seq[Any]] - .map { - case optElem: Option[_] => - optElem.map(elem => delegate.fromResult(elem.asInstanceOf[delegate.marshaller.Node])) - case elem => - delegate.fromResult(elem.asInstanceOf[delegate.marshaller.Node]) + .asInstanceOf[I[Any]] + .map { (e: Any) => + e match { + case optElem: Option[_] => + optElem.map(elem => delegate.fromResult(elem.asInstanceOf[delegate.marshaller.Node])) + case elem => + delegate.fromResult(elem.asInstanceOf[delegate.marshaller.Node]) + } } - .asInstanceOf[Seq[T]] + .asInstanceOf[I[T]] } import sangria.util.tag._ @@ -43,7 +45,10 @@ object FromInput { implicit def optionInput[T](implicit ev: FromInput[T]): FromInput[Option[T]] = ev.asInstanceOf[FromInput[Option[T]]] - implicit def seqInput[T](implicit ev: FromInput[T]): SeqFromInput[T] = new SeqFromInput[T](ev) + implicit def seqInput[T](implicit ev: FromInput[T]): IterableFromInput[T, Seq] = + new IterableFromInput[T, Seq](ev) + implicit def iterableInput[T](implicit ev: FromInput[T]): IterableFromInput[T, Iterable] = + new IterableFromInput[T, Iterable](ev) trait CoercedScalaResult trait InputObjectResult diff --git a/src/main/scala/sangria/marshalling/ResultMarshaller.scala b/src/main/scala/sangria/marshalling/ResultMarshaller.scala index 21353e7..f9b6640 100644 --- a/src/main/scala/sangria/marshalling/ResultMarshaller.scala +++ b/src/main/scala/sangria/marshalling/ResultMarshaller.scala @@ -46,7 +46,7 @@ trait ResultMarshaller { def renderCompact(node: Node): String def renderPretty(node: Node): String - def mapAndMarshal[T](seq: Seq[T], fn: T => Node): Node = { + def mapAndMarshal[T](seq: Iterable[T], fn: T => Node): Node = { val res = new VectorBuilder[Node] for (elem <- seq) From cde0579b6c1642604ae5ecec6b418029f18d4570 Mon Sep 17 00:00:00 2001 From: ubaldop Date: Mon, 9 Sep 2024 16:28:54 +0200 Subject: [PATCH 2/2] mimaBinaryIssueFilters added --- build.sbt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/build.sbt b/build.sbt index 34646e6..9b58061 100644 --- a/build.sbt +++ b/build.sbt @@ -1,3 +1,5 @@ +import com.typesafe.tools.mima.core._ + val isScala3 = Def.setting( CrossVersion.partialVersion(scalaVersion.value).exists(_._1 == 3) ) @@ -10,6 +12,17 @@ mimaPreviousArtifacts := { else Set("org.sangria-graphql" %% "sangria-marshalling-api" % "1.0.5") } +mimaBinaryIssueFilters ++= Seq( + ProblemFilters.exclude[IncompatibleMethTypeProblem]( + "sangria.marshalling.CoercedScalaResultMarshaller.mapAndMarshal"), + ProblemFilters.exclude[IncompatibleResultTypeProblem]("sangria.marshalling.FromInput.seqInput"), + ProblemFilters.exclude[IncompatibleResultTypeProblem]("sangria.marshalling.FromInput.seqInput"), + ProblemFilters.exclude[MissingClassProblem]("sangria.marshalling.FromInput$SeqFromInput"), + ProblemFilters.exclude[DirectMissingMethodProblem]( + "sangria.marshalling.ResultMarshaller.mapAndMarshal"), + ProblemFilters.exclude[IncompatibleMethTypeProblem]( + "sangria.marshalling.ScalaResultMarshaller.mapAndMarshal") +) description := "Sangria Marshalling API" homepage := Some(url("https://sangria-graphql.github.io/"))