You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@s2graph.apache.org by da...@apache.org on 2018/06/18 06:15:28 UTC

[1/5] incubator-s2graph git commit: add extension for SigmaJs

Repository: incubator-s2graph
Updated Branches:
  refs/heads/master 4f1c4ceb6 -> 35a369f55


add extension for SigmaJs


Project: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/commit/bb78c7d6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/tree/bb78c7d6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/diff/bb78c7d6

Branch: refs/heads/master
Commit: bb78c7d602614ede86e93b465f0eafee50ee0554
Parents: 32eb344
Author: daewon <da...@apache.org>
Authored: Fri Jun 8 16:58:21 2018 +0900
Committer: daewon <da...@apache.org>
Committed: Fri Jun 8 16:58:21 2018 +0900

----------------------------------------------------------------------
 .../apache/s2graph/graphql/GraphQLServer.scala  |   5 +-
 .../s2graph/graphql/middleware/SigmaJS.scala    | 101 +++++++++++++++++
 .../graphql/repository/GraphRepository.scala    |   5 +-
 .../graphql/types/PlayJsonScalarType.scala      | 112 +++++++++++++++++++
 4 files changed, 219 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/bb78c7d6/s2graphql/src/main/scala/org/apache/s2graph/graphql/GraphQLServer.scala
----------------------------------------------------------------------
diff --git a/s2graphql/src/main/scala/org/apache/s2graph/graphql/GraphQLServer.scala b/s2graphql/src/main/scala/org/apache/s2graph/graphql/GraphQLServer.scala
index eee7c93..d333c9e 100644
--- a/s2graphql/src/main/scala/org/apache/s2graph/graphql/GraphQLServer.scala
+++ b/s2graphql/src/main/scala/org/apache/s2graph/graphql/GraphQLServer.scala
@@ -28,6 +28,7 @@ import akka.http.scaladsl.server._
 import com.typesafe.config.ConfigFactory
 import org.apache.s2graph.core.S2Graph
 import org.apache.s2graph.core.utils.SafeUpdateCache
+import org.apache.s2graph.graphql.middleware.{SigmaJSFormatted}
 import org.apache.s2graph.graphql.repository.GraphRepository
 import org.apache.s2graph.graphql.types.SchemaDef
 import org.slf4j.LoggerFactory
@@ -118,6 +119,7 @@ object GraphQLServer {
   private def executeGraphQLQuery(query: Document, op: Option[String], vars: JsObject)(implicit e: ExecutionContext) = {
     val cacheKey = className + "s2Schema"
     val s2schema = schemaCache.withCache(cacheKey, broadcast = false)(createNewSchema())
+
     import GraphRepository._
     val resolver: DeferredResolver[GraphRepository] = DeferredResolver.fetchers(vertexFetcher, edgeFetcher)
 
@@ -127,7 +129,8 @@ object GraphQLServer {
       s2Repository,
       variables = vars,
       operationName = op,
-      deferredResolver = resolver
+      deferredResolver = resolver,
+      middleware = SigmaJSFormatted :: Nil
     )
       .map((res: spray.json.JsValue) => OK -> res)
       .recover {

http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/bb78c7d6/s2graphql/src/main/scala/org/apache/s2graph/graphql/middleware/SigmaJS.scala
----------------------------------------------------------------------
diff --git a/s2graphql/src/main/scala/org/apache/s2graph/graphql/middleware/SigmaJS.scala b/s2graphql/src/main/scala/org/apache/s2graph/graphql/middleware/SigmaJS.scala
new file mode 100644
index 0000000..bf03ac2
--- /dev/null
+++ b/s2graphql/src/main/scala/org/apache/s2graph/graphql/middleware/SigmaJS.scala
@@ -0,0 +1,101 @@
+package org.apache.s2graph.graphql.middleware
+
+import org.apache.s2graph.core.schema.ServiceColumn
+import org.apache.s2graph.core.{GraphElement, S2EdgeLike, S2VertexLike}
+import org.apache.s2graph.graphql.types.PlayJsonScalarType
+import org.slf4s.LoggerFactory
+import play.api.libs.json._
+import sangria.execution._
+import sangria.schema.Context
+
+
+object SigmaJSFormatted extends Middleware[Any] with MiddlewareAfterField[Any] with MiddlewareExtension[Any] {
+  implicit val logger = LoggerFactory.getLogger(this.getClass)
+
+  type QueryVal = java.util.concurrent.ConcurrentHashMap[GraphElement, Unit]
+
+  type FieldVal = Long
+
+
+  def beforeQuery(context: MiddlewareQueryContext[Any, _, _]) = {
+    new java.util.concurrent.ConcurrentHashMap[GraphElement, Unit]()
+  }
+
+  def afterQuery(queryVal: QueryVal, context: MiddlewareQueryContext[Any, _, _]) = ()
+
+  def toVertexId(v: S2VertexLike, c: ServiceColumn): String = {
+    val innerId = v.innerId.toIdString()
+
+    s"${c.service.serviceName}.${c.columnName}.${innerId}"
+  }
+
+  def toVertexJson(v: S2VertexLike, c: ServiceColumn): JsValue = {
+    Json.obj(
+      "id" -> toVertexId(v, c),
+      "label" -> v.innerId.toIdString()
+    )
+  }
+
+  def toEdgeJson(e: S2EdgeLike): JsValue = {
+    Json.obj(
+      "source" -> toVertexId(e.srcVertex, e.innerLabel.srcColumn),
+      "target" -> toVertexId(e.tgtVertex, e.innerLabel.tgtColumn),
+      "id" -> s"${toVertexId(e.srcVertex, e.innerLabel.srcColumn)}.${e.label()}.${toVertexId(e.tgtVertex, e.innerLabel.tgtColumn)}",
+      "label" -> e.label()
+    )
+  }
+
+  def afterQueryExtensions(queryVal: QueryVal,
+                           context: MiddlewareQueryContext[Any, _, _]
+                          ): Vector[Extension[_]] = {
+
+    import scala.collection.JavaConverters._
+    val elements = queryVal.keys().asScala.toVector
+
+    val edges = elements.collect { case e: S2EdgeLike => e }
+    val vertices = elements.collect { case v: S2VertexLike => v -> v.serviceColumn }
+    val verticesFromEdges = edges.flatMap { e =>
+      val label = e.innerLabel
+      Vector((e.srcVertex, label.srcColumn), (e.tgtVertex, label.srcColumn))
+    }
+
+    val verticesJson = (vertices ++ verticesFromEdges).distinct.map { case (v, c) => toVertexJson(v, c) }
+    val edgeJson = edges.distinct.map(toEdgeJson)
+
+    val jsElements = Json.obj(
+      "nodes" -> verticesJson,
+      "edges" -> edgeJson
+    )
+
+    val graph = Json.obj("graph" -> jsElements)
+
+    /**
+      * nodes: [{id, label, x, y, size}, ..],
+      * edges: [{id, source, target, label}]
+      */
+    implicit val iu = PlayJsonScalarType.PlayJsonInputUnmarshaller
+    Vector(Extension[JsValue](graph))
+  }
+
+  def beforeField(queryVal: QueryVal, mctx: MiddlewareQueryContext[Any, _, _], ctx: Context[Any, _]) = {
+    continue(System.currentTimeMillis())
+  }
+
+  def afterField(queryVal: QueryVal, fieldVal: FieldVal, value: Any, mctx: MiddlewareQueryContext[Any, _, _], ctx: Context[Any, _]) = {
+    //    logger.info(s"${ctx.parentType.name}.${ctx.field.name} = ${value.getClass.getName}")
+
+    value match {
+      case ls: Seq[_] => ls.foreach {
+        case e: GraphElement => queryVal.put(e, ())
+        case _ =>
+      }
+      case e: GraphElement => queryVal.put(e, ())
+      case _ =>
+    }
+
+    None
+  }
+}
+
+
+

http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/bb78c7d6/s2graphql/src/main/scala/org/apache/s2graph/graphql/repository/GraphRepository.scala
----------------------------------------------------------------------
diff --git a/s2graphql/src/main/scala/org/apache/s2graph/graphql/repository/GraphRepository.scala b/s2graphql/src/main/scala/org/apache/s2graph/graphql/repository/GraphRepository.scala
index 0b5a2e9..b5e65dc 100644
--- a/s2graphql/src/main/scala/org/apache/s2graph/graphql/repository/GraphRepository.scala
+++ b/s2graphql/src/main/scala/org/apache/s2graph/graphql/repository/GraphRepository.scala
@@ -123,9 +123,8 @@ class GraphRepository(val graph: S2GraphLike) {
   }
 
   def getVertices(queryParam: VertexQueryParam): Future[Seq[S2VertexLike]] = {
-    graph.asInstanceOf[S2Graph].searchVertices(queryParam).map { a =>
-      println(a)
-      a
+    graph.asInstanceOf[S2Graph].searchVertices(queryParam).map { v =>
+      v
     }
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/bb78c7d6/s2graphql/src/main/scala/org/apache/s2graph/graphql/types/PlayJsonScalarType.scala
----------------------------------------------------------------------
diff --git a/s2graphql/src/main/scala/org/apache/s2graph/graphql/types/PlayJsonScalarType.scala b/s2graphql/src/main/scala/org/apache/s2graph/graphql/types/PlayJsonScalarType.scala
new file mode 100644
index 0000000..5149d36
--- /dev/null
+++ b/s2graphql/src/main/scala/org/apache/s2graph/graphql/types/PlayJsonScalarType.scala
@@ -0,0 +1,112 @@
+package org.apache.s2graph.graphql.types
+
+import play.api.libs.json._
+import sangria.ast
+import sangria.execution.Executor
+import sangria.marshalling.{ArrayMapBuilder, InputUnmarshaller, ResultMarshaller, ScalarValueInfo}
+import sangria.schema._
+import sangria.validation.{BigIntCoercionViolation, IntCoercionViolation, ValueCoercionViolation}
+import sangria.macros._
+
+import scala.concurrent.ExecutionContext.Implicits.global
+
+object PlayJsonScalarType {
+
+  implicit object CustomPlayJsonResultMarshaller extends ResultMarshaller {
+    type Node = JsValue
+    type MapBuilder = ArrayMapBuilder[Node]
+
+    def emptyMapNode(keys: Seq[String]) = new ArrayMapBuilder[Node](keys)
+
+    def addMapNodeElem(builder: MapBuilder, key: String, value: Node, optional: Boolean) = builder.add(key, value)
+
+    def mapNode(builder: MapBuilder) = JsObject(builder.toMap)
+
+    def mapNode(keyValues: Seq[(String, JsValue)]) = Json.toJson(keyValues.toMap)
+
+    def arrayNode(values: Vector[JsValue]) = JsArray(values)
+
+    def optionalArrayNodeValue(value: Option[JsValue]) = value match {
+      case Some(v) ⇒ v
+      case None ⇒ nullNode
+    }
+
+    def scalarNode(value: Any, typeName: String, info: Set[ScalarValueInfo]) = value match {
+      case v: String ⇒ JsString(v)
+      case v: Boolean ⇒ JsBoolean(v)
+      case v: Int ⇒ JsNumber(v)
+      case v: Long ⇒ JsNumber(v)
+      case v: Float ⇒ JsNumber(BigDecimal(v))
+      case v: Double ⇒ JsNumber(v)
+      case v: BigInt ⇒ JsNumber(BigDecimal(v))
+      case v: BigDecimal ⇒ JsNumber(v)
+      case v: JsValue ⇒ v
+      case v ⇒ throw new IllegalArgumentException("Unsupported scalar value: " + v)
+    }
+
+    def enumNode(value: String, typeName: String) = JsString(value)
+
+    def nullNode = JsNull
+
+    def renderCompact(node: JsValue) = Json.stringify(node)
+
+    def renderPretty(node: JsValue) = Json.prettyPrint(node)
+  }
+
+  implicit object PlayJsonInputUnmarshaller extends InputUnmarshaller[JsValue] {
+    def getRootMapValue(node: JsValue, key: String) = node.asInstanceOf[JsObject].value get key
+
+    def isListNode(node: JsValue) = node.isInstanceOf[JsArray]
+
+    def getListValue(node: JsValue) = node.asInstanceOf[JsArray].value
+
+    def isMapNode(node: JsValue) = node.isInstanceOf[JsObject]
+
+    def getMapValue(node: JsValue, key: String) = node.asInstanceOf[JsObject].value get key
+
+    def getMapKeys(node: JsValue) = node.asInstanceOf[JsObject].fields.map(_._1)
+
+    def isDefined(node: JsValue) = node != JsNull
+
+    def getScalarValue(node: JsValue) = node match {
+      case JsBoolean(b) ⇒ b
+      case JsNumber(d) ⇒ d.toBigIntExact getOrElse d
+      case JsString(s) ⇒ s
+      case n ⇒ n
+    }
+
+    def getScalaScalarValue(node: JsValue) = getScalarValue(node)
+
+    def isEnumNode(node: JsValue) = node.isInstanceOf[JsString]
+
+    def isScalarNode(node: JsValue) = true
+
+    def isVariableNode(node: JsValue) = false
+
+    def getVariableName(node: JsValue) = throw new IllegalArgumentException("variables are not supported")
+
+    def render(node: JsValue) = Json.stringify(node)
+  }
+
+  case object JsonCoercionViolation extends ValueCoercionViolation("Not valid JSON")
+
+  implicit val JsonType = ScalarType[JsValue]("Json",
+    description = Some("Raw PlayJson value"),
+    coerceOutput = (value, _) ⇒ value,
+    coerceUserInput = {
+      case v: String ⇒ Right(JsString(v))
+      case v: Boolean ⇒ Right(JsBoolean(v))
+      case v: Int ⇒ Right(JsNumber(v))
+      case v: Long ⇒ Right(JsNumber(v))
+      case v: Float ⇒ Right(JsNumber(BigDecimal(v)))
+      case v: Double ⇒ Right(JsNumber(v))
+      case v: BigInt ⇒ Right(JsNumber(BigDecimal(v)))
+      case v: BigDecimal ⇒ Right(JsNumber(v))
+      case v: JsValue ⇒ Right(v)
+    },
+    coerceInput = {
+      case sv: ast.StringValue => Right(Json.parse(sv.value))
+      case _ ⇒
+        Left(JsonCoercionViolation)
+    })
+}


[3/5] incubator-s2graph git commit: merge master for ci

Posted by da...@apache.org.
merge master for ci


Project: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/commit/fa911bbf
Tree: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/tree/fa911bbf
Diff: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/diff/fa911bbf

Branch: refs/heads/master
Commit: fa911bbfb3dacf2772c13c6069a980352b6b1930
Parents: c13a5e9 70a7c71
Author: daewon <da...@apache.org>
Authored: Fri Jun 15 16:48:24 2018 +0900
Committer: daewon <da...@apache.org>
Committed: Mon Jun 18 14:58:26 2018 +0900

----------------------------------------------------------------------
 CHANGES                                         |  2 +
 build.sbt                                       |  4 +-
 s2core/build.sbt                                |  2 +-
 s2graphql/build.sbt                             |  4 +-
 .../apache/s2graph/graphql/GraphQLServer.scala  |  6 +-
 .../s2graph/graphql/middleware/Transform.scala  | 51 +++++++++++++++
 .../s2graph/graphql/types/FieldResolver.scala   |  2 +-
 .../s2graph/graphql/types/S2Directive.scala     | 68 ++++++++++++++++++++
 .../s2graph/graphql/types/SchemaDef.scala       | 12 +++-
 .../apache/s2graph/graphql/DirectiveTest.scala  | 53 +++++++++++++++
 .../scala/org/apache/s2graph/s2jobs/Job.scala   | 11 +++-
 .../apache/s2graph/s2jobs/task/Process.scala    | 64 +++++++++++++++++-
 .../org/apache/s2graph/s2jobs/task/Sink.scala   |  6 +-
 .../org/apache/s2graph/s2jobs/task/Source.scala | 17 ++++-
 .../org/apache/s2graph/s2jobs/task/Task.scala   |  3 +-
 15 files changed, 285 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/fa911bbf/s2graphql/src/main/scala/org/apache/s2graph/graphql/GraphQLServer.scala
----------------------------------------------------------------------
diff --cc s2graphql/src/main/scala/org/apache/s2graph/graphql/GraphQLServer.scala
index b444213,8ea4c89..b7c0381
--- a/s2graphql/src/main/scala/org/apache/s2graph/graphql/GraphQLServer.scala
+++ b/s2graphql/src/main/scala/org/apache/s2graph/graphql/GraphQLServer.scala
@@@ -116,6 -115,8 +116,8 @@@ object GraphQLServer 
      newSchema
    }
  
 -  val transformMiddleWare = new org.apache.s2graph.graphql.middleware.Transform()
++  val TransformMiddleWare = List(org.apache.s2graph.graphql.middleware.Transform())
+ 
    private def executeGraphQLQuery(query: Document, op: Option[String], vars: JsObject)(implicit e: ExecutionContext) = {
      val cacheKey = className + "s2Schema"
      val s2schema = schemaCache.withCache(cacheKey, broadcast = false)(createNewSchema())
@@@ -123,13 -123,6 +125,13 @@@
      import GraphRepository._
      val resolver: DeferredResolver[GraphRepository] = DeferredResolver.fetchers(vertexFetcher, edgeFetcher)
  
 +    val includeGrpaph = vars.fields.get("includeGraph").contains(spray.json.JsBoolean(true))
 +    val middleWares = if (includeGrpaph) {
-       GraphFormatted :: Nil
++      GraphFormatted :: TransformMiddleWare
 +    } else {
-       Nil
++      TransformMiddleWare
 +    }
 +
      Executor.execute(
        s2schema,
        query,


[4/5] incubator-s2graph git commit: Merge branch 'S2GRAPH-219'

Posted by da...@apache.org.
Merge branch 'S2GRAPH-219'

* S2GRAPH-219:
  make middleware for GraphFormatWriter
  add extension for SigmaJs


Project: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/commit/2dd88b35
Tree: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/tree/2dd88b35
Diff: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/diff/2dd88b35

Branch: refs/heads/master
Commit: 2dd88b35677c0bc3689cbc01ce2f25fff6b188f7
Parents: 4f1c4ce fa911bb
Author: daewon <da...@apache.org>
Authored: Mon Jun 18 15:14:21 2018 +0900
Committer: daewon <da...@apache.org>
Committed: Mon Jun 18 15:14:21 2018 +0900

----------------------------------------------------------------------
 .../apache/s2graph/graphql/GraphQLServer.scala  |  13 ++-
 .../graphql/middleware/GraphFormatWriter.scala  | 101 +++++++++++++++++
 .../graphql/repository/GraphRepository.scala    |   5 +-
 .../graphql/types/PlayJsonScalarType.scala      | 112 +++++++++++++++++++
 4 files changed, 226 insertions(+), 5 deletions(-)
----------------------------------------------------------------------



[5/5] incubator-s2graph git commit: [S2GRAPH-219] Added query that includes all vertices and associated edges for GraphVisualize.

Posted by da...@apache.org.
[S2GRAPH-219] Added query that includes all vertices and associated edges for GraphVisualize.

JIRA:
  [S2GRAPH-219] https://issues.apache.org/jira/browse/S2GRAPH-219

Pull Request:
  Closes #170

Author
  daewon <da...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/commit/35a369f5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/tree/35a369f5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/diff/35a369f5

Branch: refs/heads/master
Commit: 35a369f556c370e57149e06740cf128daf24313b
Parents: 2dd88b3
Author: daewon <da...@apache.org>
Authored: Mon Jun 18 15:14:52 2018 +0900
Committer: daewon <da...@apache.org>
Committed: Mon Jun 18 15:14:52 2018 +0900

----------------------------------------------------------------------
 CHANGES | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/35a369f5/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 7cc4f1d..cded3e5 100644
--- a/CHANGES
+++ b/CHANGES
@@ -93,6 +93,7 @@ Release Notes - S2Graph - Version 0.2.0
     * [S2GRAPH-183] - Provide batch job to dump data stored in HBase into file.
     * [S2GRAPH-206] - Generalize machine learning model serving.
     * [S2GRAPH-215] - Implement a Storage Backend for JDBC driver, such as H2, MySql using the Mutator and Fetcher interfaces
+    * [S2GRAPH-219] - Added query that includes all vertices and associated edges for GraphVisualize. 
 
 ** Task
     * [S2GRAPH-162] - Update year in the NOTICE file.


[2/5] incubator-s2graph git commit: make middleware for GraphFormatWriter

Posted by da...@apache.org.
make middleware for GraphFormatWriter


Project: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/commit/c13a5e92
Tree: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/tree/c13a5e92
Diff: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/diff/c13a5e92

Branch: refs/heads/master
Commit: c13a5e92d248f028fab5a110a61f9a98ea0d7993
Parents: bb78c7d
Author: daewon <da...@apache.org>
Authored: Tue Jun 12 17:04:33 2018 +0900
Committer: daewon <da...@apache.org>
Committed: Tue Jun 12 17:04:33 2018 +0900

----------------------------------------------------------------------
 .../apache/s2graph/graphql/GraphQLServer.scala  |  11 +-
 .../graphql/middleware/GraphFormatWriter.scala  | 101 +++++++++++++++++++
 .../s2graph/graphql/middleware/SigmaJS.scala    | 101 -------------------
 3 files changed, 110 insertions(+), 103 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/c13a5e92/s2graphql/src/main/scala/org/apache/s2graph/graphql/GraphQLServer.scala
----------------------------------------------------------------------
diff --git a/s2graphql/src/main/scala/org/apache/s2graph/graphql/GraphQLServer.scala b/s2graphql/src/main/scala/org/apache/s2graph/graphql/GraphQLServer.scala
index d333c9e..b444213 100644
--- a/s2graphql/src/main/scala/org/apache/s2graph/graphql/GraphQLServer.scala
+++ b/s2graphql/src/main/scala/org/apache/s2graph/graphql/GraphQLServer.scala
@@ -28,7 +28,7 @@ import akka.http.scaladsl.server._
 import com.typesafe.config.ConfigFactory
 import org.apache.s2graph.core.S2Graph
 import org.apache.s2graph.core.utils.SafeUpdateCache
-import org.apache.s2graph.graphql.middleware.{SigmaJSFormatted}
+import org.apache.s2graph.graphql.middleware.{GraphFormatted}
 import org.apache.s2graph.graphql.repository.GraphRepository
 import org.apache.s2graph.graphql.types.SchemaDef
 import org.slf4j.LoggerFactory
@@ -123,6 +123,13 @@ object GraphQLServer {
     import GraphRepository._
     val resolver: DeferredResolver[GraphRepository] = DeferredResolver.fetchers(vertexFetcher, edgeFetcher)
 
+    val includeGrpaph = vars.fields.get("includeGraph").contains(spray.json.JsBoolean(true))
+    val middleWares = if (includeGrpaph) {
+      GraphFormatted :: Nil
+    } else {
+      Nil
+    }
+
     Executor.execute(
       s2schema,
       query,
@@ -130,7 +137,7 @@ object GraphQLServer {
       variables = vars,
       operationName = op,
       deferredResolver = resolver,
-      middleware = SigmaJSFormatted :: Nil
+      middleware = middleWares
     )
       .map((res: spray.json.JsValue) => OK -> res)
       .recover {

http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/c13a5e92/s2graphql/src/main/scala/org/apache/s2graph/graphql/middleware/GraphFormatWriter.scala
----------------------------------------------------------------------
diff --git a/s2graphql/src/main/scala/org/apache/s2graph/graphql/middleware/GraphFormatWriter.scala b/s2graphql/src/main/scala/org/apache/s2graph/graphql/middleware/GraphFormatWriter.scala
new file mode 100644
index 0000000..91fea62
--- /dev/null
+++ b/s2graphql/src/main/scala/org/apache/s2graph/graphql/middleware/GraphFormatWriter.scala
@@ -0,0 +1,101 @@
+package org.apache.s2graph.graphql.middleware
+
+import org.apache.s2graph.core.schema.ServiceColumn
+import org.apache.s2graph.core.{GraphElement, S2EdgeLike, S2VertexLike}
+import org.apache.s2graph.graphql.types.PlayJsonScalarType
+import org.slf4s.LoggerFactory
+import play.api.libs.json._
+import sangria.execution._
+import sangria.schema.Context
+
+
+object GraphFormatted extends Middleware[Any] with MiddlewareAfterField[Any] with MiddlewareExtension[Any] {
+  implicit val logger = LoggerFactory.getLogger(this.getClass)
+
+  type QueryVal = java.util.concurrent.ConcurrentHashMap[GraphElement, Unit]
+
+  type FieldVal = Long
+
+
+  def beforeQuery(context: MiddlewareQueryContext[Any, _, _]) = {
+    new java.util.concurrent.ConcurrentHashMap[GraphElement, Unit]()
+  }
+
+  def afterQuery(queryVal: QueryVal, context: MiddlewareQueryContext[Any, _, _]) = ()
+
+  def toVertexId(v: S2VertexLike, c: ServiceColumn): String = {
+    val innerId = v.innerId.toIdString()
+
+    s"${c.service.serviceName}.${c.columnName}.${innerId}"
+  }
+
+  def toVertexJson(v: S2VertexLike, c: ServiceColumn): JsValue = {
+    Json.obj(
+      "id" -> toVertexId(v, c),
+      "label" -> v.innerId.toIdString()
+    )
+  }
+
+  def toEdgeJson(e: S2EdgeLike): JsValue = {
+    Json.obj(
+      "source" -> toVertexId(e.srcVertex, e.innerLabel.srcColumn),
+      "target" -> toVertexId(e.tgtVertex, e.innerLabel.tgtColumn),
+      "id" -> s"${toVertexId(e.srcVertex, e.innerLabel.srcColumn)}.${e.label()}.${toVertexId(e.tgtVertex, e.innerLabel.tgtColumn)}",
+      "label" -> e.label()
+    )
+  }
+
+  def afterQueryExtensions(queryVal: QueryVal,
+                           context: MiddlewareQueryContext[Any, _, _]
+                          ): Vector[Extension[_]] = {
+
+    import scala.collection.JavaConverters._
+    val elements = queryVal.keys().asScala.toVector
+
+    val edges = elements.collect { case e: S2EdgeLike => e }
+    val vertices = elements.collect { case v: S2VertexLike => v -> v.serviceColumn }
+    val verticesFromEdges = edges.flatMap { e =>
+      val label = e.innerLabel
+      Vector((e.srcVertex, label.srcColumn), (e.tgtVertex, label.srcColumn))
+    }
+
+    val verticesJson = (vertices ++ verticesFromEdges).map { case (v, c) => toVertexJson(v, c) }.distinct
+    val edgeJson = edges.map(toEdgeJson).distinct
+
+    val jsElements = Json.obj(
+      "nodes" -> verticesJson,
+      "edges" -> edgeJson
+    )
+
+    val graph = Json.obj("graph" -> jsElements)
+
+    /**
+      * nodes: [{id, label, x, y, size}, ..],
+      * edges: [{id, source, target, label}]
+      */
+    implicit val iu = PlayJsonScalarType.PlayJsonInputUnmarshaller
+    Vector(Extension[JsValue](graph))
+  }
+
+  def beforeField(queryVal: QueryVal, mctx: MiddlewareQueryContext[Any, _, _], ctx: Context[Any, _]) = {
+    continue(System.currentTimeMillis())
+  }
+
+  def afterField(queryVal: QueryVal, fieldVal: FieldVal, value: Any, mctx: MiddlewareQueryContext[Any, _, _], ctx: Context[Any, _]) = {
+    //    logger.info(s"${ctx.parentType.name}.${ctx.field.name} = ${value.getClass.getName}")
+
+    value match {
+      case ls: Seq[_] => ls.foreach {
+        case e: GraphElement => queryVal.put(e, ())
+        case _ =>
+      }
+      case e: GraphElement => queryVal.put(e, ())
+      case _ =>
+    }
+
+    None
+  }
+}
+
+
+

http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/c13a5e92/s2graphql/src/main/scala/org/apache/s2graph/graphql/middleware/SigmaJS.scala
----------------------------------------------------------------------
diff --git a/s2graphql/src/main/scala/org/apache/s2graph/graphql/middleware/SigmaJS.scala b/s2graphql/src/main/scala/org/apache/s2graph/graphql/middleware/SigmaJS.scala
deleted file mode 100644
index bf03ac2..0000000
--- a/s2graphql/src/main/scala/org/apache/s2graph/graphql/middleware/SigmaJS.scala
+++ /dev/null
@@ -1,101 +0,0 @@
-package org.apache.s2graph.graphql.middleware
-
-import org.apache.s2graph.core.schema.ServiceColumn
-import org.apache.s2graph.core.{GraphElement, S2EdgeLike, S2VertexLike}
-import org.apache.s2graph.graphql.types.PlayJsonScalarType
-import org.slf4s.LoggerFactory
-import play.api.libs.json._
-import sangria.execution._
-import sangria.schema.Context
-
-
-object SigmaJSFormatted extends Middleware[Any] with MiddlewareAfterField[Any] with MiddlewareExtension[Any] {
-  implicit val logger = LoggerFactory.getLogger(this.getClass)
-
-  type QueryVal = java.util.concurrent.ConcurrentHashMap[GraphElement, Unit]
-
-  type FieldVal = Long
-
-
-  def beforeQuery(context: MiddlewareQueryContext[Any, _, _]) = {
-    new java.util.concurrent.ConcurrentHashMap[GraphElement, Unit]()
-  }
-
-  def afterQuery(queryVal: QueryVal, context: MiddlewareQueryContext[Any, _, _]) = ()
-
-  def toVertexId(v: S2VertexLike, c: ServiceColumn): String = {
-    val innerId = v.innerId.toIdString()
-
-    s"${c.service.serviceName}.${c.columnName}.${innerId}"
-  }
-
-  def toVertexJson(v: S2VertexLike, c: ServiceColumn): JsValue = {
-    Json.obj(
-      "id" -> toVertexId(v, c),
-      "label" -> v.innerId.toIdString()
-    )
-  }
-
-  def toEdgeJson(e: S2EdgeLike): JsValue = {
-    Json.obj(
-      "source" -> toVertexId(e.srcVertex, e.innerLabel.srcColumn),
-      "target" -> toVertexId(e.tgtVertex, e.innerLabel.tgtColumn),
-      "id" -> s"${toVertexId(e.srcVertex, e.innerLabel.srcColumn)}.${e.label()}.${toVertexId(e.tgtVertex, e.innerLabel.tgtColumn)}",
-      "label" -> e.label()
-    )
-  }
-
-  def afterQueryExtensions(queryVal: QueryVal,
-                           context: MiddlewareQueryContext[Any, _, _]
-                          ): Vector[Extension[_]] = {
-
-    import scala.collection.JavaConverters._
-    val elements = queryVal.keys().asScala.toVector
-
-    val edges = elements.collect { case e: S2EdgeLike => e }
-    val vertices = elements.collect { case v: S2VertexLike => v -> v.serviceColumn }
-    val verticesFromEdges = edges.flatMap { e =>
-      val label = e.innerLabel
-      Vector((e.srcVertex, label.srcColumn), (e.tgtVertex, label.srcColumn))
-    }
-
-    val verticesJson = (vertices ++ verticesFromEdges).distinct.map { case (v, c) => toVertexJson(v, c) }
-    val edgeJson = edges.distinct.map(toEdgeJson)
-
-    val jsElements = Json.obj(
-      "nodes" -> verticesJson,
-      "edges" -> edgeJson
-    )
-
-    val graph = Json.obj("graph" -> jsElements)
-
-    /**
-      * nodes: [{id, label, x, y, size}, ..],
-      * edges: [{id, source, target, label}]
-      */
-    implicit val iu = PlayJsonScalarType.PlayJsonInputUnmarshaller
-    Vector(Extension[JsValue](graph))
-  }
-
-  def beforeField(queryVal: QueryVal, mctx: MiddlewareQueryContext[Any, _, _], ctx: Context[Any, _]) = {
-    continue(System.currentTimeMillis())
-  }
-
-  def afterField(queryVal: QueryVal, fieldVal: FieldVal, value: Any, mctx: MiddlewareQueryContext[Any, _, _], ctx: Context[Any, _]) = {
-    //    logger.info(s"${ctx.parentType.name}.${ctx.field.name} = ${value.getClass.getName}")
-
-    value match {
-      case ls: Seq[_] => ls.foreach {
-        case e: GraphElement => queryVal.put(e, ())
-        case _ =>
-      }
-      case e: GraphElement => queryVal.put(e, ())
-      case _ =>
-    }
-
-    None
-  }
-}
-
-
-