Skip to content

Commit

Permalink
fix some scalac warnings
Browse files Browse the repository at this point in the history
yanns committed Jan 2, 2025
1 parent 1e3842d commit f0d439c
Showing 11 changed files with 86 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -226,7 +226,7 @@ private[execution] class FutureResolver[Ctx](
private def marshallExtensions: Option[marshaller.Node] = {
val extensions =
middleware.flatMap {
case (v, m: MiddlewareExtension[Ctx]) =>
case (v, m: MiddlewareExtension[Ctx @unchecked]) =>
m.afterQueryExtensions(v.asInstanceOf[m.QueryVal], middlewareCtx)
case _ => Nil
}
Original file line number Diff line number Diff line change
@@ -85,13 +85,13 @@ case class InputDocumentMaterializer[Vars](
typeInfo.withInputType(inputType)

AstVisitor {
case v: ast.VariableValue if typeInfo.inputType.isDefined =>
case v2: ast.VariableValue if typeInfo.inputType.isDefined =>
val parentType = typeInfo.inputType.get
val parentTypeAst = SchemaRenderer.renderTypeNameAst(parentType)

state.get(v.name) match {
state.get(v2.name) match {
case None =>
state(v.name) = ast.VariableDefinition(v.name, parentTypeAst, None)
state(v2.name) = ast.VariableDefinition(v2.name, parentTypeAst, None)
VisitorCommand.Continue
case _ => VisitorCommand.Continue
}
Original file line number Diff line number Diff line change
@@ -163,7 +163,6 @@ object QueryReducerExecutor {
case ScalarAlias(aliasFor, _, _) =>
reducers.map(_.reduceScalar(path, userContext, aliasFor))
case e: EnumType[_] => reducers.map(_.reduceEnum(path, userContext, e))
case _ => initialValues
}

val reduced = fields.fields.foldLeft(Array(initialValues: _*)) {
82 changes: 63 additions & 19 deletions modules/core/src/main/scala/sangria/renderer/QueryRenderer.scala
Original file line number Diff line number Diff line change
@@ -506,13 +506,13 @@ object QueryRenderer {
node match {
case d @ Document(defs, _, _, _) =>
defs.iterator
.map(renderNode(_, config, indent))
.map(renderNode(_, config, indent, prefix = None, prev = None))
.mkString(config.definitionSeparator) +
renderTrailingComment(d, None, indent, config)

case d @ InputDocument(defs, _, _, _) =>
defs.iterator
.map(renderNode(_, config, indent))
.map(renderNode(_, config, indent, prefix = None, prev = None))
.mkString(config.definitionSeparator) +
renderTrailingComment(d, None, indent, config)

@@ -547,16 +547,21 @@ object QueryRenderer {
case vd @ VariableDefinition(name, tpe, defaultValue, dirs, _, _) =>
renderComment(vd, prev, indent, config) +
indent.str + "$" + name + ":" + config.separator +
renderNode(tpe, config, indent.zero) +
renderNode(tpe, config, indent.zero, prefix = None, prev = None) +
defaultValue.fold("")(v =>
config.separator + "=" + config.separator + renderNode(v, config, indent.zero)) +
config.separator + "=" + config.separator + renderNode(
v,
config,
indent.zero,
prefix = None,
prev = None)) +
renderDirs(dirs, config, indent, frontSep = true)

case NotNullType(ofType, _) =>
renderNode(ofType, config, indent.zero) + "!"
renderNode(ofType, config, indent.zero, prefix = None, prev = None) + "!"

case ListType(ofType, _) =>
"[" + renderNode(ofType, config, indent.zero) + "]"
"[" + renderNode(ofType, config, indent.zero, prefix = None, prev = None) + "]"

case NamedType(name, _) =>
name
@@ -589,7 +594,12 @@ object QueryRenderer {

case a @ Argument(name, value, _, _) =>
renderComment(a, prev, indent, config) +
indent.str + name + ":" + config.separator + renderNode(value, config, indent.zero)
indent.str + name + ":" + config.separator + renderNode(
value,
config,
indent.zero,
prefix = None,
prev = None)

case v @ IntValue(value, _, _) => renderInputComment(v, indent, config) + value
case v @ BigIntValue(value, _, _) => renderInputComment(v, indent, config) + value
@@ -611,9 +621,19 @@ object QueryRenderer {
if (config.formatInputValues && shouldRenderComment(v, None, config))
(if (idx != 0) config.lineBreak else "") +
config.lineBreak +
renderNode(v, config, indent + (if (addIdent(v)) 1 else 0))
renderNode(
v,
config,
indent + (if (addIdent(v)) 1 else 0),
prefix = None,
prev = None)
else
(if (idx != 0) config.separator else "") + renderNode(v, config, indent)
(if (idx != 0) config.separator else "") + renderNode(
v,
config,
indent,
prefix = None,
prev = None)

renderInputComment(v, indent, config) +
"[" + value.iterator.zipWithIndex
@@ -626,17 +646,22 @@ object QueryRenderer {
.map { case (v, idx) =>
(if (idx != 0 && config.formatInputValues && shouldRenderComment(v, None, config))
config.lineBreak
else "") + renderNode(v, config, inputFieldIndent(config, indent))
else "") + renderNode(
v,
config,
inputFieldIndent(config, indent),
prefix = None,
prev = None)
}
.mkString(config.inputFieldSeparator) +
inputLineBreak(config) + inputIndent(config, indent) + "}"
case VariableValue(name, _, _) => indent.str + "$" + name
case v @ ObjectField(name, value, _, _) =>
val rendered =
if (config.formatInputValues && shouldRenderComment(value, None, config))
config.lineBreak + renderNode(value, config, indent.inc)
config.lineBreak + renderNode(value, config, indent.inc, prefix = None, prev = None)
else
config.separator + renderNode(value, config, indent)
config.separator + renderNode(value, config, indent, prefix = None, prev = None)

(if (config.formatInputValues) renderComment(v, prev, indent, config) else "") +
indent.str + name + ":" + rendered
@@ -681,7 +706,7 @@ object QueryRenderer {
if (types.nonEmpty)
config.separator + "=" + config.separator +
types.iterator
.map(renderNode(_, config, indent.zero))
.map(renderNode(_, config, indent.zero, prefix = None, prev = None))
.mkString(config.separator + "|" + config.separator)
else
""
@@ -709,15 +734,30 @@ object QueryRenderer {
renderComment(fd, description.orElse(prev), indent, config) +
indent.str + name +
renderInputValueDefs(args, indent, config, withSep = false) +
":" + config.separator + renderNode(fieldType, config, indent.zero) +
":" + config.separator + renderNode(
fieldType,
config,
indent.zero,
prefix = None,
prev = None) +
renderDirs(dirs, config, indent, frontSep = true)

case ivd @ InputValueDefinition(name, valueType, default, dirs, description, _, _) =>
renderDescription(ivd, prev, indent, config) +
renderComment(ivd, description.orElse(prev), indent, config) +
indent.str + name + ":" + config.separator + renderNode(valueType, config, indent.zero) +
indent.str + name + ":" + config.separator + renderNode(
valueType,
config,
indent.zero,
prefix = None,
prev = None) +
default.fold("")(d =>
config.separator + "=" + config.separator + renderNode(d, config, indent.zero)) +
config.separator + "=" + config.separator + renderNode(
d,
config,
indent.zero,
prefix = None,
prev = None)) +
renderDirs(dirs, config, indent, frontSep = true)

case ted @ ObjectTypeExtensionDefinition(name, interfaces, fields, dirs, _, _, _) =>
@@ -744,7 +784,7 @@ object QueryRenderer {
if (types.nonEmpty)
config.separator + "=" + config.separator +
types.iterator
.map(renderNode(_, config, indent.zero))
.map(renderNode(_, config, indent.zero, prefix = None, prev = None))
.mkString(config.separator + "|" + config.separator)
else
""
@@ -787,7 +827,9 @@ object QueryRenderer {
renderNode(
l,
config,
if (shouldRenderComment(l, None, config)) indent.inc else indent.zero)
if (shouldRenderComment(l, None, config)) indent.inc else indent.zero,
prefix = None,
prev = None)
}

renderDescription(dd, prev, indent, config) +
@@ -815,7 +857,9 @@ object QueryRenderer {
indent.str + renderOpType(op) + ":" + config.separator + renderNode(
tpe,
config,
indent.zero)
indent.zero,
prefix = None,
prev = None)
}

private def trailingLineBreak(tc: WithTrailingComments, config: QueryRendererConfig) =
Original file line number Diff line number Diff line change
@@ -314,7 +314,6 @@ object SchemaRenderer {
case io: IntrospectionInputObjectType => renderInputObject(io)
case s: IntrospectionScalarType => renderScalar(s)
case e: IntrospectionEnumType => renderEnum(e)
case kind => throw new IllegalArgumentException(s"Unsupported kind: $kind")
}

def renderType(tpe: Type with Named): ast.TypeDefinition =
Original file line number Diff line number Diff line change
@@ -73,7 +73,7 @@ trait AstSchemaBuilder[Ctx] {
interfaces: List[InterfaceType[Ctx, Any]],
mat: AstSchemaMaterializer[Ctx]): Option[InterfaceType[Ctx, Any]]

@deprecated
@deprecated(message = "Use buildInterfaceType with interfaces parameter", since = "4.0")
def buildInterfaceType(
origin: MatOrigin,
definition: ast.InterfaceTypeDefinition,
@@ -89,7 +89,7 @@ trait AstSchemaBuilder[Ctx] {
interfaces: List[InterfaceType[Ctx, Any]],
mat: AstSchemaMaterializer[Ctx]): InterfaceType[Ctx, Any]

@deprecated
@deprecated(message = "Use extendInterfaceType with interfaces parameter", since = "4.0")
def extendInterfaceType(
origin: MatOrigin,
existing: InterfaceType[Ctx, _],
Original file line number Diff line number Diff line change
@@ -113,7 +113,9 @@ class AstSchemaMaterializer[Ctx] private (
unionTypeExtensionDefs.isEmpty)
schema
else {
existingDefsMat = schema.allTypes.mapValues(MaterializedType(existingOrigin, _)).toMap
existingDefsMat = schema.allTypes.iterator.map { case (k, v) =>
(k, MaterializedType(existingOrigin, v))
}.toMap

val queryType = getTypeFromDef(existingOrigin, schema.query)

@@ -647,9 +649,9 @@ class AstSchemaMaterializer[Ctx] private (
extendScalarAlias(origin, tpe.asInstanceOf[ScalarAlias[Any, Any]])
case tpe: EnumType[_] => extendEnumType(origin, tpe)
case tpe: InputObjectType[_] => extendInputObjectType(origin, tpe)
case tpe: UnionType[Ctx] => extendUnionType(origin, tpe)
case tpe: ObjectType[Ctx, _] => extendObjectType(origin, tpe)
case tpe: InterfaceType[Ctx, _] => extendInterfaceType(origin, tpe)
case tpe: UnionType[Ctx @unchecked] => extendUnionType(origin, tpe)
case tpe: ObjectType[Ctx @unchecked, _] => extendObjectType(origin, tpe)
case tpe: InterfaceType[Ctx @unchecked, _] => extendInterfaceType(origin, tpe)
}

def buildField(
Original file line number Diff line number Diff line change
@@ -609,9 +609,6 @@ object ResolverBasedAstSchemaBuilder {

if (iu.isMapNode(objValue)) objValue
else invalidType("Object", objValue)
case t =>
throw SchemaMaterializationException(
s"Extractor for a type '${SchemaRenderer.renderTypeName(t)}' is not supported yet.")
}

def extractFieldValue[Ctx, In](context: Context[Ctx, _])(implicit
19 changes: 10 additions & 9 deletions modules/core/src/main/scala/sangria/schema/Schema.scala
Original file line number Diff line number Diff line change
@@ -29,7 +29,6 @@ sealed trait Type {
case ListInputType(ofType) => getNamedType(ofType)
case ListType(ofType) => getNamedType(ofType)
case n: Named => n
case t => throw new IllegalStateException("Expected named type, but got: " + t)
}

getNamedType(this)
@@ -360,7 +359,7 @@ object ObjectType {
description: Option[String],
interfaces: List[InterfaceType[Ctx, _]],
fieldsFn: () => List[Field[Ctx, Val]]) =
ObjectType(
new ObjectType(
name,
description,
fieldsFn,
@@ -498,28 +497,29 @@ case class PossibleInterface[Ctx, Concrete](interfaceType: InterfaceType[Ctx, _]
object PossibleInterface extends PossibleInterfaceLowPrioImplicits {
def apply[Ctx, Abstract, Concrete](interface: InterfaceType[Ctx, Abstract])(implicit
ev: PossibleType[Abstract, Concrete]): PossibleInterface[Ctx, Concrete] =
PossibleInterface[Ctx, Concrete](interface)
new PossibleInterface[Ctx, Concrete](interface)

implicit def convert[Ctx, Abstract, Concrete](interface: InterfaceType[Ctx, Abstract])(implicit
ev: PossibleType[Abstract, Concrete]): PossibleInterface[Ctx, Concrete] =
PossibleInterface[Ctx, Concrete](interface)
new PossibleInterface[Ctx, Concrete](interface)
}

trait PossibleInterfaceLowPrioImplicits {
implicit def applyUnit[Ctx, Abstract, Concrete](interface: InterfaceType[Ctx, Abstract])(implicit
ev: PossibleType[Abstract, Concrete]): PossibleInterface[Unit, Concrete] =
PossibleInterface[Unit, Concrete](interface.asInstanceOf[InterfaceType[Unit, Abstract]])
new PossibleInterface[Unit, Concrete](interface.asInstanceOf[InterfaceType[Unit, Abstract]])
}

case class PossibleObject[Ctx, Abstract](objectType: ObjectType[Ctx, _])

object PossibleObject {
implicit def apply[Ctx, Abstract, Concrete](obj: ObjectType[Ctx, Concrete])(implicit
ev: PossibleType[Abstract, Concrete]): PossibleObject[Ctx, Abstract] =
PossibleObject[Ctx, Abstract](obj)
new PossibleObject[Ctx, Abstract](obj)

implicit def applyUnit[Ctx, Abstract, Concrete](obj: ObjectType[Unit, Concrete])(implicit
ev: PossibleType[Abstract, Concrete]): PossibleObject[Ctx, Abstract] =
PossibleObject[Ctx, Abstract](obj.asInstanceOf[ObjectType[Ctx, Concrete]])
new PossibleObject[Ctx, Abstract](obj.asInstanceOf[ObjectType[Ctx, Concrete]])
}

trait PossibleType[AbstrType, ConcreteType]
@@ -1547,8 +1547,9 @@ case class Schema[Ctx, Val](
def getOutputType(tpe: ast.Type, topLevel: Boolean = false): Option[OutputType[_]] = tpe match {
case ast.NamedType(name, _) =>
outputTypes.get(name).map(ot => if (topLevel) ot else OptionType(ot))
case ast.NotNullType(ofType, _) => getOutputType(ofType).collect { case OptionType(ot) => ot }
case ast.ListType(ofType, _) => getOutputType(ofType).map(ListType(_))
case ast.NotNullType(ofType, _) =>
getOutputType(ofType, topLevel = false).collect { case OptionType(ot) => ot }
case ast.ListType(ofType, _) => getOutputType(ofType, topLevel = false).map(ListType(_))
}

lazy val directImplementations: Map[String, Vector[ObjectLikeType[_, _]]] =
Original file line number Diff line number Diff line change
@@ -138,7 +138,7 @@ object SchemaComparator {
)

val descriptionChanges =
findDescriptionChanged(oldSchema, newSchema, SchemaChange.SchemaDescriptionChanged)
findDescriptionChanged(oldSchema, newSchema, SchemaChange.SchemaDescriptionChanged.apply)

withSubscription ++ directiveChanges ++ descriptionChanges
}
2 changes: 0 additions & 2 deletions modules/core/src/test/scala/sangria/util/CatsSupport.scala
Original file line number Diff line number Diff line change
@@ -240,8 +240,6 @@ object CatsScenarioExecutor extends FutureResultSupport {
operationName = op,
exceptionHandler = exceptionHandler)
.await))
case a =>
throw new IllegalStateException(s"Not yet supported action: $a")
}

val exceptionHandler = ExceptionHandler { case (_, e: ResolveException) =>

0 comments on commit f0d439c

Please sign in to comment.