diff --git a/.scalafmt.conf b/.scalafmt.conf index 50080d20b9..01b62bc048 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -1,16 +1,24 @@ -version = "2.7.5" +version = "3.0.6" +runner.dialect = scala213 maxColumn = 120 -align = most +align.preset = most continuationIndent.defnSite = 2 assumeStandardLibraryStripMargin = true -docstrings = JavaDoc +docstrings.style = Asterisk +docstrings.wrap = no lineEndings = preserve includeCurlyBraceInSelectChains = false -danglingParentheses = true +danglingParentheses.preset = true spaces { inImportCurlyBraces = true } optIn.annotationNewlines = true -rewrite.rules = [SortImports, RedundantBraces] \ No newline at end of file +rewrite.rules = [SortImports, RedundantBraces] + +fileOverride { + "glob:**/scala-3/**" { + runner.dialect = scala3 + } +} \ No newline at end of file diff --git a/adapters/zio-http/src/main/scala/caliban/ZHttpAdapter.scala b/adapters/zio-http/src/main/scala/caliban/ZHttpAdapter.scala index 5351fd5719..f55393d0d1 100644 --- a/adapters/zio-http/src/main/scala/caliban/ZHttpAdapter.scala +++ b/adapters/zio-http/src/main/scala/caliban/ZHttpAdapter.scala @@ -179,7 +179,7 @@ object ZHttpAdapter { val routes = Socket.collect[WebSocketFrame] { case Text(text) => ZStream .fromEffect(ZIO.fromEither(decode[GraphQLWSRequest](text))) - .collect({ + .collect { case GraphQLWSRequest("connection_init", id, payload) => val before = (callbacks.beforeInit, payload) match { case (Some(beforeInit), Some(payload)) => @@ -218,7 +218,7 @@ object ZHttpAdapter { case GraphQLWSRequest("stop", id, _) => removeSubscription(id, subscriptions) *> ZStream.empty - }) + } .flatten .catchAll(_ => connectionError) } @@ -227,11 +227,9 @@ object ZHttpAdapter { } private def queryFromQueryParams(req: Request) = { - val params = List("query", "operationName", "variables", "extensions") - .collect({ case k => - k -> req.url.queryParams.get(k).flatMap(_.headOption).getOrElse("") - }) - .toMap + val params = List("query", "operationName", "variables", "extensions").collect { case k => + k -> req.url.queryParams.get(k).flatMap(_.headOption).getOrElse("") + }.toMap ZIO.fromEither(decode[GraphQLRequest](params.asJson.noSpaces)) } @@ -289,13 +287,13 @@ object ZHttpAdapter { .foldCause(cause => GraphQLResponse(NullValue, cause.defects).asJson, _.asJson) implicit class HttpErrorOps[R, E <: Throwable, A](private val zio: ZIO[R, io.circe.Error, A]) extends AnyVal { - def handleHTTPError: ZIO[R, HttpError, A] = zio.mapError({ + def handleHTTPError: ZIO[R, HttpError, A] = zio.mapError { case DecodingFailure(error, _) => HttpError.BadRequest.apply(s"Invalid json: $error") case ParsingFailure(message, _) => HttpError.BadRequest.apply(message) case t: Throwable => HttpError.InternalServerError.apply("Internal Server Error", Some(t.getCause)) - }) + } } private val protocol = SocketProtocol.subProtocol("graphql-ws") diff --git a/build.sbt b/build.sbt index bf44621849..4e36d9a533 100644 --- a/build.sbt +++ b/build.sbt @@ -28,21 +28,21 @@ val zioHttpVersion = "1.0.0.0-RC17" inThisBuild( List( - scalaVersion := scala212, - crossScalaVersions := allScala, - organization := "com.github.ghostdogpr", - homepage := Some(url("https://github.com/ghostdogpr/caliban")), - licenses := List( + scalaVersion := scala212, + crossScalaVersions := allScala, + organization := "com.github.ghostdogpr", + homepage := Some(url("https://github.com/ghostdogpr/caliban")), + licenses := List( "Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0") ), Test / parallelExecution := false, - scmInfo := Some( + scmInfo := Some( ScmInfo( url("https://github.com/ghostdogpr/caliban/"), "scm:git:git@github.com:ghostdogpr/caliban.git" ) ), - developers := List( + developers := List( Developer( "ghostdogpr", "Pierre Ricadat", @@ -136,7 +136,7 @@ lazy val core = project .dependsOn(macros) .settings( Test / fork := true, - run / fork := true + run / fork := true ) lazy val tools = project @@ -164,25 +164,25 @@ lazy val codegenSbt = project .settings(commonSettings) .enablePlugins(BuildInfoPlugin) .settings( - buildInfoKeys := Seq[BuildInfoKey](version), + buildInfoKeys := Seq[BuildInfoKey](version), buildInfoPackage := "caliban.codegen", - buildInfoObject := "BuildInfo" + buildInfoObject := "BuildInfo" ) .settings( - sbtPlugin := true, + sbtPlugin := true, crossScalaVersions := Seq(scala212), - testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework")), + testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework")), libraryDependencies ++= Seq( "dev.zio" %% "zio-test-sbt" % zioVersion % Test ) ) .enablePlugins(SbtPlugin) .settings( - scriptedLaunchOpts := { + scriptedLaunchOpts := { scriptedLaunchOpts.value ++ Seq("-Xmx1024M", "-Xss4M", "-Dplugin.version=" + version.value) }, - scriptedBufferLog := false, + scriptedBufferLog := false, scriptedDependencies := { (macros / publishLocal).value (core / publishLocal).value @@ -372,7 +372,7 @@ lazy val clientLaminext = crossProject(JSPlatform) .settings(commonSettings) .dependsOn(clientJS) .settings( - testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework")), + testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework")), Test / scalaJSLinkerConfig ~= { _.withModuleKind(ModuleKind.ESModule) }, Test / scalaJSLinkerConfig ~= { _.withModuleSplitStyle(ModuleSplitStyle.FewestModules) }, Test / scalaJSLinkerConfig ~= { _.withSourceMap(false) }, @@ -394,7 +394,7 @@ lazy val examples = project .settings(commonSettings) .settings( publish / skip := true, - run / fork := true + run / fork := true ) .settings( crossScalaVersions -= scala3, @@ -442,7 +442,7 @@ lazy val federation = project .settings(commonSettings) .dependsOn(core % "compile->compile;test->test") .settings( - testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework")), + testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework")), libraryDependencies ++= Seq( "dev.zio" %% "zio" % zioVersion, "dev.zio" %% "zio-test" % zioVersion % Test, diff --git a/client-laminext/src/test/scala/caliban/client/laminext/Client.scala b/client-laminext/src/test/scala/caliban/client/laminext/Client.scala index 872074a040..85b90de090 100644 --- a/client-laminext/src/test/scala/caliban/client/laminext/Client.scala +++ b/client-laminext/src/test/scala/caliban/client/laminext/Client.scala @@ -57,7 +57,7 @@ object Client { roleSelectionOnEngineer: SelectionBuilder[Engineer, RoleSelection], roleSelectionOnMechanic: SelectionBuilder[Mechanic, RoleSelection], roleSelectionOnPilot: SelectionBuilder[Pilot, RoleSelection] - ): ViewSelection[RoleSelection] = (name ~ nicknames ~ origin ~ role( + ): ViewSelection[RoleSelection] = (name ~ nicknames ~ origin ~ role( roleSelectionOnCaptain, roleSelectionOnEngineer, roleSelectionOnMechanic, @@ -72,7 +72,7 @@ object Client { onEngineer: SelectionBuilder[Engineer, A], onMechanic: SelectionBuilder[Mechanic, A], onPilot: SelectionBuilder[Pilot, A] - ): SelectionBuilder[Character, Option[A]] = Field( + ): SelectionBuilder[Character, Option[A]] = Field( "role", OptionOf( ChoiceOf( @@ -131,7 +131,7 @@ object Client { */ def characters[A]( origin: Option[Origin] = None - )(innerSelection: SelectionBuilder[Character, A]): SelectionBuilder[RootQuery, List[A]] = + )(innerSelection: SelectionBuilder[Character, A]): SelectionBuilder[RootQuery, List[A]] = Field("characters", ListOf(Obj(innerSelection)), arguments = List(Argument("origin", origin, "Origin"))) @deprecated("Use `characters`", "") def character[A]( diff --git a/client/src/main/scala/caliban/client/IntrospectionClient.scala b/client/src/main/scala/caliban/client/IntrospectionClient.scala index 3d020a3c04..7619af12be 100644 --- a/client/src/main/scala/caliban/client/IntrospectionClient.scala +++ b/client/src/main/scala/caliban/client/IntrospectionClient.scala @@ -128,7 +128,7 @@ object IntrospectionClient { def description: SelectionBuilder[__Type, Option[String]] = Field("description", OptionOf(Scalar())) def fields[A]( includeDeprecated: Option[Boolean] = None - )(innerSelection: SelectionBuilder[__Field, A]): SelectionBuilder[__Type, Option[List[A]]] = + )(innerSelection: SelectionBuilder[__Field, A]): SelectionBuilder[__Type, Option[List[A]]] = Field( "fields", OptionOf(ListOf(Obj(innerSelection))), @@ -140,7 +140,7 @@ object IntrospectionClient { Field("possibleTypes", OptionOf(ListOf(Obj(innerSelection)))) def enumValues[A]( includeDeprecated: Option[Boolean] = None - )(innerSelection: SelectionBuilder[__EnumValue, A]): SelectionBuilder[__Type, Option[List[A]]] = + )(innerSelection: SelectionBuilder[__EnumValue, A]): SelectionBuilder[__Type, Option[List[A]]] = Field( "enumValues", OptionOf(ListOf(Obj(innerSelection))), diff --git a/client/src/main/scala/caliban/client/SelectionBuilder.scala b/client/src/main/scala/caliban/client/SelectionBuilder.scala index acbb2e4c04..1ce278a5d2 100644 --- a/client/src/main/scala/caliban/client/SelectionBuilder.scala +++ b/client/src/main/scala/caliban/client/SelectionBuilder.scala @@ -136,7 +136,7 @@ sealed trait SelectionBuilder[-Origin, +A] { self => /** * Maps a tupled result to a type `Res` using a function `f` with 2 parameters */ - def mapN[B, C, Res](f: (B, C) => Res)(implicit ev: A <:< (B, C)): SelectionBuilder[Origin, Res] = + def mapN[B, C, Res](f: (B, C) => Res)(implicit ev: A <:< (B, C)): SelectionBuilder[Origin, Res] = self.map(ev.andThen { case (b, c) => f(b, c) }) /** @@ -150,7 +150,7 @@ sealed trait SelectionBuilder[-Origin, +A] { self => */ def mapN[B, C, D, E, Res]( f: (B, C, D, E) => Res - )(implicit ev: A <:< (((B, C), D), E)): SelectionBuilder[Origin, Res] = + )(implicit ev: A <:< (((B, C), D), E)): SelectionBuilder[Origin, Res] = self.map(ev.andThen { case (((b, c), d), e) => f(b, c, d, e) }) /** @@ -158,7 +158,7 @@ sealed trait SelectionBuilder[-Origin, +A] { self => */ def mapN[B, C, D, E, F, Res]( f: (B, C, D, E, F) => Res - )(implicit ev: A <:< ((((B, C), D), E), F)): SelectionBuilder[Origin, Res] = + )(implicit ev: A <:< ((((B, C), D), E), F)): SelectionBuilder[Origin, Res] = self.map(ev.andThen { case ((((b, c), d), e), ff) => f(b, c, d, e, ff) }) /** @@ -166,7 +166,7 @@ sealed trait SelectionBuilder[-Origin, +A] { self => */ def mapN[B, C, D, E, F, G, Res]( f: (B, C, D, E, F, G) => Res - )(implicit ev: A <:< (((((B, C), D), E), F), G)): SelectionBuilder[Origin, Res] = + )(implicit ev: A <:< (((((B, C), D), E), F), G)): SelectionBuilder[Origin, Res] = self.map(ev.andThen { case (((((b, c), d), e), ff), g) => f(b, c, d, e, ff, g) }) /** @@ -174,7 +174,7 @@ sealed trait SelectionBuilder[-Origin, +A] { self => */ def mapN[B, C, D, E, F, G, H, Res]( f: (B, C, D, E, F, G, H) => Res - )(implicit ev: A <:< ((((((B, C), D), E), F), G), H)): SelectionBuilder[Origin, Res] = + )(implicit ev: A <:< ((((((B, C), D), E), F), G), H)): SelectionBuilder[Origin, Res] = self.map(ev.andThen { case ((((((b, c), d), e), ff), g), h) => f(b, c, d, e, ff, g, h) }) /** @@ -182,7 +182,7 @@ sealed trait SelectionBuilder[-Origin, +A] { self => */ def mapN[B, C, D, E, F, G, H, I, Res]( f: (B, C, D, E, F, G, H, I) => Res - )(implicit ev: A <:< (((((((B, C), D), E), F), G), H), I)): SelectionBuilder[Origin, Res] = + )(implicit ev: A <:< (((((((B, C), D), E), F), G), H), I)): SelectionBuilder[Origin, Res] = self.map(ev.andThen { case (((((((b, c), d), e), ff), g), h), i) => f(b, c, d, e, ff, g, h, i) }) /** @@ -190,7 +190,7 @@ sealed trait SelectionBuilder[-Origin, +A] { self => */ def mapN[B, C, D, E, F, G, H, I, J, Res]( f: (B, C, D, E, F, G, H, I, J) => Res - )(implicit ev: A <:< ((((((((B, C), D), E), F), G), H), I), J)): SelectionBuilder[Origin, Res] = + )(implicit ev: A <:< ((((((((B, C), D), E), F), G), H), I), J)): SelectionBuilder[Origin, Res] = self.map(ev.andThen { case ((((((((b, c), d), e), ff), g), h), i), j) => f(b, c, d, e, ff, g, h, i, j) }) /** @@ -198,7 +198,7 @@ sealed trait SelectionBuilder[-Origin, +A] { self => */ def mapN[B, C, D, E, F, G, H, I, J, K, Res]( f: (B, C, D, E, F, G, H, I, J, K) => Res - )(implicit ev: A <:< (((((((((B, C), D), E), F), G), H), I), J), K)): SelectionBuilder[Origin, Res] = + )(implicit ev: A <:< (((((((((B, C), D), E), F), G), H), I), J), K)): SelectionBuilder[Origin, Res] = self.map(ev.andThen { case (((((((((b, c), d), e), ff), g), h), i), j), k) => f(b, c, d, e, ff, g, h, i, j, k) }) /** @@ -206,7 +206,7 @@ sealed trait SelectionBuilder[-Origin, +A] { self => */ def mapN[B, C, D, E, F, G, H, I, J, K, L, Res]( f: (B, C, D, E, F, G, H, I, J, K, L) => Res - )(implicit ev: A <:< ((((((((((B, C), D), E), F), G), H), I), J), K), L)): SelectionBuilder[Origin, Res] = + )(implicit ev: A <:< ((((((((((B, C), D), E), F), G), H), I), J), K), L)): SelectionBuilder[Origin, Res] = self.map(ev.andThen { case ((((((((((b, c), d), e), ff), g), h), i), j), k), l) => f(b, c, d, e, ff, g, h, i, j, k, l) }) @@ -365,7 +365,7 @@ object SelectionBuilder { alias: Option[String] = None, arguments: List[Argument[_]] = Nil, directives: List[Directive] = Nil - ) extends SelectionBuilder[Origin, A] { self => + ) extends SelectionBuilder[Origin, A] { self => override def fromGraphQL(value: __Value): Either[DecodingError, A] = value match { case __ObjectValue(fields) => @@ -400,7 +400,7 @@ object SelectionBuilder { override def withAlias(alias: String): SelectionBuilder[Origin, (A, B)] = self // makes no sense, do nothing } case class Mapping[Origin, A, B](builder: SelectionBuilder[Origin, A], f: A => Either[DecodingError, B]) - extends SelectionBuilder[Origin, B] { + extends SelectionBuilder[Origin, B] { override def fromGraphQL(value: __Value): Either[DecodingError, B] = builder.fromGraphQL(value).flatMap(f) override def withDirective(directive: Directive): SelectionBuilder[Origin, B] = @@ -410,7 +410,7 @@ object SelectionBuilder { override def withAlias(alias: String): SelectionBuilder[Origin, B] = Mapping(builder.withAlias(alias), f) } - case class Pure[A](a: A) extends SelectionBuilder[Any, A] { self => + case class Pure[A](a: A) extends SelectionBuilder[Any, A] { self => override private[caliban] def toSelectionSet = Nil override private[caliban] def fromGraphQL(value: __Value) = Right(a) diff --git a/client/src/test/scala/caliban/client/TestData.scala b/client/src/test/scala/caliban/client/TestData.scala index 59f8fad4ad..0adad8896e 100644 --- a/client/src/test/scala/caliban/client/TestData.scala +++ b/client/src/test/scala/caliban/client/TestData.scala @@ -57,7 +57,7 @@ object TestData { onPilot: SelectionBuilder[Pilot, A], onMechanic: SelectionBuilder[Mechanic, A], onEngineer: SelectionBuilder[Engineer, A] - ): SelectionBuilder[Character, Option[A]] = + ): SelectionBuilder[Character, Option[A]] = Field( "role", OptionOf( diff --git a/codegen-sbt/src/main/scala/caliban/codegen/CalibanPlugin.scala b/codegen-sbt/src/main/scala/caliban/codegen/CalibanPlugin.scala index 4908e55050..6319dfcc53 100644 --- a/codegen-sbt/src/main/scala/caliban/codegen/CalibanPlugin.scala +++ b/codegen-sbt/src/main/scala/caliban/codegen/CalibanPlugin.scala @@ -11,21 +11,21 @@ object CalibanPlugin extends AutoPlugin { import autoImport._ lazy val baseSettings = Seq( - caliban := (caliban / calibanGenerator).value, - (caliban / sourceManaged) := { + caliban := (caliban / calibanGenerator).value, + (caliban / sourceManaged) := { sourceManaged.value / "caliban-codegen-sbt" }, (caliban / calibanSources) := { if (Seq(Compile, Test).contains(configuration.value)) sourceDirectory.value / "graphql" else sourceDirectory.value / "main" / "graphql" }, - caliban / calibanSettings := Seq.empty + caliban / calibanSettings := Seq.empty ) lazy val calibanScopedSettings = inTask(caliban)( Seq( - sources := (calibanSources.value ** "*.graphql").get.sorted, - clean := { + sources := (calibanSources.value ** "*.graphql").get.sorted, + clean := { val sourceDir = sourceManaged.value IO.delete((sourceDir ** "*").get) IO.createDirectory(sourceDir) diff --git a/codegen-sbt/src/main/scala/caliban/codegen/CalibanSourceGenerator.scala b/codegen-sbt/src/main/scala/caliban/codegen/CalibanSourceGenerator.scala index 41f1cca169..754a85f6e5 100644 --- a/codegen-sbt/src/main/scala/caliban/codegen/CalibanSourceGenerator.scala +++ b/codegen-sbt/src/main/scala/caliban/codegen/CalibanSourceGenerator.scala @@ -54,8 +54,7 @@ object CalibanSourceGenerator { CalibanFileSettings( file = source, - settings = fileSettings - .collect({ case needle if source.toPath.endsWith(needle.file.toPath) => needle }) + settings = fileSettings.collect { case needle if source.toPath.endsWith(needle.file.toPath) => needle } .foldLeft[CalibanCommonSettings](defaults) { case (acc, next) => acc.combine(next.settings) } ) } diff --git a/codegen-sbt/src/main/scala/caliban/codegen/CompileTimeCalibanPlugin.scala b/codegen-sbt/src/main/scala/caliban/codegen/CompileTimeCalibanPlugin.scala index a040ff45ba..add9e1af0e 100644 --- a/codegen-sbt/src/main/scala/caliban/codegen/CompileTimeCalibanPlugin.scala +++ b/codegen-sbt/src/main/scala/caliban/codegen/CompileTimeCalibanPlugin.scala @@ -235,9 +235,9 @@ object CompileTimeCalibanClientPlugin extends AutoPlugin { private lazy val pluginSettings = inTask(ctCalibanClient)( Seq( - ctCalibanClientsSettings := Seq.empty, + ctCalibanClientsSettings := Seq.empty, ctCalibanClientsVersionedCode := true, - ctCalibanClientGenerate := { + ctCalibanClientGenerate := { // That helped: https://stackoverflow.com/q/26244115/2431728 Def.taskDyn { import Functions._ diff --git a/core/src/main/scala-2/caliban/interop/play/play.scala b/core/src/main/scala-2/caliban/interop/play/play.scala index 46a27dacc2..b29701224f 100644 --- a/core/src/main/scala-2/caliban/interop/play/play.scala +++ b/core/src/main/scala-2/caliban/interop/play/play.scala @@ -232,12 +232,12 @@ object json { .read[List[CalibanError]] ) .tupled - .map({ case (data, errors) => + .map { case (data, errors) => GraphQLResponse[CalibanError]( data = data, errors = errors ) - }) + } } private[caliban] object GraphQLRequestPlayJson { diff --git a/core/src/main/scala-2/caliban/schema/ArgBuilderDerivation.scala b/core/src/main/scala-2/caliban/schema/ArgBuilderDerivation.scala index 022a783b49..b6cf597d9a 100644 --- a/core/src/main/scala-2/caliban/schema/ArgBuilderDerivation.scala +++ b/core/src/main/scala-2/caliban/schema/ArgBuilderDerivation.scala @@ -28,7 +28,7 @@ trait ArgBuilderDerivation { } def combine[T](ctx: CaseClass[ArgBuilder, T]): ArgBuilder[T] = - (input: InputValue) => { + (input: InputValue) => ctx.constructMonadic { p => input match { case InputValue.ObjectValue(fields) => @@ -38,9 +38,8 @@ trait ArgBuilderDerivation { case value => p.typeclass.build(value) } } - } - def dispatch[T](ctx: SealedTrait[ArgBuilder, T]): ArgBuilder[T] = input => { + def dispatch[T](ctx: SealedTrait[ArgBuilder, T]): ArgBuilder[T] = input => (input match { case EnumValue(value) => Some(value) case StringValue(value) => Some(value) @@ -56,7 +55,6 @@ trait ArgBuilderDerivation { } case None => Left(ExecutionError(s"Can't build a trait from input $input")) } - } implicit def gen[T]: Typeclass[T] = macro Magnolia.gen[T] } diff --git a/core/src/main/scala-2/caliban/schema/SchemaDerivation.scala b/core/src/main/scala-2/caliban/schema/SchemaDerivation.scala index 38f1ab9a48..50aab8b0bd 100644 --- a/core/src/main/scala-2/caliban/schema/SchemaDerivation.scala +++ b/core/src/main/scala-2/caliban/schema/SchemaDerivation.scala @@ -140,7 +140,7 @@ trait SchemaDerivation[R] extends LowPriorityDerivedSchema { .flatMap(_.fields(__DeprecatedArgs(Some(true)))) .flatten .groupBy(_.name) - .filter({ case (_, list) => list.lengthCompare(impl.size) == 0 }) + .filter { case (_, list) => list.lengthCompare(impl.size) == 0 } .collect { case (_, list) => Types .unify(list.map(_.`type`())) @@ -179,7 +179,7 @@ trait SchemaDerivation[R] extends LowPriorityDerivedSchema { ctx.dispatch(value)(subType => subType.typeclass.resolve(subType.cast(value))) } - private def getDirectives(annotations: Seq[Any]): List[Directive] = + private def getDirectives(annotations: Seq[Any]): List[Directive] = annotations.collect { case GQLDirective(dir) => dir }.toList private def getDirectives[Typeclass[_], Type](ctx: ReadOnlyCaseClass[Typeclass, Type]): List[Directive] = @@ -199,10 +199,10 @@ trait SchemaDerivation[R] extends LowPriorityDerivedSchema { private def getName[Typeclass[_], Type](ctx: SealedTrait[Typeclass, Type]): String = getName(ctx.annotations, ctx.typeName) - private def getName[Typeclass[_], Type](ctx: ReadOnlyParam[Typeclass, Type]): String = + private def getName[Typeclass[_], Type](ctx: ReadOnlyParam[Typeclass, Type]): String = ctx.annotations.collectFirst { case GQLName(name) => name }.getOrElse(ctx.label) - private def getDescription(annotations: Seq[Any]): Option[String] = + private def getDescription(annotations: Seq[Any]): Option[String] = annotations.collectFirst { case GQLDescription(desc) => desc } private def getDescription[Typeclass[_], Type](ctx: ReadOnlyCaseClass[Typeclass, Type]): Option[String] = diff --git a/core/src/main/scala/caliban/GraphQLInterpreter.scala b/core/src/main/scala/caliban/GraphQLInterpreter.scala index 062c171158..92dba6e57d 100644 --- a/core/src/main/scala/caliban/GraphQLInterpreter.scala +++ b/core/src/main/scala/caliban/GraphQLInterpreter.scala @@ -116,7 +116,7 @@ trait GraphQLInterpreter[-R, +E] { self => skipValidation: Boolean, enableIntrospection: Boolean, queryExecution: QueryExecution - ): URIO[R2, GraphQLResponse[E2]] = + ): URIO[R2, GraphQLResponse[E2]] = f(self.executeRequest(request, skipValidation = skipValidation, enableIntrospection, queryExecution)) } diff --git a/core/src/main/scala/caliban/GraphQLRequest.scala b/core/src/main/scala/caliban/GraphQLRequest.scala index eeff6e6538..ba97db22ac 100644 --- a/core/src/main/scala/caliban/GraphQLRequest.scala +++ b/core/src/main/scala/caliban/GraphQLRequest.scala @@ -17,7 +17,7 @@ case class GraphQLRequest( def withExtension(key: String, value: InputValue): GraphQLRequest = copy(extensions = Some(extensions.foldLeft(Map(key -> value))(_ ++ _))) - def withFederatedTracing: GraphQLRequest = + def withFederatedTracing: GraphQLRequest = withExtension(`apollo-federation-include-trace`, StringValue(ftv1)) } diff --git a/core/src/main/scala/caliban/Value.scala b/core/src/main/scala/caliban/Value.scala index 5b2343c872..9023611308 100644 --- a/core/src/main/scala/caliban/Value.scala +++ b/core/src/main/scala/caliban/Value.scala @@ -13,7 +13,7 @@ object InputValue extends ValueJsonCompat { override def toInputString: String = values.map(_.toInputString).mkString("[", ", ", "]") } case class ObjectValue(fields: Map[String, InputValue]) extends InputValue { - override def toString: String = + override def toString: String = fields.map { case (name, value) => s""""$name:${value.toString}"""" }.mkString("{", ",", "}") override def toInputString: String = @@ -35,7 +35,7 @@ object ResponseValue extends ValueJsonCompat { override def toString: String = values.mkString("[", ",", "]") } case class ObjectValue(fields: List[(String, ResponseValue)]) extends ResponseValue { - override def toString: String = + override def toString: String = fields.map { case (name, value) => s""""$name":${value.toString}""" }.mkString("{", ",", "}") override def hashCode: Int = fields.toSet.hashCode() diff --git a/core/src/main/scala/caliban/execution/Field.scala b/core/src/main/scala/caliban/execution/Field.scala index 1d92e005a1..1bc8ec20ea 100644 --- a/core/src/main/scala/caliban/execution/Field.scala +++ b/core/src/main/scala/caliban/execution/Field.scala @@ -6,7 +6,7 @@ import caliban.Value.{ BooleanValue, NullValue } import caliban.introspection.adt.{ __DeprecatedArgs, __Type, __TypeKind } import caliban.parsing.SourceMapper import caliban.parsing.adt.Definition.ExecutableDefinition.FragmentDefinition -import caliban.parsing.adt.Selection.{ FragmentSpread, InlineFragment, Field => F } +import caliban.parsing.adt.Selection.{ Field => F, FragmentSpread, InlineFragment } import caliban.parsing.adt.{ Directive, LocationInfo, Selection, Type, VariableDefinition } import caliban.schema.{ RootType, Types } @@ -103,7 +103,7 @@ object Field { value match { case InputValue.ListValue(values) => InputValue.ListValue(values.map(resolveVariable)) case InputValue.ObjectValue(fields) => - InputValue.ObjectValue(fields.map({ case (k, v) => k -> resolveVariable(v) })) + InputValue.ObjectValue(fields.map { case (k, v) => k -> resolveVariable(v) }) case InputValue.VariableValue(name) => (for { definition <- variableDefinitions.find(_.name == name) @@ -112,7 +112,7 @@ object Field { } yield resolveEnumValues(value, definition, rootType)) getOrElse NullValue case value: Value => value } - arguments.map({ case (k, v) => k -> resolveVariable(v) }) + arguments.map { case (k, v) => k -> resolveVariable(v) } } // Since we cannot separate a String from an Enum when variables diff --git a/core/src/main/scala/caliban/interop/circe/circe.scala b/core/src/main/scala/caliban/interop/circe/circe.scala index 8ceffb75c7..b4ac73a65e 100644 --- a/core/src/main/scala/caliban/interop/circe/circe.scala +++ b/core/src/main/scala/caliban/interop/circe/circe.scala @@ -43,7 +43,7 @@ object json { private[caliban] object ValueCirce { import io.circe._ val valueEncoder: Encoder[Value] = Encoder - .instance[Value]({ + .instance[Value] { case NullValue => Json.Null case v: IntValue => v match { @@ -60,7 +60,7 @@ object json { case StringValue(value) => Json.fromString(value) case BooleanValue(value) => Json.fromBoolean(value) case EnumValue(value) => Json.fromString(value) - }) + } private def jsonToInputValue(json: Json): InputValue = json.fold( NullValue, @@ -75,13 +75,13 @@ object json { ) val inputValueDecoder: Decoder[InputValue] = Decoder.instance(hcursor => Right(jsonToInputValue(hcursor.value))) val inputValueEncoder: Encoder[InputValue] = Encoder - .instance[InputValue]({ + .instance[InputValue] { case value: Value => valueEncoder.apply(value) case InputValue.ListValue(values) => Json.arr(values.map(inputValueEncoder.apply): _*) case InputValue.ObjectValue(fields) => Json.obj(fields.map { case (k, v) => k -> inputValueEncoder.apply(v) }.toList: _*) case InputValue.VariableValue(name) => Json.fromString(name) - }) + } private def jsonToResponseValue(json: Json): ResponseValue = json.fold( NullValue, @@ -105,13 +105,13 @@ object json { val responseValueDecoder: Decoder[ResponseValue] = Decoder.instance(hcursor => Right(jsonToResponseValue(hcursor.value))) val responseValueEncoder: Encoder[ResponseValue] = Encoder - .instance[ResponseValue]({ + .instance[ResponseValue] { case value: Value => valueEncoder.apply(value) case ResponseValue.ListValue(values) => Json.arr(values.map(responseValueEncoder.apply): _*) case ResponseValue.ObjectValue(fields) => Json.obj(fields.map { case (k, v) => k -> responseValueEncoder.apply(v) }: _*) case s: ResponseValue.StreamValue => Json.fromString(s.toString) - }) + } } private[caliban] object ErrorCirce { @@ -121,7 +121,7 @@ object json { private def locationToJson(li: LocationInfo): Json = Json.obj("line" -> li.line.asJson, "column" -> li.column.asJson) - val errorValueEncoder: Encoder[CalibanError] = Encoder.instance[CalibanError] { + val errorValueEncoder: Encoder[CalibanError] = Encoder.instance[CalibanError] { case CalibanError.ParsingError(msg, locationInfo, _, extensions) => Json .obj( diff --git a/core/src/main/scala/caliban/schema/Schema.scala b/core/src/main/scala/caliban/schema/Schema.scala index 1a691c2920..bcdfab71ca 100644 --- a/core/src/main/scala/caliban/schema/Schema.scala +++ b/core/src/main/scala/caliban/schema/Schema.scala @@ -90,8 +90,8 @@ trait Schema[-R, T] { self => * @param inputName new name for the type when it's an input type (by default "Input" is added after the name) */ def rename(name: String, inputName: Option[String] = None): Schema[R, T] = new Schema[R, T] { - override def optional: Boolean = self.optional - override def arguments: List[__InputValue] = self.arguments + override def optional: Boolean = self.optional + override def arguments: List[__InputValue] = self.arguments override def toType(isInput: Boolean, isSubscription: Boolean): __Type = { val newName = if (isInput) inputName.getOrElse(Schema.customizeInputTypeName(name)) else name self.toType_(isInput, isSubscription).copy(name = Some(newName)) @@ -358,7 +358,7 @@ trait GenericSchema[R] extends SchemaDerivation[R] with TemporalSchema { arg1: ArgBuilder[A], ev1: Schema[RA, A], ev2: Schema[RB, B] - ): Schema[RA with RB, A => B] = + ): Schema[RA with RB, A => B] = new Schema[RA with RB, A => B] { private lazy val inputType = ev1.toType_(true) private val unwrappedArgumentName = "value" @@ -410,7 +410,7 @@ trait GenericSchema[R] extends SchemaDerivation[R] with TemporalSchema { } implicit def effectSchema[R0, R1 >: R0, R2 >: R0, E <: Throwable, A](implicit ev: Schema[R2, A] - ): Schema[R0, ZIO[R1, E, A]] = + ): Schema[R0, ZIO[R1, E, A]] = new Schema[R0, ZIO[R1, E, A]] { override def optional: Boolean = true override def toType(isInput: Boolean, isSubscription: Boolean): __Type = ev.toType_(isInput, isSubscription) @@ -418,7 +418,7 @@ trait GenericSchema[R] extends SchemaDerivation[R] with TemporalSchema { } def customErrorEffectSchema[R0, R1 >: R0, R2 >: R0, E, A](convertError: E => ExecutionError)(implicit ev: Schema[R2, A] - ): Schema[R0, ZIO[R1, E, A]] = + ): Schema[R0, ZIO[R1, E, A]] = new Schema[R0, ZIO[R1, E, A]] { override def optional: Boolean = true override def toType(isInput: Boolean, isSubscription: Boolean): __Type = ev.toType_(isInput, isSubscription) @@ -428,7 +428,7 @@ trait GenericSchema[R] extends SchemaDerivation[R] with TemporalSchema { } implicit def infallibleQuerySchema[R0, R1 >: R0, R2 >: R0, A](implicit ev: Schema[R2, A] - ): Schema[R0, ZQuery[R1, Nothing, A]] = + ): Schema[R0, ZQuery[R1, Nothing, A]] = new Schema[R0, ZQuery[R1, Nothing, A]] { override def optional: Boolean = ev.optional override def toType(isInput: Boolean, isSubscription: Boolean): __Type = ev.toType_(isInput, isSubscription) @@ -436,7 +436,7 @@ trait GenericSchema[R] extends SchemaDerivation[R] with TemporalSchema { } implicit def querySchema[R0, R1 >: R0, R2 >: R0, E <: Throwable, A](implicit ev: Schema[R2, A] - ): Schema[R0, ZQuery[R1, E, A]] = + ): Schema[R0, ZQuery[R1, E, A]] = new Schema[R0, ZQuery[R1, E, A]] { override def optional: Boolean = true override def toType(isInput: Boolean, isSubscription: Boolean): __Type = ev.toType_(isInput, isSubscription) @@ -444,7 +444,7 @@ trait GenericSchema[R] extends SchemaDerivation[R] with TemporalSchema { } def customErrorQuerySchema[R0, R1 >: R0, R2 >: R0, E, A](convertError: E => ExecutionError)(implicit ev: Schema[R2, A] - ): Schema[R0, ZQuery[R1, E, A]] = + ): Schema[R0, ZQuery[R1, E, A]] = new Schema[R0, ZQuery[R1, E, A]] { override def optional: Boolean = true override def toType(isInput: Boolean, isSubscription: Boolean): __Type = ev.toType_(isInput, isSubscription) @@ -452,36 +452,36 @@ trait GenericSchema[R] extends SchemaDerivation[R] with TemporalSchema { } implicit def infallibleStreamSchema[R1, R2 >: R1, A](implicit ev: Schema[R2, A] - ): Schema[R1, ZStream[R1, Nothing, A]] = + ): Schema[R1, ZStream[R1, Nothing, A]] = new Schema[R1, ZStream[R1, Nothing, A]] { - override def optional: Boolean = false + override def optional: Boolean = false override def toType(isInput: Boolean, isSubscription: Boolean): __Type = { val t = ev.toType_(isInput, isSubscription) if (isSubscription) t else makeList(if (ev.optional) t else makeNonNull(t)) } - override def resolve(value: ZStream[R1, Nothing, A]): Step[R1] = StreamStep(value.map(ev.resolve)) + override def resolve(value: ZStream[R1, Nothing, A]): Step[R1] = StreamStep(value.map(ev.resolve)) } implicit def streamSchema[R0, R1 >: R0, R2 >: R0, E <: Throwable, A](implicit ev: Schema[R2, A] - ): Schema[R0, ZStream[R1, E, A]] = + ): Schema[R0, ZStream[R1, E, A]] = new Schema[R0, ZStream[R1, E, A]] { - override def optional: Boolean = true + override def optional: Boolean = true override def toType(isInput: Boolean, isSubscription: Boolean): __Type = { val t = ev.toType_(isInput, isSubscription) if (isSubscription) t else makeList(if (ev.optional) t else makeNonNull(t)) } - override def resolve(value: ZStream[R1, E, A]): Step[R0] = StreamStep(value.map(ev.resolve)) + override def resolve(value: ZStream[R1, E, A]): Step[R0] = StreamStep(value.map(ev.resolve)) } def customErrorStreamSchema[R0, R1 >: R0, R2 >: R0, E, A](convertError: E => ExecutionError)(implicit ev: Schema[R2, A] - ): Schema[R0, ZStream[R1, E, A]] = + ): Schema[R0, ZStream[R1, E, A]] = new Schema[R0, ZStream[R1, E, A]] { - override def optional: Boolean = true + override def optional: Boolean = true override def toType(isInput: Boolean, isSubscription: Boolean): __Type = { val t = ev.toType_(isInput, isSubscription) if (isSubscription) t else makeList(if (ev.optional) t else makeNonNull(t)) } - override def resolve(value: ZStream[R1, E, A]): Step[R0] = StreamStep(value.mapBoth(convertError, ev.resolve)) + override def resolve(value: ZStream[R1, E, A]): Step[R0] = StreamStep(value.mapBoth(convertError, ev.resolve)) } } diff --git a/core/src/main/scala/caliban/schema/Step.scala b/core/src/main/scala/caliban/schema/Step.scala index 03c5ac508b..ffdb3c1fff 100644 --- a/core/src/main/scala/caliban/schema/Step.scala +++ b/core/src/main/scala/caliban/schema/Step.scala @@ -30,8 +30,8 @@ object Step { def mergeRootSteps[R](step1: Step[R], step2: Step[R]): Step[R] = (step1, step2) match { case (ObjectStep(name, fields1), ObjectStep(_, fields2)) => ObjectStep(name, fields1 ++ fields2) // fields2 override fields1 in case of conflict - case (ObjectStep(_, _), _) => step1 // if only step1 is an object, keep it - case _ => step2 // otherwise keep step2 + case (ObjectStep(_, _), _) => step1 // if only step1 is an object, keep it + case _ => step2 // otherwise keep step2 } } diff --git a/core/src/main/scala/caliban/validation/FieldMap.scala b/core/src/main/scala/caliban/validation/FieldMap.scala index dabb91767b..c817bb55c5 100644 --- a/core/src/main/scala/caliban/validation/FieldMap.scala +++ b/core/src/main/scala/caliban/validation/FieldMap.scala @@ -38,7 +38,7 @@ object FieldMap { } def apply(context: Context, parentType: __Type, selectionSet: Iterable[Selection]): FieldMap = - selectionSet.foldLeft(FieldMap.empty)({ case (fields, selection) => + selectionSet.foldLeft(FieldMap.empty) { case (fields, selection) => selection match { case FragmentSpread(name, _) => context.fragments @@ -54,5 +54,5 @@ object FieldMap { val typ = getType(typeCondition, parentType, context) apply(context, typ, selectionSet) |+| fields } - }) + } } diff --git a/core/src/main/scala/caliban/validation/FragmentValidator.scala b/core/src/main/scala/caliban/validation/FragmentValidator.scala index e8282efc59..40c142aca2 100644 --- a/core/src/main/scala/caliban/validation/FragmentValidator.scala +++ b/core/src/main/scala/caliban/validation/FragmentValidator.scala @@ -44,12 +44,12 @@ object FragmentValidator { case Some(value) => value case None => val fields = FieldMap(context, parentType, set) - val res = Chunk.fromIterable(fields.flatMap({ case (_, fields) => + val res = Chunk.fromIterable(fields.flatMap { case (_, fields) => groupByCommonParents(fields).flatMap { group => val merged = group.flatMap(_.selection.selectionSet) requireSameNameAndArguments(group) ++ sameForCommonParentsByName(merged) } - })) + }) parentsCache.update(set, res) res } @@ -93,17 +93,16 @@ object FragmentValidator { val concreteGroups = mutable.Map.empty[String, Set[SelectedField]] - fields - .foreach({ - case field @ SelectedField( - __Type(_, Some(name), _, _, _, _, _, _, _, _, _), - _, - _ - ) if isConcrete(field.parentType) => - val value = concreteGroups.get(name).map(_ + field).getOrElse(Set(field)) - concreteGroups.update(name, value) - case _ => () - }) + fields.foreach { + case field @ SelectedField( + __Type(_, Some(name), _, _, _, _, _, _, _, _, _), + _, + _ + ) if isConcrete(field.parentType) => + val value = concreteGroups.get(name).map(_ + field).getOrElse(Set(field)) + concreteGroups.update(name, value) + case _ => () + } val res = if (concreteGroups.size < 1) Chunk(fields) diff --git a/core/src/main/scala/caliban/validation/Utils.scala b/core/src/main/scala/caliban/validation/Utils.scala index c92d794bcc..01b250e7ed 100644 --- a/core/src/main/scala/caliban/validation/Utils.scala +++ b/core/src/main/scala/caliban/validation/Utils.scala @@ -57,7 +57,7 @@ object Utils { def getType(t: NamedType, context: Context): Option[__Type] = context.rootType.types.get(t.name) - def cross[A](a: Iterable[A]): Chunk[(A, A)] = + def cross[A](a: Iterable[A]): Chunk[(A, A)] = Chunk.fromIterable(for (xs <- a; ys <- a) yield (xs, ys)) def cross[A](a: Iterable[A], b: Iterable[A]): Chunk[(A, A)] = diff --git a/core/src/main/scala/caliban/validation/Validator.scala b/core/src/main/scala/caliban/validation/Validator.scala index 259947f56f..3f3f31fc1b 100644 --- a/core/src/main/scala/caliban/validation/Validator.scala +++ b/core/src/main/scala/caliban/validation/Validator.scala @@ -179,19 +179,19 @@ object Validator { } def collectVariableValues(values: List[InputValue]): List[VariableValue] = - values.flatMap({ + values.flatMap { case InputValue.ListValue(values) => collectVariableValues(values) case InputValue.ObjectValue(fields) => collectVariableValues(fields.values.toList) case v: VariableValue => List(v) case _: Value => List() - }) + } val allValues = collectValues(selectionSet) val varValues = collectVariableValues(allValues) varValues.map(_.name).toSet } private def collectSelectionSets(selectionSet: List[Selection]): List[Selection] = { - val sets = List.newBuilder[Selection] + val sets = List.newBuilder[Selection] def loop(selectionSet: List[Selection]): Unit = { sets ++= selectionSet selectionSet.foreach { diff --git a/core/src/main/scala/caliban/validation/ValueValidator.scala b/core/src/main/scala/caliban/validation/ValueValidator.scala index 8515a9a082..025d09511f 100644 --- a/core/src/main/scala/caliban/validation/ValueValidator.scala +++ b/core/src/main/scala/caliban/validation/ValueValidator.scala @@ -58,8 +58,7 @@ object ValueValidator { case ObjectValue(fields) => IO.foreach_(inputType.inputFields.getOrElse(List.empty)) { f => val value = - fields - .collectFirst({ case (name, fieldValue) if name == f.name => fieldValue }) + fields.collectFirst { case (name, fieldValue) if name == f.name => fieldValue } .getOrElse(NullValue) validateType(f.`type`(), value, s"Field ${f.name} in $errorContext") } diff --git a/core/src/main/scala/caliban/wrappers/ApolloCaching.scala b/core/src/main/scala/caliban/wrappers/ApolloCaching.scala index 5a5f7d4e52..f40f736275 100644 --- a/core/src/main/scala/caliban/wrappers/ApolloCaching.scala +++ b/core/src/main/scala/caliban/wrappers/ApolloCaching.scala @@ -22,10 +22,10 @@ object ApolloCaching { object CacheControl { - def apply(scope: ApolloCaching.CacheScope): Directive = + def apply(scope: ApolloCaching.CacheScope): Directive = Directive(directiveName, Map("scope" -> EnumValue(scope.toString))) - def apply(maxAge: Duration): Directive = + def apply(maxAge: Duration): Directive = Directive(directiveName, Map("maxAge" -> IntValue(maxAge.toMillis / 1000))) def apply(maxAge: Duration, scope: ApolloCaching.CacheScope): Directive = diff --git a/core/src/main/scala/caliban/wrappers/Wrappers.scala b/core/src/main/scala/caliban/wrappers/Wrappers.scala index 5abd74041d..7502c2d173 100644 --- a/core/src/main/scala/caliban/wrappers/Wrappers.scala +++ b/core/src/main/scala/caliban/wrappers/Wrappers.scala @@ -42,7 +42,7 @@ object Wrappers { * Returns a wrapper that prints slow queries * @param duration threshold above which queries are considered slow */ - def printSlowQueries(duration: Duration): OverallWrapper[Console with Clock] = + def printSlowQueries(duration: Duration): OverallWrapper[Console with Clock] = onSlowQueries(duration) { case (time, query) => putStrLn(s"Slow query took ${time.render}:\n$query").orDie } /** diff --git a/core/src/test/scala/caliban/TestUtils.scala b/core/src/test/scala/caliban/TestUtils.scala index 378bd93b6f..cb5fca1103 100644 --- a/core/src/test/scala/caliban/TestUtils.scala +++ b/core/src/test/scala/caliban/TestUtils.scala @@ -30,7 +30,7 @@ object TestUtils { case object MARS extends Origin case object BELT extends Origin @GQLDeprecated("Use: EARTH | MARS | BELT") - case object MOON extends Origin + case object MOON extends Origin } sealed trait Role @@ -348,7 +348,7 @@ object TestUtils { sealed trait FieldInterface { val a: String } - object FieldInterface { + object FieldInterface { case class FieldObject(a: String, b: Int) extends FieldInterface } case class TestFieldObject(fieldInterface: FieldObject) @@ -513,7 +513,7 @@ object TestUtils { case class TestWrongFieldArgDirectiveName( field: WrongDirectiveName => UIO[Unit] ) - val resolverWrongFieldArgDirectiveName = RootResolver( + val resolverWrongFieldArgDirectiveName = RootResolver( TestWrongFieldArgDirectiveName(_ => UIO.unit) ) diff --git a/core/src/test/scala/caliban/execution/ExecutionSpec.scala b/core/src/test/scala/caliban/execution/ExecutionSpec.scala index e16bea1454..cbedbf02e7 100644 --- a/core/src/test/scala/caliban/execution/ExecutionSpec.scala +++ b/core/src/test/scala/caliban/execution/ExecutionSpec.scala @@ -674,7 +674,7 @@ object ExecutionSpec extends DefaultRunnableSpec { def id: String def name: String } - object Character { + object Character { case class Human( id: String, name: String, diff --git a/core/src/test/scala/caliban/execution/FieldArgsSpec.scala b/core/src/test/scala/caliban/execution/FieldArgsSpec.scala index df6f6acec0..6fb48b9e54 100644 --- a/core/src/test/scala/caliban/execution/FieldArgsSpec.scala +++ b/core/src/test/scala/caliban/execution/FieldArgsSpec.scala @@ -65,10 +65,9 @@ object FieldArgsSpec extends DefaultRunnableSpec { api = graphQL( RootResolver( Query( - query = info => { - i => - ref.set(Option(info)) *> - ZIO.succeed(i.string) + query = info => { i => + ref.set(Option(info)) *> + ZIO.succeed(i.string) } ) ) diff --git a/core/src/test/scala/caliban/schema/SchemaSpec.scala b/core/src/test/scala/caliban/schema/SchemaSpec.scala index 6ecba5fa67..4f867c7394 100644 --- a/core/src/test/scala/caliban/schema/SchemaSpec.scala +++ b/core/src/test/scala/caliban/schema/SchemaSpec.scala @@ -156,7 +156,7 @@ object SchemaSpec extends DefaultRunnableSpec { @GQLInterface sealed trait MyInterface - object MyInterface { + object MyInterface { case class A(common: Int, different: String) extends MyInterface case class B(common: Int, different: Boolean) extends MyInterface } @@ -171,7 +171,7 @@ object SchemaSpec extends DefaultRunnableSpec { @GQLUnion sealed trait RedirectingUnion - object RedirectingUnion { + object RedirectingUnion { case class B(common: Int) case class A(common: Int) extends RedirectingUnion diff --git a/core/src/test/scala/caliban/wrappers/WrappersSpec.scala b/core/src/test/scala/caliban/wrappers/WrappersSpec.scala index 6e67e3a4bc..0dce529181 100644 --- a/core/src/test/scala/caliban/wrappers/WrappersSpec.scala +++ b/core/src/test/scala/caliban/wrappers/WrappersSpec.scala @@ -268,13 +268,12 @@ object WrappersSpec extends DefaultRunnableSpec { def wrap[R1 <: Any]( f: ExecutionRequest => ZIO[R1, Nothing, GraphQLResponse[CalibanError]] ): ExecutionRequest => ZIO[R1, Nothing, GraphQLResponse[CalibanError]] = - request => { + request => if (request.field.directives.exists(_.name == "customQueryDirective")) { UIO { GraphQLResponse(Value.BooleanValue(true), Nil) } } else f(request) - } } val customQueryDirective = __Directive( "customQueryDirective", diff --git a/interop/monix/src/main/scala/caliban/interop/monix/MonixInterop.scala b/interop/monix/src/main/scala/caliban/interop/monix/MonixInterop.scala index f93b5347c0..e400fd1d99 100644 --- a/interop/monix/src/main/scala/caliban/interop/monix/MonixInterop.scala +++ b/interop/monix/src/main/scala/caliban/interop/monix/MonixInterop.scala @@ -60,12 +60,12 @@ object MonixInterop { queueSize: Int )(implicit ev: Schema[R, A], ev2: ConcurrentEffect[MonixTask]): Schema[R, Observable[A]] = new Schema[R, Observable[A]] { - override def optional: Boolean = true + override def optional: Boolean = true override def toType(isInput: Boolean, isSubscription: Boolean): __Type = { val t = ev.toType_(isInput, isSubscription) if (isSubscription) t else Types.makeList(if (ev.optional) t else Types.makeNonNull(t)) } - override def resolve(value: Observable[A]): Step[R] = + override def resolve(value: Observable[A]): Step[R] = StreamStep( ZStream .fromEffect( diff --git a/interop/tapir/src/test/scala/caliban/interop/tapir/TapirSpec.scala b/interop/tapir/src/test/scala/caliban/interop/tapir/TapirSpec.scala index 8cf2e71f95..85603e387d 100644 --- a/interop/tapir/src/test/scala/caliban/interop/tapir/TapirSpec.scala +++ b/interop/tapir/src/test/scala/caliban/interop/tapir/TapirSpec.scala @@ -26,7 +26,7 @@ object TapirSpec extends DefaultRunnableSpec { override def spec: ZSpec[TestEnvironment, Any] = suite("TapirSpec")( testM("test simple endpoint") { - val api = getBook.toGraphQL[Any]({ case (title, token) => UIO(s"$title+$token") }) + val api = getBook.toGraphQL[Any] { case (title, token) => UIO(s"$title+$token") } val interpreter = api.interpreter val query = gqldoc(""" query test { @@ -38,7 +38,7 @@ object TapirSpec extends DefaultRunnableSpec { ) }, testM("test simple endpoint with ZQuery") { - val api = getBook.toGraphQLQuery({ case (title, token) => ZQuery.succeed(s"$title+$token") }) + val api = getBook.toGraphQLQuery { case (title, token) => ZQuery.succeed(s"$title+$token") } val interpreter = api.interpreter val query = gqldoc(""" query test { @@ -52,7 +52,7 @@ object TapirSpec extends DefaultRunnableSpec { testM("test override operation name") { val api = getBook .name("overRide with IllEgal-ChaRs !@()[]/,>") - .toGraphQLQuery({ case (title, token) => ZQuery.succeed(s"$title+$token") }) + .toGraphQLQuery { case (title, token) => ZQuery.succeed(s"$title+$token") } val interpreter = api.interpreter val query = gqldoc(""" query test { diff --git a/tools/src/main/scala/caliban/tools/ClientWriter.scala b/tools/src/main/scala/caliban/tools/ClientWriter.scala index 4f234f56fe..391fb12b54 100644 --- a/tools/src/main/scala/caliban/tools/ClientWriter.scala +++ b/tools/src/main/scala/caliban/tools/ClientWriter.scala @@ -389,7 +389,7 @@ object ClientWriter { field -> s"${field.rawName}Selection" } - val genericSelectionFieldTypes = + val genericSelectionFieldTypes = genericSelectionFields.map { case (field, name) => (field, name.capitalize) } val genericSelectionFieldsMap = genericSelectionFields.toMap diff --git a/tools/src/main/scala/caliban/tools/Formatter.scala b/tools/src/main/scala/caliban/tools/Formatter.scala index 9524cd76bc..44fecee210 100644 --- a/tools/src/main/scala/caliban/tools/Formatter.scala +++ b/tools/src/main/scala/caliban/tools/Formatter.scala @@ -9,7 +9,7 @@ import java.nio.file.{ Files, Path, Paths } object Formatter { - def format(str: String, fmtPath: Option[String]): RIO[Blocking, String] = + def format(str: String, fmtPath: Option[String]): RIO[Blocking, String] = format(List("Nil.scala" -> str), fmtPath).map(_.head._2) def format(strs: List[(String, String)], fmtPath: Option[String]): RIO[Blocking, List[(String, String)]] = diff --git a/tools/src/main/scala/caliban/tools/RemoteSchema.scala b/tools/src/main/scala/caliban/tools/RemoteSchema.scala index fe0cbe8da4..3962a6bcbf 100644 --- a/tools/src/main/scala/caliban/tools/RemoteSchema.scala +++ b/tools/src/main/scala/caliban/tools/RemoteSchema.scala @@ -44,7 +44,7 @@ object RemoteSchema { description = definition.description, interfaces = toInterfaces(definition.implements, definitions), directives = toDirectives(definition.directives), - fields = (args: __DeprecatedArgs) => { + fields = (args: __DeprecatedArgs) => if (definition.fields.nonEmpty) Some( definition.fields @@ -52,7 +52,6 @@ object RemoteSchema { .filter(filterDeprecated(_, args)) ) else None - } ) private def toField( diff --git a/tools/src/main/scala/caliban/tools/SchemaComparison.scala b/tools/src/main/scala/caliban/tools/SchemaComparison.scala index 61843e2c04..32171b56f2 100644 --- a/tools/src/main/scala/caliban/tools/SchemaComparison.scala +++ b/tools/src/main/scala/caliban/tools/SchemaComparison.scala @@ -276,9 +276,9 @@ object SchemaComparison { val argChanges = compareArguments(left.args.map(a => a.name -> a).toMap, right.args.map(a => a.name -> a).toMap, target) - val locationAdded = + val locationAdded = (right.locations -- left.locations).map(l => DirectiveLocationAdded(l, left.name)).toList - val locationDeleted = + val locationDeleted = (left.locations -- right.locations).map(l => DirectiveLocationDeleted(l, left.name)).toList descriptionChanges ++ argChanges ++ locationAdded ++ locationDeleted diff --git a/tools/src/main/scala/caliban/tools/SchemaComparisonChange.scala b/tools/src/main/scala/caliban/tools/SchemaComparisonChange.scala index dd65fcda5a..75564e2649 100644 --- a/tools/src/main/scala/caliban/tools/SchemaComparisonChange.scala +++ b/tools/src/main/scala/caliban/tools/SchemaComparisonChange.scala @@ -117,7 +117,7 @@ object SchemaComparisonChange { from: InputValue, to: InputValue, target: Target - ) extends SchemaComparisonChange { + ) extends SchemaComparisonChange { override def toString: String = s"Argument '$argName' was changed from '$from' to '$to' on directive '$directiveName' on $target." override def breaking: Boolean = true diff --git a/tools/src/main/scala/caliban/tools/SchemaWriter.scala b/tools/src/main/scala/caliban/tools/SchemaWriter.scala index 3851d78bd6..a40a27a9ea 100644 --- a/tools/src/main/scala/caliban/tools/SchemaWriter.scala +++ b/tools/src/main/scala/caliban/tools/SchemaWriter.scala @@ -116,7 +116,7 @@ object SchemaWriter { } def writeSubscriptionField(field: FieldDefinition, od: ObjectTypeDefinition)(implicit scalarMappings: ScalarMappings - ): String = + ): String = "%s:%s ZStream[Any, Nothing, %s]".format( safeName(field.name), if (field.args.nonEmpty) s" ${argsName(field, od)} =>" else "", diff --git a/tools/src/main/scala/caliban/tools/compiletime/Config.scala b/tools/src/main/scala/caliban/tools/compiletime/Config.scala index dd4ecc7321..91cb0758be 100644 --- a/tools/src/main/scala/caliban/tools/compiletime/Config.scala +++ b/tools/src/main/scala/caliban/tools/compiletime/Config.scala @@ -13,7 +13,7 @@ trait Config { splitFiles: Boolean = false, enableFmt: Boolean = true, extensibleEnums: Boolean = false - ) { + ) { private[caliban] def toCalibanCommonSettings: CalibanCommonSettings = CalibanCommonSettings( clientName = Some(clientName), diff --git a/tools/src/main/scala/caliban/tools/compiletime/Utils.scala b/tools/src/main/scala/caliban/tools/compiletime/Utils.scala index 1c11192ce4..19ab81d946 100644 --- a/tools/src/main/scala/caliban/tools/compiletime/Utils.scala +++ b/tools/src/main/scala/caliban/tools/compiletime/Utils.scala @@ -2,7 +2,7 @@ package caliban.tools.compiletime private[caliban] object Utils { - def packagePath(packageName: String): String = packageName.split('.').mkString(java.io.File.separator) + def packagePath(packageName: String): String = packageName.split('.').mkString(java.io.File.separator) def toPathDir(baseDir: String, packageName: String): String = { val isVersioned = !baseDir.contains("src_managed") if (isVersioned) s"$baseDir/src/main/scala/${packagePath(packageName)}" @@ -13,6 +13,6 @@ private[caliban] object Utils { if (l.isEmpty) "List.empty" else s"List(${l.map(asScalaCode).mkString(",")})" def toScalaCode(l: List[(String, String)]): String = - toScalaCode[(String, String)](l)({ case (a, b) => s"""("$a","$b")""" }) + toScalaCode[(String, String)](l) { case (a, b) => s"""("$a","$b")""" } } diff --git a/tools/src/main/scala/caliban/tools/stitching/RemoteQuery.scala b/tools/src/main/scala/caliban/tools/stitching/RemoteQuery.scala index fb5ce300db..a7e827e953 100644 --- a/tools/src/main/scala/caliban/tools/stitching/RemoteQuery.scala +++ b/tools/src/main/scala/caliban/tools/stitching/RemoteQuery.scala @@ -47,7 +47,7 @@ object RemoteQuery { case StringValue(value) => s""""$value"""" case ListValue(values) => values.map(renderInputValue).mkString("[", ",", "]") case ObjectValue(fields) => - fields.map({ case (k, v) => s"""$k: ${renderInputValue(v)}""" }).mkString("{ ", ", ", " }") + fields.map { case (k, v) => s"""$k: ${renderInputValue(v)}""" }.mkString("{ ", ", ", " }") case NullValue => "null" case VariableValue(name) => s"$$$name" case BigDecimalNumber(value) => s"$value" @@ -68,8 +68,7 @@ object RemoteQuery { private def renderArguments(args: Map[String, InputValue]): String = if (args.isEmpty) "" else - args - .map({ case (k, v) => s"$k: ${renderInputValue(v)}" }) + args.map { case (k, v) => s"$k: ${renderInputValue(v)}" } .mkString("(", ", ", ")") } } diff --git a/tools/src/main/scala/caliban/tools/stitching/RemoteSchemaResolver.scala b/tools/src/main/scala/caliban/tools/stitching/RemoteSchemaResolver.scala index 36589782e9..ea12cce9ac 100644 --- a/tools/src/main/scala/caliban/tools/stitching/RemoteSchemaResolver.scala +++ b/tools/src/main/scala/caliban/tools/stitching/RemoteSchemaResolver.scala @@ -26,27 +26,26 @@ case class RemoteSchemaResolver(schema: __Schema, typeMap: Map[String, __Type]) rootType: Option[__Type], resolver: Option[RemoteResolver[R, ExecutionError, Field, ResponseValue]] ): Option[Operation[R]] = - (rootType zip resolver).headOption - .map({ case (rootType, resolver) => - Operation[R]( - rootType, - Step.ObjectStep( - rootType.name.getOrElse(""), - rootType - .fields(__DeprecatedArgs(Some(true))) - .getOrElse(List()) - .map { field => - field.name -> - Step.MetadataFunctionStep((args: caliban.execution.Field) => - Step.QueryStep( - ZQuery.fromEffect(resolver.run(args)).map(Step.PureStep) - ) + (rootType zip resolver).headOption.map { case (rootType, resolver) => + Operation[R]( + rootType, + Step.ObjectStep( + rootType.name.getOrElse(""), + rootType + .fields(__DeprecatedArgs(Some(true))) + .getOrElse(List()) + .map { field => + field.name -> + Step.MetadataFunctionStep((args: caliban.execution.Field) => + Step.QueryStep( + ZQuery.fromEffect(resolver.run(args)).map(Step.PureStep) ) - } - .toMap - ) + ) + } + .toMap ) - }) + ) + } val builder = RootSchemaBuilder( query = toOperation(Option(schema.queryType), Option(resolver)), diff --git a/tools/src/test/scala/caliban/tools/ClientWriterSpec.scala b/tools/src/test/scala/caliban/tools/ClientWriterSpec.scala index 2c3549ecb0..45eec2abe2 100644 --- a/tools/src/test/scala/caliban/tools/ClientWriterSpec.scala +++ b/tools/src/test/scala/caliban/tools/ClientWriterSpec.scala @@ -2,7 +2,7 @@ package caliban.tools import caliban.parsing.Parser import caliban.tools.implicits.ScalarMappings -import zio.{ RIO, Task } +import zio.RIO import zio.blocking.Blocking import zio.test.Assertion._ import zio.test._ @@ -516,7 +516,7 @@ object Client { * name */ @deprecated("blah", "") - def name: SelectionBuilder[Character, String] = _root_.caliban.client.SelectionBuilder.Field("name", Scalar()) + def name: SelectionBuilder[Character, String] = _root_.caliban.client.SelectionBuilder.Field("name", Scalar()) @deprecated("", "") def nicknames: SelectionBuilder[Character, List[String]] = _root_.caliban.client.SelectionBuilder.Field("nicknames", ListOf(Scalar())) diff --git a/tools/src/test/scala/caliban/tools/ClientWriterViewSpec.scala b/tools/src/test/scala/caliban/tools/ClientWriterViewSpec.scala index b010f98646..34ecb2c596 100644 --- a/tools/src/test/scala/caliban/tools/ClientWriterViewSpec.scala +++ b/tools/src/test/scala/caliban/tools/ClientWriterViewSpec.scala @@ -2,7 +2,7 @@ package caliban.tools import caliban.parsing.Parser import caliban.tools.implicits.ScalarMappings -import zio.{ RIO, Task } +import zio.RIO import zio.blocking.Blocking import zio.test.Assertion._ import zio.test._ @@ -110,7 +110,7 @@ object Client { def age: SelectionBuilder[Character, Int] = _root_.caliban.client.SelectionBuilder.Field("age", Scalar()) def nicknames(arg: Option[Int] = None)(implicit encoder0: ArgEncoder[Option[Int]] - ): SelectionBuilder[Character, List[String]] = _root_.caliban.client.SelectionBuilder + ): SelectionBuilder[Character, List[String]] = _root_.caliban.client.SelectionBuilder .Field("nicknames", ListOf(Scalar()), arguments = List(Argument("arg", arg, "Int")(encoder0))) } @@ -171,7 +171,7 @@ object Client { def age: SelectionBuilder[Character, Int] = _root_.caliban.client.SelectionBuilder.Field("age", Scalar()) def friends[A](filter: Option[String] = None)(innerSelection: SelectionBuilder[Character, A])(implicit encoder0: ArgEncoder[Option[String]] - ): SelectionBuilder[Character, List[A]] = _root_.caliban.client.SelectionBuilder + ): SelectionBuilder[Character, List[A]] = _root_.caliban.client.SelectionBuilder .Field("friends", ListOf(Obj(innerSelection)), arguments = List(Argument("filter", filter, "String")(encoder0))) } @@ -300,11 +300,11 @@ object Client { def edges[A]( innerSelection: SelectionBuilder[ProjectMemberEdge, A] - ): SelectionBuilder[ProjectMemberConnection, Option[List[Option[A]]]] = + ): SelectionBuilder[ProjectMemberConnection, Option[List[Option[A]]]] = _root_.caliban.client.SelectionBuilder.Field("edges", OptionOf(ListOf(OptionOf(Obj(innerSelection))))) def nodes[A]( innerSelection: SelectionBuilder[ProjectMember, A] - ): SelectionBuilder[ProjectMemberConnection, Option[List[Option[A]]]] = + ): SelectionBuilder[ProjectMemberConnection, Option[List[Option[A]]]] = _root_.caliban.client.SelectionBuilder.Field("nodes", OptionOf(ListOf(OptionOf(Obj(innerSelection))))) def pageInfo[A](innerSelection: SelectionBuilder[PageInfo, A]): SelectionBuilder[ProjectMemberConnection, A] = _root_.caliban.client.SelectionBuilder.Field("pageInfo", Obj(innerSelection)) @@ -417,7 +417,7 @@ object Client { def role[A]( onCaptain: SelectionBuilder[Captain, A], onPilot: SelectionBuilder[Pilot, A] - ): SelectionBuilder[Character, Option[A]] = _root_.caliban.client.SelectionBuilder + ): SelectionBuilder[Character, Option[A]] = _root_.caliban.client.SelectionBuilder .Field("role", OptionOf(ChoiceOf(Map("Captain" -> Obj(onCaptain), "Pilot" -> Obj(onPilot))))) } diff --git a/tools/src/test/scala/caliban/tools/SchemaWriterSpec.scala b/tools/src/test/scala/caliban/tools/SchemaWriterSpec.scala index 712ee71479..d3c092b108 100644 --- a/tools/src/test/scala/caliban/tools/SchemaWriterSpec.scala +++ b/tools/src/test/scala/caliban/tools/SchemaWriterSpec.scala @@ -323,7 +323,7 @@ Captain or Pilot or Stewart\"\"\"""" object Types { @GQLDescription($role) - sealed trait Role extends scala.Product with scala.Serializable + sealed trait Role extends scala.Product with scala.Serializable @GQLDescription($role2) sealed trait Role2 extends scala.Product with scala.Serializable @@ -334,7 +334,7 @@ object Types { final case class Captain( @GQLDescription("ship") shipName: String - ) extends Role + ) extends Role with Role2 final case class Pilot(shipName: String) extends Role with Role2