From 042af427dcf26787412b686a668d79292cecd0c8 Mon Sep 17 00:00:00 2001 From: Yann Simon Date: Fri, 29 Oct 2021 08:19:43 +0200 Subject: [PATCH] avoid breaking sangria slow logs Follow-up on https://github.com/sangria-graphql/sangria/pull/769 avoid breaking types of `path` and `cacheKey`. Fix https://github.com/sangria-graphql/sangria/issues/773 --- build.sbt | 2 -- .../sangria/execution/ExecutionPath.scala | 25 ++++++++++--------- .../execution/DeprecationTrackerSpec.scala | 4 ++- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/build.sbt b/build.sbt index d6ddd83d..67ae9f8b 100644 --- a/build.sbt +++ b/build.sbt @@ -120,10 +120,8 @@ ThisBuild / mimaBinaryIssueFilters ++= Seq( ProblemFilters.exclude[DirectMissingMethodProblem]("sangria.execution.ExecutionPath.apply"), ProblemFilters.exclude[DirectMissingMethodProblem]( "sangria.execution.ExecutionPath.productElementNames"), - ProblemFilters.exclude[IncompatibleResultTypeProblem]("sangria.execution.ExecutionPath.path"), ProblemFilters.exclude[DirectMissingMethodProblem]( "sangria.execution.ExecutionPath.cacheKeyPath"), - ProblemFilters.exclude[IncompatibleResultTypeProblem]("sangria.execution.ExecutionPath.cacheKey"), ProblemFilters.exclude[DirectMissingMethodProblem]("sangria.execution.ExecutionPath.copy"), ProblemFilters.exclude[DirectMissingMethodProblem]( "sangria.execution.ExecutionPath.copy$default$*"), diff --git a/modules/core/src/main/scala/sangria/execution/ExecutionPath.scala b/modules/core/src/main/scala/sangria/execution/ExecutionPath.scala index 260174f1..3b2950e2 100644 --- a/modules/core/src/main/scala/sangria/execution/ExecutionPath.scala +++ b/modules/core/src/main/scala/sangria/execution/ExecutionPath.scala @@ -6,20 +6,21 @@ import sangria.schema.ObjectType class ExecutionPath private ( _path: List[Any], - cacheKeyPath: ExecutionPath.PathCacheKey, + cacheKeyPath: List[String], pathSizeWithoutIndexes: Int) { - lazy val path: List[Any] = _path.reverse + lazy val path: Vector[Any] = _path.reverseIterator.toVector - def add(field: ast.Field, parentType: ObjectType[_, _]) = + def add(field: ast.Field, parentType: ObjectType[_, _]): ExecutionPath = new ExecutionPath( field.outputName :: _path, - parentType.name :: field.outputName :: cacheKey, + parentType.name :: field.outputName :: cacheKeyPath, pathSizeWithoutIndexes = pathSizeWithoutIndexes + 1) - def withIndex(idx: Int) = new ExecutionPath(idx :: _path, cacheKey, pathSizeWithoutIndexes) + def withIndex(idx: Int): ExecutionPath = + new ExecutionPath(idx :: _path, cacheKeyPath, pathSizeWithoutIndexes) - def isEmpty = _path.isEmpty - def nonEmpty = _path.nonEmpty + def isEmpty: Boolean = _path.isEmpty + def nonEmpty: Boolean = _path.nonEmpty /** @return * last index in the path, if available @@ -29,30 +30,30 @@ class ExecutionPath private ( /** @return * the size of the path excluding the indexes */ - def size = pathSizeWithoutIndexes + def size: Int = pathSizeWithoutIndexes def marshal(m: ResultMarshaller): m.Node = m.arrayNode(_path.reverseIterator.map { case s: String => m.scalarNode(s, "String", Set.empty) case i: Int => m.scalarNode(i, "Int", Set.empty) }.toVector) - def cacheKey: ExecutionPath.PathCacheKey = cacheKeyPath + def cacheKey: ExecutionPath.PathCacheKey = cacheKeyPath.reverseIterator.toVector - override def toString = _path.reverseIterator + override def toString: String = _path.reverseIterator .foldLeft(new StringBuilder) { case (builder, str: String) => if (builder.isEmpty) builder.append(str) else builder.append(".").append(str) case (builder, idx: Int) => builder.append("[").append(idx).append("]") case (builder, other) => - if (builder.isEmpty) builder.append(other.toString()) + if (builder.isEmpty) builder.append(other.toString) else builder.append(".").append(other.toString) } .result() } object ExecutionPath { - type PathCacheKey = List[String] + type PathCacheKey = Vector[String] val empty = new ExecutionPath(List.empty, List.empty, pathSizeWithoutIndexes = 0) } diff --git a/modules/core/src/test/scala/sangria/execution/DeprecationTrackerSpec.scala b/modules/core/src/test/scala/sangria/execution/DeprecationTrackerSpec.scala index b2fabf3d..53cfcd9b 100644 --- a/modules/core/src/test/scala/sangria/execution/DeprecationTrackerSpec.scala +++ b/modules/core/src/test/scala/sangria/execution/DeprecationTrackerSpec.scala @@ -104,7 +104,9 @@ class DeprecationTrackerSpec Executor.execute(schema, query, deprecationTracker = deprecationTracker).await deprecationTracker.times.get should be(1) - deprecationTracker.ctx.get.path.path should be(List("nested", "aa", "bb")) + deprecationTracker.ctx.get.path.path should be(Vector("nested", "aa", "bb")) + deprecationTracker.ctx.get.path.cacheKey should be( + Vector("nested", "TestType", "aa", "TestType", "bb", "TestType")) deprecationTracker.ctx.get.field.name should be("deprecated") deprecationTracker.ctx.get.parentType.name should be("TestType") }