-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGraphQlConfig.kt
34 lines (30 loc) · 1.28 KB
/
GraphQlConfig.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package com.example.graphqldemo.config
import com.example.graphqldemo.failure.FailureException
import org.springframework.boot.autoconfigure.graphql.GraphQlSourceBuilderCustomizer
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.graphql.execution.GraphQlSource.SchemaResourceBuilder
import org.springframework.graphql.execution.SchemaReport
@Configuration
class GraphQlConfig {
@Bean
fun sourceBuilderCustomizer(): GraphQlSourceBuilderCustomizer {
return GraphQlSourceBuilderCustomizer { builder: SchemaResourceBuilder ->
builder.inspectSchemaMappings { schemaReport ->
if(schemaReport.unmappedFields().size > 0 || schemaReport.unmappedRegistrations().isNotEmpty()) {
throw GraphQlSchemaFailureException(schemaReport)
}
}
}
}
class GraphQlSchemaFailureException(
private val schemaReport: SchemaReport
): FailureException() {
override fun getDescription(): String {
return "Invalid schema mappings. SchemaReport:\n\n$schemaReport\n"
}
override fun getAction(): String {
return "See description for details of invalid schema mappings."
}
}
}