Skip to content

Commit

Permalink
Allow multiple aliases for the same field (#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
ghostdogpr authored Dec 6, 2019
1 parent 2ed8c93 commit 949a8fc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 3 additions & 2 deletions core/src/main/scala/caliban/execution/Executor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,11 @@ object Executor {
fields
.foldLeft(ListMap.empty[String, Field]) {
case (result, field) =>
val name = field.alias.getOrElse(field.name)
result.updated(
field.name,
name,
result
.get(field.name)
.get(name)
.fold(field)(f => f.copy(selectionSet = f.selectionSet ++ field.selectionSet))
)
}
Expand Down
8 changes: 6 additions & 2 deletions core/src/test/scala/caliban/execution/ExecutionSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,16 @@ object ExecutionSpec
amos: character(name: "Amos Burton") {
name
nicknames
}
},
naomi: character(name: "Naomi Nagata") {
name
nicknames
},
}""")

assertM(
interpreter.execute(query).map(_.data.toString),
equalTo("""{"amos":{"name":"Amos Burton","nicknames":[]}}""")
equalTo("""{"amos":{"name":"Amos Burton","nicknames":[]},"naomi":{"name":"Naomi Nagata","nicknames":[]}}""")
)
},
testM("fragment") {
Expand Down

0 comments on commit 949a8fc

Please sign in to comment.