add dummy object for empty input 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/bce636c8 Tree: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/tree/bce636c8 Diff: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/diff/bce636c8 Branch: refs/heads/master Commit: bce636c8f376c40e75655c0bb840bd622aa14f80 Parents: ca35bb5 Author: daewon <[email protected]> Authored: Tue Mar 6 20:05:19 2018 +0900 Committer: daewon <[email protected]> Committed: Wed Mar 7 11:09:58 2018 +0900 ---------------------------------------------------------------------- .../apache/s2graph/core/mysqls/LabelMeta.scala | 4 +- s2graphql/build.sbt | 1 + .../graphql/types/S2ManagementType.scala | 8 +- .../org/apache/s2graph/graphql/SchemaTest.scala | 102 ++++++++++++++++--- 4 files changed, 95 insertions(+), 20 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/bce636c8/s2core/src/main/scala/org/apache/s2graph/core/mysqls/LabelMeta.scala ---------------------------------------------------------------------- diff --git a/s2core/src/main/scala/org/apache/s2graph/core/mysqls/LabelMeta.scala b/s2core/src/main/scala/org/apache/s2graph/core/mysqls/LabelMeta.scala index c715c47..3f54f49 100644 --- a/s2core/src/main/scala/org/apache/s2graph/core/mysqls/LabelMeta.scala +++ b/s2core/src/main/scala/org/apache/s2graph/core/mysqls/LabelMeta.scala @@ -205,7 +205,9 @@ case class LabelMeta(id: Option[Int], defaultValue: String, dataType: String, storeInGlobalIndex: Boolean = false) { - lazy val toJson = Json.obj("name" -> name, "defaultValue" -> defaultValue, "dataType" -> dataType) + + lazy val toJson = Json.obj("name" -> name, "defaultValue" -> defaultValue, "dataType" -> dataType, "storeInGlobalIndex" -> storeInGlobalIndex) + override def equals(other: Any): Boolean = { if (!other.isInstanceOf[LabelMeta]) false else { http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/bce636c8/s2graphql/build.sbt ---------------------------------------------------------------------- diff --git a/s2graphql/build.sbt b/s2graphql/build.sbt index 9e74b7d..a3fbec0 100644 --- a/s2graphql/build.sbt +++ b/s2graphql/build.sbt @@ -28,6 +28,7 @@ scalacOptions ++= Seq("-deprecation", "-feature") libraryDependencies ++= Seq( "org.sangria-graphql" %% "sangria" % "1.4.0", "org.sangria-graphql" %% "sangria-spray-json" % "1.0.0", + "org.sangria-graphql" %% "sangria-play-json" % "1.0.1" % Test, "com.typesafe.akka" %% "akka-http" % "10.0.10", "com.typesafe.akka" %% "akka-http-spray-json" % "10.0.10", http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/bce636c8/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 3317755..cf0fa32 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 @@ -208,25 +208,25 @@ class S2ManagementType(repo: GraphRepository) { val AddPropServiceType = InputObjectType[Vector[PartialServiceColumn]]( "Input_Service_ServiceColumn_Props", description = "desc", - fields = serviceColumnOnServiceWithPropInputObjectFields + fields = DummyInputField +: serviceColumnOnServiceWithPropInputObjectFields ) val ServiceColumnSelectType = InputObjectType[Vector[PartialServiceColumn]]( "Input_Service_ServiceColumn", description = "desc", - fields = serviceColumnOnServiceInputObjectFields + fields = DummyInputField +: serviceColumnOnServiceInputObjectFields ) val LabelPropType = InputObjectType[Vector[PartialLabelMeta]]( "Input_Label_Props", description = "desc", - fields = labelPropsInputFields + fields = DummyInputField +: labelPropsInputFields ) val InputServiceType = InputObjectType[PartialServiceColumn]( "Input_Service", description = "desc", - fields = serviceColumnOnServiceInputObjectFields + fields = DummyInputField +: serviceColumnOnServiceInputObjectFields ) lazy val serviceField: Field[GraphRepository, Any] = Field( http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/bce636c8/s2graphql/src/test/scala/org/apache/s2graph/graphql/SchemaTest.scala ---------------------------------------------------------------------- diff --git a/s2graphql/src/test/scala/org/apache/s2graph/graphql/SchemaTest.scala b/s2graphql/src/test/scala/org/apache/s2graph/graphql/SchemaTest.scala index 6ff3d02..b866130 100644 --- a/s2graphql/src/test/scala/org/apache/s2graph/graphql/SchemaTest.scala +++ b/s2graphql/src/test/scala/org/apache/s2graph/graphql/SchemaTest.scala @@ -1,13 +1,16 @@ package org.apache.s2graph.graphql +import java.io + import com.typesafe.config.{Config, ConfigFactory} import org.apache.s2graph.core.Management.JsonModel.Prop import org.apache.s2graph.core.mysqls.{Label, Service} import org.apache.s2graph.core.{Management, S2Graph} import org.apache.s2graph.core.rest.RequestParser +import org.apache.s2graph.core.utils.logger import org.apache.s2graph.graphql.repository.GraphRepository import org.scalatest.{BeforeAndAfterAll, FunSuite, Matchers} -import play.api.libs.json.{JsObject, JsString, Json} +import play.api.libs.json.{JsObject, JsString, JsValue, Json} import sangria.ast.Document import scala.concurrent.Await @@ -18,6 +21,7 @@ import sangria.execution.Executor import sangria.execution.deferred.DeferredResolver import sangria.parser.QueryParser import sangria.renderer.SchemaRenderer +import sangria.schema.Schema import scala.util._ @@ -27,6 +31,7 @@ class SchemaTest extends FunSuite with Matchers with BeforeAndAfterAll { var management: Management = _ var config: Config = _ var s2Repository: GraphRepository = _ + var s2Schema: Schema[GraphRepository, Any] = _ override def beforeAll = { config = ConfigFactory.load() @@ -76,6 +81,13 @@ class SchemaTest extends FunSuite with Matchers with BeforeAndAfterAll { val isPrepared = List(serviceTry, serviceColumnTry, labelTry).forall(_.isSuccess) + s2Schema = new SchemaDef(s2Repository).S2GraphSchema + + println("-" * 80) + println(SchemaRenderer.renderSchema(s2Schema)) + println("-" * 80) + + require(isPrepared, "should created metadata") } @@ -83,13 +95,6 @@ class SchemaTest extends FunSuite with Matchers with BeforeAndAfterAll { graph.shutdown(true) } - test("s2 schema") { - val s2Schema = new SchemaDef(s2Repository).S2GraphSchema - println(SchemaRenderer.renderSchema(s2Schema)) - - true - } - test("s2 schema should has types") { val s2Schema = new SchemaDef(s2Repository).S2GraphSchema @@ -176,16 +181,83 @@ class SchemaTest extends FunSuite with Matchers with BeforeAndAfterAll { ) ) + val actual = Await.result(Executor.execute(s2Schema, query, s2Repository), Duration("10 sec")) + val maps = actual.asInstanceOf[Map[String, Map[String, Map[String, Vector[Map[String, String]]]]]]("data")("__schema")("types") - val ret = Await.result(Executor.execute(s2Schema, query, s2Repository), Duration("10 sec")) - val maps = ret.asInstanceOf[Map[String, Map[String, Map[String, Vector[Map[String, String]]]]]]("data")("__schema")("types") + val expectedSet = expected("data")("__schema")("types").flatMap(_.values.headOption).toSet + val actualSet = maps.flatMap(_.values.headOption).toSet - val expectedSet = (expected("data")("__schema")("types").flatMap(_.values.headOption).toSet) - val retSet = (maps.flatMap(_.values.headOption).toSet) + logger.info(s"expected only has: ${expectedSet -- actualSet}") + logger.info(s"actual only has: ${actualSet -- expectedSet}") - println(expectedSet -- retSet) - println(retSet -- expectedSet) + actualSet should be(expectedSet) + } - retSet should be(expectedSet) + test("Management query should have service: 'kakao'") { + val Success(query) = QueryParser.parse( + """ + query GetServiceAndLabel { + Management { + Services(name: kakao) { + serviceColumns { + props { + name + defaultValue + dataType + } + } + } + } + } + """) + + implicit val playJsonMarshaller = sangria.marshalling.playJson.PlayJsonResultMarshaller + + val actual: JsValue = Await.result(Executor.execute(s2Schema, query, s2Repository), Duration("10 sec")) + +// val expected: Map[String, Map[String, Map[String, Vector[Map[String, Vector[Map[String, Vector[Map[String, String]]]]]]]]] = +// Map("data" -> +// Map("Management" -> +// Map("Services" -> +// Vector( +// Map("serviceColumns" -> +// Vector( +// Map( +// "props" -> +// Vector( +// Map("name" -> "age", "defaultValue" -> "0", "dataType" -> "int"), +// Map("name" -> "gender", "defaultValue" -> "", "dataType" -> "string") +// ) +// ) +// ) +// ) +// ) +// ) +// ) +// ) + + true + } + + test("Management query should have label: 'friends'") { + val Success(query) = QueryParser.parse( + """ + query Management { + Management { + Labels(name: friends) { + name + props { + name + defaultValue + dataType + } + } + } + } + """) + + val actual = Await.result(Executor.execute(s2Schema, query, s2Repository), Duration("10 sec")) + true } + }
