From 6f9077a5539dff051a130829d75785c2d227045b Mon Sep 17 00:00:00 2001 From: Rob Norris Date: Thu, 7 Sep 2023 16:20:00 -0500 Subject: [PATCH] progress --- .../lucuma/odb/graphql/OdbSchema.graphql | 15 ++++++++++++++- .../lucuma/odb/graphql/binding/EnumBinding.scala | 7 +++---- .../odb/graphql/binding/EnumeratedBinding.scala | 2 +- .../lucuma/odb/graphql/binding/TagBinding.scala | 2 +- .../lucuma/odb/graphql/input/DecimalInput.scala | 2 +- .../odb/graphql/mapping/MutationMapping.scala | 6 +++--- .../odb/graphql/mapping/SubscriptionMapping.scala | 6 +++--- .../lucuma/odb/graphql/util/SchemaSemigroup.scala | 8 ++++++++ .../odb/graphql/mutation/addConditionsEntry.scala | 2 +- .../odb/graphql/mutation/createProgram.scala | 2 +- 10 files changed, 36 insertions(+), 16 deletions(-) diff --git a/modules/schema/src/main/resources/lucuma/odb/graphql/OdbSchema.graphql b/modules/schema/src/main/resources/lucuma/odb/graphql/OdbSchema.graphql index b6dd59c6f..ee523bcb1 100644 --- a/modules/schema/src/main/resources/lucuma/odb/graphql/OdbSchema.graphql +++ b/modules/schema/src/main/resources/lucuma/odb/graphql/OdbSchema.graphql @@ -1,3 +1,16 @@ + + +enum Partner { DUMMY } +enum ConditionsMeasurementSource { DUMMY } +enum SeeingTrend { DUMMY } +enum ConditionsExpectationType { DUMMY } +enum ObsAttachmentType { DUMMY } +enum FilterType { DUMMY } +enum ProposalAttachmentType { DUMMY } + + + + "DatasetEvent creation parameters." input AddDatasetEventInput { @@ -3074,7 +3087,7 @@ type RecordGmosSouthVisitResult { Right Ascension, choose one of the available units """ input RightAscensionInput { - microarcseconds: Long @deprecated + microarcseconds: Long # @deprecated microseconds: Long degrees: BigDecimal hours: BigDecimal diff --git a/modules/service/src/main/scala/lucuma/odb/graphql/binding/EnumBinding.scala b/modules/service/src/main/scala/lucuma/odb/graphql/binding/EnumBinding.scala index 2439d8041..6402766d0 100644 --- a/modules/service/src/main/scala/lucuma/odb/graphql/binding/EnumBinding.scala +++ b/modules/service/src/main/scala/lucuma/odb/graphql/binding/EnumBinding.scala @@ -3,8 +3,7 @@ package lucuma.odb.graphql.binding -import edu.gemini.grackle.Ast.Value.EnumValue -import edu.gemini.grackle.Ast.Name +import edu.gemini.grackle.Value.EnumValue -val EnumBinding: Matcher[Name] = - primitiveBinding("Enum") { case EnumValue(name) => name } +val EnumBinding: Matcher[String] = + primitiveBinding("EnumValue") { case EnumValue(name) => name } diff --git a/modules/service/src/main/scala/lucuma/odb/graphql/binding/EnumeratedBinding.scala b/modules/service/src/main/scala/lucuma/odb/graphql/binding/EnumeratedBinding.scala index 26e7ec0e1..cd6ed8bb6 100644 --- a/modules/service/src/main/scala/lucuma/odb/graphql/binding/EnumeratedBinding.scala +++ b/modules/service/src/main/scala/lucuma/odb/graphql/binding/EnumeratedBinding.scala @@ -8,6 +8,6 @@ import io.circe.Json import lucuma.core.util.Enumerated def enumeratedBinding[A](implicit ev: Enumerated[A]): Matcher[A] = - EnumBinding.map(n => Json.fromString(n.value)).emap { j => + EnumBinding.map(n => Json.fromString(n)).emap { j => ev.decodeJson(j).leftMap(_.message) } diff --git a/modules/service/src/main/scala/lucuma/odb/graphql/binding/TagBinding.scala b/modules/service/src/main/scala/lucuma/odb/graphql/binding/TagBinding.scala index 75ca6022b..4e7e1fcb8 100644 --- a/modules/service/src/main/scala/lucuma/odb/graphql/binding/TagBinding.scala +++ b/modules/service/src/main/scala/lucuma/odb/graphql/binding/TagBinding.scala @@ -6,4 +6,4 @@ package lucuma.odb.graphql.binding import lucuma.odb.data.Tag val TagBinding = - EnumBinding.map(n => Tag(n.value.toLowerCase)) + EnumBinding.map(n => Tag(n.toLowerCase)) diff --git a/modules/service/src/main/scala/lucuma/odb/graphql/input/DecimalInput.scala b/modules/service/src/main/scala/lucuma/odb/graphql/input/DecimalInput.scala index 6b394e4bc..a93abb425 100644 --- a/modules/service/src/main/scala/lucuma/odb/graphql/input/DecimalInput.scala +++ b/modules/service/src/main/scala/lucuma/odb/graphql/input/DecimalInput.scala @@ -27,7 +27,7 @@ import lucuma.odb.graphql.binding._ BigDecimalBinding("value", rValue), EnumBinding("units", rEnum) ) => - (rValue, rEnum.map(_.value)).parTupled.flatMap { + (rValue, rEnum).parTupled.flatMap { case (value, label) => handler.lift((value, label)) match { case Some(r) => r diff --git a/modules/service/src/main/scala/lucuma/odb/graphql/mapping/MutationMapping.scala b/modules/service/src/main/scala/lucuma/odb/graphql/mapping/MutationMapping.scala index 6387ea310..932043534 100644 --- a/modules/service/src/main/scala/lucuma/odb/graphql/mapping/MutationMapping.scala +++ b/modules/service/src/main/scala/lucuma/odb/graphql/mapping/MutationMapping.scala @@ -128,11 +128,11 @@ trait MutationMapping[F[_]] extends Predicates[F] { def apply[I: ClassTag: TypeName](fieldName: String, inputBinding: Matcher[I])(f: (I, Query) => F[Result[Query]]) = new MutationField { val FieldMapping = - RootEffect.computeChild(fieldName) { (child, tpe, env) => + RootEffect.computeChild(fieldName) { (child, _, _) => child match { - case Environment(x, child2) => + case Environment(env, child2) => Nested(env.getR[I]("input").flatTraverse(i => f(i, child2))) - .map(child3 => Environment(x, child3)) + .map(child3 => Environment(env, child3)) .value case _ => Result.failure(s"Unexpected: $child").pure[F] diff --git a/modules/service/src/main/scala/lucuma/odb/graphql/mapping/SubscriptionMapping.scala b/modules/service/src/main/scala/lucuma/odb/graphql/mapping/SubscriptionMapping.scala index 212d5beb5..8d8fa8a4d 100644 --- a/modules/service/src/main/scala/lucuma/odb/graphql/mapping/SubscriptionMapping.scala +++ b/modules/service/src/main/scala/lucuma/odb/graphql/mapping/SubscriptionMapping.scala @@ -59,11 +59,11 @@ trait SubscriptionMapping[F[_]] extends Predicates[F] { def apply[I: ClassTag: TypeName](fieldName: String, inputBinding: Matcher[I])(f: (I, Query) => Stream[F, Result[Query]]) = new SubscriptionField { val FieldMapping = - RootStream.computeChild(fieldName) { (child, tpe, env) => + RootStream.computeChild(fieldName) { (child, _, _) => child match - case Environment(a, child2) => + case Environment(env, child2) => Nested(env.getR[I]("input").flatTraverse(f(_, child2))) - .map(child3 => Environment(a, child3)) + .map(child3 => Environment(env, child3)) .value case _ => Result.failure(s"Unexpected: $child").pure[Stream[F, *]] diff --git a/modules/service/src/main/scala/lucuma/odb/graphql/util/SchemaSemigroup.scala b/modules/service/src/main/scala/lucuma/odb/graphql/util/SchemaSemigroup.scala index 3a394ba23..dfb36c08a 100644 --- a/modules/service/src/main/scala/lucuma/odb/graphql/util/SchemaSemigroup.scala +++ b/modules/service/src/main/scala/lucuma/odb/graphql/util/SchemaSemigroup.scala @@ -12,6 +12,7 @@ import edu.gemini.grackle.Schema import edu.gemini.grackle.Type import org.tpolecat.sourcepos.SourcePos import edu.gemini.grackle.DirectiveDef +import edu.gemini.grackle.EnumType /** A mixin that provides Semigroup[Schema]. */ trait SchemaSemigroup[F[_]] extends Mapping[F] { @@ -35,6 +36,13 @@ trait SchemaSemigroup[F[_]] extends Mapping[F] { (a.interfaces ++ b.interfaces).distinctBy(_.name), (a.directives ++ b.directives).distinctBy(_.name), ) + case ((a: EnumType, b: EnumType)) if sameName(a, b) => + EnumType( + a.name, + a.description, + (a.enumValues ++ b.enumValues).distinctBy(_.name).filterNot(_.name == "DUMMY"), + (a.directives ++ b.directives).distinctBy(_.name) + ) // todo: other named types case (a, _) => a } diff --git a/modules/service/src/test/scala/lucuma/odb/graphql/mutation/addConditionsEntry.scala b/modules/service/src/test/scala/lucuma/odb/graphql/mutation/addConditionsEntry.scala index 2555da6fd..189ffd3bb 100644 --- a/modules/service/src/test/scala/lucuma/odb/graphql/mutation/addConditionsEntry.scala +++ b/modules/service/src/test/scala/lucuma/odb/graphql/mutation/addConditionsEntry.scala @@ -58,7 +58,7 @@ class addConditionsEntry extends OdbSuite { } """, expected = Left(List( - "Value of type ConditionsMeasurementSource required for 'source'" + "Value of type ConditionsMeasurementSource required for 'source' in field 'addConditionsEntry' of type 'Mutation'" )) ) } diff --git a/modules/service/src/test/scala/lucuma/odb/graphql/mutation/createProgram.scala b/modules/service/src/test/scala/lucuma/odb/graphql/mutation/createProgram.scala index 50693ca8d..b12a0fd7f 100644 --- a/modules/service/src/test/scala/lucuma/odb/graphql/mutation/createProgram.scala +++ b/modules/service/src/test/scala/lucuma/odb/graphql/mutation/createProgram.scala @@ -288,7 +288,7 @@ class createProgram extends OdbSuite { "c_mod_pi_user_id" : true, "c_mod_program_id" : true, "c_new_pi_user_id" : "u-1", - "c_new_program_id" : "p-108", + "c_new_program_id" : ${pid}, "c_mod_pi_user_type" : true, "c_new_pi_user_type" : "standard", "c_mod_pts_execution" : true,