add vertices on add edges

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

Branch: refs/heads/master
Commit: 18c2219eed3f1f02a4677173f36ec555c393324a
Parents: a5afdf2
Author: daewon <[email protected]>
Authored: Fri Mar 23 19:19:36 2018 +0900
Committer: daewon <[email protected]>
Committed: Fri Mar 23 19:19:36 2018 +0900

----------------------------------------------------------------------
 .../apache/s2graph/graphql/types/S2Type.scala   | 21 +++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/18c2219e/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 59506d4..c2f7f6e 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
@@ -149,6 +149,8 @@ object S2Type {
         ),
         description = Option("desc here"),
         resolve = c => {
+          implicit val ec = c.ctx.ec
+
           val ids = c.argOpt[Any]("id").toSeq ++ 
c.argOpt[List[Any]]("ids").toList.flatten
           val vertices = ids.map(vid => c.ctx.toS2VertexLike(vid, column))
 
@@ -156,8 +158,12 @@ object S2Type {
             f.selections.map(s => s.asInstanceOf[sangria.ast.Field].name)
           }
 
-          if (selectedFields.forall(_ == "id")) 
scala.concurrent.Future.successful(vertices)
+          val a = if (selectedFields.forall(_ == "id")) 
scala.concurrent.Future.successful(vertices)
           else repo.getVertices(vertices) // fill props
+
+          println(a)
+          a.foreach(println)
+          a
         }
       ): Field[GraphRepository, Any]
     }
@@ -242,6 +248,7 @@ class S2Type(repo: GraphRepository) {
     */
   lazy val serviceFields: List[Field[GraphRepository, Any]] = 
repo.allServices.map { service =>
     lazy val serviceFields = DummyObjectTypeField :: makeServiceField(service, 
repo.allLabels())
+
     lazy val ServiceType = ObjectType(
       s"Service_${service.serviceName}",
       fields[GraphRepository, Any](serviceFields: _*)
@@ -261,11 +268,12 @@ class S2Type(repo: GraphRepository) {
   lazy val addVertexArg = {
     val serviceArguments = repo.allServices().map { service =>
       val serviceFields = DummyInputField +: makeInputFieldsOnService(service)
-      val serviceInputType = InputObjectType[List[AddVertexParam]](
+
+      val ServiceInputType = InputObjectType[List[AddVertexParam]](
         s"Input_vertex_${service.serviceName}_param",
         () => serviceFields.toList
       )
-      Argument(service.serviceName, OptionInputType(serviceInputType))
+      Argument(service.serviceName, OptionInputType(ServiceInputType))
     }
 
     serviceArguments
@@ -318,6 +326,13 @@ class S2Type(repo: GraphRepository) {
           }
         }
 
+        c.ctx.addVertices(edges.toSeq.flatMap { e =>
+          Seq(
+            c.ctx.toS2VertexLike(e.srcVertex.innerId, 
e.srcVertex.serviceColumn),
+            c.ctx.toS2VertexLike(e.tgtVertex.innerId, 
e.tgtVertex.serviceColumn)
+          )
+        })
+
         c.ctx.addEdges(edges.toSeq)
       }
     )

Reply via email to