Skip to content

Commit

Permalink
Merge pull request #774 from sangria-graphql/fix_7900_break_sangria_s…
Browse files Browse the repository at this point in the history
…low_logs

avoid breaking sangria slow logs
  • Loading branch information
yanns authored Oct 29, 2021
2 parents e751ee8 + 042af42 commit 3deafc1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
2 changes: 0 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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$*"),
Expand Down
25 changes: 13 additions & 12 deletions modules/core/src/main/scala/sangria/execution/ExecutionPath.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down

0 comments on commit 3deafc1

Please sign in to comment.