@@ -8,6 +8,8 @@ import graphql.execution.AsyncExecutionStrategy
88import graphql.execution.instrumentation.parameters.InstrumentationCreateStateParameters
99import graphql.execution.instrumentation.parameters.InstrumentationExecutionParameters
1010import graphql.execution.instrumentation.parameters.InstrumentationValidationParameters
11+ import graphql.schema.DataFetcher
12+ import graphql.schema.DataFetchingEnvironment
1113import graphql.validation.ValidationError
1214import spock.lang.Specification
1315
@@ -227,6 +229,78 @@ class ChainedInstrumentationStateTest extends Specification {
227229 assertCalls(c)
228230 }
229231
232+ def " basic chaining and state management when exception raised in data fetching" () {
233+
234+ def a = new NamedInstrumentation (" A" )
235+ def b = new NamedInstrumentation (" B" )
236+ def c = new NamedInstrumentation (" C" )
237+ def nullState = new SimplePerformantInstrumentation ()
238+
239+ def chainedInstrumentation = new ChainedInstrumentation ([
240+ a,
241+ b,
242+ nullState,
243+ c,
244+ ])
245+
246+ def query = """
247+ query HeroNameAndFriendsQuery {
248+ hero {
249+ id
250+ }
251+ }
252+ """
253+
254+ def expected = " onExceptionHandled:fetch-id"
255+
256+
257+ when :
258+ def strategy = new AsyncExecutionStrategy ()
259+ def schema = StarWarsSchema . starWarsSchema
260+ def graphQL = GraphQL
261+ .newGraphQL(schema. transform { schemaBuilder ->
262+ // throw exception when fetching the hero id
263+ def exceptionDataFetcher = new DataFetcher () {
264+ @Override
265+ Object get (DataFetchingEnvironment environment ) {
266+ throw new RuntimeException (" Data fetcher exception" )
267+ }
268+ }
269+ schemaBuilder. codeRegistry(schema. codeRegistry. transform {
270+ it. dataFetcher(
271+ schema. getObjectType(" Human" ),
272+ schema. getObjectType(" Human" ). getFieldDefinition(" id" ),
273+ exceptionDataFetcher
274+ )
275+ it. dataFetcher(
276+ schema. getObjectType(" Droid" ),
277+ schema. getObjectType(" Droid" ). getFieldDefinition(" id" ),
278+ exceptionDataFetcher
279+ )
280+ return it
281+ }
282+ )
283+ })
284+ .queryExecutionStrategy(strategy)
285+ .instrumentation(chainedInstrumentation)
286+ .build()
287+
288+ graphQL. execute(query)
289+
290+ then :
291+
292+ chainedInstrumentation. getInstrumentations(). size() == 4
293+
294+ a. executionList. any { it == expected }
295+ b. executionList. any { it == expected }
296+ c. executionList. any { it == expected }
297+
298+ assertCalls(a)
299+ assertCalls(b)
300+ assertCalls(c)
301+
302+ }
303+
230304 def " empty chain" () {
231305 def chainedInstrumentation = new ChainedInstrumentation (Arrays . asList())
232306
0 commit comments