diff --git a/modules/core/src/main/scala/sangria/execution/FutureResolver.scala b/modules/core/src/main/scala/sangria/execution/FutureResolver.scala index e4b582b9..aec059f3 100644 --- a/modules/core/src/main/scala/sangria/execution/FutureResolver.scala +++ b/modules/core/src/main/scala/sangria/execution/FutureResolver.scala @@ -447,7 +447,7 @@ private[execution] class FutureResolver[Ctx]( val sfield = tpe.getField(schema, origField.name).head val fieldPath = path.add(fields.head, tpe) - def resolveUc(v: Any) = newUc.map(_.ctxFn(v)).getOrElse(uc) + def resolveUc(v: Any) = newUc.fold(uc)(_.ctxFn(v)) def resolveError(e: Throwable) = { try newUc.foreach(_.onError(e)) @@ -875,7 +875,7 @@ private[execution] class FutureResolver[Ctx]( } private def resolveUc(newUc: Option[MappedCtxUpdate[Ctx, Any, Any]], v: Any, userCtx: Ctx) = - newUc.map(_.ctxFn(v)).getOrElse(userCtx) + newUc.fold(userCtx)(_.ctxFn(v)) private def resolveVal(newUc: Option[MappedCtxUpdate[Ctx, Any, Any]], v: Any) = newUc match { case Some(MappedCtxUpdate(_, mapFn, _)) => mapFn(v) diff --git a/modules/core/src/main/scala/sangria/execution/QueryReducerExecutor.scala b/modules/core/src/main/scala/sangria/execution/QueryReducerExecutor.scala index d6d3dc82..46767a93 100644 --- a/modules/core/src/main/scala/sangria/execution/QueryReducerExecutor.scala +++ b/modules/core/src/main/scala/sangria/execution/QueryReducerExecutor.scala @@ -154,12 +154,11 @@ object QueryReducerExecutor { case abst: AbstractType => schema.possibleTypes .get(abst.name) - .map(types => + .fold(initialValues)(types => types.map(loop(path, _, astFields)).transpose.zipWithIndex.map { case (values, idx) => val reducer = reducers(idx) reducer.reduceAlternatives(values.asInstanceOf[Seq[reducer.Acc]]) }) - .getOrElse(initialValues) case s: ScalarType[_] => reducers.map(_.reduceScalar(path, userContext, s)) case ScalarAlias(aliasFor, _, _) => reducers.map(_.reduceScalar(path, userContext, aliasFor)) diff --git a/modules/core/src/main/scala/sangria/introspection/IntrospectionParser.scala b/modules/core/src/main/scala/sangria/introspection/IntrospectionParser.scala index 12cc5ca9..916f8381 100644 --- a/modules/core/src/main/scala/sangria/introspection/IntrospectionParser.scala +++ b/modules/core/src/main/scala/sangria/introspection/IntrospectionParser.scala @@ -159,7 +159,7 @@ object IntrospectionParser { private def parseNamedTypeRef[In: InputUnmarshaller](in: In, path: Vector[String]) = IntrospectionNamedTypeRef( - mapStringFieldOpt(in, "kind", path).map(TypeKind.fromString).getOrElse(TypeKind.Object), + mapStringFieldOpt(in, "kind", path).fold(TypeKind.Object)(TypeKind.fromString), mapStringField(in, "name", path)) private def parseTypeRef[In: InputUnmarshaller]( diff --git a/modules/core/src/main/scala/sangria/renderer/QueryRenderer.scala b/modules/core/src/main/scala/sangria/renderer/QueryRenderer.scala index 9967daed..8e7aaabb 100644 --- a/modules/core/src/main/scala/sangria/renderer/QueryRenderer.scala +++ b/modules/core/src/main/scala/sangria/renderer/QueryRenderer.scala @@ -548,10 +548,8 @@ object QueryRenderer { renderComment(vd, prev, indent, config) + indent.str + "$" + name + ":" + config.separator + renderNode(tpe, config, indent.zero) + - defaultValue - .map(v => - config.separator + "=" + config.separator + renderNode(v, config, indent.zero)) - .getOrElse("") + + defaultValue.fold("")(v => + config.separator + "=" + config.separator + renderNode(v, config, indent.zero)) + renderDirs(dirs, config, indent, frontSep = true) case NotNullType(ofType, _) => @@ -565,7 +563,7 @@ object QueryRenderer { case f @ Field(alias, name, args, dirs, sels, _, _, _) => renderComment(f, prev, indent, config) + - indent.str + alias.map(_ + ":" + config.separator).getOrElse("") + name + + indent.str + alias.fold("")(_ + ":" + config.separator) + name + renderArgs(args, indent, config, withSep = false) + (if (dirs.nonEmpty || sels.nonEmpty) config.separator else "") + renderDirs(dirs, config, indent, withSep = sels.nonEmpty) + diff --git a/modules/core/src/main/scala/sangria/schema/Action.scala b/modules/core/src/main/scala/sangria/schema/Action.scala index 75f851b0..99d90302 100644 --- a/modules/core/src/main/scala/sangria/schema/Action.scala +++ b/modules/core/src/main/scala/sangria/schema/Action.scala @@ -98,7 +98,7 @@ case class PartialFutureValue[Ctx, Val](value: Future[PartialValue[Ctx, Val]]) PartialFutureValue(value.map(_.map(fn) match { case v: PartialValue[Ctx, NewVal] => v case TryValue(Failure(e)) => throw e - case v => throw new IllegalStateException("Unexpected result from `PartialValue.map`: " + v) + case v => throw new IllegalStateException(s"Unexpected result from `PartialValue.map`: $v") })) } diff --git a/modules/core/src/main/scala/sangria/schema/Schema.scala b/modules/core/src/main/scala/sangria/schema/Schema.scala index a203fa9e..502a414c 100644 --- a/modules/core/src/main/scala/sangria/schema/Schema.scala +++ b/modules/core/src/main/scala/sangria/schema/Schema.scala @@ -1487,12 +1487,10 @@ case class Schema[Ctx, Val]( val queryTypesWithAdditions = additionalTypes.foldLeft(queryTypes) { case (acc, tpe) => collectTypes("additional type", 10, tpe, acc) } - val queryAndSubTypes = mutation - .map(collectTypes("a mutation type", 10, _, queryTypesWithAdditions)) - .getOrElse(queryTypesWithAdditions) - val queryAndSubAndMutTypes = subscription - .map(collectTypes("a subscription type", 10, _, queryAndSubTypes)) - .getOrElse(queryAndSubTypes) + val queryAndSubTypes = mutation.fold(queryTypesWithAdditions)( + collectTypes("a mutation type", 10, _, queryTypesWithAdditions)) + val queryAndSubAndMutTypes = subscription.fold(queryAndSubTypes)( + collectTypes("a subscription type", 10, _, queryAndSubTypes)) val queryAndSubAndMutAndDirArgTypes = directives.foldLeft(queryAndSubAndMutTypes) { case (acc, dir) => diff --git a/modules/core/src/main/scala/sangria/validation/Violation.scala b/modules/core/src/main/scala/sangria/validation/Violation.scala index fbf3c0ec..347c4e39 100644 --- a/modules/core/src/main/scala/sangria/validation/Violation.scala +++ b/modules/core/src/main/scala/sangria/validation/Violation.scala @@ -115,7 +115,7 @@ case class VarTypeMismatchViolation( } lazy val simpleErrorMessage = - s"Variable '$$$definitionName' expected value of type '$expectedType' but ${input.map("got: " + _).getOrElse("value is undefined")}. Reason: $violationMessage" + s"Variable '$$$definitionName' expected value of type '$expectedType' but ${input.fold("value is undefined")("got: " + _)}. Reason: $violationMessage" } case class UnknownVariableTypeViolation( @@ -343,9 +343,7 @@ case class MisplacedDirectiveViolation( val code = "misplacedDirective" val args = Map( "directiveName" -> name, - "location" -> correctPlacement - .map(loc => DirectiveLocation.toSpecString(loc._1)) - .getOrElse("here")) + "location" -> correctPlacement.fold("here")(loc => DirectiveLocation.toSpecString(loc._1))) lazy val simpleErrorMessage = s"Directive '$name' may not be used ${correctPlacement.fold("here")("on " + _._2)}." diff --git a/modules/derivation/src/main/scala-2/sangria/macros/derive/DeriveEnumTypeMacro.scala b/modules/derivation/src/main/scala-2/sangria/macros/derive/DeriveEnumTypeMacro.scala index a7130ec8..cb878f0b 100644 --- a/modules/derivation/src/main/scala-2/sangria/macros/derive/DeriveEnumTypeMacro.scala +++ b/modules/derivation/src/main/scala-2/sangria/macros/derive/DeriveEnumTypeMacro.scala @@ -108,7 +108,7 @@ class DeriveEnumTypeMacro(context: blackbox.Context) val upperCase = config.exists(_.isInstanceOf[MacroUppercaseValues]) val transformed = - transformFnOpt.map(fn => q"$fn($nonTransformedName)").getOrElse(nonTransformedName) + transformFnOpt.fold(nonTransformedName)(fn => q"$fn($nonTransformedName)") if (upperCase) q"sangria.util.StringUtil.camelCaseToUnderscore($transformed).toUpperCase" else