change createLabel param type

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

Branch: refs/heads/master
Commit: eb9bb0fb9c1a4d2d845e62c9128186df34c6b02e
Parents: 36e4e03
Author: daewon <[email protected]>
Authored: Fri Mar 2 15:22:13 2018 +0900
Committer: daewon <[email protected]>
Committed: Fri Mar 2 15:22:13 2018 +0900

----------------------------------------------------------------------
 .../s2graph/graphql/marshaller/package.scala    | 11 ++++--
 .../graphql/repository/GraphRepository.scala    | 24 ++++++------
 .../graphql/types/S2ManagementType.scala        | 40 +++++++++++---------
 .../apache/s2graph/graphql/types/S2Type.scala   |  3 ++
 4 files changed, 46 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/eb9bb0fb/s2graphql/src/main/scala/org/apache/s2graph/graphql/marshaller/package.scala
----------------------------------------------------------------------
diff --git 
a/s2graphql/src/main/scala/org/apache/s2graph/graphql/marshaller/package.scala 
b/s2graphql/src/main/scala/org/apache/s2graph/graphql/marshaller/package.scala
index 28579db..cb7f705 100644
--- 
a/s2graphql/src/main/scala/org/apache/s2graph/graphql/marshaller/package.scala
+++ 
b/s2graphql/src/main/scala/org/apache/s2graph/graphql/marshaller/package.scala
@@ -25,12 +25,17 @@ package object marshaller {
     }
   }
 
-  implicit object LabelServiceFromInput extends FromInput[LabelServiceProp] {
+  implicit object PartialServiceColumnFromInput extends 
FromInput[PartialServiceColumn] {
     val marshaller = CoercedScalaResultMarshaller.default
 
     def fromResult(node: marshaller.Node) = {
-      val input = node.asInstanceOf[Map[String, String]]
-      LabelServiceProp(input("name"), input("columnName"), input("dataType"))
+      val input = node.asInstanceOf[Map[String, Any]]
+      val serviceColumns = input.collect { case (serviceName, Some(map: 
Map[String, Any])) =>
+        val columnName = map("columnName").asInstanceOf[String]
+        PartialServiceColumn(serviceName = serviceName, columnName = 
columnName)
+      }
+
+      serviceColumns.head
     }
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/eb9bb0fb/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 edaebbd..5697319 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
@@ -164,8 +164,8 @@ class GraphRepository(val graph: S2GraphLike) {
   def deleteServiceColumn(args: Args): List[Try[ServiceColumn]] = {
     println(args)
     //Args(Map(s2graph -> Some(Map(columnName -> 
_))),Set(),Set(s2graph),Set(),TrieMap())
-    val serviceColumns = args.raw.collect { case (serviceName, Some(map: 
Map[String, String])) =>
-      val columnName = map("columnName")
+    val serviceColumns = args.raw.collect { case (serviceName, Some(map: 
Map[String, Any])) =>
+      val columnName = map("columnName").asInstanceOf[String]
       Management.deleteColumn(serviceName, columnName)
     }
 
@@ -175,13 +175,15 @@ class GraphRepository(val graph: S2GraphLike) {
   def createLabel(args: Args): Try[Label] = {
     val labelName = args.arg[String]("name")
 
-    val srcServiceProp = args.arg[LabelServiceProp]("sourceService")
-    val tgtServiceProp = args.arg[LabelServiceProp]("targetService")
+    val srcServiceProp = args.arg[PartialServiceColumn]("sourceService")
+    val srcServiceColumn = 
ServiceColumn.find(Service.findByName(srcServiceProp.serviceName).get.id.get, 
srcServiceProp.columnName).get
+    val tgtServiceProp = args.arg[PartialServiceColumn]("targetService")
+    val tgtServiceColumn = 
ServiceColumn.find(Service.findByName(tgtServiceProp.serviceName).get.id.get, 
tgtServiceProp.columnName).get
 
     val allProps = args.argOpt[Vector[Prop]]("props").getOrElse(Vector.empty)
     val indices = args.argOpt[Vector[Index]]("indices").getOrElse(Vector.empty)
 
-    val serviceName = 
args.argOpt[String]("serviceName").getOrElse(tgtServiceProp.name)
+    val serviceName = 
args.argOpt[String]("serviceName").getOrElse(tgtServiceColumn.service.serviceName)
     val consistencyLevel = 
args.argOpt[String]("consistencyLevel").getOrElse("weak")
     val hTableName = args.argOpt[String]("hTableName")
     val hTableTTL = args.argOpt[Int]("hTableTTL")
@@ -193,12 +195,12 @@ class GraphRepository(val graph: S2GraphLike) {
 
     val labelTry: scala.util.Try[Label] = management.createLabel(
       labelName,
-      srcServiceProp.name,
-      srcServiceProp.columnName,
-      srcServiceProp.dataType,
-      tgtServiceProp.name,
-      tgtServiceProp.columnName,
-      tgtServiceProp.dataType,
+      srcServiceProp.serviceName,
+      srcServiceColumn.columnName,
+      srcServiceColumn.columnType,
+      tgtServiceProp.serviceName,
+      tgtServiceColumn.columnName,
+      tgtServiceColumn.columnType,
       isDirected,
       serviceName,
       indices,

http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/eb9bb0fb/s2graphql/src/main/scala/org/apache/s2graph/graphql/types/S2ManagementType.scala
----------------------------------------------------------------------
diff --git 
a/s2graphql/src/main/scala/org/apache/s2graph/graphql/types/S2ManagementType.scala
 
b/s2graphql/src/main/scala/org/apache/s2graph/graphql/types/S2ManagementType.scala
index b1cc299..67a4b30 100644
--- 
a/s2graphql/src/main/scala/org/apache/s2graph/graphql/types/S2ManagementType.scala
+++ 
b/s2graphql/src/main/scala/org/apache/s2graph/graphql/types/S2ManagementType.scala
@@ -31,17 +31,13 @@ import sangria.schema._
 
 import scala.language.existentials
 import scala.util.{Failure, Success, Try}
-
 import org.apache.s2graph.graphql.marshaller._
+import org.apache.s2graph.graphql.types.S2Type.PartialServiceColumn
 
 object S2ManagementType {
 
   import sangria.schema._
 
-  case class LabelServiceProp(name: String,
-                              columnName: String,
-                              dataType: String)
-
   case class MutationResponse[T](result: Try[T])
 
   def makeMutationResponseType[T](name: String, desc: String, tpe: 
ObjectType[_, T]) = {
@@ -101,6 +97,14 @@ class S2ManagementType(repo: GraphRepository) {
     Argument(service.serviceName, OptionInputType(ServiceColumnOnServiceType))
   }
 
+  lazy val ServiceColumnOnServiceInputObjectType = repo.allServices.map { 
service =>
+    InputField(service.serviceName, OptionInputType(InputObjectType(
+      "columnName",
+      description = "desc here",
+      fields = List(InputField("columnName", 
makeServiceColumnEnumTypeOnService(service)))
+    )))
+  }
+
   def makeServiceColumnEnumTypeOnService(service: Service): EnumType[String] = 
{
     val columns = service.serviceColumns(false).toList
     EnumType(
@@ -160,17 +164,6 @@ class S2ManagementType(repo: GraphRepository) {
       }
   )
 
-  lazy val InputLabelServiceType = InputObjectType[LabelServiceProp](
-    "LabelServiceProp",
-    description = "desc here",
-    fields = List(
-      InputField("name", ServiceListType),
-      InputField("columnName", StringType),
-      InputField("dataType", DataTypeType)
-    )
-  )
-
-
   lazy val ServiceMutationResponseType = makeMutationResponseType[Service](
     "MutateService",
     "desc here",
@@ -223,10 +216,21 @@ class S2ManagementType(repo: GraphRepository) {
     "hTableTTL" -> IntType
   ).map { case (name, _type) => Argument(name, OptionInputType(_type)) }
 
+  val SourceServiceType = InputObjectType[PartialServiceColumn](
+    "sourceService",
+    description = "desc",
+    fields = ServiceColumnOnServiceInputObjectType
+  )
+
+  val TargetServiceType = InputObjectType[PartialServiceColumn](
+    "sourceService",
+    description = "desc",
+    fields = ServiceColumnOnServiceInputObjectType
+  )
 
   lazy val labelRequiredArg = List(
-    "sourceService" -> InputLabelServiceType,
-    "targetService" -> InputLabelServiceType
+    "sourceService" -> SourceServiceType,
+    "targetService" -> TargetServiceType
   ).map { case (name, _type) => Argument(name, _type) }
 
   val labelOptsArgs = List(

http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/eb9bb0fb/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 478d37e..23874e1 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
@@ -36,6 +36,9 @@ import org.apache.s2graph.graphql.marshaller._
 
 object S2Type {
 
+  case class PartialServiceColumn(serviceName: String,
+                                  columnName: String)
+
   case class PartialServiceParam(service: Service,
                                  vid: Any)
 

Reply via email to