Skip to content

Commit

Permalink
Reformat with scalafmt 3.8.5
Browse files Browse the repository at this point in the history
Executed command: scalafmt --non-interactive
  • Loading branch information
scala-steward committed Jan 19, 2025
1 parent dcef8bd commit d9458f6
Show file tree
Hide file tree
Showing 39 changed files with 2,306 additions and 2,196 deletions.
12 changes: 6 additions & 6 deletions modules/ast/src/main/scala/sangria/ast/QueryAst.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ case class Document(
with WithTrailingComments {

/** Map of operation name to its definition. */
lazy val operations: Map[Option[String], OperationDefinition] = Map(definitions.collect {
case op: OperationDefinition =>
lazy val operations: Map[Option[String], OperationDefinition] = Map(
definitions.collect { case op: OperationDefinition =>
op.name -> op
}: _*)
}: _*)

/** Map of fragment name to its definition. */
lazy val fragments: Map[String, FragmentDefinition] = Map(definitions.collect {
case fragment: FragmentDefinition =>
lazy val fragments: Map[String, FragmentDefinition] = Map(
definitions.collect { case fragment: FragmentDefinition =>
fragment.name -> fragment
}: _*)
}: _*)

lazy val source: Option[String] = sourceMapper.map(_.source)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ private[execution] class FutureResolver[Ctx](
.asInstanceOf[scheme.Result[Ctx, marshaller.Node]]

case es: ExecutionScheme.StreamBasedExecutionScheme[
({ type X[_] })#X @unchecked] @unchecked =>
({ type X [_] })#X @unchecked] @unchecked =>
val (_, res) = resolveSubs(
ExecutionPath.empty,
tpe,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,9 @@ object ValueCollector {
}

case class VariableValue(
fn: (
ResultMarshaller,
ResultMarshaller,
InputType[_]) => Either[Vector[Violation], Trinary[ResultMarshaller#Node]]) {
fn: (ResultMarshaller, ResultMarshaller, InputType[_]) => Either[
Vector[Violation],
Trinary[ResultMarshaller#Node]]) {
private val cache =
Cache.empty[(Int, Int), Either[Vector[Violation], Trinary[ResultMarshaller#Node]]]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,8 @@ package object introspection {
name = "__schema",
fieldType = __Schema,
description = Some("Access the current type schema of this server."),
resolve = _.schema.asInstanceOf[Schema[Any, Any]])
resolve = _.schema.asInstanceOf[Schema[Any, Any]]
)

val TypeMetaField: Field[Unit, Unit] = Field(
name = "__type",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,8 @@ class AstSchemaMaterializer[Ctx] private (
origin = origin,
definition = directive,
arguments =
directive.arguments.flatMap(buildArgument(origin, Left(directive), None, _)) toList,
locations = directive.locations.map(buildDirectiveLocation) toSet,
directive.arguments.flatMap(buildArgument(origin, Left(directive), None, _)).toList,
locations = directive.locations.map(buildDirectiveLocation).toSet,
mat = this
))

Expand Down Expand Up @@ -659,7 +659,7 @@ class AstSchemaMaterializer[Ctx] private (
typeDefinition: Either[ast.TypeDefinition, ObjectLikeType[Ctx, _]],
extensions: Vector[ast.ObjectLikeTypeExtensionDefinition],
field: ast.FieldDefinition): Option[Field[Ctx, Any]] = {
val args = field.arguments.flatMap(buildArgument(origin, typeDefinition, Some(field), _)) toList
val args = field.arguments.flatMap(buildArgument(origin, typeDefinition, Some(field), _)).toList
val fieldType = builder.buildFieldType(origin, typeDefinition, extensions, field, args, this)

builder.buildField(origin, typeDefinition, extensions, field, fieldType, args, this)
Expand Down Expand Up @@ -772,7 +772,7 @@ class AstSchemaMaterializer[Ctx] private (
val extraFields = extensions.flatMap(_.fields)

val fieldsFn = () => {
val ef = extraFields.flatMap(buildInputField(origin, Right(tpe), _, extensions)) toList
val ef = extraFields.flatMap(buildInputField(origin, Right(tpe), _, extensions)).toList
val f = tpe.fields.map(extendInputField(origin, tpe, _))

f ++ ef
Expand Down Expand Up @@ -899,7 +899,7 @@ class AstSchemaMaterializer[Ctx] private (
origin,
extensions,
tpe,
withExtensions.map(getObjectType(origin, _)) toList,
withExtensions.map(getObjectType(origin, _)).toList,
this)
}

Expand All @@ -908,7 +908,7 @@ class AstSchemaMaterializer[Ctx] private (
val extraTypes = extensions.flatMap(_.types)

val t = tpe.types.map(getTypeFromDef(origin, _))
val et = extraTypes.map(getObjectType(origin, _)) toList
val et = extraTypes.map(getObjectType(origin, _)).toList

builder.extendUnionType(origin, extensions, tpe, t ++ et, this)
}
Expand All @@ -935,7 +935,7 @@ class AstSchemaMaterializer[Ctx] private (
origin,
extensions,
tpe,
() => withExtensions.flatMap(buildInputField(origin, Left(tpe), _, extensions)) toList,
() => withExtensions.flatMap(buildInputField(origin, Left(tpe), _, extensions)).toList,
this)
}

Expand All @@ -954,7 +954,7 @@ class AstSchemaMaterializer[Ctx] private (
origin,
extensions,
tpe,
withExtensions.flatMap(buildEnumValue(origin, Left(tpe), _, extensions)) toList,
withExtensions.flatMap(buildEnumValue(origin, Left(tpe), _, extensions)).toList,
this)
}

Expand Down
21 changes: 10 additions & 11 deletions modules/core/src/main/scala/sangria/schema/AstSchemaResolver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -161,17 +161,16 @@ object InstanceCheck {
def field[Ctx, T: InputUnmarshaller](fieldName: String): InstanceCheck[Ctx] = {
val iu = implicitly[InputUnmarshaller[T]]

InstanceCheck(c =>
(value, _) => {
val node = value.asInstanceOf[T]

if (!iu.isMapNode(node)) false
else
iu.getMapValue(node, fieldName) match {
case Some(v) => iu.isScalarNode(v) && iu.getScalaScalarValue(v) == c.definition.name
case None => false
}
})
InstanceCheck { c => (value, _) =>
val node = value.asInstanceOf[T]

if (!iu.isMapNode(node)) false
else
iu.getMapValue(node, fieldName) match {
case Some(v) => iu.isScalarNode(v) && iu.getScalaScalarValue(v) == c.definition.name
case None => false
}
}
}
}

Expand Down
18 changes: 11 additions & 7 deletions modules/core/src/main/scala/sangria/schema/SchemaComparator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,9 @@ object SchemaChange {
oldDefault: Option[ast.Value],
newDefault: Option[ast.Value])
extends AbstractChange(
s"`${tpe.name}.${field.name}` default value changed from ${oldDefault.fold("none")(d => s"`${QueryRenderer.renderCompact(d)}`")} to ${newDefault.fold("none")(d => s"`${QueryRenderer.renderCompact(d)}`")}",
s"`${tpe.name}.${field.name}` default value changed from ${oldDefault.fold("none")(d =>
s"`${QueryRenderer.renderCompact(d)}`")} to ${newDefault.fold("none")(d =>
s"`${QueryRenderer.renderCompact(d)}`")}",
breakingChange = false
)
with TypeChange
Expand All @@ -854,7 +856,8 @@ object SchemaChange {
newDefault: Option[ast.Value])
extends AbstractChange(
s"`${tpe.name}.${field.name}(${argument.name})` default value changed from ${oldDefault
.fold("none")(d => s"`${QueryRenderer.renderCompact(d)}`")} to ${newDefault.fold("none")(d => s"`${QueryRenderer.renderCompact(d)}`")}",
.fold("none")(d => s"`${QueryRenderer.renderCompact(d)}`")} to ${newDefault.fold(
"none")(d => s"`${QueryRenderer.renderCompact(d)}`")}",
breakingChange = false,
dangerousChange = true
)
Expand All @@ -866,7 +869,9 @@ object SchemaChange {
oldDefault: Option[ast.Value],
newDefault: Option[ast.Value])
extends AbstractChange(
s"`${directive.name}(${argument.name})` default value changed from ${oldDefault.fold("none")(d => "`" + QueryRenderer.renderCompact(d) + "`")} to ${newDefault.fold("none")(d => "`" + QueryRenderer.renderCompact(d) + "`")}",
s"`${directive.name}(${argument.name})` default value changed from ${oldDefault.fold(
"none")(d => "`" + QueryRenderer.renderCompact(d) + "`")} to ${newDefault.fold("none")(
d => "`" + QueryRenderer.renderCompact(d) + "`")}",
breakingChange = false,
dangerousChange = true
)
Expand Down Expand Up @@ -1175,15 +1180,14 @@ object SchemaChange {
case class SchemaMutationTypeChanged(
oldType: Option[ObjectType[_, _]],
newType: Option[ObjectType[_, _]])
extends AbstractChange(
s"Schema mutation type changed from ${oldType.fold("none")(t => "`" + t.name + "`")} to ${newType.fold("none")(t => "`" + t.name + "`")} type",
oldType.nonEmpty)
extends AbstractChange(s"Schema mutation type changed from ${oldType.fold("none")(t => "`" + t.name + "`")} to ${newType.fold("none")(t => "`" + t.name + "`")} type", oldType.nonEmpty)

case class SchemaSubscriptionTypeChanged(
oldType: Option[ObjectType[_, _]],
newType: Option[ObjectType[_, _]])
extends AbstractChange(
s"Schema subscription type changed from ${oldType.fold("none")(t => "`" + t.name + "`")} to ${newType.fold("none")(t => "`" + t.name + "`")} type",
s"Schema subscription type changed from ${oldType.fold("none")(t =>
"`" + t.name + "`")} to ${newType.fold("none")(t => "`" + t.name + "`")} type",
oldType.nonEmpty
)

Expand Down
25 changes: 13 additions & 12 deletions modules/core/src/test/scala/sangria/execution/ActionMapSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,19 @@ class ActionMapSpec extends AnyWordSpec with Matchers with FutureResultSupport {
""")

Executor.execute(schema, doc, deferredResolver = new ColorResolver).await should be(
Map("data" -> Map(
"value" -> "light-red",
"doubleMap" -> "light-red-color",
"future" -> "light-green",
"futureDouble" -> Map("name" -> "light-green"),
"futureTriple" -> "super-light-green",
"deferred" -> "[168]345",
"futureDeferred" -> "[79]56",
"futureDeferredDouble" -> "Yay! [79]576 +++",
"futureDeferredTriple" -> "Yay! [79]576 +++",
"ctxUpdate" -> Map("name" -> "(![56]?576)")
)))
Map(
"data" -> Map(
"value" -> "light-red",
"doubleMap" -> "light-red-color",
"future" -> "light-green",
"futureDouble" -> Map("name" -> "light-green"),
"futureTriple" -> "super-light-green",
"deferred" -> "[168]345",
"futureDeferred" -> "[79]56",
"futureDeferredDouble" -> "Yay! [79]576 +++",
"futureDeferredTriple" -> "Yay! [79]576 +++",
"ctxUpdate" -> Map("name" -> "(![56]?576)")
)))
}

"produce partial errors" in {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,8 @@ class ExceptionHandlingSpec
HandledException.multiple(
Vector(
("Error 1", Map("errorCode" -> m.scalarNode("OOPS", "String", Set.empty)), Nil),
("Error 2", Map.empty[String, m.Node], doc.operations.head._2.location.toList)))
("Error 2", Map.empty[String, m.Node], doc.operations.head._2.location.toList)
))
}

Executor.execute(schema, doc, exceptionHandler = exceptionHandler).await should be(
Expand Down
78 changes: 41 additions & 37 deletions modules/core/src/test/scala/sangria/execution/ExecutorSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,9 @@ class ExecutorSpec extends AnyWordSpec with Matchers with FutureResultSupport {
OptionInputType(IntType)) :: Argument[Option[String @@ CoercedScalaResult]](
"stringArg",
OptionInputType(StringType)) :: Nil,
resolve = ctx => { resolvedArgs = ctx.args.raw; None }
resolve = ctx => {
resolvedArgs = ctx.args.raw; None
}
))
))

Expand All @@ -548,29 +550,30 @@ class ExecutorSpec extends AnyWordSpec with Matchers with FutureResultSupport {
}
}

val schema = Schema(
ObjectType(
"Type",
fields[Unit, Data](
Field("sync", OptionType(StringType), resolve = _.value.sync),
Field("syncError", OptionType(StringType), resolve = _.value.syncError),
Field("async", OptionType(StringType), resolve = _.value.async),
Field("asyncReject", OptionType(StringType), resolve = ctx => ctx.value.asyncReject),
Field("asyncError", OptionType(StringType), resolve = _.value.asyncError),
Field(
"syncDeferError",
OptionType(StringType),
resolve = ctx =>
DeferredValue(throw new IllegalStateException("Error getting syncDeferError"))),
Field(
"asyncDeferError",
OptionType(StringType),
resolve = _ =>
DeferredFutureValue(
Future.failed(throw new IllegalStateException("Error getting asyncDeferError")))
val schema =
Schema(
ObjectType(
"Type",
fields[Unit, Data](
Field("sync", OptionType(StringType), resolve = _.value.sync),
Field("syncError", OptionType(StringType), resolve = _.value.syncError),
Field("async", OptionType(StringType), resolve = _.value.async),
Field("asyncReject", OptionType(StringType), resolve = ctx => ctx.value.asyncReject),
Field("asyncError", OptionType(StringType), resolve = _.value.asyncError),
Field(
"syncDeferError",
OptionType(StringType),
resolve = ctx =>
DeferredValue(throw new IllegalStateException("Error getting syncDeferError"))),
Field(
"asyncDeferError",
OptionType(StringType),
resolve = _ =>
DeferredFutureValue(
Future.failed(throw new IllegalStateException("Error getting asyncDeferError")))
)
)
)
))
))

val Success(doc) = QueryParser.parse("""
{
Expand Down Expand Up @@ -1289,20 +1292,21 @@ class ExecutorSpec extends AnyWordSpec with Matchers with FutureResultSupport {
OptionType(ListType(OptionType(IntType))),
resolve = c =>
Action
.sequence(Seq(
LeafAction(Some(1)),
LeafAction(None),
LeafAction(Some(2)),
LeafAction(Success(Some(3))),
LeafAction(Future(Some(4))),
LeafAction(PartialValue(Some(5), Vector(error))),
PartialFutureValue[Unit, Option[Int]](
Future(PartialValue(Some(6), Vector(error)))),
LeafAction(fetcher.deferOpt(7)),
LeafAction(fetcher.deferOpt(8)),
LeafAction(Future(fetcher.deferOpt(9))),
LeafAction(Future(fetcher.deferOpt(10)))
).map(_.map(_.map(_ + 10))))
.sequence(
Seq(
LeafAction(Some(1)),
LeafAction(None),
LeafAction(Some(2)),
LeafAction(Success(Some(3))),
LeafAction(Future(Some(4))),
LeafAction(PartialValue(Some(5), Vector(error))),
PartialFutureValue[Unit, Option[Int]](
Future(PartialValue(Some(6), Vector(error)))),
LeafAction(fetcher.deferOpt(7)),
LeafAction(fetcher.deferOpt(8)),
LeafAction(Future(fetcher.deferOpt(9))),
LeafAction(Future(fetcher.deferOpt(10)))
).map(_.map(_.map(_ + 10))))
.map(vs => vs.map(_.map(_ + 1)))
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ class MiddlewareSpec extends AnyWordSpec with Matchers with FutureResultSupport
"""))
}

"Mutation" should {
"Mutation" should
behave.like(properFieldLevelMiddleware(graphql"""
mutation Foo {
someString
Expand All @@ -598,7 +598,6 @@ class MiddlewareSpec extends AnyWordSpec with Matchers with FutureResultSupport
errorInAfter
}
"""))
}

private[this] def properFieldLevelMiddleware(query: Document): Unit =
"should support before and after at field level " in {
Expand Down
Loading

0 comments on commit d9458f6

Please sign in to comment.