change addVertex api, add test case for addVertex
Project: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/commit/574c89d6 Tree: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/tree/574c89d6 Diff: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/diff/574c89d6 Branch: refs/heads/master Commit: 574c89d6167b5bd5620beea20cf1fbc59498b4ec Parents: 717b9b8 Author: daewon <[email protected]> Authored: Wed Mar 21 18:42:26 2018 +0900 Committer: daewon <[email protected]> Committed: Wed Mar 21 18:42:26 2018 +0900 ---------------------------------------------------------------------- .../s2graph/graphql/marshaller/package.scala | 79 +++++------ .../graphql/repository/GraphRepository.scala | 74 ++++------- .../graphql/types/S2ManagementType.scala | 8 +- .../apache/s2graph/graphql/types/S2Type.scala | 130 ++++++++----------- .../apache/s2graph/graphql/types/package.scala | 1 - .../apache/s2graph/graphql/ScenarioTest.scala | 88 ++++++++++--- 6 files changed, 188 insertions(+), 192 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/574c89d6/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 46351b8..97a8097 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 @@ -2,19 +2,39 @@ package org.apache.s2graph.graphql import org.apache.s2graph.core.Management.JsonModel._ import org.apache.s2graph.graphql.types.S2Type._ -import org.apache.s2graph.graphql.types.S2ManagementType._ import sangria.marshalling._ package object marshaller { - - def unwrap(map: Map[String, Any]): Map[String, Any] = map.map { + def unwrapOption(map: Map[String, Any]): Map[String, Any] = map.map { case (k, v: Some[_]) => v.get match { - case m: Map[_, _] => k -> unwrap(m.asInstanceOf[Map[String, Any]]) + case m: Map[_, _] => k -> unwrapOption(m.asInstanceOf[Map[String, Any]]) case _ => k -> v.get } + case (k, v: Map[_, _]) => k -> unwrapOption(v.asInstanceOf[Map[String, Any]]) case org@_ => org } + implicit object AddVertexParamFromInput extends FromInput[Vector[AddVertexParam]] { + val marshaller = CoercedScalaResultMarshaller.default + + def fromResult(node: marshaller.Node) = { + val currentTime = System.currentTimeMillis() + val inenrMap = unwrapOption(node.asInstanceOf[Map[String, Any]]) + + val params = inenrMap.flatMap { case (serviceName, serviceColumnMap) => + serviceColumnMap.asInstanceOf[Map[String, Any]].map { case (columnName, vertexParamMap) => + val propMap = vertexParamMap.asInstanceOf[Map[String, Any]] + val id = propMap("id") + val ts = propMap.getOrElse("timestamp", currentTime).asInstanceOf[Long] + + AddVertexParam(ts, id, serviceName, columnName, propMap.filterKeys(k => k != "timestamp" || k != "id")) + } + } + + params.toVector + } + } + implicit object IndexFromInput extends FromInput[Index] { val marshaller = CoercedScalaResultMarshaller.default @@ -39,17 +59,17 @@ package object marshaller { } } - implicit object PartialServiceColumnFromInput extends FromInput[PartialServiceColumn] { + implicit object ServiceColumnParamFromInput extends FromInput[ServiceColumnParam] { val marshaller = CoercedScalaResultMarshaller.default - def fromResult(node: marshaller.Node) = PartialServiceColumnsFromInput.fromResult(node).head + def fromResult(node: marshaller.Node) = ServiceColumnParamsFromInput.fromResult(node).head } - implicit object PartialServiceColumnsFromInput extends FromInput[Vector[PartialServiceColumn]] { + implicit object ServiceColumnParamsFromInput extends FromInput[Vector[ServiceColumnParam]] { val marshaller = CoercedScalaResultMarshaller.default def fromResult(node: marshaller.Node) = { - val input = unwrap(node.asInstanceOf[Map[String, Any]]) + val input = unwrapOption(node.asInstanceOf[Map[String, Any]]) val partialServiceColumns = input.map { case (serviceName, serviceColumnMap) => val innerMap = serviceColumnMap.asInstanceOf[Map[String, Any]] @@ -58,51 +78,14 @@ package object marshaller { vs.map(PropFromInput.fromResult) } - PartialServiceColumn(serviceName, columnName, props) + ServiceColumnParam(serviceName, columnName, props) } partialServiceColumns.toVector } } - implicit object PartialServiceVertexParamFromInput extends FromInput[Vector[PartialServiceVertexParam]] { - val marshaller = CoercedScalaResultMarshaller.default - - def fromResult(node: marshaller.Node) = { - val inputMap = node.asInstanceOf[Map[String, marshaller.Node]] - - val ret = inputMap.toVector.map { case (columnName, node) => - val param = PartialVertexFromInput.fromResult(node) - PartialServiceVertexParam(columnName, param) - } - - ret - } - } - - implicit object PartialVertexFromInput extends FromInput[PartialVertexParam] { - val marshaller = CoercedScalaResultMarshaller.default - - def fromResult(node: marshaller.Node) = { - - val _inputMap = node.asInstanceOf[Option[Map[String, Any]]] - val inputMap = _inputMap.get - - val id = inputMap("id") - val ts = inputMap.get("timestamp") match { - case Some(Some(v)) => v.asInstanceOf[Long] - case _ => System.currentTimeMillis() - } - val props = inputMap.get("props") match { - case Some(Some(v)) => v.asInstanceOf[Map[String, Option[Any]]].filter(_._2.isDefined).mapValues(_.get) - case _ => Map.empty[String, Any] - } - - PartialVertexParam(ts, id, props) - } - } - - implicit object PartialEdgeFromInput extends FromInput[PartialEdgeParam] { + implicit object AddEdgeParamFromInput extends FromInput[AddEdgeParam] { val marshaller = CoercedScalaResultMarshaller.default def fromResult(node: marshaller.Node) = { @@ -126,7 +109,7 @@ package object marshaller { case _ => Map.empty[String, Any] } - PartialEdgeParam(ts, from, to, dir, props) + AddEdgeParam(ts, from, to, dir, props) } } http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/574c89d6/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 6c9158c..4c802c3 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 @@ -40,26 +40,13 @@ object GraphRepository { * @param graph */ class GraphRepository(val graph: S2GraphLike) { + val management = graph.management val parser = new RequestParser(graph) implicit val ec = graph.ec - def partialServiceParamToVertex(column: ServiceColumn, param: PartialServiceParam): S2VertexLike = { - val vid = JSONParser.toInnerVal(param.vid, column.columnType, column.schemaVersion) - graph.toVertex(param.service.serviceName, column.columnName, vid) - } - - def partialVertexParamToS2Vertex(serviceName: String, columnName: String, param: PartialVertexParam): S2VertexLike = { - graph.toVertex( - serviceName = serviceName, - columnName = columnName, - id = param.id, - props = param.props, - ts = param.ts) - } - - def partialEdgeParamToS2Edge(labelName: String, param: PartialEdgeParam): S2EdgeLike = { + def AddEdgeParamToS2Edge(labelName: String, param: AddEdgeParam): S2EdgeLike = { graph.toEdge( srcId = param.from, tgtId = param.to, @@ -69,36 +56,33 @@ class GraphRepository(val graph: S2GraphLike) { ) } - def addVertex(args: Args): Future[Option[MutateResponse]] = { - val vertices: Seq[S2VertexLike] = args.raw.keys.toList.flatMap { serviceName => - val innerMap = args.arg[Vector[PartialServiceVertexParam]](serviceName) - val ret = innerMap.map { param => - partialVertexParamToS2Vertex(serviceName, param.columnName, param.vertexParam) - } - - ret - } - - graph.mutateVertices(vertices, withWait = true).map(_.headOption) + def toVertex(vid: Any, column: ServiceColumn): S2VertexLike = { + graph.toVertex(column.service.serviceName, column.columnName, vid) } - def addVertices(args: Args): Future[Seq[MutateResponse]] = { - val vertices: Seq[S2VertexLike] = args.raw.keys.toList.flatMap { serviceName => - val innerMap = args.arg[Map[String, Vector[PartialVertexParam]]](serviceName) + def parseAddVertexParam(args: Args): Seq[S2VertexLike] = { + val vertexParams = args.arg[Vector[Vector[AddVertexParam]]]("vertex") - innerMap.flatMap { case (columnName, params) => - params.map { param => - partialVertexParamToS2Vertex(serviceName, columnName, param) - } + vertexParams.flatMap { params => + params.map { param => + graph.toVertex( + serviceName = param.serviceName, + columnName = param.columnName, + id = param.id, + props = param.props, + ts = param.timestamp) } } + } + + def addVertex(vertices: Seq[S2VertexLike]): Future[Seq[MutateResponse]] = { graph.mutateVertices(vertices, withWait = true) } def addEdges(args: Args): Future[Seq[MutateResponse]] = { val edges: Seq[S2EdgeLike] = args.raw.keys.toList.flatMap { labelName => - val params = args.arg[Vector[PartialEdgeParam]](labelName) - params.map(param => partialEdgeParamToS2Edge(labelName, param)) + val params = args.arg[Vector[AddEdgeParam]](labelName) + params.map(param => AddEdgeParamToS2Edge(labelName, param)) } graph.mutateEdges(edges, withWait = true) @@ -106,19 +90,15 @@ class GraphRepository(val graph: S2GraphLike) { def addEdge(args: Args): Future[Option[MutateResponse]] = { val edges: Seq[S2EdgeLike] = args.raw.keys.toList.map { labelName => - val param = args.arg[PartialEdgeParam](labelName) - partialEdgeParamToS2Edge(labelName, param) + val param = args.arg[AddEdgeParam](labelName) + AddEdgeParamToS2Edge(labelName, param) } graph.mutateEdges(edges, withWait = true).map(_.headOption) } - def getVertex(vertex: S2VertexLike): Future[Seq[S2VertexLike]] = { - val f = graph.getVertices(Seq(vertex)) - f.foreach { a => - println(a) - } - f + def getVertices(vertex: Seq[S2VertexLike]): Future[Seq[S2VertexLike]] = { + graph.getVertices(vertex) } def getEdges(vertex: S2VertexLike, label: Label, _dir: String): Future[Seq[S2EdgeLike]] = { @@ -166,7 +146,7 @@ class GraphRepository(val graph: S2GraphLike) { } def deleteServiceColumn(args: Args): List[Try[ServiceColumn]] = { - val partialColumns = args.arg[Vector[PartialServiceColumn]]("serviceName") + val partialColumns = args.arg[Vector[ServiceColumnParam]]("serviceName") val serviceColumns = partialColumns.map { pc => val serviceName = pc.serviceName @@ -193,7 +173,7 @@ class GraphRepository(val graph: S2GraphLike) { def addPropsToServiceColumn(args: Args): Try[ServiceColumn] = { Try { - val pc = args.arg[Vector[PartialServiceColumn]]("service").head + val pc = args.arg[Vector[ServiceColumnParam]]("service").head val serviceName = pc.serviceName val columnName = pc.columnName @@ -210,9 +190,9 @@ class GraphRepository(val graph: S2GraphLike) { def createLabel(args: Args): Try[Label] = { val labelName = args.arg[String]("name") - val srcServiceProp = args.arg[PartialServiceColumn]("sourceService") + val srcServiceProp = args.arg[ServiceColumnParam]("sourceService") val srcServiceColumn = ServiceColumn.find(Service.findByName(srcServiceProp.serviceName).get.id.get, srcServiceProp.columnName).get - val tgtServiceProp = args.arg[PartialServiceColumn]("targetService") + val tgtServiceProp = args.arg[ServiceColumnParam]("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) http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/574c89d6/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 51cc448..e7e6a3f 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 @@ -32,7 +32,7 @@ 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} +import org.apache.s2graph.graphql.types.S2Type.{ServiceColumnParam} object S2ManagementType { @@ -216,19 +216,19 @@ class S2ManagementType(repo: GraphRepository) { "hTableTTL" -> IntType ).map { case (name, _type) => Argument(name, OptionInputType(_type)) } - val AddPropServiceType = InputObjectType[Vector[PartialServiceColumn]]( + val AddPropServiceType = InputObjectType[Vector[ServiceColumnParam]]( "Input_Service_ServiceColumn_Props", description = "desc", fields = DummyInputField +: serviceColumnOnServiceWithPropInputObjectFields ) - val ServiceColumnSelectType = InputObjectType[Vector[PartialServiceColumn]]( + val ServiceColumnSelectType = InputObjectType[Vector[ServiceColumnParam]]( "Input_Service_ServiceColumn", description = "desc", fields = DummyInputField +: serviceColumnOnServiceInputObjectFields ) - val InputServiceType = InputObjectType[PartialServiceColumn]( + val InputServiceType = InputObjectType[ServiceColumnParam]( "Input_Service", description = "desc", fields = DummyInputField +: serviceColumnOnServiceInputObjectFields http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/574c89d6/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 51c66e5..698de5a 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,25 +36,23 @@ import org.apache.s2graph.graphql.marshaller._ object S2Type { - case class PartialServiceColumn(serviceName: String, - columnName: String, - props: Seq[Prop] = Nil) + case class AddVertexParam(timestamp: Long, + id: Any, + serviceName: String, + columnName: String, + props: Map[String, Any]) - case class PartialServiceParam(service: Service, - vid: Any) + case class AddEdgeParam(ts: Long, + from: Any, + to: Any, + direction: String, + props: Map[String, Any]) - case class PartialVertexParam(ts: Long, - id: Any, - props: Map[String, Any]) + // management params + case class ServiceColumnParam(serviceName: String, + columnName: String, + props: Seq[Prop] = Nil) - case class PartialServiceVertexParam(columnName: String, - vertexParam: PartialVertexParam) - - case class PartialEdgeParam(ts: Long, - from: Any, - to: Any, - direction: String, - props: Map[String, Any]) val DirArg = Argument("direction", OptionInputType(DirectionType), "desc here", defaultValue = "out") @@ -95,30 +93,7 @@ object S2Type { } } - def makeInputPartialVertexParamType(service: Service, - serviceColumn: ServiceColumn): InputObjectType[PartialVertexParam] = { - lazy val InputPropsType = InputObjectType[Map[String, ScalarType[_]]]( - s"Input_${service.serviceName}_${serviceColumn.columnName}_vertex_props", - description = "desc here", - () => serviceColumn.metas.filter(ColumnMeta.isValid).map { lm => - InputField(lm.name, OptionInputType(s2TypeToScalarType(lm.dataType))) - } - ) - - lazy val fields = List( - InputField("_", OptionInputType(LongType)) - ) - - InputObjectType[PartialVertexParam]( - s"Input_${service.serviceName}_${serviceColumn.columnName}_vertex_mutate", - description = "desc here", - () => - if (!serviceColumn.metas.exists(ColumnMeta.isValid)) fields - else List(InputField("props", OptionInputType(InputPropsType))) - ) - } - - def makeInputPartialEdgeParamType(label: Label): InputObjectType[PartialEdgeParam] = { + def makeInputPartialEdgeParamType(label: Label): InputObjectType[AddEdgeParam] = { lazy val InputPropsType = InputObjectType[Map[String, ScalarType[_]]]( s"Input_${label.label}_edge_props", description = "desc here", @@ -134,7 +109,7 @@ object S2Type { InputField("direction", OptionInputType(DirectionType)) ) - InputObjectType[PartialEdgeParam]( + InputObjectType[AddEdgeParam]( s"Input_${label.label}_edge_mutate", description = "desc here", () => @@ -169,22 +144,17 @@ object S2Type { ), description = Option("desc here"), resolve = c => { - println(c.parentType.name) - c.astFields.foreach { f => - f.selections.foreach(s => { - println(s) - }) - } - val id = c.argOpt[Any]("id").toSeq + val id = c.argOpt[Any]("id").toSeq val ids = c.argOpt[List[Any]]("ids").toList.flatten val svc = c.ctx.findServiceByName(service.serviceName).get - val vids = (id ++ ids).map { vid => - val vp = PartialServiceParam(svc, vid) - c.ctx.partialServiceParamToVertex(column, vp) + val vertices = (id ++ ids).map(vid => c.ctx.toVertex(vid, column)) + + val selectedFields = c.astFields.flatMap{ f => + f.selections.map(s => s.asInstanceOf[sangria.ast.Field].name) } - repo.getVertex(vids.head) + if (selectedFields.forall(_ == "id")) vertices else repo.getVertices(vertices) // fill props } ): Field[GraphRepository, Any] } @@ -213,9 +183,9 @@ object S2Type { val vertex: S2VertexLike = c.value match { case v: S2VertexLike => v case e: S2Edge => if (dir == "out") e.tgtVertex else e.srcVertex - case vp: PartialServiceParam => - if (dir == "out") c.ctx.partialServiceParamToVertex(label.tgtColumn, vp) - else c.ctx.partialServiceParamToVertex(label.srcColumn, vp) +// case vp: ServiceParam => +// if (dir == "out") c.ctx.toVertex(label.tgtColumn, vp) +// else c.ctx.toVertex(label.srcColumn, vp) } c.ctx.getEdges(vertex, label, dir) @@ -254,18 +224,31 @@ class S2Type(repo: GraphRepository) { /** * arguments */ - lazy val addVertexArg = repo.allServices.flatMap { service => - service.serviceColumns(false).map { serviceColumn => - val inputPartialVertexParamType = makeInputPartialVertexParamType(service, serviceColumn) - Argument(serviceColumn.columnName, OptionInputType(inputPartialVertexParamType)) - } - } + lazy val addVertexArg = { + val fields = repo.allServices.map { service => + val inputFields = service.serviceColumns(false).map { serviceColumn => + val idField = InputField("id", s2TypeToScalarType(serviceColumn.columnType)) + val propFields = serviceColumn.metas.filter(ColumnMeta.isValid).map { lm => + InputField(lm.name, OptionInputType(s2TypeToScalarType(lm.dataType))) + } - lazy val addVerticesArg = repo.allServices.flatMap { service => - service.serviceColumns(false).map { serviceColumn => - val inputPartialVertexParamType = makeInputPartialVertexParamType(service, serviceColumn) - Argument(serviceColumn.columnName, OptionInputType(ListInputType(inputPartialVertexParamType))) + val vertexMutateType = InputObjectType[Map[String, Any]]( + s"Input_${service.serviceName}_${serviceColumn.columnName}_vertex_mutate", + description = "desc here", + () => idField :: propFields + ) + + InputField[Any](serviceColumn.columnName, vertexMutateType) + } + + val tpe = InputObjectType[Any]( + s"${service.serviceName}_param", fields = DummyInputField :: inputFields.toList + ) + + InputField(service.serviceName, OptionInputType(tpe)) } + + InputObjectType[Vector[AddVertexParam]]("vertex_input", fields = DummyInputField :: fields) } lazy val addEdgeArg = repo.allLabels().map { label => @@ -287,24 +270,17 @@ class S2Type(repo: GraphRepository) { lazy val mutationFields: List[Field[GraphRepository, Any]] = List( Field("addVertex", - OptionType(MutateResponseType), - arguments = addVertexArg, - resolve = c => c.ctx.addVertex(c.args) - ), - Field("addVertices", ListType(MutateResponseType), - arguments = addVerticesArg, - resolve = c => c.ctx.addVertices(c.args) + arguments = Argument("vertex", ListInputType(addVertexArg)) :: Nil, + resolve = c => { + val vertices = repo.parseAddVertexParam(c.args) + c.ctx.addVertex(vertices) + } ), Field("addEdge", OptionType(MutateResponseType), arguments = addEdgeArg, resolve = c => c.ctx.addEdge(c.args) - ), - Field("addEdges", - ListType(MutateResponseType), - arguments = addEdgesArg, - resolve = c => c.ctx.addEdges(c.args) ) ) } http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/574c89d6/s2graphql/src/main/scala/org/apache/s2graph/graphql/types/package.scala ---------------------------------------------------------------------- diff --git a/s2graphql/src/main/scala/org/apache/s2graph/graphql/types/package.scala b/s2graphql/src/main/scala/org/apache/s2graph/graphql/types/package.scala index 72498d8..ec633f7 100644 --- a/s2graphql/src/main/scala/org/apache/s2graph/graphql/types/package.scala +++ b/s2graphql/src/main/scala/org/apache/s2graph/graphql/types/package.scala @@ -24,7 +24,6 @@ import org.apache.s2graph.core.{JSONParser, S2EdgeLike, S2VertexLike} import org.apache.s2graph.core.mysqls._ import org.apache.s2graph.core.storage.MutateResponse import org.apache.s2graph.graphql.repository.GraphRepository -import org.apache.s2graph.graphql.types.S2Type.PartialServiceParam import sangria.macros.derive._ import sangria.schema._ http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/574c89d6/s2graphql/src/test/scala/org/apache/s2graph/graphql/ScenarioTest.scala ---------------------------------------------------------------------- diff --git a/s2graphql/src/test/scala/org/apache/s2graph/graphql/ScenarioTest.scala b/s2graphql/src/test/scala/org/apache/s2graph/graphql/ScenarioTest.scala index 6a06a31..0c08125 100644 --- a/s2graphql/src/test/scala/org/apache/s2graph/graphql/ScenarioTest.scala +++ b/s2graphql/src/test/scala/org/apache/s2graph/graphql/ScenarioTest.scala @@ -321,29 +321,87 @@ class ScenarioTest extends FunSpec with Matchers with BeforeAndAfterAll { } } - describe("Add vertex to kakao.user'") { - val query = - graphql""" + describe("Add vertex to kakao.user' and fetch ") { + it("add vertices daewon(age: 20), shon(age: 19) to kakao#user") { + val query = + graphql""" + mutation { - addVertex( - labelName: friends - props: { - name: "score" - dataType: float - defaultValue: "0" - storeInGlobalIndex: true - }) - { + addVertex( + vertex: [{ + kakao: { + user: { + id: "daewon" + age: 20 + } + } + }, + { + kakao: { + user: { + id: "shon" + age: 19 + } + } + }] + ) { isSuccess } } """ - } + val actual = testGraph.queryAsJs(query) + val expected = Json.parse( + """ + { + "data": { + "addVertex": [{ + "isSuccess": true + }, { + "isSuccess": true + }] + } + } + """) - describe("Add edge to label 'friends'") { + actual shouldBe expected + } - } + it("fetch vertex daewon(age: 20), shon(age: 19)") { + val query = + graphql""" + + query FetchVertices { + kakao { + user(ids: ["daewon", "shon"]) { + id + age + } + } + } + """ + val actual = testGraph.queryAsJs(query) + val expected = Json.parse( + """ + { + "data": { + "kakao": { + "user": [{ + "id": "daewon", + "age": 20 + }, { + "id": "shon", + "age": 19 + }] + } + } + } + """ + ) + + actual shouldBe expected + } + } } }
