From a72721ca331f33758379563070fe4c54fb5c0052 Mon Sep 17 00:00:00 2001 From: Jan Chyb Date: Thu, 23 Jun 2022 11:14:51 +0200 Subject: [PATCH] Allow to compile and pass sangria core tests in Scala 3 --- .scalafmt.conf | 6 ++ build.sbt | 15 ++-- .../scala-2/sangria/macros/ParseMacro.scala | 1 + .../scala-3/sangria/macros/ToExprGivens.scala | 2 +- .../scala/sangria/execution/Resolver.scala | 2 +- .../execution/ValueCoercionHelper.scala | 2 +- .../sangria/execution/ValueCollector.scala | 4 +- .../scala/sangria/introspection/package.scala | 2 +- .../ResolverBasedAstSchemaBuilder.scala | 13 ++-- .../main/scala/sangria/schema/Schema.scala | 7 +- .../main/scala/sangria/schema/package.scala | 2 +- .../overlappingfields/SortedArraySet.scala | 4 +- .../execution/DeprecationTrackerSpec.scala | 10 +-- .../execution/ExceptionHandlingSpec.scala | 2 +- .../execution/ExecutorSchemaSpec.scala | 15 ++-- .../sangria/execution/ExecutorSpec.scala | 13 +++- .../InputDocumentMaterializerSpec.scala | 4 +- .../sangria/execution/ScalarAliasSpec.scala | 15 ++-- .../execution/ScalarMiddlewareSpec.scala | 13 +++- .../execution/UnionInterfaceSpec.scala | 7 +- .../sangria/execution/VariablesSpec.scala | 66 ++++++++++++----- .../execution/batch/BatchExecutorSpec.scala | 9 ++- .../execution/deferred/FetcherSpec.scala | 25 ++++--- .../sangria/marshalling/FromInputSpec.scala | 34 +++++---- .../sangria/marshalling/IonSupportSpec.scala | 2 +- .../sangria/renderer/SchemaRenderSpec.scala | 56 ++++++++++----- .../test/scala/sangria/schema/ArgsSpec.scala | 5 +- .../schema/DefaultValueApplicationSpec.scala | 11 ++- .../sangria/schema/DefaultValuesSpec.scala | 4 +- .../scala/sangria/schema/EnumTypeSpec.scala | 11 +-- .../IntrospectionSchemaMaterializerSpec.scala | 59 ++++++++++------ .../ResolverBasedAstSchemaBuilderSpec.scala | 54 ++++++++------ .../sangria/schema/SchemaExtensionSpec.scala | 6 +- .../schema/TypeFieldConstraintsSpec.scala | 13 ++-- .../sangria/starWars/StarWarsQuerySpec.scala | 2 +- .../test/scala/sangria/util/CatsSupport.scala | 18 ++--- .../test/scala/sangria/util/DebugUtil.scala | 2 +- .../sangria/util/ValidationSupport.scala | 70 ++++++++++--------- .../validation/DocumentAnalyzerSpec.scala | 10 ++- 39 files changed, 382 insertions(+), 214 deletions(-) diff --git a/.scalafmt.conf b/.scalafmt.conf index 0a1d5a17..ef1b6713 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -2,6 +2,12 @@ version = 3.5.2 runner.dialect = scala213 +fileOverride { + "glob:**/src/main/scala-3/**" { + runner.dialect = scala3 + } +} + maxColumn = 100 // Vertical alignment is pretty, but leads to bigger diffs diff --git a/build.sbt b/build.sbt index 3828d45c..0223f678 100644 --- a/build.sbt +++ b/build.sbt @@ -86,21 +86,16 @@ lazy val core = project Test / testOptions += Tests.Argument(TestFrameworks.ScalaTest, "-oF"), libraryDependencies ++= Seq( // AST Visitor - if (isScala3.value) "org.sangria-graphql" %% "macro-visit" % "0.1.0-SNAPSHOT" - else "org.sangria-graphql" %% "macro-visit" % "0.1.3", // TODO needs release + "org.sangria-graphql" %% "macro-visit" % "0.2.0-RC1", // Marshalling - if (isScala3.value) - "org.sangria-graphql" %% "sangria-marshalling-api" % "1.0.7+58-480b4c06-SNAPSHOT" - else "org.sangria-graphql" %% "sangria-marshalling-api" % "1.0.7", // TODO needs release + "org.sangria-graphql" %% "sangria-marshalling-api" % "1.0.8", // Streaming "org.sangria-graphql" %% "sangria-streaming-api" % "1.0.3", // Testing "co.fs2" %% "fs2-core" % "2.5.11" % Test, "org.scalatest" %% "scalatest" % "3.2.12" % Test, "org.sangria-graphql" %% "sangria-marshalling-testkit" % "1.0.4" % Test, - if (isScala3.value) - "org.sangria-graphql" %% "sangria-spray-json" % "0.1.0-SNAPSHOT" % Test // TODO needs release - else "org.sangria-graphql" %% "sangria-spray-json" % "1.0.2" % Test, + "org.sangria-graphql" %% "sangria-spray-json" % "1.0.3" % Test, "org.sangria-graphql" %% "sangria-argonaut" % "1.0.2" % Test, "org.sangria-graphql" %% "sangria-ion" % "2.0.1" % Test, "org.sangria-graphql" %% "sangria-monix" % "2.0.1" % Test, @@ -126,9 +121,9 @@ lazy val derivation = project name := "sangria-derivation", Test / testOptions += Tests.Argument(TestFrameworks.ScalaTest, "-oF"), mimaPreviousArtifacts := Set("org.sangria-graphql" %% "sangria-derivation" % "3.0.0"), - // Macros + // Macros libraryDependencies ++= (if (isScala3.value) Seq.empty - else Seq( "org.scala-lang" % "scala-reflect" % scalaVersion.value)), + else Seq("org.scala-lang" % "scala-reflect" % scalaVersion.value)), apiURL := { val ver = CrossVersion.binaryScalaVersion(scalaVersion.value) Some(url(s"https://www.javadoc.io/doc/org.sangria-graphql/sangria-derivation_$ver/latest/")) diff --git a/modules/core/src/main/scala-2/sangria/macros/ParseMacro.scala b/modules/core/src/main/scala-2/sangria/macros/ParseMacro.scala index e703b98b..d524531b 100644 --- a/modules/core/src/main/scala-2/sangria/macros/ParseMacro.scala +++ b/modules/core/src/main/scala-2/sangria/macros/ParseMacro.scala @@ -9,6 +9,7 @@ class ParseMacro(context: blackbox.Context) val c = context } with MacroAstLiftable { + import c.universe._ def impl(args: Expr[Any]*) = diff --git a/modules/core/src/main/scala-3/sangria/macros/ToExprGivens.scala b/modules/core/src/main/scala-3/sangria/macros/ToExprGivens.scala index 6c991c6f..ab76bbd5 100644 --- a/modules/core/src/main/scala-3/sangria/macros/ToExprGivens.scala +++ b/modules/core/src/main/scala-3/sangria/macros/ToExprGivens.scala @@ -402,7 +402,7 @@ trait ToExprGivens { ${ Expr(p) }, _root_.scala.Some( new _root_.sangria.ast.DefaultSourceMapper( - ${ Expr { doc.sourceMapper.get.id } }, + ${ Expr(doc.sourceMapper.get.id) }, _root_.sangria.parser.ParserConfig .parboiledToSourceMapper(_root_.org.parboiled2.ParserInput(${ Expr(doc.source.get) diff --git a/modules/core/src/main/scala/sangria/execution/Resolver.scala b/modules/core/src/main/scala/sangria/execution/Resolver.scala index b8c69189..17d266df 100644 --- a/modules/core/src/main/scala/sangria/execution/Resolver.scala +++ b/modules/core/src/main/scala/sangria/execution/Resolver.scala @@ -1508,7 +1508,7 @@ class Resolver[Ctx]( case None => field.resolve match { case pfn: Projector[Ctx, Any, _] => - pfn(updatedCtx.asInstanceOf[Context[Ctx, Any]], collectProjections(path, field, astFields, pfn.maxLevel)) + pfn(updatedCtx, collectProjections(path, field, astFields, pfn.maxLevel)) case fn => fn(updatedCtx) } diff --git a/modules/core/src/main/scala/sangria/execution/ValueCoercionHelper.scala b/modules/core/src/main/scala/sangria/execution/ValueCoercionHelper.scala index 38fa038d..289ece6e 100644 --- a/modules/core/src/main/scala/sangria/execution/ValueCoercionHelper.scala +++ b/modules/core/src/main/scala/sangria/execution/ValueCoercionHelper.scala @@ -58,7 +58,7 @@ class ValueCoercionHelper[Ctx]( acc: marshaller.MapBuilder, value: Option[Either[Vector[Violation], Trinary[marshaller.Node]]] ): marshaller.MapBuilder = { - val valueMapTyped: Any => marshaller.Node = valueMap.asInstanceOf[Any => marshaller.Node] + val valueMapTyped = valueMap.asInstanceOf[Any => marshaller.Node] def locations = inputFor match { diff --git a/modules/core/src/main/scala/sangria/execution/ValueCollector.scala b/modules/core/src/main/scala/sangria/execution/ValueCollector.scala index 110b5fdc..96d4cf11 100644 --- a/modules/core/src/main/scala/sangria/execution/ValueCollector.scala +++ b/modules/core/src/main/scala/sangria/execution/ValueCollector.scala @@ -146,9 +146,7 @@ object ValueCollector { marshaller, fromInput.marshaller, errors = errors, - valueMap = - ((a: Any) => fromInput.fromResult(a.asInstanceOf[fromInput.marshaller.Node])) - .asInstanceOf[Any => Any], + valueMap = (v: Any) => fromInput.fromResult.asInstanceOf[Any => Any](v), defaultValueInfo = defaultInfo, undefinedValues = undefinedArgs, isArgument = true, diff --git a/modules/core/src/main/scala/sangria/introspection/package.scala b/modules/core/src/main/scala/sangria/introspection/package.scala index 6e78b529..98470261 100644 --- a/modules/core/src/main/scala/sangria/introspection/package.scala +++ b/modules/core/src/main/scala/sangria/introspection/package.scala @@ -3,7 +3,7 @@ package sangria import sangria.parser.QueryParser import sangria.schema._ -import sangria.util.tag.@@ // Scala 3 workaround +import sangria.util.tag.@@ // Scala 3 issue workaround import sangria.marshalling.FromInput.CoercedScalaResult package object introspection { diff --git a/modules/core/src/main/scala/sangria/schema/ResolverBasedAstSchemaBuilder.scala b/modules/core/src/main/scala/sangria/schema/ResolverBasedAstSchemaBuilder.scala index aa4ff968..fdce4877 100644 --- a/modules/core/src/main/scala/sangria/schema/ResolverBasedAstSchemaBuilder.scala +++ b/modules/core/src/main/scala/sangria/schema/ResolverBasedAstSchemaBuilder.scala @@ -611,9 +611,11 @@ object ResolverBasedAstSchemaBuilder { } def defaultInputResolver[Ctx, In: InputUnmarshaller] = - FieldResolver[Ctx]({ case (_, _) => - extractFieldValue[Ctx, In] - }, PartialFunction.empty) + FieldResolver[Ctx]( + { case (_, _) => + extractFieldValue[Ctx, In] + }, + PartialFunction.empty) def defaultExistingInputResolver[Ctx, In: InputUnmarshaller] = ExistingFieldResolver[Ctx] { case (_, _, _) => @@ -649,7 +651,10 @@ object ResolverBasedAstSchemaBuilder { implicit val marshaller = gd.marshaller resolve( - GenericDynamicDirectiveContext(astDir, node, createDynamicArgs(astDir)(marshaller))) + GenericDynamicDirectiveContext( + astDir, + node, + createDynamicArgs(astDir)(marshaller))) } } diff --git a/modules/core/src/main/scala/sangria/schema/Schema.scala b/modules/core/src/main/scala/sangria/schema/Schema.scala index 8820bbc0..e7ca3541 100644 --- a/modules/core/src/main/scala/sangria/schema/Schema.scala +++ b/modules/core/src/main/scala/sangria/schema/Schema.scala @@ -70,7 +70,7 @@ sealed trait AbstractType extends Type with Named { .flatMap(_.find(_.isInstanceOf(value)).asInstanceOf[Option[ObjectType[Ctx, _]]]) } -sealed trait MappedAbstractType[T] extends Type with AbstractType{ +sealed trait MappedAbstractType[T] extends Type with AbstractType { def contraMap(value: T): Any } @@ -652,7 +652,10 @@ object Field { fieldType, description, arguments, - ctx => SubscriptionValue[Ctx, StreamSource, stream.StreamSource](resolve(ctx).asInstanceOf[stream.StreamSource[Any]], s), + ctx => + SubscriptionValue[Ctx, StreamSource, stream.StreamSource]( + resolve(ctx).asInstanceOf[stream.StreamSource[Any]], + s), deprecationReason, SubscriptionField[stream.StreamSource](s) +: tags, complexity, diff --git a/modules/core/src/main/scala/sangria/schema/package.scala b/modules/core/src/main/scala/sangria/schema/package.scala index 1db93034..d01bb9b3 100644 --- a/modules/core/src/main/scala/sangria/schema/package.scala +++ b/modules/core/src/main/scala/sangria/schema/package.scala @@ -245,7 +245,7 @@ package object schema { val DefaultDeprecationReason = "No longer supported" - val ReasonArg: Argument[Option[String]] = Argument( + val ReasonArg: Argument[String] = Argument( "reason", OptionInputType(StringType), description = "Explains why this element was deprecated, usually also including a " + diff --git a/modules/core/src/main/scala/sangria/validation/rules/overlappingfields/SortedArraySet.scala b/modules/core/src/main/scala/sangria/validation/rules/overlappingfields/SortedArraySet.scala index 11f168db..c2aad19b 100644 --- a/modules/core/src/main/scala/sangria/validation/rules/overlappingfields/SortedArraySet.scala +++ b/modules/core/src/main/scala/sangria/validation/rules/overlappingfields/SortedArraySet.scala @@ -80,8 +80,8 @@ object SortedArraySet { val first_from = members.get(from) members.set(into, first_from) into += 1 - while({ - from += 1 + while ({ + from += 1 (from < members.size() && members.get(from) == first_from) }) () } diff --git a/modules/core/src/test/scala/sangria/execution/DeprecationTrackerSpec.scala b/modules/core/src/test/scala/sangria/execution/DeprecationTrackerSpec.scala index 49e1801d..7165da99 100644 --- a/modules/core/src/test/scala/sangria/execution/DeprecationTrackerSpec.scala +++ b/modules/core/src/test/scala/sangria/execution/DeprecationTrackerSpec.scala @@ -19,7 +19,7 @@ class DeprecationTrackerSpec var ctx: Option[Context[_, _]] = None var enumValue: Option[Any] = None - var enum: Option[String] = None + var `enum`: Option[String] = None def deprecatedFieldUsed[Ctx](ctx: Context[Ctx, _]) = { times.incrementAndGet() @@ -27,10 +27,10 @@ class DeprecationTrackerSpec this.ctx = Some(ctx) } - def deprecatedEnumValueUsed[T, Ctx](enum: EnumType[T], value: T, userContext: Ctx) = { + def deprecatedEnumValueUsed[T, Ctx](`enum`: EnumType[T], value: T, userContext: Ctx) = { times.incrementAndGet() this.enumValue = Some(value) - this.enum = Some(enum.name) + this.`enum` = Some(`enum`.name) } } @@ -179,7 +179,7 @@ class DeprecationTrackerSpec Executor.execute(schema, query, deprecationTracker = deprecationTracker).await deprecationTracker.times.get should be(1) - deprecationTracker.enum should be(Some("TestEnum")) + deprecationTracker.`enum` should be(Some("TestEnum")) deprecationTracker.enumValue should be(Some(2)) } @@ -216,7 +216,7 @@ class DeprecationTrackerSpec Executor.execute(schema, query, deprecationTracker = deprecationTracker).await deprecationTracker.times.get should be(0) - deprecationTracker.enum should be(None) + deprecationTracker.`enum` should be(None) deprecationTracker.enumValue should be(None) } } diff --git a/modules/core/src/test/scala/sangria/execution/ExceptionHandlingSpec.scala b/modules/core/src/test/scala/sangria/execution/ExceptionHandlingSpec.scala index ee52bbc5..d82cf1a7 100644 --- a/modules/core/src/test/scala/sangria/execution/ExceptionHandlingSpec.scala +++ b/modules/core/src/test/scala/sangria/execution/ExceptionHandlingSpec.scala @@ -38,7 +38,7 @@ class ExceptionHandlingSpec Field( "success", OptionType(StringType), - arguments = Argument("num", OptionInputType(IntType)) :: Nil, + arguments = List(Argument("num", OptionInputType(IntType))), resolve = _ => "Yay"), Field( "errorInScalar", diff --git a/modules/core/src/test/scala/sangria/execution/ExecutorSchemaSpec.scala b/modules/core/src/test/scala/sangria/execution/ExecutorSchemaSpec.scala index 74c0d89d..2a0ff05f 100644 --- a/modules/core/src/test/scala/sangria/execution/ExecutorSchemaSpec.scala +++ b/modules/core/src/test/scala/sangria/execution/ExecutorSchemaSpec.scala @@ -13,6 +13,9 @@ import scala.concurrent.ExecutionContext.Implicits.global import org.scalatest.matchers.should.Matchers import org.scalatest.wordspec.AnyWordSpec +import sangria.util.tag.@@ // Scala 3 issue workaround +import sangria.marshalling.FromInput.CoercedScalaResult + class ExecutorSchemaSpec extends AnyWordSpec with Matchers with FutureResultSupport { case class Image(url: Option[String], width: Option[Int], height: Option[Int]) @@ -49,9 +52,11 @@ class ExecutorSchemaSpec extends AnyWordSpec with Matchers with FutureResultSupp Field( "pic", OptionType(BlogImageType), - arguments = Argument("width", OptionInputType(IntType)) :: Argument( - "height", - OptionInputType(IntType)) :: Nil, + arguments = Argument[Option[Int @@ CoercedScalaResult]]( + "width", + OptionInputType(IntType)) :: Argument[Option[ + Int @@ CoercedScalaResult + ]]("height", OptionInputType(IntType)) :: Nil, resolve = ctx => for { w <- ctx.argOpt[Int]("width") @@ -87,7 +92,7 @@ class ExecutorSchemaSpec extends AnyWordSpec with Matchers with FutureResultSupp Field( "article", OptionType(BlogArticleType), - arguments = Argument("id", OptionInputType(IDType)) :: Nil, + arguments = List(Argument("id", OptionInputType(IDType))), resolve = ctx => ctx.argOpt[String]("id").flatMap(id => article(id.toInt)) ), Field( @@ -103,7 +108,7 @@ class ExecutorSchemaSpec extends AnyWordSpec with Matchers with FutureResultSupp Field( "articleSubscribe", OptionType(BlogArticleType), - arguments = Argument("id", OptionInputType(IDType)) :: Nil, + arguments = List(Argument("id", OptionInputType(IDType))), resolve = ctx => ctx.argOpt[String]("id").flatMap(id => article(id.toInt)) )) ) diff --git a/modules/core/src/test/scala/sangria/execution/ExecutorSpec.scala b/modules/core/src/test/scala/sangria/execution/ExecutorSpec.scala index d4c12c72..0807dad0 100644 --- a/modules/core/src/test/scala/sangria/execution/ExecutorSpec.scala +++ b/modules/core/src/test/scala/sangria/execution/ExecutorSpec.scala @@ -18,6 +18,9 @@ import scala.concurrent.ExecutionContext.Implicits.global import org.scalatest.matchers.should.Matchers import org.scalatest.wordspec.AnyWordSpec +import sangria.util.tag.@@ // Scala 3 issue workaround +import sangria.marshalling.FromInput.CoercedScalaResult + class ExecutorSpec extends AnyWordSpec with Matchers with FutureResultSupport { class TestSubject { def a: Option[String] = Some("Apple") @@ -123,8 +126,10 @@ class ExecutorSpec extends AnyWordSpec with Matchers with FutureResultSupport { Field( "pic", OptionType(StringType), - arguments = Argument("size", OptionInputType(IntType)) :: Nil, - resolve = ctx => ctx.value.pic(ctx.argOpt[Int]("size"))), + arguments = + Argument[Option[Int @@ CoercedScalaResult]]("size", OptionInputType(IntType)) :: Nil, + resolve = ctx => ctx.value.pic(ctx.argOpt[Int]("size")) + ), Field("deep", OptionType(DeepDataType), resolve = _.value.deep), Field("future", OptionType(DataType), resolve = _.value.future) ) @@ -512,7 +517,9 @@ class ExecutorSpec extends AnyWordSpec with Matchers with FutureResultSupport { fields[Unit, Unit](Field( "b", OptionType(StringType), - arguments = Argument("numArg", OptionInputType(IntType)) :: Argument( + arguments = Argument[Option[Int @@ CoercedScalaResult]]( + "numArg", + OptionInputType(IntType)) :: Argument[Option[String @@ CoercedScalaResult]]( "stringArg", OptionInputType(StringType)) :: Nil, resolve = ctx => { resolvedArgs = ctx.args.raw; None } diff --git a/modules/core/src/test/scala/sangria/execution/InputDocumentMaterializerSpec.scala b/modules/core/src/test/scala/sangria/execution/InputDocumentMaterializerSpec.scala index 6b69a7cd..30d7fc17 100644 --- a/modules/core/src/test/scala/sangria/execution/InputDocumentMaterializerSpec.scala +++ b/modules/core/src/test/scala/sangria/execution/InputDocumentMaterializerSpec.scala @@ -22,8 +22,8 @@ class InputDocumentMaterializerSpec extends AnyWordSpec with Matchers with Strin comments: Vector[Option[Comment]]) object MyJsonProtocol extends DefaultJsonProtocol { - implicit val commentFormat = jsonFormat2(Comment.apply) - implicit val articleFormat = jsonFormat4(Article.apply) + implicit val commentFormat: JsonFormat[Comment] = jsonFormat2(Comment.apply) + implicit val articleFormat: JsonFormat[Article] = jsonFormat4(Article.apply) } import MyJsonProtocol._ diff --git a/modules/core/src/test/scala/sangria/execution/ScalarAliasSpec.scala b/modules/core/src/test/scala/sangria/execution/ScalarAliasSpec.scala index e01a9f3c..a356ad5a 100644 --- a/modules/core/src/test/scala/sangria/execution/ScalarAliasSpec.scala +++ b/modules/core/src/test/scala/sangria/execution/ScalarAliasSpec.scala @@ -16,6 +16,9 @@ import scala.concurrent.ExecutionContext.Implicits.global import org.scalatest.matchers.should.Matchers import org.scalatest.wordspec.AnyWordSpec +import sangria.util.tag.@@ // Scala 3 issue workaround +import sangria.marshalling.FromInput.CoercedScalaResult + class ScalarAliasSpec extends AnyWordSpec with Matchers with FutureResultSupport { import ScalarAliasSpec._ @@ -23,12 +26,14 @@ class ScalarAliasSpec extends AnyWordSpec with Matchers with FutureResultSupport case class RefineViolation(error: String) extends ValueCoercionViolation(error) - implicit val UserIdType = ScalarAlias[UserId, String](StringType, _.id, id => Right(UserId(id))) + implicit val UserIdType: ScalarAlias[UserId, String] = + ScalarAlias[UserId, String](StringType, _.id, id => Right(UserId(id))) - implicit val PositiveIntType = ScalarAlias[Int Refined Positive, Int]( - IntType, - _.value, - i => refineV[Positive](i).left.map(RefineViolation)) + implicit val PositiveIntType: ScalarAlias[Int Refined Positive, Int] = + ScalarAlias[Int Refined Positive, Int]( + IntType, + _.value, + i => refineV[Positive](i).left.map(RefineViolation)) case object IDViolation extends ValueCoercionViolation("Invalid ID") diff --git a/modules/core/src/test/scala/sangria/execution/ScalarMiddlewareSpec.scala b/modules/core/src/test/scala/sangria/execution/ScalarMiddlewareSpec.scala index 3ec1a6dd..101fb8c9 100644 --- a/modules/core/src/test/scala/sangria/execution/ScalarMiddlewareSpec.scala +++ b/modules/core/src/test/scala/sangria/execution/ScalarMiddlewareSpec.scala @@ -10,6 +10,9 @@ import scala.concurrent.ExecutionContext.Implicits.global import org.scalatest.matchers.should.Matchers import org.scalatest.wordspec.AnyWordSpec +import sangria.util.tag.@@ // Scala 3 issue workaround +import sangria.marshalling.FromInput.CoercedScalaResult + class ScalarMiddlewareSpec extends AnyWordSpec with Matchers with FutureResultSupport { import ScalarMiddlewareSpec._ @@ -43,9 +46,15 @@ class ScalarMiddlewareSpec extends AnyWordSpec with Matchers with FutureResultSu InputField("name", StringType))) val IdArg = Argument("id", EncodedIdType) - val IdArgWithDefault = Argument("id", OptionInputType(EncodedIdType), defaultValue = "SOME_ID") + val IdArgWithDefault = Argument[Option[String @@ CoercedScalaResult], String]( + "id", + OptionInputType(EncodedIdType), + defaultValue = "SOME_ID") val IdArgWithValidDefault = - Argument("id", OptionInputType(EncodedIdType), defaultValue = "test-SOME_ID") + Argument[Option[String @@ CoercedScalaResult], String]( + "id", + OptionInputType(EncodedIdType), + defaultValue = "test-SOME_ID") val ComplexArg = Argument("c", ComplexInputType) val ComplexArgWithDefault = Argument("c", ComplexInputWithDefaultType) val ComplexArgWithValidDefault = Argument("c", ComplexInputWithValidDefaultType) diff --git a/modules/core/src/test/scala/sangria/execution/UnionInterfaceSpec.scala b/modules/core/src/test/scala/sangria/execution/UnionInterfaceSpec.scala index e1a14a40..3bfb4b76 100644 --- a/modules/core/src/test/scala/sangria/execution/UnionInterfaceSpec.scala +++ b/modules/core/src/test/scala/sangria/execution/UnionInterfaceSpec.scala @@ -7,6 +7,9 @@ import scala.concurrent.ExecutionContext.Implicits.global import org.scalatest.matchers.should.Matchers import org.scalatest.wordspec.AnyWordSpec +import sangria.util.tag.@@ // Scala 3 issue workaround +import sangria.marshalling.FromInput.CoercedScalaResult + class UnionInterfaceSpec extends AnyWordSpec with Matchers @@ -369,7 +372,9 @@ class UnionInterfaceSpec Field( "quz", OptionType(ListType(OptionType(QuzType))), - arguments = Argument("id", OptionInputType(ListInputType(StringType))) :: Nil, + arguments = Argument[Option[Seq[String @@ CoercedScalaResult]]]( + "id", + OptionInputType(ListInputType(StringType))) :: Nil, resolve = c => c.argOpt[Seq[String]]("id") .map(queried => c.value.quz.filter(quz => queried.contains(quz.id))) diff --git a/modules/core/src/test/scala/sangria/execution/VariablesSpec.scala b/modules/core/src/test/scala/sangria/execution/VariablesSpec.scala index e965691c..3a6fae25 100644 --- a/modules/core/src/test/scala/sangria/execution/VariablesSpec.scala +++ b/modules/core/src/test/scala/sangria/execution/VariablesSpec.scala @@ -15,6 +15,10 @@ import scala.concurrent.ExecutionContext.Implicits.global import org.scalatest.matchers.should.Matchers import org.scalatest.wordspec.AnyWordSpec +import sangria.util.tag.@@ // Scala 3 issue workaround +import sangria.marshalling.FromInput.CoercedScalaResult +import sangria.marshalling.ScalaInput + class VariablesSpec extends AnyWordSpec with Matchers with GraphQlSupport { val TestInputObject = InputObjectType( "TestInputObject", @@ -42,7 +46,9 @@ class VariablesSpec extends AnyWordSpec with Matchers with GraphQlSupport { Field( "fieldWithNullableStringInput", OptionType(StringType), - arguments = Argument("input", OptionInputType(StringType)) :: Nil, + arguments = Argument[Option[String @@ CoercedScalaResult]]( + "input", + OptionInputType(StringType)) :: Nil, resolve = ctx => ctx .argOpt[Any]("input") @@ -52,7 +58,9 @@ class VariablesSpec extends AnyWordSpec with Matchers with GraphQlSupport { Field( "fieldWithNullableStringInputDefined", BooleanType, - arguments = Argument("input", OptionInputType(StringType)) :: Nil, + arguments = Argument[Option[String @@ CoercedScalaResult]]( + "input", + OptionInputType(StringType)) :: Nil, resolve = ctx => ctx.argDefinedInQuery("input") ), Field( @@ -65,8 +73,10 @@ class VariablesSpec extends AnyWordSpec with Matchers with GraphQlSupport { Field( "fieldWithDefaultArgumentValue", OptionType(StringType), - arguments = - Argument("input", OptionInputType(StringType), defaultValue = "Hello World") :: Nil, + arguments = Argument[Option[String @@ CoercedScalaResult], String]( + "input", + OptionInputType(StringType), + defaultValue = "Hello World") :: Nil, resolve = ctx => DefaultValueRenderer.renderCoercedInputValueCompact( ctx.arg[Any]("input"), @@ -84,8 +94,9 @@ class VariablesSpec extends AnyWordSpec with Matchers with GraphQlSupport { Field( "list", OptionType(StringType), - arguments = - Argument("input", OptionInputType(ListInputType(OptionInputType(StringType)))) :: Nil, + arguments = Argument[Option[Seq[Option[String @@ CoercedScalaResult]]]]( + "input", + OptionInputType(ListInputType(OptionInputType(StringType)))) :: Nil, resolve = ctx => ctx .argOpt[Any]("input") @@ -97,7 +108,9 @@ class VariablesSpec extends AnyWordSpec with Matchers with GraphQlSupport { Field( "nnList", OptionType(StringType), - arguments = Argument("input", ListInputType(OptionInputType(StringType))) :: Nil, + arguments = Argument[Seq[Option[String @@ CoercedScalaResult]]]( + "input", + ListInputType(OptionInputType(StringType))) :: Nil, resolve = ctx => DefaultValueRenderer.renderCoercedInputValueCompact( ctx.arg[Any]("input"), @@ -106,7 +119,9 @@ class VariablesSpec extends AnyWordSpec with Matchers with GraphQlSupport { Field( "listNN", OptionType(StringType), - arguments = Argument("input", OptionInputType(ListInputType(StringType))) :: Nil, + arguments = Argument[Option[Seq[String @@ CoercedScalaResult]]]( + "input", + OptionInputType(ListInputType(StringType))) :: Nil, resolve = ctx => ctx .argOpt[Any]("input") @@ -116,7 +131,8 @@ class VariablesSpec extends AnyWordSpec with Matchers with GraphQlSupport { Field( "nnListNN", OptionType(StringType), - arguments = Argument("input", ListInputType(StringType)) :: Nil, + arguments = + Argument[Seq[String @@ CoercedScalaResult]]("input", ListInputType(StringType)) :: Nil, resolve = ctx => DefaultValueRenderer.renderCoercedInputValueCompact( ctx.arg[Any]("input"), @@ -125,7 +141,7 @@ class VariablesSpec extends AnyWordSpec with Matchers with GraphQlSupport { ) ) - def schema = Schema(TestType) + def schema = Schema[Unit, Unit](TestType) "Execute: Handles inputs" when { "Handles objects and nullability" when { @@ -395,7 +411,13 @@ class VariablesSpec extends AnyWordSpec with Matchers with GraphQlSupport { "executes with complex input (scala input)" in { val args = Map("input" -> Map("a" -> "foo", "b" -> List("bar"), "c" -> "baz")) - Executor.execute(schema, testQuery, variables = mapVars(args)).await should be( + Executor + .execute( + schema.asInstanceOf[Schema[Unit, Unit]], + testQuery, + variables = mapVars(args) + ) + .await should be( Map( "data" -> Map( "fieldWithObjectInput" -> """{a:"foo",b:["bar"],c:"baz"}""" @@ -405,7 +427,9 @@ class VariablesSpec extends AnyWordSpec with Matchers with GraphQlSupport { "executes with complex input (json input)" in { val args = """{"input": {"a": "foo", "b": ["bar"], "c": "baz"}}""".parseJson - Executor.execute(schema, testQuery, variables = args).await should be( + Executor + .execute(schema.asInstanceOf[Schema[Unit, Unit]], testQuery, variables = args) + .await should be( Map( "data" -> Map( "fieldWithObjectInput" -> """{a:"foo",b:["bar"],c:"baz"}""" @@ -428,7 +452,9 @@ class VariablesSpec extends AnyWordSpec with Matchers with GraphQlSupport { "properly coerces single value to array (scala input)" in { val args = Map("input" -> Map("a" -> "foo", "b" -> "bar", "c" -> "baz")) - Executor.execute(schema, testQuery, variables = mapVars(args)).await should be( + Executor + .execute(schema.asInstanceOf[Schema[Unit, Unit]], testQuery, variables = mapVars(args)) + .await should be( Map( "data" -> Map( "fieldWithObjectInput" -> """{a:"foo",b:["bar"],c:"baz"}""" @@ -438,7 +464,9 @@ class VariablesSpec extends AnyWordSpec with Matchers with GraphQlSupport { "properly coerces single value to array (json input)" in { val args = """{"input": {"a": "foo", "b": "bar", "c": "baz"}}""".parseJson - Executor.execute(schema, testQuery, variables = args).await should be( + Executor + .execute(schema.asInstanceOf[Schema[Unit, Unit]], testQuery, variables = args) + .await should be( Map( "data" -> Map( "fieldWithObjectInput" -> """{a:"foo",b:["bar"],c:"baz"}""" @@ -447,7 +475,7 @@ class VariablesSpec extends AnyWordSpec with Matchers with GraphQlSupport { def assertErrorResult[T: InputUnmarshaller](args: T, expectedError: String) = { val result = Executor - .execute(schema, testQuery, variables = args) + .execute(schema.asInstanceOf[Schema[Unit, Unit]], testQuery, variables = args) .awaitAndRecoverQueryAnalysisScala .asInstanceOf[Map[String, AnyRef]] @@ -532,7 +560,9 @@ class VariablesSpec extends AnyWordSpec with Matchers with GraphQlSupport { } """) - Executor.execute(schema, query, variables = args).await should be( + Executor + .execute(schema.asInstanceOf[Schema[Unit, Unit]], query, variables = args) + .await should be( Map( "data" -> Map( "fieldWithNullableStringInput" -> null @@ -548,7 +578,9 @@ class VariablesSpec extends AnyWordSpec with Matchers with GraphQlSupport { } """) - Executor.execute(schema, query, variables = args).await should be( + Executor + .execute(schema.asInstanceOf[Schema[Unit, Unit]], query, variables = args) + .await should be( Map( "data" -> Map( "fieldWithNullableStringInput" -> "\"a\"" diff --git a/modules/core/src/test/scala/sangria/execution/batch/BatchExecutorSpec.scala b/modules/core/src/test/scala/sangria/execution/batch/BatchExecutorSpec.scala index 3a843aaf..d027fcf6 100644 --- a/modules/core/src/test/scala/sangria/execution/batch/BatchExecutorSpec.scala +++ b/modules/core/src/test/scala/sangria/execution/batch/BatchExecutorSpec.scala @@ -13,14 +13,17 @@ import sangria.util.SimpleGraphQlSupport._ import org.scalatest.matchers.should.Matchers import org.scalatest.wordspec.AnyWordSpec +import sangria.util.tag.@@ // Scala 3 issue workaround +import sangria.marshalling.FromInput.CoercedScalaResult + class BatchExecutorSpec extends AnyWordSpec with Matchers with FutureResultSupport { implicit val ec: ExecutionContext = ExecutionContext.global implicit val contextShift: ContextShift[IO] = IO.contextShift(ExecutionContext.global) - val IdsArg = Argument("ids", ListInputType(IntType)) + val IdsArg = Argument[Seq[Int @@ CoercedScalaResult]]("ids", ListInputType(IntType)) val IdArg = Argument("id", IntType) val NameArg = Argument("name", StringType) - val NamesArg = Argument("names", ListInputType(StringType)) + val NamesArg = Argument[Seq[String @@ CoercedScalaResult]]("names", ListInputType(StringType)) val DataType = ObjectType( "Data", @@ -294,7 +297,7 @@ class BatchExecutorSpec extends AnyWordSpec with Matchers with FutureResultSuppo val res = BatchExecutor.executeBatch(schema, query, operationNames = List("q1", "q2")) - res.compile.toVector.unsafeRunSync.toSet should be( + res.compile.toVector.unsafeRunSync().toSet should be( Set( """ { diff --git a/modules/core/src/test/scala/sangria/execution/deferred/FetcherSpec.scala b/modules/core/src/test/scala/sangria/execution/deferred/FetcherSpec.scala index b2183d9b..45594191 100644 --- a/modules/core/src/test/scala/sangria/execution/deferred/FetcherSpec.scala +++ b/modules/core/src/test/scala/sangria/execution/deferred/FetcherSpec.scala @@ -8,6 +8,8 @@ import sangria.macros._ import sangria.schema._ import sangria.util.{FutureResultSupport, Pos} import sangria.util.SimpleGraphQlSupport._ +import sangria.util.tag.@@ +import sangria.marshalling.FromInput.CoercedScalaResult import scala.concurrent.{ExecutionContext, Future} import org.scalatest.matchers.should.Matchers @@ -23,11 +25,11 @@ class FetcherSpec extends AnyWordSpec with Matchers with FutureResultSupport { case class ColorDeferred(id: String) extends Deferred[String] object Category { - implicit val hasId = HasId[Category, String](_.id) + implicit val hasId: HasId[Category, String] = HasId[Category, String](_.id) } object Product { - implicit val hasId = HasId[Product, Int](_.id) + implicit val hasId: HasId[Product, Int] = HasId[Product, Int](_.id) } val prodCat = Relation[Product, String]("product-category", _.inCategories) @@ -101,13 +103,13 @@ class FetcherSpec extends AnyWordSpec with Matchers with FutureResultSupport { lazy val ProductType: ObjectType[Repo, Product] = ObjectType( "Product", () => - fields( - Field("id", IntType, resolve = c => c.value.id), - Field("name", StringType, resolve = c => c.value.name), + fields[Repo, Product]( + Field("id", IntType, resolve = (c: Context[_, Product]) => c.value.id), + Field("name", StringType, resolve = (c: Context[_, Product]) => c.value.name), Field( "categories", ListType(CategoryType), - resolve = c => fetcherCat.deferSeqOpt(c.value.inCategories)), + resolve = (c: Context[_, Product]) => fetcherCat.deferSeqOpt(c.value.inCategories)), Field( "categoryRel", CategoryType, @@ -126,7 +128,7 @@ class FetcherSpec extends AnyWordSpec with Matchers with FutureResultSupport { lazy val CategoryType: ObjectType[Repo, Category] = ObjectType( "Category", () => - fields( + fields[Repo, Category]( Field("id", StringType, resolve = c => c.value.id), Field("name", StringType, resolve = c => c.value.name), Field("color", StringType, resolve = c => ColorDeferred("red")), @@ -200,12 +202,15 @@ class FetcherSpec extends AnyWordSpec with Matchers with FutureResultSupport { Field( "productOpt", OptionType(ProductType), - arguments = Argument("id", OptionInputType(IntType)) :: Nil, - resolve = c => fetcherProd.deferOpt(c.argOpt[Int]("id"))), + arguments = + Argument[Option[Int @@ CoercedScalaResult]]("id", OptionInputType(IntType)) :: Nil, + resolve = c => fetcherProd.deferOpt(c.argOpt[Int]("id")) + ), Field( "productsOptExplicit", ListType(OptionType(ProductType)), - arguments = Argument("ids", ListInputType(IntType)) :: Nil, + arguments = + Argument[Seq[Int @@ CoercedScalaResult]]("ids", ListInputType(IntType)) :: Nil, resolve = c => fetcherProd.deferSeqOptExplicit(c.arg[Seq[Int]]("ids")) ), Field("root", CategoryType, resolve = _ => fetcherCat.defer("1")), diff --git a/modules/core/src/test/scala/sangria/marshalling/FromInputSpec.scala b/modules/core/src/test/scala/sangria/marshalling/FromInputSpec.scala index b5bd8b22..629ab013 100644 --- a/modules/core/src/test/scala/sangria/marshalling/FromInputSpec.scala +++ b/modules/core/src/test/scala/sangria/marshalling/FromInputSpec.scala @@ -6,6 +6,9 @@ import spray.json._ import org.scalatest.matchers.should.Matchers import org.scalatest.wordspec.AnyWordSpec +import sangria.util.tag.@@ // Scala 3 issue workaround +import sangria.marshalling.FromInput.InputObjectResult + class FromInputSpec extends AnyWordSpec with Matchers { case class Comment(author: String, text: Option[String]) case class Article( @@ -15,8 +18,8 @@ class FromInputSpec extends AnyWordSpec with Matchers { comments: Vector[Option[Comment]]) object MyJsonProtocol extends DefaultJsonProtocol { - implicit val commentFormat = jsonFormat2(Comment.apply) - implicit val articleFormat = jsonFormat4(Article.apply) + implicit val commentFormat: JsonFormat[Comment] = jsonFormat2(Comment.apply) + implicit val articleFormat: JsonFormat[Article] = jsonFormat4(Article.apply) } import sangria.marshalling.sprayJson.sprayJsonWriterToInput @@ -130,20 +133,21 @@ class FromInputSpec extends AnyWordSpec with Matchers { "" + value }) }, { - val arg = Argument( - "articles", - OptionInputType(ListInputType(OptionInputType(Article1Type))), - Vector( - Some( - Article( - "def1", - None, - Some(Vector("c", "d")), - Vector(Some(Comment("c1", None)), None))), - None, - Some(Article("def2", Some("some text"), None, Vector.empty)) + val arg = + Argument[Option[Seq[Option[Article @@ InputObjectResult]]], Seq[Option[Article]]]( + "articles", + OptionInputType(ListInputType(OptionInputType(Article1Type))), + Vector( + Some( + Article( + "def1", + None, + Some(Vector("c", "d")), + Vector(Some(Comment("c1", None)), None))), + None, + Some(Article("def2", Some("some text"), None, Vector.empty)) + ) ) - ) Field( "optListOpt", diff --git a/modules/core/src/test/scala/sangria/marshalling/IonSupportSpec.scala b/modules/core/src/test/scala/sangria/marshalling/IonSupportSpec.scala index 65ac3c75..ee0154fc 100644 --- a/modules/core/src/test/scala/sangria/marshalling/IonSupportSpec.scala +++ b/modules/core/src/test/scala/sangria/marshalling/IonSupportSpec.scala @@ -20,7 +20,7 @@ class IonSupportSpec extends AnyWordSpec with Matchers with FutureResultSupport import sangria.marshalling.ion._ - implicit val ionSystem = IonSystemBuilder.standard().build() + implicit val ionSystem: software.amazon.ion.IonSystem = IonSystemBuilder.standard().build() val dateFormat = new SimpleDateFormat("yyyy-MM-dd") diff --git a/modules/core/src/test/scala/sangria/renderer/SchemaRenderSpec.scala b/modules/core/src/test/scala/sangria/renderer/SchemaRenderSpec.scala index f64777e8..72c12e11 100644 --- a/modules/core/src/test/scala/sangria/renderer/SchemaRenderSpec.scala +++ b/modules/core/src/test/scala/sangria/renderer/SchemaRenderSpec.scala @@ -12,10 +12,14 @@ import sangria.validation.IntCoercionViolation import scala.concurrent.ExecutionContext.Implicits.global import sangria.marshalling.sprayJson._ import sangria.marshalling.ScalaInput.scalaInput +import sangria.marshalling.ScalaInput import sangria.parser.QueryParser import org.scalatest.matchers.should.Matchers import org.scalatest.wordspec.AnyWordSpec +import sangria.util.tag.@@ // Scala 3 issue workaround +import sangria.marshalling.FromInput.CoercedScalaResult + class SchemaRenderSpec extends AnyWordSpec with Matchers @@ -139,7 +143,8 @@ class SchemaRenderSpec "Prints String Field With Int Arg" in { renderSingleFieldSchema( tpe = OptionType(StringType), - args = Argument("argOne", OptionInputType(IntType)) :: Nil + args = + Argument[Option[Int @@ CoercedScalaResult]]("argOne", OptionInputType(IntType)) :: Nil ) should equal(""" |schema { | query: Root @@ -154,7 +159,10 @@ class SchemaRenderSpec "Prints String Field With Int Arg With Default" in { renderSingleFieldSchema( tpe = OptionType(StringType), - args = Argument("argOne", OptionInputType(IntType), 2) :: Nil + args = Argument[Option[Int @@ CoercedScalaResult], Int]( + "argOne", + OptionInputType(IntType), + 2) :: Nil ) should equal(""" |schema { | query: Root @@ -184,7 +192,9 @@ class SchemaRenderSpec "Prints String Field With Multiple Args" in { renderSingleFieldSchema( tpe = OptionType(StringType), - args = Argument("argOne", OptionInputType(IntType)) :: Argument( + args = Argument[Option[Int @@ CoercedScalaResult]]( + "argOne", + OptionInputType(IntType)) :: Argument[Option[String @@ CoercedScalaResult]]( "argTwo", OptionInputType(StringType)) :: Nil ) should equal(""" @@ -201,10 +211,13 @@ class SchemaRenderSpec "Prints String Field With Multiple Args, First is Default" in { renderSingleFieldSchema( tpe = OptionType(StringType), - args = Argument("argOne", OptionInputType(IntType), 1) :: - Argument("argTwo", OptionInputType(StringType)) :: - Argument("argThree", OptionInputType(BooleanType)) :: - Nil + args = + Argument[Option[Int @@ CoercedScalaResult], Int]("argOne", OptionInputType(IntType), 1) :: + Argument[Option[String @@ CoercedScalaResult]]("argTwo", OptionInputType(StringType)) :: + Argument[Option[Boolean @@ CoercedScalaResult]]( + "argThree", + OptionInputType(BooleanType)) :: + Nil ) should equal(""" |schema { | query: Root @@ -219,9 +232,14 @@ class SchemaRenderSpec "Prints String Field With Multiple Args, Second is Default" in { renderSingleFieldSchema( tpe = OptionType(StringType), - args = Argument("argOne", OptionInputType(IntType)) :: - Argument("argTwo", OptionInputType(StringType), defaultValue = "foo") :: - Argument("argThree", OptionInputType(BooleanType)) :: + args = Argument[Option[Int @@ CoercedScalaResult]]("argOne", OptionInputType(IntType)) :: + Argument[Option[String @@ CoercedScalaResult], String]( + "argTwo", + OptionInputType(StringType), + defaultValue = "foo") :: + Argument[Option[Boolean @@ CoercedScalaResult]]( + "argThree", + OptionInputType(BooleanType)) :: Nil ) should equal(""" |schema { @@ -237,9 +255,12 @@ class SchemaRenderSpec "Prints String Field With Multiple Args, Last is Default" in { renderSingleFieldSchema( tpe = OptionType(StringType), - args = Argument("argOne", OptionInputType(IntType)) :: - Argument("argTwo", OptionInputType(StringType)) :: - Argument("argThree", OptionInputType(BooleanType), false) :: + args = Argument[Option[Int @@ CoercedScalaResult]]("argOne", OptionInputType(IntType)) :: + Argument[Option[String @@ CoercedScalaResult]]("argTwo", OptionInputType(StringType)) :: + Argument[Option[Boolean @@ CoercedScalaResult], Boolean]( + "argThree", + OptionInputType(BooleanType), + false) :: Nil ) should equal(""" |schema { @@ -703,17 +724,20 @@ class SchemaRenderSpec "myDirective", description = Some( "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec posuere ornare nulla, non bibendum nisi dictum at. Etiam consequat velit ut leo fringilla mollis. Integer ut fringilla ante. Curabitur sagittis malesuada nibh sed vestibulum.\nNunc eu metus felis. Cras tellus nibh, porta nec lorem quis, elementum egestas tellus. Etiam vitae tellus vitae dui varius lobortis."), - arguments = Argument( + arguments = Argument[Option[Seq[String @@ CoercedScalaResult]], List[String] @@ ScalaInput]( "first", OptionInputType(ListInputType(StringType)), "Some descr", scalaInput(List("foo", "bar", "baz"))) :: - Argument( + Argument[Option[Seq[String @@ CoercedScalaResult]], Int @@ ScalaInput]( "middle", OptionInputType(ListInputType(StringType)), "Several\n lines\nof \"description\"", scalaInput(123)) :: - Argument("last", OptionInputType(IntType), "Another descr") :: + Argument[Option[Int @@ CoercedScalaResult]]( + "last", + OptionInputType(IntType), + "Another descr") :: Nil, locations = Set(DirectiveLocation.FieldDefinition, DirectiveLocation.InputFieldDefinition), shouldInclude = _ => true diff --git a/modules/core/src/test/scala/sangria/schema/ArgsSpec.scala b/modules/core/src/test/scala/sangria/schema/ArgsSpec.scala index 071b0efb..a72e7bc5 100644 --- a/modules/core/src/test/scala/sangria/schema/ArgsSpec.scala +++ b/modules/core/src/test/scala/sangria/schema/ArgsSpec.scala @@ -7,6 +7,9 @@ import spray.json._ import org.scalatest.matchers.should.Matchers import org.scalatest.wordspec.AnyWordSpec +import sangria.util.tag.@@ // Scala 3 issue workaround +import sangria.marshalling.FromInput.CoercedScalaResult + class ArgsSpec extends AnyWordSpec with Matchers { val NonDefaultArgumentName = "nonDefaultArgument" val DefaultArgumentName = "defaultArgument" @@ -19,7 +22,7 @@ class ArgsSpec extends AnyWordSpec with Matchers { description = "Argument without default value" ) - val defaultArgument = Argument( + val defaultArgument = Argument[Option[Int @@ CoercedScalaResult], Int]( name = DefaultArgumentName, argumentType = OptionInputType(IntType), defaultValue = 10, diff --git a/modules/core/src/test/scala/sangria/schema/DefaultValueApplicationSpec.scala b/modules/core/src/test/scala/sangria/schema/DefaultValueApplicationSpec.scala index c653bdcf..70f5e462 100644 --- a/modules/core/src/test/scala/sangria/schema/DefaultValueApplicationSpec.scala +++ b/modules/core/src/test/scala/sangria/schema/DefaultValueApplicationSpec.scala @@ -13,6 +13,9 @@ import sangria.marshalling.sprayJson._ import org.scalatest.matchers.should.Matchers import org.scalatest.wordspec.AnyWordSpec +import sangria.util.tag.@@ // Scala 3 issue workaround +import sangria.marshalling.FromInput.CoercedScalaResult + class DefaultValueApplicationSpec extends AnyWordSpec with Matchers with FutureResultSupport { "Default value application" should { "use default value if argument is not provided" in { @@ -181,10 +184,14 @@ class DefaultValueApplicationSpec extends AnyWordSpec with Matchers with FutureR InputField("f", OptionInputType(StringType), defaultValue = "default"), InputField("fo", OptionInputType(StringType)))) - private[this] val AArg = Argument("a", OptionInputType(StringType), defaultValue = "default") + private[this] val AArg = Argument[Option[String @@ CoercedScalaResult], String]( + "a", + OptionInputType(StringType), + defaultValue = "default") private[this] val InpArg = Argument("inp", TestInputType) private[this] val InpJsonArg = Argument("inpJson", TestInputJsonType) - private[this] val SizeArg = Argument("size", OptionInputType(IntType), 42) + private[this] val SizeArg = + Argument[Option[Int @@ CoercedScalaResult], Int]("size", OptionInputType(IntType), 42) private[this] val QueryType = ObjectType( "Query", diff --git a/modules/core/src/test/scala/sangria/schema/DefaultValuesSpec.scala b/modules/core/src/test/scala/sangria/schema/DefaultValuesSpec.scala index abc6750f..59710507 100644 --- a/modules/core/src/test/scala/sangria/schema/DefaultValuesSpec.scala +++ b/modules/core/src/test/scala/sangria/schema/DefaultValuesSpec.scala @@ -339,8 +339,8 @@ class DefaultValuesSpec extends AnyWordSpec with Matchers with FutureResultSuppo "generated typeclass-based serialisation" in { object MyJsonProtocol extends DefaultJsonProtocol { - implicit val sharesFormat = jsonFormat2(Shares.apply) - implicit val commentFormat = jsonFormat3(Comment.apply) + implicit val sharesFormat: JsonFormat[Shares] = jsonFormat2(Shares.apply) + implicit val commentFormat: JsonFormat[Comment] = jsonFormat3(Comment.apply) } import MyJsonProtocol._ diff --git a/modules/core/src/test/scala/sangria/schema/EnumTypeSpec.scala b/modules/core/src/test/scala/sangria/schema/EnumTypeSpec.scala index f97238c0..d944f6cc 100644 --- a/modules/core/src/test/scala/sangria/schema/EnumTypeSpec.scala +++ b/modules/core/src/test/scala/sangria/schema/EnumTypeSpec.scala @@ -15,8 +15,8 @@ class EnumTypeSpec extends AnyWordSpec with Matchers with GraphQlSupport { )) object Args { - val fromEnum = Argument("fromEnum", OptionInputType(ColorType)) - val fromInt = Argument("fromInt", OptionInputType(IntType)) + val fromEnum: Argument[Option[Int]] = Argument("fromEnum", OptionInputType(ColorType)) + val fromInt: Argument[Option[Int]] = Argument("fromInt", OptionInputType(IntType)) } val QueryType = ObjectType( @@ -43,7 +43,7 @@ class EnumTypeSpec extends AnyWordSpec with Matchers with GraphQlSupport { "favoriteEnum", OptionType(ColorType), arguments = Args.fromEnum :: Nil, - resolve = _.args.arg(Args.fromEnum)) + resolve = _.args.arg[Option[Int]](Args.fromEnum)) )) val SubscriptionType = ObjectType( @@ -53,8 +53,9 @@ class EnumTypeSpec extends AnyWordSpec with Matchers with GraphQlSupport { "subscribeToEnum", OptionType(ColorType), arguments = Args.fromEnum :: Nil, - resolve = _.args.arg(Args.fromEnum)) - )) + resolve = _.args.arg[Option[Int]](Args.fromEnum)) + ) + ) val schema = Schema(QueryType, Some(MutationType), Some(SubscriptionType)) diff --git a/modules/core/src/test/scala/sangria/schema/IntrospectionSchemaMaterializerSpec.scala b/modules/core/src/test/scala/sangria/schema/IntrospectionSchemaMaterializerSpec.scala index c99e33fe..beeceb8e 100644 --- a/modules/core/src/test/scala/sangria/schema/IntrospectionSchemaMaterializerSpec.scala +++ b/modules/core/src/test/scala/sangria/schema/IntrospectionSchemaMaterializerSpec.scala @@ -19,6 +19,10 @@ import spray.json._ import org.scalatest.matchers.should.Matchers import org.scalatest.wordspec.AnyWordSpec +import sangria.util.tag.@@ +import sangria.marshalling.FromInput.CoercedScalaResult +import sangria.marshalling.ScalaInput + class IntrospectionSchemaMaterializerSpec extends AnyWordSpec with Matchers @@ -134,13 +138,15 @@ class IntrospectionSchemaMaterializerSpec mutation = Some(ObjectType( "MutationType", "This is a simple mutation type", - fields[Any, Any]( - Field( - "setString", - OptionType(StringType), - Some("Set the string field"), - arguments = Argument("value", OptionInputType(StringType)) :: Nil, - resolve = _ => "foo")) + fields[Any, Any](Field( + "setString", + OptionType(StringType), + Some("Set the string field"), + arguments = Argument[Option[String @@ CoercedScalaResult]]( + "value", + OptionInputType(StringType)) :: Nil, + resolve = _ => "foo" + )) )), subscription = Some(ObjectType( "SubscriptionType", @@ -242,7 +248,7 @@ class IntrospectionSchemaMaterializerSpec "one", OptionType(StringType), Some("A field with a single arg"), - arguments = Argument( + arguments = Argument[Option[Int @@ CoercedScalaResult]]( "intArg", OptionInputType(IntType), description = "This is an int arg") :: Nil, @@ -252,7 +258,7 @@ class IntrospectionSchemaMaterializerSpec "two", OptionType(StringType), Some("A field with a two args"), - arguments = Argument( + arguments = Argument[Option[Seq[Option[Int @@ CoercedScalaResult]]]]( "listArg", OptionInputType(ListInputType(OptionInputType(IntType))), description = "This is an list of int arg") :: @@ -283,7 +289,7 @@ class IntrospectionSchemaMaterializerSpec "food", OptionType(foodType), Some("Repeats the arg you give it"), - arguments = Argument( + arguments = Argument[Option[Int @@ CoercedScalaResult]]( "kind", OptionInputType(foodType), description = "what kind of food?") :: Nil, @@ -347,15 +353,20 @@ class IntrospectionSchemaMaterializerSpec Field( "defaultInt", OptionType(StringType), - arguments = Argument("intArg", OptionInputType(IntType), 10) :: Nil, - resolve = _ => None), + arguments = Argument[Option[Int @@ CoercedScalaResult], Int]( + "intArg", + OptionInputType(IntType), + 10) :: Nil, + resolve = _ => None + ), Field( "defaultList", OptionType(StringType), - arguments = Argument( - "listArg", - OptionInputType(ListInputType(OptionInputType(IntType))), - scalaInput(Vector(1, 2, 3))) :: Nil, + arguments = + Argument[Option[Seq[Option[Int @@ CoercedScalaResult]]], Vector[Int] @@ ScalaInput]( + "listArg", + OptionInputType(ListInputType(OptionInputType(IntType))), + scalaInput(Vector(1, 2, 3))) :: Nil, resolve = _ => None ), Field( @@ -441,8 +452,12 @@ class IntrospectionSchemaMaterializerSpec fields[Any, Any](Field( "foo", OptionType(StringType), - arguments = Argument("custom1", OptionInputType(CustomScalar)) :: - Argument("custom2", OptionInputType(CustomScalar)) :: + arguments = Argument[Option[Int @@ CoercedScalaResult]]( + "custom1", + OptionInputType(CustomScalar)) :: + Argument[Option[Int @@ CoercedScalaResult]]( + "custom2", + OptionInputType(CustomScalar)) :: Nil, resolve = _ => None )) @@ -469,8 +484,12 @@ class IntrospectionSchemaMaterializerSpec fields[Any, Any](Field( "foo", OptionType(IntType), - arguments = Argument("custom1", OptionInputType(CustomScalar)) :: - Argument("custom2", OptionInputType(CustomScalar)) :: + arguments = Argument[Option[Int @@ CoercedScalaResult]]( + "custom1", + OptionInputType(CustomScalar)) :: + Argument[Option[Int @@ CoercedScalaResult]]( + "custom2", + OptionInputType(CustomScalar)) :: Nil, resolve = _ => None )) diff --git a/modules/core/src/test/scala/sangria/schema/ResolverBasedAstSchemaBuilderSpec.scala b/modules/core/src/test/scala/sangria/schema/ResolverBasedAstSchemaBuilderSpec.scala index 94b1335b..21cfb2d9 100644 --- a/modules/core/src/test/scala/sangria/schema/ResolverBasedAstSchemaBuilderSpec.scala +++ b/modules/core/src/test/scala/sangria/schema/ResolverBasedAstSchemaBuilderSpec.scala @@ -18,6 +18,9 @@ import sangria.util.SimpleGraphQlSupport._ import org.scalatest.matchers.should.Matchers import org.scalatest.wordspec.AnyWordSpec +import sangria.util.tag.@@ // Scala 3 issue workaround +import sangria.marshalling.FromInput.CoercedScalaResult + class ResolverBasedAstSchemaBuilderSpec extends AnyWordSpec with Matchers with FutureResultSupport { case object UUIDViolation extends BaseViolation("Invalid UUID") @@ -44,7 +47,7 @@ class ResolverBasedAstSchemaBuilderSpec extends AnyWordSpec with Matchers with F "provide basic resolution capabilities" in { import sangria.marshalling.sprayJson._ - val ValueArg = Argument("value", StringType) + val ValueArg: Argument[String] = Argument("value", StringType) val TestDir = Directive("test", arguments = ValueArg :: Nil, locations = Set(DL.FieldDefinition)) @@ -101,11 +104,13 @@ class ResolverBasedAstSchemaBuilderSpec extends AnyWordSpec with Matchers with F c.withArgs(MinArg, MaxArg)((min, max) => c.inputType(c.definition.valueType, intValidationAlias(min, max)))), DirectiveScalarResolver(CoolDir, _ => StringType), - DirectiveResolver(TestDir, resolve = _.arg(ValueArg)), + DirectiveResolver(TestDir, resolve = _.arg[String](ValueArg)), DynamicDirectiveResolver[Any, JsValue]("json", resolve = _.args), - FieldResolver { case (TypeName("Query"), FieldName("id")) => - _ => UUID.fromString("a26bdfd4-0fcf-484f-b363-585091b3319f") - }, + FieldResolver( + { case (TypeName("Query"), FieldName("id")) => + _ => UUID.fromString("a26bdfd4-0fcf-484f-b363-585091b3319f") + }, + PartialFunction.empty), AnyFieldResolver.defaultInput[Any, JsValue] ) @@ -269,7 +274,7 @@ class ResolverBasedAstSchemaBuilderSpec extends AnyWordSpec with Matchers with F } "resolve fields based on the directives" in { - val ValueArg = Argument("value", StringType) + val ValueArg: Argument[String] = Argument("value", StringType) val ConstDir = Directive("const", arguments = ValueArg :: Nil, locations = Set(DL.FieldDefinition)) @@ -278,7 +283,7 @@ class ResolverBasedAstSchemaBuilderSpec extends AnyWordSpec with Matchers with F val AddFinalDir = Directive("addFinal", locations = Set(DL.Schema, DL.FieldDefinition)) val builder = resolverBased[Any]( - DirectiveResolver(ConstDir, c => c.arg(ValueArg)), + DirectiveResolver(ConstDir, c => c.arg[String](ValueArg)), DirectiveResolver( AddDir, c => @@ -336,11 +341,14 @@ class ResolverBasedAstSchemaBuilderSpec extends AnyWordSpec with Matchers with F case (TypeName("Color"), v) if v.name == "GREEN" => "#00FF00" case (TypeName("Color"), v) if v.name == "BLUE" => "#0000FF" }, - FieldResolver { case (TypeName("Mutation"), FieldName("eat")) => - ctx => - "tasty " + ctx.arg[String]("color") + " " + ctx.arg[InputObjectType.DefaultInput]( - "fruit")("color") - } + FieldResolver( + { case (TypeName("Mutation"), FieldName("eat")) => + ctx => + "tasty " + ctx.arg[String]("color") + " " + ctx.arg[InputObjectType.DefaultInput]( + "fruit")("color") + }, + PartialFunction.empty + ) ) val schemaAst = @@ -464,10 +472,13 @@ class ResolverBasedAstSchemaBuilderSpec extends AnyWordSpec with Matchers with F "resolve fields based on names" in { val builder = resolverBased[Unit]( - FieldResolver { - case (TypeName("Query"), field @ FieldName(fieldName)) if fieldName.startsWith("test") => - c => c.arg[Int](field.arguments.head.name) + 1 - }, + FieldResolver( + { + case (TypeName("Query"), field @ FieldName(fieldName)) + if fieldName.startsWith("test") => + c => c.arg[Int](field.arguments.head.name) + 1 + }, + PartialFunction.empty), FieldResolver.map("Query" -> Map("a" -> (_ => "a value"), "b" -> (_ => "b value"))), ExistingFieldResolver { case (_, _, field) if field.name.startsWith("existing") => @@ -736,10 +747,13 @@ class ResolverBasedAstSchemaBuilderSpec extends AnyWordSpec with Matchers with F } """ - val builder = resolverBased[Any](FieldResolver { - case (_, FieldName("name")) => _ => "test" - case (_, _) => _ => () - }) + val builder = resolverBased[Any]( + FieldResolver( + { + case (_, FieldName("name")) => _ => "test" + case (_, _) => _ => () + }, + PartialFunction.empty)) val resolverBuilder = builder.validateSchemaWithException(schemaDocument) diff --git a/modules/core/src/test/scala/sangria/schema/SchemaExtensionSpec.scala b/modules/core/src/test/scala/sangria/schema/SchemaExtensionSpec.scala index 57ce8011..b4566444 100644 --- a/modules/core/src/test/scala/sangria/schema/SchemaExtensionSpec.scala +++ b/modules/core/src/test/scala/sangria/schema/SchemaExtensionSpec.scala @@ -30,7 +30,7 @@ class SchemaExtensionSpec val SomeInterfaceType: InterfaceType[Unit, SomeInterface] = InterfaceType( "SomeInterface", () => - fields( + fields[Unit, SomeInterface]( Field("name", OptionType(StringType), resolve = _.value.name), Field("some", OptionType(SomeInterfaceType), resolve = _.value.some) ) @@ -40,7 +40,7 @@ class SchemaExtensionSpec "Foo", interfaces = interfaces(SomeInterfaceType), () => - fields( + fields[Unit, Foo]( Field("name", OptionType(StringType), resolve = _.value.name), Field("some", OptionType(SomeInterfaceType), resolve = _.value.some), Field("tree", ListType(OptionType(FooType)), resolve = _.value.tree) @@ -51,7 +51,7 @@ class SchemaExtensionSpec "Bar", interfaces = interfaces(SomeInterfaceType), () => - fields( + fields[Unit, Bar]( Field("name", OptionType(StringType), resolve = _.value.name), Field("some", OptionType(SomeInterfaceType), resolve = _.value.some), Field("foo", OptionType(FooType), resolve = _.value.foo) diff --git a/modules/core/src/test/scala/sangria/schema/TypeFieldConstraintsSpec.scala b/modules/core/src/test/scala/sangria/schema/TypeFieldConstraintsSpec.scala index c6b6643a..b832aef6 100644 --- a/modules/core/src/test/scala/sangria/schema/TypeFieldConstraintsSpec.scala +++ b/modules/core/src/test/scala/sangria/schema/TypeFieldConstraintsSpec.scala @@ -5,6 +5,9 @@ import sangria.util.SimpleGraphQlSupport._ import org.scalatest.matchers.should.Matchers import org.scalatest.wordspec.AnyWordSpec +import sangria.util.tag.@@ // Scala 3 issue workaround +import sangria.marshalling.FromInput.CoercedScalaResult + class TypeFieldConstraintsSpec extends AnyWordSpec with Matchers { "ObjectType" should { @@ -425,10 +428,12 @@ class TypeFieldConstraintsSpec extends AnyWordSpec with Matchers { Field( "slice", IntType, - arguments = Argument("parts", IntType) :: Argument( - "careful", - OptionInputType(BooleanType)) :: Nil, - resolve = _.args.arg[Int]("parts")), + arguments = + Argument("parts", IntType) :: Argument[Option[Boolean @@ CoercedScalaResult]]( + "careful", + OptionInputType(BooleanType)) :: Nil, + resolve = _.args.arg[Int]("parts") + ), Field("color", StringType, resolve = _.value.color) ) ) diff --git a/modules/core/src/test/scala/sangria/starWars/StarWarsQuerySpec.scala b/modules/core/src/test/scala/sangria/starWars/StarWarsQuerySpec.scala index 5162861f..2656f17c 100644 --- a/modules/core/src/test/scala/sangria/starWars/StarWarsQuerySpec.scala +++ b/modules/core/src/test/scala/sangria/starWars/StarWarsQuerySpec.scala @@ -523,7 +523,7 @@ class StarWarsQuerySpec extends AnyWordSpec with Matchers with FutureResultSuppo lazy val A: ObjectType[Unit, Any] = ObjectType( "A", () => - fields( + fields[Unit, Any]( Field("nullableA", OptionType(A), resolve = _ => ""), Field("nonNullA", A, resolve = _ => ""), Field("throws", A, resolve = _ => throw PrivacyError("Catch me if you can")) diff --git a/modules/core/src/test/scala/sangria/util/CatsSupport.scala b/modules/core/src/test/scala/sangria/util/CatsSupport.scala index 49538f25..2becec38 100644 --- a/modules/core/src/test/scala/sangria/util/CatsSupport.scala +++ b/modules/core/src/test/scala/sangria/util/CatsSupport.scala @@ -62,11 +62,11 @@ trait CatsSupport { this: AnyWordSpec with Matchers => val testData = testTestData.orElse(bgTestData).getOrElse(JsObject.empty) - val given = getGiven(test, testSchema) + val `given` = getGiven(test, testSchema) val action = getAction(test, testName, testData) val assertions = getAssertions(test, testName) - val result = executeAction(given, action) + val result = executeAction(`given`, action) assertions.foreach { a => assertActionResult(result, a) @@ -213,26 +213,26 @@ object CatsScenarioExecutor extends FutureResultSupport { value.asInstanceOf[JsValue].get("type").exists(_.stringValue == c.definition.name)) ) - def executeAction(given: Given[Any, Any], action: Action) = action match { + def executeAction(`given`: Given[Any, Any], action: Action) = action match { case Parse => ParsingResult( - QueryParser.parse(given.query).toEither.left.map(_.asInstanceOf[SangriaSyntaxError])) + QueryParser.parse(`given`.query).toEither.left.map(_.asInstanceOf[SangriaSyntaxError])) case Validate(rules) => ValidationResult( new RuleBasedQueryValidator(rules.toList) - .validateQuery(given.schema, QueryParser.parse(given.query).get)) + .validateQuery(`given`.schema, QueryParser.parse(`given`.query).get)) case Execute(validate, value, vars, op) => val validator = if (validate) QueryValidator.default else QueryValidator.empty ExecutionResult( QueryParser - .parse(given.query) + .parse(`given`.query) .map(queryAst => Executor .execute( - given.schema, + `given`.schema, queryAst, root = value, queryValidator = validator, @@ -586,8 +586,8 @@ object CatsScenarioData { } def getGiven(value: YamlValue, schema: Option[Schema[Any, Any]]) = { - val given = value("given") - val query = given("query").stringValue + val `given` = value("given") + val query = `given`("query").stringValue Given(query, schema) } diff --git a/modules/core/src/test/scala/sangria/util/DebugUtil.scala b/modules/core/src/test/scala/sangria/util/DebugUtil.scala index aa5309fb..d7f71495 100644 --- a/modules/core/src/test/scala/sangria/util/DebugUtil.scala +++ b/modules/core/src/test/scala/sangria/util/DebugUtil.scala @@ -83,7 +83,7 @@ object DebugUtil { } } - private implicit val conf = myPrettifier + private implicit val conf: Prettifier = myPrettifier def prettyRender[T](obj: T): String = obj.pretty diff --git a/modules/core/src/test/scala/sangria/util/ValidationSupport.scala b/modules/core/src/test/scala/sangria/util/ValidationSupport.scala index c2d27de1..dae8e6d7 100644 --- a/modules/core/src/test/scala/sangria/util/ValidationSupport.scala +++ b/modules/core/src/test/scala/sangria/util/ValidationSupport.scala @@ -8,6 +8,9 @@ import sangria.util.SimpleGraphQlSupport._ import scala.util.Success import org.scalatest.matchers.should.Matchers +import sangria.util.tag.@@ +import sangria.marshalling.FromInput.CoercedScalaResult + trait ValidationSupport extends Matchers { type TestField = Field[Unit, Unit] @@ -29,9 +32,12 @@ trait ValidationSupport extends Matchers { Field( "name", OptionType(StringType), - arguments = Argument("surname", OptionInputType(BooleanType)) :: Nil, + arguments = Argument[Option[Boolean @@ CoercedScalaResult]]( + "surname", + OptionInputType(BooleanType)) :: Nil, resolve = _ => None) - )) + ) + ) val DogCommand = EnumType( "DogCommand", @@ -57,7 +63,9 @@ trait ValidationSupport extends Matchers { Field( "name", OptionType(StringType), - arguments = Argument("surname", OptionInputType(BooleanType)) :: Nil, + arguments = Argument[Option[Boolean @@ CoercedScalaResult]]( + "surname", + OptionInputType(BooleanType)) :: Nil, resolve = _ => None), Field("nickname", OptionType(StringType), resolve = _ => None), Field("barks", OptionType(BooleanType), resolve = _ => None), @@ -65,18 +73,18 @@ trait ValidationSupport extends Matchers { Field( "doesKnowCommand", OptionType(BooleanType), - arguments = Argument("dogCommand", OptionInputType(DogCommand)) :: Nil, + arguments = List(Argument("dogCommand", OptionInputType(DogCommand))), resolve = _ => None), Field( "isHousetrained", OptionType(BooleanType), - arguments = Argument("atOtherHomes", OptionInputType(BooleanType), true) :: Nil, + arguments = List(Argument("atOtherHomes", OptionInputType(BooleanType), true)), resolve = _ => None), Field( "isAtLocation", OptionType(BooleanType), arguments = - Argument("x", OptionInputType(IntType)) :: Argument("y", OptionInputType(IntType)) :: Nil, + List(Argument("x", OptionInputType(IntType)), Argument("y", OptionInputType(IntType))), resolve = _ => None) ) ) @@ -109,7 +117,7 @@ trait ValidationSupport extends Matchers { Field( "name", OptionType(StringType), - arguments = Argument("surname", OptionInputType(BooleanType)) :: Nil, + arguments = List(Argument("surname", OptionInputType(BooleanType))), resolve = _ => None), Field("pets", OptionType(ListType(OptionType(Pet))), resolve = _ => None), Field("relatives", OptionType(ListType(OptionType(Human))), resolve = _ => None) @@ -143,88 +151,86 @@ trait ValidationSupport extends Matchers { Field( "intArgField", OptionType(StringType), - arguments = Argument("intArg", OptionInputType(IntType)) :: Nil, + arguments = List(Argument("intArg", OptionInputType(IntType))), resolve = _ => None), Field( "bigIntArgField", OptionType(StringType), - arguments = Argument("bigIntArg", OptionInputType(BigIntType)) :: Nil, + arguments = List(Argument("bigIntArg", OptionInputType(BigIntType))), resolve = _ => None), Field( "nonNullIntArgField", OptionType(StringType), - arguments = Argument("nonNullIntArg", IntType) :: Nil, + arguments = List(Argument("nonNullIntArg", IntType)), resolve = _ => None), Field( "stringArgField", OptionType(StringType), - arguments = Argument("stringArg", OptionInputType(StringType)) :: Nil, + arguments = List(Argument("stringArg", OptionInputType(StringType))), resolve = _ => None), Field( "booleanArgField", OptionType(StringType), - arguments = Argument("booleanArg", OptionInputType(BooleanType)) :: Nil, + arguments = List(Argument("booleanArg", OptionInputType(BooleanType))), resolve = _ => None), Field( "enumArgField", OptionType(StringType), - arguments = Argument("enumArg", OptionInputType(FurColor)) :: Nil, + arguments = List(Argument("enumArg", OptionInputType(FurColor))), resolve = _ => None), Field( "floatArgField", OptionType(StringType), - arguments = Argument("floatArg", OptionInputType(FloatType)) :: Nil, + arguments = List(Argument("floatArg", OptionInputType(FloatType))), resolve = _ => None), Field( "bigDecimalArgField", OptionType(StringType), - arguments = Argument("bigDecimalArg", OptionInputType(BigDecimalType)) :: Nil, + arguments = List(Argument("bigDecimalArg", OptionInputType(BigDecimalType))), resolve = _ => None), Field( "idArgField", OptionType(StringType), - arguments = Argument("idArg", OptionInputType(IDType)) :: Nil, + arguments = List(Argument("idArg", OptionInputType(IDType))), resolve = _ => None), Field( "stringListArgField", OptionType(StringType), - arguments = Argument( - "stringListArg", - OptionInputType(ListInputType(OptionInputType(StringType)))) :: Nil, + arguments = List( + Argument("stringListArg", OptionInputType(ListInputType(OptionInputType(StringType))))), resolve = _ => None ), Field( "complexArgField", OptionType(StringType), - arguments = Argument("complexArg", OptionInputType(ComplexInput)) :: Nil, + arguments = List(Argument("complexArg", OptionInputType(ComplexInput))), resolve = _ => None), Field( "multipleReqs", OptionType(StringType), - arguments = Argument("req1", IntType) :: Argument("req2", IntType) :: Nil, + arguments = List(Argument("req1", IntType), Argument("req2", IntType)), resolve = _ => None), Field( "nonNullFieldWithDefault", OptionType(StringType), - arguments = Argument("arg", IntType, 0) :: Nil, + arguments = List(Argument("arg", IntType, 0)), resolve = _ => None), Field( "multipleOpts", OptionType(StringType), - arguments = Argument("opt1", OptionInputType(IntType), 0) :: Argument( - "opt2", - OptionInputType(IntType), - 0) :: Nil, + arguments = List( + Argument("opt1", OptionInputType(IntType), 0), + Argument("opt2", OptionInputType(IntType), 0)), resolve = _ => None ), Field( "multipleOptAndReq", OptionType(StringType), - arguments = Argument("req1", IntType) :: - Argument("req2", IntType) :: - Argument("opt1", OptionInputType(IntType), 0) :: - Argument("opt2", OptionInputType(IntType), 0) :: - Nil, + arguments = List( + Argument("req1", IntType), + Argument("req2", IntType), + Argument("opt1", OptionInputType(IntType), 0), + Argument("opt2", OptionInputType(IntType), 0)), resolve = _ => None ) ) @@ -236,7 +242,7 @@ trait ValidationSupport extends Matchers { Field( "human", OptionType(Human), - arguments = Argument("id", OptionInputType(IDType)) :: Nil, + arguments = List(Argument("id", OptionInputType(IDType))), resolve = _ => None), Field("alien", OptionType(Alien), resolve = _ => None), Field("dog", OptionType(Dog), resolve = _ => None), diff --git a/modules/core/src/test/scala/sangria/validation/DocumentAnalyzerSpec.scala b/modules/core/src/test/scala/sangria/validation/DocumentAnalyzerSpec.scala index e6897428..3c2b2622 100644 --- a/modules/core/src/test/scala/sangria/validation/DocumentAnalyzerSpec.scala +++ b/modules/core/src/test/scala/sangria/validation/DocumentAnalyzerSpec.scala @@ -7,6 +7,9 @@ import org.scalatest.matchers.should.Matchers import org.scalatest.wordspec.AnyWordSpec import sangria.renderer.QueryRenderer +import sangria.util.tag.@@ // Scala 3 issue workaround +import sangria.marshalling.FromInput.CoercedScalaResult + class DocumentAnalyzerSpec extends AnyWordSpec with Matchers with StringMatchers { val NumberType = EnumType( "Number", @@ -20,8 +23,11 @@ class DocumentAnalyzerSpec extends AnyWordSpec with Matchers with StringMatchers Field( "normalField", OptionType(NumberType), - arguments = Argument("enumArg", OptionInputType(NumberType)) :: Nil, - resolve = ctx => ctx.argOpt[Int]("enumArg")), + arguments = Argument[Option[Int @@ CoercedScalaResult]]( + "enumArg", + OptionInputType(NumberType)) :: Nil, + resolve = ctx => ctx.argOpt[Int]("enumArg") + ), Field( "deprecatedField", OptionType(StringType),