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/04/11 08:08:09 UTC
[3/5] incubator-s2graph git commit: move module
move module
Project: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/commit/a3e1e391
Tree: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/tree/a3e1e391
Diff: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/diff/a3e1e391
Branch: refs/heads/master
Commit: a3e1e391f3e2554fd7b7bff0befed5ee19cb9199
Parents: 1fe5768
Author: daewon <da...@apache.org>
Authored: Fri Apr 6 14:02:49 2018 +0900
Committer: daewon <da...@apache.org>
Committed: Fri Apr 6 14:05:20 2018 +0900
----------------------------------------------------------------------
.../s2graph/graphql/bind/Unmarshaller.scala | 48 ------------
.../s2graph/graphql/types/FieldResolver.scala | 77 ++++++++++++++++++++
.../apache/s2graph/graphql/types/S2Type.scala | 66 +++++++----------
3 files changed, 103 insertions(+), 88 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/a3e1e391/s2graphql/src/main/scala/org/apache/s2graph/graphql/bind/Unmarshaller.scala
----------------------------------------------------------------------
diff --git a/s2graphql/src/main/scala/org/apache/s2graph/graphql/bind/Unmarshaller.scala b/s2graphql/src/main/scala/org/apache/s2graph/graphql/bind/Unmarshaller.scala
index 94c1e01..807fe48 100644
--- a/s2graphql/src/main/scala/org/apache/s2graph/graphql/bind/Unmarshaller.scala
+++ b/s2graphql/src/main/scala/org/apache/s2graph/graphql/bind/Unmarshaller.scala
@@ -124,52 +124,4 @@ object Unmarshaller {
partialServiceColumns.toVector
}
}
-
- def labelField(label: Label, c: Context[GraphRepository, Any]): (S2VertexLike, QueryParam) = {
- val vertex = c.value.asInstanceOf[S2VertexLike]
-
- val dir = c.arg[String]("direction")
- val offset = c.arg[Int]("offset") + 1 // +1 for skip degree edge: currently not support
- val limit = c.arg[Int]("limit")
- val whereClauseOpt = c.argOpt[String]("filter")
- val where = c.ctx.parser.extractWhere(label, whereClauseOpt)
-
- val qp = QueryParam(
- labelName = label.label,
- direction = dir,
- offset = offset,
- limit = limit,
- whereRawOpt = whereClauseOpt,
- where = where
- )
-
- (vertex, qp)
- }
-
- def serviceColumnFieldOnService(column: ServiceColumn, c: Context[GraphRepository, Any]): (Seq[S2VertexLike], Boolean) = {
- val ids = c.argOpt[Any]("id").toSeq ++ c.argOpt[List[Any]]("ids").toList.flatten
- val vertices = ids.map(vid => c.ctx.toS2VertexLike(vid, column))
-
- val columnFields = column.metasInvMap.keySet
- val selectedFields = AstHelper.selectedFields(c.astFields)
-
- val canSkipFetch = selectedFields.forall(f => f == "id" || !columnFields(f))
-
- (vertices, canSkipFetch)
- }
-
- def serviceColumnFieldOnLabel(c: Context[GraphRepository, Any]): (S2VertexLike, Boolean) = {
- val edge = c.value.asInstanceOf[S2EdgeLike]
-
- val vertex = edge.tgtForVertex
- val column = vertex.serviceColumn
-
- val selectedFields = AstHelper.selectedFields(c.astFields)
- val columnFields = column.metasInvMap.keySet
-
- val canSkipFetch = selectedFields.forall(f => f == "id" || !columnFields(f))
-
- (vertex, canSkipFetch)
- }
-
}
http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/a3e1e391/s2graphql/src/main/scala/org/apache/s2graph/graphql/types/FieldResolver.scala
----------------------------------------------------------------------
diff --git a/s2graphql/src/main/scala/org/apache/s2graph/graphql/types/FieldResolver.scala b/s2graphql/src/main/scala/org/apache/s2graph/graphql/types/FieldResolver.scala
new file mode 100644
index 0000000..4f092dd
--- /dev/null
+++ b/s2graphql/src/main/scala/org/apache/s2graph/graphql/types/FieldResolver.scala
@@ -0,0 +1,77 @@
+package org.apache.s2graph.graphql.types
+
+import org.apache.s2graph.core._
+import org.apache.s2graph.core.mysqls._
+import org.apache.s2graph.graphql.bind.AstHelper
+import org.apache.s2graph.graphql.repository.GraphRepository
+import sangria.schema._
+
+object FieldResolver {
+
+ def graphElement[A](name: String, cType: String, c: Context[GraphRepository, Any]): A = {
+ c.value match {
+ case v: S2VertexLike => name match {
+ case "timestamp" => v.ts.asInstanceOf[A]
+ case _ =>
+ val innerVal = v.propertyValue(name).get
+ JSONParser.innerValToAny(innerVal, cType).asInstanceOf[A]
+ }
+ case e: S2EdgeLike => name match {
+ case "timestamp" => e.ts.asInstanceOf[A]
+ case "direction" => e.getDirection().asInstanceOf[A]
+ case _ =>
+ val innerVal = e.propertyValue(name).get.innerVal
+ JSONParser.innerValToAny(innerVal, cType).asInstanceOf[A]
+ }
+ case _ =>
+ throw new RuntimeException(s"Error on resolving field: ${name}, ${cType}, ${c.value.getClass}")
+ }
+ }
+
+ def label(label: Label, c: Context[GraphRepository, Any]): (S2VertexLike, QueryParam) = {
+ val vertex = c.value.asInstanceOf[S2VertexLike]
+
+ val dir = c.arg[String]("direction")
+ val offset = c.arg[Int]("offset") + 1 // +1 for skip degree edge: currently not support
+ val limit = c.arg[Int]("limit")
+ val whereClauseOpt = c.argOpt[String]("filter")
+ val where = c.ctx.parser.extractWhere(label, whereClauseOpt)
+
+ val qp = QueryParam(
+ labelName = label.label,
+ direction = dir,
+ offset = offset,
+ limit = limit,
+ whereRawOpt = whereClauseOpt,
+ where = where
+ )
+
+ (vertex, qp)
+ }
+
+ def serviceColumnOnService(column: ServiceColumn, c: Context[GraphRepository, Any]): (Seq[S2VertexLike], Boolean) = {
+ val ids = c.argOpt[Any]("id").toSeq ++ c.argOpt[List[Any]]("ids").toList.flatten
+ val vertices = ids.map(vid => c.ctx.toS2VertexLike(vid, column))
+
+ val columnFields = column.metasInvMap.keySet
+ val selectedFields = AstHelper.selectedFields(c.astFields)
+
+ val canSkipFetch = selectedFields.forall(f => f == "id" || !columnFields(f))
+
+ (vertices, canSkipFetch)
+ }
+
+ def serviceColumnOnLabel(c: Context[GraphRepository, Any]): (S2VertexLike, Boolean) = {
+ val edge = c.value.asInstanceOf[S2EdgeLike]
+
+ val vertex = edge.tgtForVertex
+ val column = vertex.serviceColumn
+
+ val selectedFields = AstHelper.selectedFields(c.astFields)
+ val columnFields = column.metasInvMap.keySet
+
+ val canSkipFetch = selectedFields.forall(f => f == "id" || !columnFields(f))
+
+ (vertex, canSkipFetch)
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/a3e1e391/s2graphql/src/main/scala/org/apache/s2graph/graphql/types/S2Type.scala
----------------------------------------------------------------------
diff --git a/s2graphql/src/main/scala/org/apache/s2graph/graphql/types/S2Type.scala b/s2graphql/src/main/scala/org/apache/s2graph/graphql/types/S2Type.scala
index 7a46bd1..d458ba4 100644
--- a/s2graphql/src/main/scala/org/apache/s2graph/graphql/types/S2Type.scala
+++ b/s2graphql/src/main/scala/org/apache/s2graph/graphql/types/S2Type.scala
@@ -23,9 +23,11 @@ import scala.concurrent._
import org.apache.s2graph.core.Management.JsonModel.{Index, Prop}
import org.apache.s2graph.core._
import org.apache.s2graph.core.mysqls._
+import org.apache.s2graph.graphql
import org.apache.s2graph.graphql.repository.GraphRepository
import sangria.schema._
-import org.apache.s2graph.graphql.bind.{AstHelper, Unmarshaller}
+import org.apache.s2graph.graphql.bind.AstHelper
+import org.apache.s2graph.graphql.repository
import org.apache.s2graph.graphql.types.StaticTypes._
import scala.language.existentials
@@ -48,37 +50,23 @@ object S2Type {
columnName: String,
props: Seq[Prop] = Nil)
- def makeField[A](name: String, cType: String, tpe: ScalarType[A]): Field[GraphRepository, Any] =
- Field(name,
- OptionType(tpe),
- description = Option("desc here"),
- resolve = c => c.value match {
- case v: S2VertexLike => name match {
- case "timestamp" => v.ts.asInstanceOf[A]
- case _ =>
- val innerVal = v.propertyValue(name).get
- JSONParser.innerValToAny(innerVal, cType).asInstanceOf[A]
- }
- case e: S2EdgeLike => name match {
- case "timestamp" => e.ts.asInstanceOf[A]
- case "direction" => e.getDirection().asInstanceOf[A]
- case _ =>
- val innerVal = e.propertyValue(name).get.innerVal
- JSONParser.innerValToAny(innerVal, cType).asInstanceOf[A]
- }
- case _ =>
- throw new RuntimeException(s"Error on resolving field: ${name}, ${cType}, ${c.value.getClass}")
- }
- )
+ def makeGraphElementField(cName: String, cType: String): Field[GraphRepository, Any] = {
+ def makeField[A](name: String, cType: String, tpe: ScalarType[A]): Field[GraphRepository, Any] =
+ Field(name,
+ OptionType(tpe),
+ description = Option("desc here"),
+ resolve = c => FieldResolver.graphElement[A](name, cType, c)
+ )
- def makePropField(cName: String, cType: String): Field[GraphRepository, Any] = cType match {
- case "boolean" | "bool" => makeField[Boolean](cName, cType, BooleanType)
- case "string" | "str" | "s" => makeField[String](cName, cType, StringType)
- case "int" | "integer" | "i" | "int32" | "integer32" => makeField[Int](cName, cType, IntType)
- case "long" | "l" | "int64" | "integer64" => makeField[Long](cName, cType, LongType)
- case "double" | "d" => makeField[Double](cName, cType, FloatType)
- case "float64" | "float" | "f" | "float32" => makeField[Double](cName, "double", FloatType)
- case _ => throw new RuntimeException(s"Cannot support data type: ${cType}")
+ cType match {
+ case "boolean" | "bool" => makeField[Boolean](cName, cType, BooleanType)
+ case "string" | "str" | "s" => makeField[String](cName, cType, StringType)
+ case "int" | "integer" | "i" | "int32" | "integer32" => makeField[Int](cName, cType, IntType)
+ case "long" | "l" | "int64" | "integer64" => makeField[Long](cName, cType, LongType)
+ case "double" | "d" => makeField[Double](cName, cType, FloatType)
+ case "float64" | "float" | "f" | "float32" => makeField[Double](cName, "double", FloatType)
+ case _ => throw new RuntimeException(s"Cannot support data type: ${cType}")
+ }
}
def makeInputFieldsOnService(service: Service): Seq[InputField[Any]] = {
@@ -125,7 +113,7 @@ object S2Type {
val inLabels = diffLabel.filter(l => column == l.tgtColumn).distinct.toList
val inOutLabels = sameLabel.filter(l => l.srcColumn == column && l.tgtColumn == column)
- lazy val columnFields = (reservedFields ++ columnMetasKv).map { case (k, v) => makePropField(k, v) }
+ lazy val columnFields = (reservedFields ++ columnMetasKv).map { case (k, v) => makeGraphElementField(k, v) }
lazy val outLabelFields: List[Field[GraphRepository, Any]] = outLabels.map(l => makeLabelField("out", l, allLabels))
lazy val inLabelFields: List[Field[GraphRepository, Any]] = inLabels.map(l => makeLabelField("in", l, allLabels))
@@ -138,14 +126,14 @@ object S2Type {
}
def makeServiceField(service: Service, allLabels: List[Label])(implicit repo: GraphRepository): List[Field[GraphRepository, Any]] = {
- lazy val columnsOnService = service.serviceColumns(false).toList.map { column =>
+ val columnsOnService = service.serviceColumns(false).toList.map { column =>
lazy val serviceColumnFields = makeServiceColumnFields(column, allLabels)
lazy val ColumnType = ObjectType(
s"ServiceColumn_${service.serviceName}_${column.columnName}",
() => fields[GraphRepository, Any](serviceColumnFields: _*)
)
- val v = Field(column.columnName,
+ Field(column.columnName,
ListType(ColumnType),
arguments = List(
Argument("id", OptionInputType(toScalarType(column.columnType))),
@@ -154,14 +142,12 @@ object S2Type {
description = Option("desc here"),
resolve = c => {
implicit val ec = c.ctx.ec
- val (vertices, canSkipFetchVertex) = Unmarshaller.serviceColumnFieldOnService(column, c)
+ val (vertices, canSkipFetchVertex) = graphql.types.FieldResolver.serviceColumnOnService(column, c)
if (canSkipFetchVertex) Future.successful(vertices)
else c.ctx.getVertices(vertices)
}
): Field[GraphRepository, Any]
-
- v
}
columnsOnService
@@ -174,7 +160,7 @@ object S2Type {
val column = if (dir == "out") label.tgtColumn else label.srcColumn
lazy val labelFields: List[Field[GraphRepository, Any]] =
- (labelReserved ++ labelProps).map { case (k, v) => makePropField(k, v) }
+ (labelReserved ++ labelProps).map { case (k, v) => makeGraphElementField(k, v) }
lazy val labelPropField = wrapField(s"Label_${label.label}_props", "props", labelFields)
@@ -184,7 +170,7 @@ object S2Type {
lazy val serviceColumnField: Field[GraphRepository, Any] = Field(column.columnName, labelColumnType, resolve = c => {
implicit val ec = c.ctx.ec
- val (vertex, canSkipFetchVertex) = Unmarshaller.serviceColumnFieldOnLabel(c)
+ val (vertex, canSkipFetchVertex) = graphql.types.FieldResolver.serviceColumnOnLabel(c)
if (canSkipFetchVertex) Future.successful(vertex)
else c.ctx.getVertices(Seq(vertex)).map(_.head) // fill props
@@ -225,7 +211,7 @@ object S2Type {
arguments = dirArgs ++ paramArgs,
description = Some("fetch edges"),
resolve = { c =>
- val (vertex, queryParam) = Unmarshaller.labelField(label, c)
+ val (vertex, queryParam) = graphql.types.FieldResolver.label(label, c)
c.ctx.getEdges(vertex, queryParam)
}
)