From 16961776feac78090a4d7f41c8251eaa9b1a00fa Mon Sep 17 00:00:00 2001 From: Pierre Ricadat Date: Mon, 4 Oct 2021 22:28:28 +0900 Subject: [PATCH] Fix fragment spreads parsing in Scala 3 --- core/src/main/scala-3/caliban/parsing/Parser.scala | 2 +- core/src/test/scala/caliban/parsing/ParserSpec.scala | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/src/main/scala-3/caliban/parsing/Parser.scala b/core/src/main/scala-3/caliban/parsing/Parser.scala index 663e2b61f..77787a021 100644 --- a/core/src/main/scala-3/caliban/parsing/Parser.scala +++ b/core/src/main/scala-3/caliban/parsing/Parser.scala @@ -286,7 +286,7 @@ object Parser { private val fragmentName: P[String] = name.filter(_ != "on") private val fragmentSpread: P[FragmentSpread] = - ((P.string("...").soft *> fragmentName <* whitespaceWithComment) ~ directives.?).map { case (name, dirs) => + ((P.string("...").soft *> fragmentName <* whitespaceWithComment).backtrack ~ directives.?).map { case (name, dirs) => FragmentSpread(name, dirs.getOrElse(Nil)) } diff --git a/core/src/test/scala/caliban/parsing/ParserSpec.scala b/core/src/test/scala/caliban/parsing/ParserSpec.scala index c30653883..402a9fe80 100644 --- a/core/src/test/scala/caliban/parsing/ParserSpec.scala +++ b/core/src/test/scala/caliban/parsing/ParserSpec.scala @@ -324,7 +324,7 @@ object ParserSpec extends DefaultRunnableSpec { val query = """query inlineFragmentTyping { | profiles(handles: ["zuck", "cocacola"]) { | handle - | ... on User { + | ...on User { | friends { | count | } @@ -350,13 +350,13 @@ object ParserSpec extends DefaultRunnableSpec { Some(NamedType("User", nonNull = false)), Nil, List( - simpleField("friends", selectionSet = List(simpleField("count", index = 126)), index = 108) + simpleField("friends", selectionSet = List(simpleField("count", index = 125)), index = 107) ) ), InlineFragment( Some(NamedType("Page", nonNull = false)), Nil, - List(simpleField("likers", selectionSet = List(simpleField("count", index = 187)), index = 170)) + List(simpleField("likers", selectionSet = List(simpleField("count", index = 186)), index = 169)) ) ), index = 31