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 @@ -196,10 +196,10 @@ class DgsSchemaProvider(
val javaClass = AopUtils.getTargetClass(dgsComponent)

javaClass.methods.asSequence()
.filter { method -> MergedAnnotations.from(method).isPresent(DgsData::class.java) }
.filter { method -> MergedAnnotations.from(method, MergedAnnotations.SearchStrategy.TYPE_HIERARCHY).isPresent(DgsData::class.java) }
.forEach { method ->

val dgsDataAnnotation = MergedAnnotations.from(method).get(DgsData::class.java)
val dgsDataAnnotation = MergedAnnotations.from(method, MergedAnnotations.SearchStrategy.TYPE_HIERARCHY).get(DgsData::class.java)
val field = dgsDataAnnotation.getString("field").ifEmpty { method.name }
val parentType = dgsDataAnnotation.getString("parentType")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ internal class DgsSchemaProviderTest {
}
}

private interface DefaultHelloFetcherInterface {
@DgsData(parentType = "Query", field = "hello")
fun someFetcher(): String
}

private val interfaceHelloFetcher = object : DefaultHelloFetcherInterface {
override fun someFetcher(): String =
"Hello"
}

@Test
fun findSchemaFiles() {
val findSchemaFiles = DgsSchemaProvider(
Expand Down Expand Up @@ -350,6 +360,22 @@ internal class DgsSchemaProviderTest {
assertThat(provider.dataFetcherInstrumentationEnabled["Query.hello"]).isTrue
}

@Test
fun enableInstrumentationForDataFetchersFromInterfaces() {
every { applicationContextMock.getBeansWithAnnotation(DgsComponent::class.java) } returns mapOf(
Pair(
"helloFetcher",
interfaceHelloFetcher
)
)
every { applicationContextMock.getBeansWithAnnotation(DgsScalar::class.java) } returns emptyMap()

val provider = DgsSchemaProvider(applicationContextMock, Optional.empty(), Optional.empty(), Optional.empty())
provider.schema()
assertThat(provider.dataFetcherInstrumentationEnabled).containsKey("Query.hello")
assertThat(provider.dataFetcherInstrumentationEnabled["Query.hello"]).isTrue
}

@Test
fun disableInstrumentationForDataFetchersWithAnnotation() {

Expand Down