Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ data class SchemaConfiguration(

val executor: Executor,
val timeout: Long?,
val introspection: Boolean = true,
val plugins: MutableMap<KClass<*>, Any>
) {
@Suppress("UNCHECKED_CAST")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ class DefaultSchema (
?.let { VariablesJson.Defined(configuration.objectMapper, variables) }
?: VariablesJson.Empty()

if (!configuration.introspection && request.isIntrospection()) {
throw GraphQLError("GraphQL introspection is not allowed")
}

val document = Parser(request).parseDocument()

val executor = options.executor?.let(this@DefaultSchema::getExecutor) ?: defaultRequestExecutor
Expand All @@ -55,6 +59,8 @@ class DefaultSchema (
)
}

private fun String.isIntrospection() = this.contains("__schema") || this.contains("__type")

override fun typeByKClass(kClass: KClass<*>): Type? = model.queryTypes[kClass]

override fun typeByKType(kType: KType): Type? = typeByKClass(kType.jvmErasure)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ open class SchemaConfigurationDSL {
var wrapErrors: Boolean = true
var executor: Executor = Executor.Parallel
var timeout: Long? = null
var introspection: Boolean = true

private val plugins: MutableMap<KClass<*>, Any> = mutableMapOf()

Expand All @@ -42,6 +43,7 @@ open class SchemaConfigurationDSL {
wrapErrors,
executor,
timeout,
introspection,
plugins
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,28 @@ class SchemaBuilderTest {
assertThat(introspection.extract<String>("data/__schema/queryType/fields[0]/args[0]/description"), equalTo(expectedDescription))
}

@Test
fun `introspections query should be disabled`(){
val expectedDescription = "Int Argument"
val expectedDefaultValue = 33
val schema = defaultSchema {

configure {
introspection = false
}

query("data"){
resolver { int: Int -> int }.withArgs {
arg <Int> { name = "int"; defaultValue = expectedDefaultValue; description = expectedDescription }
}
}
}

expect<GraphQLError> {
schema.executeBlocking("{__schema{queryType{fields{name, args{name, description, defaultValue}}}}}")
}
}

@Test
@Suppress("UNUSED_ANONYMOUS_PARAMETER")
fun `arg name must match exactly one of type property`(){
Expand Down