Skip to content

Commit

Permalink
Merge pull request #1067 from asteinwedel/enum-introspection-bug
Browse files Browse the repository at this point in the history
include enums on directive args in schema introspection
  • Loading branch information
yanns authored Oct 17, 2023
2 parents cf69200 + 607fb59 commit 7782dbc
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
10 changes: 9 additions & 1 deletion modules/core/src/main/scala/sangria/schema/Schema.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1494,7 +1494,15 @@ case class Schema[Ctx, Val](
.map(collectTypes("a subscription type", 10, _, queryAndSubTypes))
.getOrElse(queryAndSubTypes)

queryAndSubAndMutTypes
val queryAndSubAndMutAndDirArgTypes = directives.foldLeft(queryAndSubAndMutTypes) {
case (acc, dir) =>
val argumentTypes = dir.arguments.map(_.argumentType)
argumentTypes.foldLeft(acc) { case (acc, arg) =>
collectTypes("an argument type", 10, arg, acc)
}
}

queryAndSubAndMutAndDirArgTypes
}

lazy val typeList: Vector[Type with Named] =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package sangria.introspection

import sangria.execution.Executor
import sangria.macros._
import sangria.parser.QueryParser
import sangria.schema._
import sangria.util.FutureResultSupport
Expand Down Expand Up @@ -1257,6 +1258,56 @@ class IntrospectionSpec extends AnyWordSpec with Matchers with FutureResultSuppo
"Null value was provided for the NotNull Type 'String!' at path 'name'.")
}

"exposes enum types from AST based schema" in {
val ast = gql"""
enum SomeEnum {
FOO
BAR
}

directive @customDirective(something: SomeEnum!) on FIELD

type Query {
foo: String
}
"""

val builder = AstSchemaBuilder.default[Any]
val schema = Schema.buildFromAst(ast, builder)

val Success(query) = QueryParser.parse("""{
__schema {
types {
kind
name
enumValues {
name
}
}
}
} """)

val introspection = Executor.execute(schema, query).await

val types =
introspection
.asInstanceOf[Map[String, Any]]("data")
.asInstanceOf[Map[String, Any]]("__schema")
.asInstanceOf[Map[String, Any]]("types")
.asInstanceOf[Vector[Map[String, Any]]]

types should contain(
Map(
"kind" -> "ENUM",
"name" -> "SomeEnum",
"enumValues" -> Vector(
Map("name" -> "FOO"),
Map("name" -> "BAR")
)
)
)
}

"exposes descriptions on types and fields" in {
val schema =
Schema(ObjectType("QueryRoot", fields[Unit, Unit](Field("foo", IntType, resolve = _ => 1))))
Expand Down

0 comments on commit 7782dbc

Please sign in to comment.