Skip to content

Commit

Permalink
Merge pull request #757 from sangria-graphql/remove_useLegacyCommentD…
Browse files Browse the repository at this point in the history
…escriptions

remove deprecated useLegacyCommentDescriptions
  • Loading branch information
yanns authored Oct 24, 2021
2 parents be47416 + 3de699e commit cd97f13
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 74 deletions.
5 changes: 5 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ ThisBuild / mimaBinaryIssueFilters ++= Seq(
ProblemFilters.exclude[MissingClassProblem]("sangria.validation.rules.Conflict$"),
ProblemFilters.exclude[MissingClassProblem]("sangria.validation.rules.PairSet"),
ProblemFilters.exclude[Problem]("sangria.validation.rules.experimental.*"),
ProblemFilters.exclude[DirectMissingMethodProblem]("sangria.schema.AstSchemaBuilder.defaultWithLegacyCommentDescriptions"),
ProblemFilters.exclude[DirectMissingMethodProblem]("sangria.schema.DefaultAstSchemaBuilder.useLegacyCommentDescriptions"),
ProblemFilters.exclude[MissingClassProblem]("sangria.schema.LegacyCommentDescriptionsResolver"),
ProblemFilters.exclude[MissingClassProblem]("sangria.schema.LegacyCommentDescriptionsResolver$"),
ProblemFilters.exclude[DirectMissingMethodProblem]("sangria.schema.ResolverBasedAstSchemaBuilder.useLegacyCommentDescriptions")
)

lazy val root = project
Expand Down
26 changes: 6 additions & 20 deletions modules/core/src/main/scala/sangria/schema/AstSchemaBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,6 @@ object AstSchemaBuilder {
def resolverBased[Ctx](resolvers: AstSchemaResolver[Ctx]*) =
new ResolverBasedAstSchemaBuilder[Ctx](resolvers)

@deprecated("Please migrate to new string-based description format", "1.3.3")
def defaultWithLegacyCommentDescriptions[Ctx] = new DefaultAstSchemaBuilder[Ctx] {
override def useLegacyCommentDescriptions = true
}

object TypeName {
def unapply(definition: ast.TypeDefinition): Option[String] =
Some(definition.name)
Expand Down Expand Up @@ -851,35 +846,26 @@ class DefaultAstSchemaBuilder[Ctx] extends AstSchemaBuilder[Ctx] {
def directiveName(definition: ast.DirectiveDefinition): String =
definition.name

@deprecated("Please migrate to new string-based description format", "1.3.3")
def useLegacyCommentDescriptions: Boolean = false

def commentDescription(node: ast.WithComments): Option[String] =
AstSchemaBuilder.extractDescription(node)

def typeDescription(definition: ast.TypeDefinition): Option[String] =
if (useLegacyCommentDescriptions) commentDescription(definition)
else definition.description.map(_.value)
definition.description.map(_.value)

def fieldDescription(definition: ast.FieldDefinition): Option[String] =
if (useLegacyCommentDescriptions) commentDescription(definition)
else definition.description.map(_.value)
definition.description.map(_.value)

def argumentDescription(definition: ast.InputValueDefinition): Option[String] =
if (useLegacyCommentDescriptions) commentDescription(definition)
else definition.description.map(_.value)
definition.description.map(_.value)

def inputFieldDescription(definition: ast.InputValueDefinition): Option[String] =
if (useLegacyCommentDescriptions) commentDescription(definition)
else definition.description.map(_.value)
definition.description.map(_.value)

def enumValueDescription(definition: ast.EnumValueDefinition): Option[String] =
if (useLegacyCommentDescriptions) commentDescription(definition)
else definition.description.map(_.value)
definition.description.map(_.value)

def directiveDescription(definition: ast.DirectiveDefinition): Option[String] =
if (useLegacyCommentDescriptions) commentDescription(definition)
else definition.description.map(_.value)
definition.description.map(_.value)

def enumValue(
typeDefinition: Either[ast.EnumTypeDefinition, EnumType[_]],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,6 @@ object AdditionalTypes {
case class AdditionalDirectives[Ctx](additionalDirectives: Seq[Directive])
extends AstSchemaResolver[Ctx]

@deprecated("Please migrate to new string-based description format", "1.4.0")
class LegacyCommentDescriptionsResolver[Ctx] extends AstSchemaResolver[Ctx]

object LegacyCommentDescriptionsResolver {
@deprecated("Please migrate to new string-based description format", "1.4.0")
def apply[Ctx]() = new LegacyCommentDescriptionsResolver[Ctx]
}

case class DirectiveResolver[Ctx](
directive: Directive,
resolve: AstDirectiveContext[Ctx] => Action[Ctx, Any],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ class ResolverBasedAstSchemaBuilder[Ctx](val resolvers: Seq[AstSchemaResolver[Ct
protected lazy val validationSchema =
Schema(stubQueryType, directives = directives.toList ++ BuiltinDirectives)

override def useLegacyCommentDescriptions: Boolean =
resolvers.exists(_.isInstanceOf[LegacyCommentDescriptionsResolver[Ctx]])

override lazy val additionalTypes: List[MaterializedType] = resolvers.flatMap {
case AdditionalTypes(at) => at
case _ => Nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1121,48 +1121,6 @@ class AstSchemaMaterializerSpec
query.fields(1).description should be(Some("the second field!"))
}

"Support legacy comment-based SDL descriptions" in {
val schemaDef =
"""# fooo bar
|# baz
|enum MyEnum {
| # value1
| VALUE
|
| # value 2
| # line 2
| OLD_VALUE @deprecated
|
| # value 3
| OTHER_VALUE @deprecated(reason: "Terrible reasons")
|}
|
|# My super query!
|type Query {
| field1: String @deprecated
|
| # the second field!
| field2: Int @deprecated(reason: "Because I said so")
| enum: MyEnum
|}""".stripMargin

val schema = Schema.buildFromAst(
QueryParser.parse(schemaDef),
AstSchemaBuilder.defaultWithLegacyCommentDescriptions)

val myEnum = schema.inputTypes("MyEnum").asInstanceOf[EnumType[_]]

myEnum.description should be(Some("fooo bar\nbaz"))
myEnum.values(0).description should be(Some("value1"))
myEnum.values(1).description should be(Some("value 2\nline 2"))
myEnum.values(2).description should be(Some("value 3"))

val query = schema.outputTypes("Query").asInstanceOf[ObjectType[_, _]]

query.description should be(Some("My super query!"))
query.fields(1).description should be(Some("the second field!"))
}

"Use comments for descriptions on arguments" in {
val schemaDef =
s"""schema {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ class ResolverBasedAstSchemaBuilderSpec extends AnyWordSpec with Matchers with F
FieldResolver { case (TypeName("Query"), FieldName("id")) =>
_ => UUID.fromString("a26bdfd4-0fcf-484f-b363-585091b3319f")
},
LegacyCommentDescriptionsResolver(),
AnyFieldResolver.defaultInput[Any, JsValue]
)

Expand Down

0 comments on commit cd97f13

Please sign in to comment.