Skip to content
This repository has been archived by the owner on Oct 26, 2020. It is now read-only.

Commit

Permalink
Revert "extend ProjectionNames to include Args"
Browse files Browse the repository at this point in the history
This reverts commit f9b9219 as it introduced an issue:
#10 (comment)
  • Loading branch information
yanns committed Jan 9, 2020
1 parent 9c4ba24 commit 7db300a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 38 deletions.
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), Args(field, astField)))
ProjectedName(name, loop(path.add(astField, objTpe), field.fieldType, fields, currLevel + 1)))
}
.flatten
case Failure(_) => Vector.empty
Expand Down
2 changes: 1 addition & 1 deletion modules/core/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, args: Args = Args.empty) {
case class ProjectedName(name: String, children: Vector[ProjectedName] = Vector.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: 19 additions & 36 deletions modules/core/src/test/scala/sangria/execution/ProjectorSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ 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 @@ -40,7 +37,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 @@ -54,11 +51,8 @@ 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),
arguments = StringArgument :: Nil,
resolve = _.value.right.get.variants.tail)
Field("variants", ListType(VariantType), resolve = _.value.right.get.variants.tail)
))

val QueryType = ObjectType("Query", fields[Ctx, Unit](
Expand Down Expand Up @@ -116,7 +110,7 @@ class ProjectorSpec extends WordSpec with Matchers with FutureResultSupport {
projectAll {
id
typeId
variants(stringArg: "a") {
variants {
id
attributes {
name
Expand All @@ -128,7 +122,7 @@ class ProjectorSpec extends WordSpec with Matchers with FutureResultSupport {
relatedProducts {
id
typeId
variants(stringArg: "b") {
variants {
id
}
}
Expand All @@ -137,7 +131,7 @@ class ProjectorSpec extends WordSpec with Matchers with FutureResultSupport {
projectOne {
id
typeId
variants(stringArg: "c") {
variants {
id
typeId
}
Expand Down Expand Up @@ -201,9 +195,7 @@ class ProjectorSpec extends WordSpec with Matchers with FutureResultSupport {
ProjectedName("rp", Vector(
ProjectedName("id", Vector.empty),
ProjectedName("variants", Vector(
ProjectedName("id", Vector.empty)),
Args(StringArgument :: Nil, Map("stringArg" -> "b")))))),
Args(StringArgument :: Nil, Map("stringArg" -> "a"))))
ProjectedName("id", Vector.empty))))))))

ctx.allProjections.zip(expected).map {
case (x, y) => compareUnorderedProjectedNames(x, y)
Expand All @@ -212,8 +204,7 @@ class ProjectorSpec extends WordSpec with Matchers with FutureResultSupport {
ctx.oneLevelprojections should be (
Vector(
ProjectedName("id", Vector.empty),
ProjectedName("variants", Vector.empty,
Args(StringArgument :: Nil, Map("stringArg" -> "c")))))
ProjectedName("variants", Vector.empty)))
}

"handle multiple projected names" in {
Expand All @@ -223,10 +214,10 @@ class ProjectorSpec extends WordSpec with Matchers with FutureResultSupport {
projectAll {
id
variantIds
masterVariant(intArg: 1) {
masterVariant {
mixed
}
variants(stringArg: "a") {
variants {
id
mixed
}
Expand All @@ -235,10 +226,10 @@ class ProjectorSpec extends WordSpec with Matchers with FutureResultSupport {
projectOne {
id
variantIds
masterVariant(intArg: 2) {
masterVariant {
mixed
}
variants(stringArg: "b") {
variants {
id
mixed
}
Expand Down Expand Up @@ -279,34 +270,26 @@ 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)),
Args(IntArgument :: Nil, Map("intArg" -> 1))),
ProjectedName("master2",
Vector(
ProjectedName("mixed2", Vector.empty))),
ProjectedName("master2", Vector(
ProjectedName("mixed1", Vector.empty),
ProjectedName("mixed2", Vector.empty)),
Args(IntArgument :: Nil, Map("intArg" -> 1))),
ProjectedName("mixed2", Vector.empty))),
ProjectedName("variants",
Vector(
ProjectedName("id", Vector.empty),
ProjectedName("mixed1", Vector.empty),
ProjectedName("mixed2", Vector.empty)),
Args(StringArgument :: Nil, Map("stringArg" -> "a")))))
ProjectedName("mixed2", Vector.empty)))))

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

0 comments on commit 7db300a

Please sign in to comment.