Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

include enums on directive args in schema introspection #1067

Merged
merged 1 commit into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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