-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
replaced simple vector path with
ExecutionPath
(#143)
- Loading branch information
1 parent
2936845
commit 523ac7d
Showing
15 changed files
with
212 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package sangria.execution | ||
|
||
import sangria.marshalling.ResultMarshaller | ||
import sangria.ast | ||
|
||
case class ExecutionPath private (path: Vector[Any], cacheKeyPath: ExecutionPath.PathCacheKey) { | ||
def +(fieldName: String) = new ExecutionPath(path :+ fieldName, cacheKey :+ fieldName) | ||
def +(field: ast.Field) = new ExecutionPath(path :+ field.outputName, cacheKey :+ field.outputName) | ||
|
||
def isEmpty = path.isEmpty | ||
def nonEmpty = path.nonEmpty | ||
|
||
/** | ||
* @return last index in the path, if available | ||
*/ | ||
def lastIndex: Option[Int] = path.lastOption.collect {case i: Int ⇒ i} | ||
|
||
/** | ||
* @return the size of the path excluding the indexes | ||
*/ | ||
def size = cacheKeyPath.size | ||
|
||
def marshal(m: ResultMarshaller): m.Node = m.arrayNode(path.map { | ||
case s: String ⇒ m.scalarNode(s, "String", Set.empty) | ||
case i: Int ⇒ m.scalarNode(i, "Int", Set.empty) | ||
}) | ||
|
||
def cacheKey: ExecutionPath.PathCacheKey = cacheKeyPath | ||
|
||
override def toString = path.foldLeft("") { | ||
case ("", str: String) ⇒ str | ||
case (acc, str: String) ⇒ acc + "." + str | ||
case (acc, idx: Int) ⇒ acc + "[" + idx + "]" | ||
} | ||
} | ||
|
||
object ExecutionPath { | ||
type PathCacheKey = Vector[String] | ||
|
||
val empty = new ExecutionPath(Vector.empty, Vector.empty) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.