diff --git a/modules/core/src/main/scala/parser.scala b/modules/core/src/main/scala/parser.scala index bc9361bb..21ce3449 100644 --- a/modules/core/src/main/scala/parser.scala +++ b/modules/core/src/main/scala/parser.scala @@ -32,7 +32,8 @@ object GraphQLParser { maxSelectionDepth: Int, maxSelectionWidth: Int, maxInputValueDepth: Int, - maxListTypeDepth: Int + maxListTypeDepth: Int, + terseError: Boolean ) val defaultConfig: Config = @@ -40,7 +41,8 @@ object GraphQLParser { maxSelectionDepth = 100, maxSelectionWidth = 1000, maxInputValueDepth = 5, - maxListTypeDepth = 5 + maxListTypeDepth = 5, + terseError = true ) def apply(config: Config): GraphQLParser = @@ -49,14 +51,19 @@ object GraphQLParser { def toResult[T](pr: Either[Parser.Error, T]): Result[T] = Result.fromEither(pr.leftMap(_.show)) + def toResultTerseError[T](pr: Either[Parser.Error, T]): Result[T] = + Result.fromEither(pr.leftMap(_.copy().show)) + import CommentedText._ import Literals._ private final class Impl(config: Config) extends GraphQLParser { import config._ - def parseText(text: String): Result[Ast.Document] = - toResult(Document.parseAll(text)) + def parseText(text: String): Result[Ast.Document] = { + val res = Document.parseAll(text) + if (config.terseError) toResultTerseError(res) else toResult(res) + } val nameInitial = ('A' to 'Z') ++ ('a' to 'z') ++ Seq('_') val nameSubsequent = nameInitial ++ ('0' to '9') diff --git a/modules/core/src/test/scala/compiler/CompilerSuite.scala b/modules/core/src/test/scala/compiler/CompilerSuite.scala index 25e6c1a7..c45f085c 100644 --- a/modules/core/src/test/scala/compiler/CompilerSuite.scala +++ b/modules/core/src/test/scala/compiler/CompilerSuite.scala @@ -26,7 +26,7 @@ import Predicate._, Value._, UntypedOperation._ import QueryCompiler._, ComponentElaborator.TrivialJoin final class CompilerSuite extends CatsEffectSuite { - val queryParser = QueryParser(GraphQLParser(GraphQLParser.defaultConfig)) + val queryParser = QueryParser(GraphQLParser(GraphQLParser.defaultConfig.copy(terseError = false))) test("simple query") { val query = """ diff --git a/modules/core/src/test/scala/parser/ParserSuite.scala b/modules/core/src/test/scala/parser/ParserSuite.scala index bfe3f0b3..91fd5364 100644 --- a/modules/core/src/test/scala/parser/ParserSuite.scala +++ b/modules/core/src/test/scala/parser/ParserSuite.scala @@ -22,7 +22,7 @@ import grackle.syntax._ import Ast._, OperationType._, OperationDefinition._, Selection._, Value._, Type.Named final class ParserSuite extends CatsEffectSuite { - val parser = GraphQLParser(GraphQLParser.defaultConfig) + val parser = mkParser() test("simple query") { val query = doc""" @@ -801,12 +801,15 @@ final class ParserSuite extends CatsEffectSuite { maxSelectionDepth: Int = GraphQLParser.defaultConfig.maxSelectionDepth, maxSelectionWidth: Int = GraphQLParser.defaultConfig.maxSelectionWidth, maxInputValueDepth: Int = GraphQLParser.defaultConfig.maxInputValueDepth, - maxListTypeDepth: Int = GraphQLParser.defaultConfig.maxListTypeDepth): GraphQLParser = + maxListTypeDepth: Int = GraphQLParser.defaultConfig.maxListTypeDepth, + ): GraphQLParser = GraphQLParser( GraphQLParser.Config( maxSelectionDepth = maxSelectionDepth, maxSelectionWidth = maxSelectionWidth, maxInputValueDepth = maxInputValueDepth, - maxListTypeDepth = maxListTypeDepth) + maxListTypeDepth = maxListTypeDepth, + terseError = false ) + ) }