add tc for management api
Project: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/commit/1c60e256 Tree: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/tree/1c60e256 Diff: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/diff/1c60e256 Branch: refs/heads/master Commit: 1c60e256c585a7bc253e524862d72288fbef2db2 Parents: 0c8057f Author: daewon <[email protected]> Authored: Mon Mar 26 12:57:26 2018 +0900 Committer: daewon <[email protected]> Committed: Mon Mar 26 12:57:26 2018 +0900 ---------------------------------------------------------------------- .../s2graph/graphql/marshaller/package.scala | 5 +- .../graphql/repository/GraphRepository.scala | 22 ++-- .../graphql/types/S2ManagementType.scala | 13 +-- .../apache/s2graph/graphql/ScenarioTest.scala | 100 +++++++++++++++++++ 4 files changed, 116 insertions(+), 24 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/1c60e256/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 ac73e14..82394fb 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 @@ -57,7 +57,7 @@ package object marshaller { val marshaller = CoercedScalaResultMarshaller.default def fromResult(node: marshaller.Node) = { - val input = node.asInstanceOf[Map[String, Any]] + val input = node.asInstanceOf[RawNode] Index(input("name").asInstanceOf[String], input("propNames").asInstanceOf[Seq[String]]) } } @@ -66,7 +66,7 @@ package object marshaller { val marshaller = CoercedScalaResultMarshaller.default def fromResult(node: marshaller.Node) = { - val input = node.asInstanceOf[Map[String, Any]] + val input = node.asInstanceOf[RawNode] val name = input("name").asInstanceOf[String] val defaultValue = input("defaultValue").asInstanceOf[String] @@ -102,5 +102,4 @@ package object marshaller { partialServiceColumns.toVector } } - } http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/1c60e256/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 55abacb..c934fd5 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 @@ -124,17 +124,13 @@ class GraphRepository(val graph: S2GraphLike) { } } - def deleteServiceColumn(args: Args): List[Try[ServiceColumn]] = { - val partialColumns = args.arg[Vector[ServiceColumnParam]]("serviceName") + def deleteServiceColumn(args: Args): Try[ServiceColumn] = { + val serviceColumnParam = args.arg[ServiceColumnParam]("service") - val serviceColumns = partialColumns.map { pc => - val serviceName = pc.serviceName - val columnName = pc.columnName + val serviceName = serviceColumnParam.serviceName + val columnName = serviceColumnParam.columnName - Management.deleteColumn(serviceName, columnName) - } - - serviceColumns.toList + Management.deleteColumn(serviceName, columnName) } def addPropsToLabel(args: Args): Try[Label] = { @@ -152,12 +148,12 @@ class GraphRepository(val graph: S2GraphLike) { def addPropsToServiceColumn(args: Args): Try[ServiceColumn] = { Try { - val pc = args.arg[Vector[ServiceColumnParam]]("service").head + val serviceColumnParam = args.arg[ServiceColumnParam]("service") - val serviceName = pc.serviceName - val columnName = pc.columnName + val serviceName = serviceColumnParam.serviceName + val columnName = serviceColumnParam.columnName - pc.props.foreach { prop => + serviceColumnParam.props.foreach { prop => Management.addVertexProp(serviceName, columnName, prop.name, prop.dataType, prop.defaultValue, prop.storeInGlobalIndex) } http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/1c60e256/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 e7e6a3f..7c6ce38 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 @@ -216,13 +216,13 @@ class S2ManagementType(repo: GraphRepository) { "hTableTTL" -> IntType ).map { case (name, _type) => Argument(name, OptionInputType(_type)) } - val AddPropServiceType = InputObjectType[Vector[ServiceColumnParam]]( + val AddPropServiceType = InputObjectType[ServiceColumnParam]( "Input_Service_ServiceColumn_Props", description = "desc", fields = DummyInputField +: serviceColumnOnServiceWithPropInputObjectFields ) - val ServiceColumnSelectType = InputObjectType[Vector[ServiceColumnParam]]( + val ServiceColumnSelectType = InputObjectType[ServiceColumnParam]( "Input_Service_ServiceColumn", description = "desc", fields = DummyInputField +: serviceColumnOnServiceInputObjectFields @@ -307,7 +307,6 @@ class S2ManagementType(repo: GraphRepository) { arguments = NameArg :: serviceOptArgs, resolve = c => MutationResponse(c.ctx.createService(c.args)) ), - Field("createLabel", LabelMutationResponseType, arguments = NameArg :: PropArg :: IndicesArg :: labelRequiredArg ::: labelOptsArgs, @@ -318,18 +317,16 @@ class S2ManagementType(repo: GraphRepository) { arguments = LabelNameArg :: Nil, resolve = c => MutationResponse(c.ctx.deleteLabel(c.args)) ), - Field("createServiceColumn", ServiceColumnMutationResponseType, arguments = List(ServiceNameRawArg, Argument("columnName", StringType), ColumnTypeArg, PropArg), resolve = c => MutationResponse(c.ctx.createServiceColumn(c.args)) ), Field("deleteServiceColumn", - ListType(ServiceColumnMutationResponseType), - arguments = Argument("serviceName", ServiceColumnSelectType) :: Nil, - resolve = c => c.ctx.deleteServiceColumn(c.args).map(MutationResponse(_)) + ServiceColumnMutationResponseType, + arguments = Argument("service", ServiceColumnSelectType) :: Nil, + resolve = c => MutationResponse(c.ctx.deleteServiceColumn(c.args)) ), - Field("addPropsToServiceColumn", ServiceColumnMutationResponseType, arguments = Argument("service", AddPropServiceType) :: Nil, http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/1c60e256/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 c5ea043..caa4584 100644 --- a/s2graphql/src/test/scala/org/apache/s2graph/graphql/ScenarioTest.scala +++ b/s2graphql/src/test/scala/org/apache/s2graph/graphql/ScenarioTest.scala @@ -3,6 +3,7 @@ package org.apache.s2graph.graphql import com.typesafe.config.ConfigFactory import org.scalatest._ import play.api.libs.json._ +import sangria.execution.ValidationError import sangria.macros._ class ScenarioTest extends FunSpec with Matchers with BeforeAndAfterAll { @@ -494,4 +495,103 @@ class ScenarioTest extends FunSpec with Matchers with BeforeAndAfterAll { actual shouldBe expected } } + + describe("Management: Delete label, service column") { + + it("should delete label: 'friends' and serviceColumn: 'user' on kakao") { + val query = + graphql""" + + mutation { + Management { + deleteLabel(name: friends) { + isSuccess + } + + deleteServiceColumn(service: { + kakao: { + columnName: user + } + }) { + isSuccess + } + } + } + """ + + val actual = testGraph.queryAsJs(query) + val expected = Json.parse( + """ + { + "data": { + "Management": { + "deleteLabel": { + "isSuccess": true + }, + "deleteServiceColumn": { + "isSuccess": true + } + } + } + } + """) + + actual shouldBe expected + } + + it("should fetch failed label: 'friends' and serviceColumn: 'user'") { + val query = + graphql""" + + query { + Management { + Label(name: friends) { + name + props { + name + dataType + } + } + + } + } + """ + + // label 'friends' was deleted + assertThrows[ValidationError] { + testGraph.queryAsJs(query) + } + + val queryServiceColumn = + graphql""" + + query { + Management { + Service(name: kakao) { + serviceColumns { + name + } + } + } + } + """ + + // serviceColumn 'user' was deleted + val actual = testGraph.queryAsJs(queryServiceColumn) + val expected = Json.parse( + """ + { + "data": { + "Management": { + "Service": { + "serviceColumns": [] + } + } + } + } + """) + + actual shouldBe expected + } + } }
