Skip to content

Commit a0b56c7

Browse files
committed
Stop reading the custom context class from the legacy context object
1 parent 2fb1ce1 commit a0b56c7

2 files changed

Lines changed: 13 additions & 18 deletions

File tree

‎src/main/kotlin/graphql/kickstart/tools/resolver/MethodFieldResolver.kt‎

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import kotlinx.coroutines.ensureActive
2020
import kotlinx.coroutines.future.future
2121
import org.apache.commons.lang3.reflect.TypeUtils
2222
import org.reactivestreams.Publisher
23-
import org.slf4j.LoggerFactory
2423
import java.lang.reflect.InvocationTargetException
2524
import java.lang.reflect.Method
2625
import java.util.*
@@ -41,8 +40,6 @@ internal class MethodFieldResolver(
4140
private val scalarNames: Set<String>
4241
) : FieldResolver(field, search, options) {
4342

44-
private val log = LoggerFactory.getLogger(javaClass)
45-
4643
private val isSuspendFunction = method.isSuspendFunction()
4744
private val numberOfParameters = method.parameterCountWithoutContinuation()
4845

@@ -105,21 +102,7 @@ internal class MethodFieldResolver(
105102
val firstTrailingParameter = field.inputValueDefinitions.size + search.firstArgumentIndex
106103
method.parameterTypes.slice(firstTrailingParameter until numberOfParameters).forEach { parameterType ->
107104
when (parameterType) {
108-
options.contextClass -> args.add { environment ->
109-
val context: Any? = environment.graphQlContext[options.contextClass]
110-
if (context != null) {
111-
context
112-
} else {
113-
log.warn(
114-
"Generic context class has been deprecated by graphql-java. " +
115-
"To continue using a custom context class as the last parameter in resolver methods " +
116-
"please insert it into the GraphQLContext map when building the ExecutionInput. " +
117-
"This warning will become an error in the future."
118-
)
119-
@Suppress("DEPRECATION")
120-
environment.getContext() // TODO: remove deprecated use in next major release
121-
}
122-
}
105+
options.contextClass -> args.add { environment -> environment.graphQlContext[options.contextClass] }
123106

124107
GraphQLContext::class.java -> args.add { environment -> environment.graphQlContext }
125108
else -> args.add { environment -> environment }

‎src/test/kotlin/graphql/kickstart/tools/MethodFieldResolverDataFetcherTest.kt‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,18 @@ class MethodFieldResolverDataFetcherTest {
275275
assertEquals(resolver.get(createEnvironment(DataClass(), context = context)), true)
276276
}
277277

278+
@Test
279+
fun `data fetcher does not read custom context from the legacy context object`() {
280+
val options = SchemaParserOptions.newOptions().contextClass(ContextClass::class).build()
281+
val resolver = createFetcher("active", options = options, resolver = object : GraphQLResolver<DataClass> {
282+
fun isActive(dataClass: DataClass, ctx: ContextClass?): Boolean {
283+
return ctx != null
284+
}
285+
})
286+
287+
assertEquals(resolver.get(createEnvironment(DataClass(), legacyContext = ContextClass())), false)
288+
}
289+
278290
@Test
279291
fun `data fetcher passes custom context and environment if method has both as extra arguments`() {
280292
val customContext = ContextClass()

0 commit comments

Comments
 (0)