From f7f3028ad5293b648e96ee8176719d9ebc74aa3c Mon Sep 17 00:00:00 2001 From: Yann Simon Date: Thu, 2 Jan 2025 19:30:22 +0100 Subject: [PATCH] fix some scalac warnings --- .../sangria/execution/FutureResolver.scala | 2 +- .../execution/InputDocumentMaterializer.scala | 6 +- .../execution/QueryReducerExecutor.scala | 1 - .../sangria/renderer/QueryRenderer.scala | 82 ++++++++++++++----- .../sangria/renderer/SchemaRenderer.scala | 1 - .../sangria/schema/AstSchemaBuilder.scala | 4 +- .../schema/AstSchemaMaterializer.scala | 10 ++- .../ResolverBasedAstSchemaBuilder.scala | 3 - .../main/scala/sangria/schema/Schema.scala | 19 +++-- .../sangria/schema/SchemaComparator.scala | 2 +- .../test/scala/sangria/util/CatsSupport.scala | 2 - 11 files changed, 86 insertions(+), 46 deletions(-) diff --git a/modules/core/src/main/scala/sangria/execution/FutureResolver.scala b/modules/core/src/main/scala/sangria/execution/FutureResolver.scala index aec059f3..12c5bffb 100644 --- a/modules/core/src/main/scala/sangria/execution/FutureResolver.scala +++ b/modules/core/src/main/scala/sangria/execution/FutureResolver.scala @@ -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 } diff --git a/modules/core/src/main/scala/sangria/execution/InputDocumentMaterializer.scala b/modules/core/src/main/scala/sangria/execution/InputDocumentMaterializer.scala index ab2453ca..e0ba6d30 100644 --- a/modules/core/src/main/scala/sangria/execution/InputDocumentMaterializer.scala +++ b/modules/core/src/main/scala/sangria/execution/InputDocumentMaterializer.scala @@ -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 } diff --git a/modules/core/src/main/scala/sangria/execution/QueryReducerExecutor.scala b/modules/core/src/main/scala/sangria/execution/QueryReducerExecutor.scala index 46767a93..e3d6da1b 100644 --- a/modules/core/src/main/scala/sangria/execution/QueryReducerExecutor.scala +++ b/modules/core/src/main/scala/sangria/execution/QueryReducerExecutor.scala @@ -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: _*)) { diff --git a/modules/core/src/main/scala/sangria/renderer/QueryRenderer.scala b/modules/core/src/main/scala/sangria/renderer/QueryRenderer.scala index 8e7aaabb..f5dae92c 100644 --- a/modules/core/src/main/scala/sangria/renderer/QueryRenderer.scala +++ b/modules/core/src/main/scala/sangria/renderer/QueryRenderer.scala @@ -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,7 +646,12 @@ 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) + "}" @@ -634,9 +659,9 @@ object QueryRenderer { 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) = diff --git a/modules/core/src/main/scala/sangria/renderer/SchemaRenderer.scala b/modules/core/src/main/scala/sangria/renderer/SchemaRenderer.scala index fb827aaf..9f07c9e1 100644 --- a/modules/core/src/main/scala/sangria/renderer/SchemaRenderer.scala +++ b/modules/core/src/main/scala/sangria/renderer/SchemaRenderer.scala @@ -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 = diff --git a/modules/core/src/main/scala/sangria/schema/AstSchemaBuilder.scala b/modules/core/src/main/scala/sangria/schema/AstSchemaBuilder.scala index a91fef51..a65d4ffe 100644 --- a/modules/core/src/main/scala/sangria/schema/AstSchemaBuilder.scala +++ b/modules/core/src/main/scala/sangria/schema/AstSchemaBuilder.scala @@ -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, _], diff --git a/modules/core/src/main/scala/sangria/schema/AstSchemaMaterializer.scala b/modules/core/src/main/scala/sangria/schema/AstSchemaMaterializer.scala index 45db33aa..3b0b8f16 100644 --- a/modules/core/src/main/scala/sangria/schema/AstSchemaMaterializer.scala +++ b/modules/core/src/main/scala/sangria/schema/AstSchemaMaterializer.scala @@ -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( diff --git a/modules/core/src/main/scala/sangria/schema/ResolverBasedAstSchemaBuilder.scala b/modules/core/src/main/scala/sangria/schema/ResolverBasedAstSchemaBuilder.scala index c0549829..774da162 100644 --- a/modules/core/src/main/scala/sangria/schema/ResolverBasedAstSchemaBuilder.scala +++ b/modules/core/src/main/scala/sangria/schema/ResolverBasedAstSchemaBuilder.scala @@ -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 diff --git a/modules/core/src/main/scala/sangria/schema/Schema.scala b/modules/core/src/main/scala/sangria/schema/Schema.scala index 502a414c..e55923d3 100644 --- a/modules/core/src/main/scala/sangria/schema/Schema.scala +++ b/modules/core/src/main/scala/sangria/schema/Schema.scala @@ -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,16 +497,17 @@ 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, _]) @@ -515,11 +515,11 @@ 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[_, _]]] = diff --git a/modules/core/src/main/scala/sangria/schema/SchemaComparator.scala b/modules/core/src/main/scala/sangria/schema/SchemaComparator.scala index 068ace7d..0750edb9 100644 --- a/modules/core/src/main/scala/sangria/schema/SchemaComparator.scala +++ b/modules/core/src/main/scala/sangria/schema/SchemaComparator.scala @@ -138,7 +138,7 @@ object SchemaComparator { ) val descriptionChanges = - findDescriptionChanged(oldSchema, newSchema, SchemaChange.SchemaDescriptionChanged) + findDescriptionChanged(oldSchema, newSchema, SchemaChange.SchemaDescriptionChanged.apply) withSubscription ++ directiveChanges ++ descriptionChanges } diff --git a/modules/core/src/test/scala/sangria/util/CatsSupport.scala b/modules/core/src/test/scala/sangria/util/CatsSupport.scala index 1fdaee32..205f3a78 100644 --- a/modules/core/src/test/scala/sangria/util/CatsSupport.scala +++ b/modules/core/src/test/scala/sangria/util/CatsSupport.scala @@ -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) =>