Skip to content

Commit

Permalink
Merge pull request #440 from jluhrs/grackle_update_0.15.0
Browse files Browse the repository at this point in the history
Updated grackle to 0.15.0
  • Loading branch information
jluhrs authored Oct 23, 2023
2 parents 3f34e69 + b13ecdc commit 4743ab8
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 124 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import cats.parse.Rfc5234.{alpha, digit, wsp}
import cats.parse.{Parser, Parser0}
import cats.syntax.all.*
import cats.{Applicative, Eq, Monad}
import edu.gemini.grackle.*
import grackle.*
import eu.timepit.refined.types.string.NonEmptyString
import eu.timepit.refined.cats.given

Expand Down Expand Up @@ -134,8 +134,8 @@ object SchemaStitcher {
val nextVals = uniqueNews
.flatMap {
case fields: TypeWithFields => fields.fields.map(_.tpe.underlying.asNamed).flattenOption
case UnionType(name, description, members) => members
case InputObjectType(_, _, inputFields) =>
case UnionType(_, _, members, _) => members
case InputObjectType(_, _, inputFields, _) =>
inputFields.map(_.tpe.underlying.asNamed).flattenOption
case _ => List.empty
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import cats.Eq
import cats.data.Ior
import cats.effect.{IO, Resource}
import cats.syntax.all.*
import edu.gemini.grackle.{Result, Schema}
import grackle.Result.Success
import grackle.{Result, Schema}
import junit.framework.TestCase
import munit.Assertions.*
import munit.CatsEffectSuite
Expand Down Expand Up @@ -40,7 +41,7 @@ class SchemaStitcherTest extends CatsEffectSuite {
test("SchemaStitcher should compose schema") {
SchemaStitcher[IO](Path.of("baseSchema.graphql"), schemaResolver).build.map { x =>
(x, expectedSchema) match {
case (Ior.Right(a), Ior.Right(b)) => assertEquals(a.toString, b.toString)
case (Success(a), Success(b)) => assertEquals(a.toString, b.toString)
case _ => fail("Error creating schema")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import coulomb.syntax.*
import coulomb.units.si.*
import coulomb.units.si.given
import coulomb.units.si.prefixes.*
import edu.gemini.grackle.Value
import edu.gemini.grackle.Value.FloatValue
import edu.gemini.grackle.Value.IntValue
import edu.gemini.grackle.Value.ObjectValue
import edu.gemini.grackle.Value.StringValue
import grackle.Value
import grackle.Value.FloatValue
import grackle.Value.IntValue
import grackle.Value.ObjectValue
import grackle.Value.StringValue
import lucuma.core.math.Angle
import lucuma.core.math.Declination
import lucuma.core.math.Epoch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package navigate.web.server.http4s
import cats.effect.Async
import cats.syntax.all.*
import fs2.compression.Compression
import lucuma.graphql.routes.GrackleGraphQLService
import lucuma.graphql.routes.GraphQLService
import lucuma.graphql.routes.Routes
import natchez.Trace
import navigate.model.security.UserDetails
Expand All @@ -26,10 +26,7 @@ class GraphQlRoutes[F[_]: Async: Logger: Trace: Compression](
) extends Http4sDsl[F] {

private def commandServices(wsb: WebSocketBuilder2[F]): HttpRoutes[F] = GZip(
Routes.forService(_ => NavigateMappings(eng).map(GrackleGraphQLService[F](_).some),
wsb,
"navigate"
)
Routes.forService(_ => NavigateMappings(eng).map(GraphQLService[F](_).some), wsb, "navigate")
)

def service(wsb: WebSocketBuilder2[F]): HttpRoutes[F] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,32 @@ import cats.data.NonEmptyChain
import cats.effect.Sync
import cats.effect.syntax.all.*
import cats.syntax.all.*
import edu.gemini.grackle.Cursor
import edu.gemini.grackle.Mapping
import edu.gemini.grackle.Path
import edu.gemini.grackle.Predicate.Eql
import edu.gemini.grackle.Problem
import edu.gemini.grackle.Query
import edu.gemini.grackle.Query.Binding
import edu.gemini.grackle.Query.Environment
import edu.gemini.grackle.Query.Filter
import edu.gemini.grackle.Query.Select
import edu.gemini.grackle.Query.Unique
import edu.gemini.grackle.QueryCompiler.SelectElaborator
import edu.gemini.grackle.Result
import edu.gemini.grackle.Schema
import edu.gemini.grackle.TypeRef
import edu.gemini.grackle.Value
import edu.gemini.grackle.Value.BooleanValue
import edu.gemini.grackle.Value.FloatValue
import edu.gemini.grackle.Value.IntValue
import edu.gemini.grackle.Value.ObjectValue
import edu.gemini.grackle.Value.StringValue
import edu.gemini.grackle.circe.CirceMapping
import edu.gemini.schema.util.SchemaStitcher
import edu.gemini.schema.util.SourceResolver
import grackle.Cursor
import grackle.Env
import grackle.Mapping
import grackle.Path
import grackle.Predicate.Eql
import grackle.Problem
import grackle.Query
import grackle.Query.Binding
import grackle.Query.Environment
import grackle.Query.Select
import grackle.Query.Unique
import grackle.QueryCompiler.Elab
import grackle.QueryCompiler.SelectElaborator
import grackle.Result
import grackle.Schema
import grackle.TypeRef
import grackle.Value
import grackle.Value.BooleanValue
import grackle.Value.FloatValue
import grackle.Value.IntValue
import grackle.Value.ObjectValue
import grackle.Value.StringValue
import grackle.circe.CirceMapping
import grackle.syntax.given
import io.circe.Decoder
import io.circe.Encoder
import io.circe.Json
Expand Down Expand Up @@ -82,15 +84,15 @@ class NavigateMappings[F[_]: Sync](server: NavigateEngine[F])(override val schem
extends CirceMapping[F] {
import NavigateMappings._

def mountPark(p: Path, env: Cursor.Env): F[Result[OperationOutcome]] =
def mountPark(p: Path, env: Env): F[Result[OperationOutcome]] =
server.mcsPark.attempt
.map(x =>
Result.Success(
x.fold(e => OperationOutcome.failure(e.getMessage), _ => OperationOutcome.success)
)
)

def mountFollow(p: Path, env: Cursor.Env): F[Result[OperationOutcome]] =
def mountFollow(p: Path, env: Env): F[Result[OperationOutcome]] =
env
.get[Boolean]("enable")
.map { en =>
Expand All @@ -107,15 +109,15 @@ class NavigateMappings[F[_]: Sync](server: NavigateEngine[F])(override val schem
Result.failure[OperationOutcome]("mountFollow parameter could not be parsed.").pure[F]
)

def rotatorPark(p: Path, env: Cursor.Env): F[Result[OperationOutcome]] =
def rotatorPark(p: Path, env: Env): F[Result[OperationOutcome]] =
server.rotPark.attempt
.map(x =>
Result.Success(
x.fold(e => OperationOutcome.failure(e.getMessage), _ => OperationOutcome.success)
)
)

def rotatorFollow(p: Path, env: Cursor.Env): F[Result[OperationOutcome]] =
def rotatorFollow(p: Path, env: Env): F[Result[OperationOutcome]] =
env
.get[Boolean]("enable")
.map { en =>
Expand All @@ -132,7 +134,7 @@ class NavigateMappings[F[_]: Sync](server: NavigateEngine[F])(override val schem
Result.failure("rotatorFollow parameter could not be parsed.").pure[F]
)

def instrumentSpecifics(p: Path, env: Cursor.Env): F[Result[OperationOutcome]] =
def instrumentSpecifics(p: Path, env: Env): F[Result[OperationOutcome]] =
env
.get[InstrumentSpecifics]("instrumentSpecificsParams")(classTag[InstrumentSpecifics])
.map { isp =>
Expand All @@ -151,7 +153,7 @@ class NavigateMappings[F[_]: Sync](server: NavigateEngine[F])(override val schem
.pure[F]
)

def slew(p: Path, env: Cursor.Env): F[Result[OperationOutcome]] =
def slew(p: Path, env: Env): F[Result[OperationOutcome]] =
env
.get[SlewConfig]("slewParams")(classTag[SlewConfig])
.map { sc =>
Expand All @@ -166,7 +168,7 @@ class NavigateMappings[F[_]: Sync](server: NavigateEngine[F])(override val schem
}
.getOrElse(Result.failure[OperationOutcome]("Slew parameters could not be parsed.").pure[F])

def oiwfsTarget(p: Path, env: Cursor.Env): F[Result[OperationOutcome]] =
def oiwfsTarget(p: Path, env: Env): F[Result[OperationOutcome]] =
env
.get[Target]("target")(classTag[Target])
.map { oi =>
Expand All @@ -183,7 +185,7 @@ class NavigateMappings[F[_]: Sync](server: NavigateEngine[F])(override val schem
Result.failure[OperationOutcome]("oiwfsTarget parameters could not be parsed.").pure[F]
)

def oiwfsProbeTracking(p: Path, env: Cursor.Env): F[Result[OperationOutcome]] =
def oiwfsProbeTracking(p: Path, env: Env): F[Result[OperationOutcome]] =
env
.get[TrackingConfig]("config")(classTag[TrackingConfig])
.map { tc =>
Expand All @@ -208,84 +210,55 @@ class NavigateMappings[F[_]: Sync](server: NavigateEngine[F])(override val schem
val OperationOutcomeType: TypeRef = schema.ref("OperationOutcome")
val OperationResultType: TypeRef = schema.ref("OperationResult")

override val selectElaborator: SelectElaborator = new SelectElaborator(
Map(
MutationType -> {
case Select("mountFollow", List(Binding("enable", BooleanValue(en))), child) =>
Result.Success(
Environment(
Cursor.Env("enable" -> en),
Select("mountFollow", Nil, child)
)
)
case Select("rotatorFollow", List(Binding("enable", BooleanValue(en))), child) =>
Result.Success(
Environment(
Cursor.Env("enable" -> en),
Select("rotatorFollow", Nil, child)
)
)
case Select("slew", List(Binding("slewParams", ObjectValue(fields))), child) =>
Result.fromOption(
parseSlewConfigInput(fields).map { x =>
Environment(
Cursor.Env("slewParams" -> x),
Select("slew", Nil, child)
)
},
"Could not parse Slew parameters."
)
case Select("instrumentSpecifics",
List(Binding("instrumentSpecificsParams", ObjectValue(fields))),
child
) =>
Result.fromOption(
parseInstrumentSpecificsInput(fields).map { x =>
Environment(
Cursor.Env("instrumentSpecificsParams" -> x),
Select("instrumentSpecifics", Nil, child)
)
},
"Could not parse instrumentSpecifics parameters."
)
case Select("oiwfsTarget", List(Binding("target", ObjectValue(fields))), child) =>
Result.fromOption(
parseTargetInput(fields).map { x =>
Environment(
Cursor.Env("target" -> x),
Select("oiwfsTarget", Nil, child)
)
},
"Could not parse oiwfsTarget parameters."
)
case Select("oiwfsProbeTracking", List(Binding("config", ObjectValue(fields))), child) =>
Result.fromOption(
parseTrackingInput(fields).map { x =>
Environment(
Cursor.Env("config" -> x),
Select("oiwfsProbeTracking", Nil, child)
)
},
"Could not parse oiwfsProbeTracking parameters."
)
}
)
)
override val selectElaborator: SelectElaborator = SelectElaborator {
case (MutationType, "mountFollow", List(Binding("enable", BooleanValue(en)))) =>
Elab.env("enable" -> en)
case (MutationType, "rotatorFollow", List(Binding("enable", BooleanValue(en)))) =>
Elab.env("enable" -> en)
case (MutationType, "slew", List(Binding("slewParams", ObjectValue(fields)))) =>
for {
x <- Elab.liftR(parseSlewConfigInput(fields).toResult("Could not parse Slew parameters."))
_ <- Elab.env("slewParams" -> x)
} yield ()
case (MutationType,
"instrumentSpecifics",
List(Binding("instrumentSpecificsParams", ObjectValue(fields)))
) =>
for {
x <- Elab.liftR(
parseInstrumentSpecificsInput(fields).toResult(
"Could not parse instrumentSpecifics parameters."
)
)
_ <- Elab.env("instrumentSpecificsParams" -> x)
} yield ()
case (MutationType, "oiwfsTarget", List(Binding("target", ObjectValue(fields)))) =>
for {
x <-
Elab.liftR(parseTargetInput(fields).toResult("Could not parse oiwfsTarget parameters."))
_ <- Elab.env("target" -> x)
} yield ()
case (MutationType, "oiwfsProbeTracking", List(Binding("config", ObjectValue(fields)))) =>
for {
x <- Elab.liftR(
parseTrackingInput(fields).toResult("Could not parse oiwfsProbeTracking parameters.")
)
_ <- Elab.env("config" -> x)
} yield ()
}

override val typeMappings: List[TypeMapping] = List(
ObjectMapping(
tpe = MutationType,
fieldMappings = List(
RootEffect.computeEncodable("mountPark")((_, p, env) => mountPark(p, env)),
RootEffect.computeEncodable("mountFollow")((_, p, env) => mountFollow(p, env)),
RootEffect.computeEncodable("rotatorPark")((_, p, env) => rotatorPark(p, env)),
RootEffect.computeEncodable("rotatorFollow")((_, p, env) => rotatorFollow(p, env)),
RootEffect.computeEncodable("slew")((_, p, env) => slew(p, env)),
RootEffect.computeEncodable("instrumentSpecifics")((_, p, env) =>
instrumentSpecifics(p, env)
),
RootEffect.computeEncodable("oiwfsTarget")((_, p, env) => oiwfsTarget(p, env)),
RootEffect.computeEncodable("oiwfsProbeTracking")((_, p, env) => oiwfsProbeTracking(p, env))
RootEffect.computeEncodable("mountPark")((p, env) => mountPark(p, env)),
RootEffect.computeEncodable("mountFollow")((p, env) => mountFollow(p, env)),
RootEffect.computeEncodable("rotatorPark")((p, env) => rotatorPark(p, env)),
RootEffect.computeEncodable("rotatorFollow")((p, env) => rotatorFollow(p, env)),
RootEffect.computeEncodable("slew")((p, env) => slew(p, env)),
RootEffect.computeEncodable("instrumentSpecifics")((p, env) => instrumentSpecifics(p, env)),
RootEffect.computeEncodable("oiwfsTarget")((p, env) => oiwfsTarget(p, env)),
RootEffect.computeEncodable("oiwfsProbeTracking")((p, env) => oiwfsProbeTracking(p, env))
)
),
LeafMapping[ParkStatus](ParkStatusType),
Expand Down
12 changes: 6 additions & 6 deletions project/Settings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ object Settings {
val lucumaUI = "0.66.0"
val lucumaSchemas = "0.62.0"

val grackle = "0.13.0"
val grackle = "0.15.0"

val graphQLRoutes = "0.6.6"
val graphQLRoutes = "0.8.0"

val clue = "0.24.1"

Expand Down Expand Up @@ -289,14 +289,14 @@ object Settings {

val Grackle = Def.setting(
Seq(
"edu.gemini" %% "gsp-graphql-core" % LibraryVersions.grackle,
"edu.gemini" %% "gsp-graphql-generic" % LibraryVersions.grackle,
"edu.gemini" %% "gsp-graphql-circe" % LibraryVersions.grackle
"org.typelevel" %% "grackle-core" % LibraryVersions.grackle,
"org.typelevel" %% "grackle-generic" % LibraryVersions.grackle,
"org.typelevel" %% "grackle-circe" % LibraryVersions.grackle
)
)

val GrackleRoutes =
"edu.gemini" %% "lucuma-graphql-routes-grackle" % LibraryVersions.graphQLRoutes
"edu.gemini" %% "lucuma-graphql-routes" % LibraryVersions.graphQLRoutes

val Clue = "edu.gemini" %% "clue-core" % LibraryVersions.clue
val ClueHttp4s = "edu.gemini" %% "clue-http4s-jdk-client" % LibraryVersions.clue
Expand Down

0 comments on commit 4743ab8

Please sign in to comment.