Skip to content

Commit

Permalink
Merge eef99d7 into 65ffe26
Browse files Browse the repository at this point in the history
  • Loading branch information
robconrad committed Dec 24, 2018
2 parents 65ffe26 + eef99d7 commit ca91cdc
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 22 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name := "sangria"
organization := "org.sangria-graphql"
version := "1.4.3-SNAPSHOT"
version := "1.4.4-SNAPSHOT"

description := "Scala GraphQL implementation"
homepage := Some(url("http://sangria-graphql.org"))
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/sangria/execution/Resolver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1165,7 +1165,7 @@ class Resolver[Ctx](
else Vector(field.name)

projectedName.map (name
ProjectedName(name, loop(path.add(astField, objTpe), field.fieldType, fields, currLevel + 1)))
ProjectedName(name, loop(path.add(astField, objTpe), field.fieldType, fields, currLevel + 1), Args(field, astField)))
}
.flatten
case Failure(_) Vector.empty
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/sangria/schema/Context.scala
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ object Projector {
}
}

case class ProjectedName(name: String, children: Vector[ProjectedName] = Vector.empty) {
case class ProjectedName(name: String, children: Vector[ProjectedName] = Vector.empty, args: Args = Args.empty) {
lazy val asVector = {
def loop(name: ProjectedName): Vector[Vector[String]] =
Vector(name.name) +: (name.children flatMap loop map (name.name +: _))
Expand Down
55 changes: 36 additions & 19 deletions src/test/scala/sangria/execution/ProjectorSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ class ProjectorSpec extends WordSpec with Matchers with FutureResultSupport {

case class ProductDefer(productIds: List[String]) extends Deferred[List[Right[String, Product]]]

val IntArgument = Argument("intArg", IntType)
val StringArgument = Argument("stringArg", StringType)

val ProductAttributeType = InterfaceType("ProductAttribute", fields[Unit, (String, Any)](
Field("name", StringType, resolve = _.value._1)))

Expand All @@ -37,7 +40,7 @@ class ProjectorSpec extends WordSpec with Matchers with FutureResultSupport {
Field("relatedProducts", ListType(ProductType),
tags = ProjectionName("rp") :: Nil,
resolve = Projector(1, (ctx, projected) projected match {
case Vector(ProjectedName("id", _)) Value(ctx.value.relatedProductIds map (Left(_)))
case Vector(ProjectedName("id", _, _)) Value(ctx.value.relatedProductIds map (Left(_)))
case _ ProductDefer(ctx.value.relatedProductIds)
}))
))
Expand All @@ -51,8 +54,11 @@ class ProjectorSpec extends WordSpec with Matchers with FutureResultSupport {
Field("typeId", StringType, tags = ProjectionExclude :: Nil, resolve = _ "product"),
Field("masterVariant", VariantType,
tags = ProjectionName("master1") :: ProjectionName("master2") :: Nil,
arguments = IntArgument :: Nil,
resolve = _.value.right.get.variants.head),
Field("variants", ListType(VariantType), resolve = _.value.right.get.variants.tail)
Field("variants", ListType(VariantType),
arguments = StringArgument :: Nil,
resolve = _.value.right.get.variants.tail)
))

val QueryType = ObjectType("Query", fields[Ctx, Unit](
Expand Down Expand Up @@ -103,7 +109,7 @@ class ProjectorSpec extends WordSpec with Matchers with FutureResultSupport {
projectAll {
id
typeId
variants {
variants(stringArg: "a") {
id
attributes {
name
Expand All @@ -115,7 +121,7 @@ class ProjectorSpec extends WordSpec with Matchers with FutureResultSupport {
relatedProducts {
id
typeId
variants {
variants(stringArg: "b") {
id
}
}
Expand All @@ -124,7 +130,7 @@ class ProjectorSpec extends WordSpec with Matchers with FutureResultSupport {
projectOne {
id
typeId
variants {
variants(stringArg: "c") {
id
typeId
}
Expand Down Expand Up @@ -189,12 +195,15 @@ class ProjectorSpec extends WordSpec with Matchers with FutureResultSupport {
ProjectedName("rp", Vector(
ProjectedName("id", Vector.empty),
ProjectedName("variants", Vector(
ProjectedName("id", Vector.empty)))))))))
ProjectedName("id", Vector.empty)),
Args(StringArgument :: Nil, "stringArg" -> "b"))))),
Args(StringArgument :: Nil, "stringArg" -> "a"))))

ctx.oneLevelprojections should be (
Vector(
ProjectedName("id", Vector.empty),
ProjectedName("variants", Vector.empty)))
ProjectedName("variants", Vector.empty,
Args(StringArgument :: Nil, "stringArg" -> "c"))))
}

"handle multiple projected names" in {
Expand All @@ -204,10 +213,10 @@ class ProjectorSpec extends WordSpec with Matchers with FutureResultSupport {
projectAll {
id
variantIds
masterVariant {
masterVariant(intArg: 1) {
mixed
}
variants {
variants(stringArg: "a") {
id
mixed
}
Expand All @@ -216,10 +225,10 @@ class ProjectorSpec extends WordSpec with Matchers with FutureResultSupport {
projectOne {
id
variantIds
masterVariant {
masterVariant(intArg: 2) {
mixed
}
variants {
variants(stringArg: "b") {
id
mixed
}
Expand Down Expand Up @@ -260,26 +269,34 @@ class ProjectorSpec extends WordSpec with Matchers with FutureResultSupport {
ProjectedName("id", Vector.empty),
ProjectedName("masterVariant.id", Vector.empty),
ProjectedName("variants.id", Vector.empty),
ProjectedName("master1", Vector(
ProjectedName("master1",
Vector(
ProjectedName("mixed1", Vector.empty),
ProjectedName("mixed2", Vector.empty))),
ProjectedName("master2", Vector(
ProjectedName("mixed2", Vector.empty)),
Args(IntArgument :: Nil, "intArg" -> 1)),
ProjectedName("master2",
Vector(
ProjectedName("mixed1", Vector.empty),
ProjectedName("mixed2", Vector.empty))),
ProjectedName("mixed2", Vector.empty)),
Args(IntArgument :: Nil, "intArg" -> 1)),
ProjectedName("variants",
Vector(
ProjectedName("id", Vector.empty),
ProjectedName("mixed1", Vector.empty),
ProjectedName("mixed2", Vector.empty)))))
ProjectedName("mixed2", Vector.empty)),
Args(StringArgument :: Nil, "stringArg" -> "a"))))

ctx.oneLevelprojections should be (
Vector(
ProjectedName("id", Vector.empty),
ProjectedName("masterVariant.id", Vector.empty),
ProjectedName("variants.id", Vector.empty),
ProjectedName("master1", Vector.empty),
ProjectedName("master2", Vector.empty),
ProjectedName("variants", Vector.empty)))
ProjectedName("master1", Vector.empty,
Args(IntArgument :: Nil, "intArg" -> 2)),
ProjectedName("master2", Vector.empty,
Args(IntArgument :: Nil, "intArg" -> 2)),
ProjectedName("variants", Vector.empty,
Args(StringArgument :: Nil, "stringArg" -> "b"))))
}
}
}

0 comments on commit ca91cdc

Please sign in to comment.