@@ -4,13 +4,19 @@ import graphql.AssertException
4
4
import graphql.annotations.annotationTypes.GraphQLField
5
5
import graphql.annotations.annotationTypes.GraphQLName
6
6
import graphql.annotations.processor.GraphQLAnnotations
7
+ import graphql.execution.instrumentation.Instrumentation
8
+ import graphql.execution.instrumentation.InstrumentationState
9
+ import graphql.execution.instrumentation.SimpleInstrumentation
10
+ import graphql.execution.instrumentation.parameters.InstrumentationCreateStateParameters
7
11
import graphql.kickstart.execution.GraphQLRequest
8
12
import graphql.kickstart.execution.config.ExecutionStrategyProvider
13
+ import graphql.kickstart.execution.config.InstrumentationProvider
9
14
import graphql.kickstart.execution.context.DefaultGraphQLContext
10
15
import graphql.kickstart.execution.context.GraphQLContext
11
16
import graphql.kickstart.servlet.context.GraphQLServletContextBuilder
12
17
import graphql.kickstart.servlet.core.GraphQLServletListener
13
18
import graphql.kickstart.servlet.core.GraphQLServletRootObjectBuilder
19
+ import graphql.kickstart.servlet.input.NoOpBatchInputPreProcessor
14
20
import graphql.kickstart.servlet.osgi.*
15
21
import graphql.schema.*
16
22
import org.dataloader.DataLoaderRegistry
@@ -25,19 +31,19 @@ class OsgiGraphQLHttpServletSpec extends Specification {
25
31
26
32
@Override
27
33
Collection<GraphQLFieldDefinition > getQueries () {
28
- List<GraphQLFieldDefinition > fieldDefinitions = new ArrayList<> ();
34
+ List<GraphQLFieldDefinition > fieldDefinitions = new ArrayList<> ()
29
35
fieldDefinitions. add(newFieldDefinition()
30
36
.name(" query" )
31
37
.type(new GraphQLAnnotations (). object(Query . class))
32
38
.staticValue(new Query ())
33
- .build());
34
- return fieldDefinitions;
39
+ .build())
40
+ return fieldDefinitions
35
41
}
36
42
37
43
@GraphQLName (" query" )
38
44
static class Query {
39
45
@GraphQLField
40
- public String field;
46
+ public String field
41
47
}
42
48
43
49
}
@@ -55,15 +61,15 @@ class OsgiGraphQLHttpServletSpec extends Specification {
55
61
query. getType(). name == " query"
56
62
57
63
when :
58
- query = servlet. getConfiguration(). getInvocationInputFactory(). getSchemaProvider(). getReadOnlySchema(null ). getQueryType(). getFieldDefinition(" query" )
64
+ query = servlet. getConfiguration(). getInvocationInputFactory(). getSchemaProvider(). getReadOnlySchema(). getQueryType(). getFieldDefinition(" query" )
59
65
then :
60
66
query. getType(). name == " query"
61
67
62
68
when :
63
69
servlet. unbindQueryProvider(queryProvider)
64
70
then :
65
71
servlet. getConfiguration(). getInvocationInputFactory(). getSchemaProvider(). getSchema(). getQueryType(). getFieldDefinitions(). get(0 ). name == " _empty"
66
- servlet. getConfiguration(). getInvocationInputFactory(). getSchemaProvider(). getReadOnlySchema(null ). getQueryType(). getFieldDefinitions(). get(0 ). name == " _empty"
72
+ servlet. getConfiguration(). getInvocationInputFactory(). getSchemaProvider(). getReadOnlySchema(). getQueryType(). getFieldDefinitions(). get(0 ). name == " _empty"
67
73
}
68
74
69
75
static class TestMutationProvider implements GraphQLMutationProvider {
@@ -110,7 +116,7 @@ class OsgiGraphQLHttpServletSpec extends Specification {
110
116
@GraphQLName (" subscription" )
111
117
static class Subscription {
112
118
@GraphQLField
113
- public String field;
119
+ public String field
114
120
}
115
121
}
116
122
@@ -127,7 +133,7 @@ class OsgiGraphQLHttpServletSpec extends Specification {
127
133
subscription. getType(). getName() == " subscription"
128
134
129
135
when :
130
- subscription = servlet. getConfiguration(). getInvocationInputFactory(). getSchemaProvider(). getReadOnlySchema(null ). getSubscriptionType(). getFieldDefinition(" subscription" )
136
+ subscription = servlet. getConfiguration(). getInvocationInputFactory(). getSchemaProvider(). getReadOnlySchema(). getSubscriptionType(). getFieldDefinition(" subscription" )
131
137
then :
132
138
subscription. getType(). getName() == " subscription"
133
139
@@ -151,7 +157,7 @@ class OsgiGraphQLHttpServletSpec extends Specification {
151
157
static class TestCodeRegistryProvider implements GraphQLCodeRegistryProvider {
152
158
@Override
153
159
GraphQLCodeRegistry getCodeRegistry () {
154
- return GraphQLCodeRegistry . newCodeRegistry(). typeResolver(" Type" , { env -> null }). build();
160
+ return GraphQLCodeRegistry . newCodeRegistry(). typeResolver(" Type" , { env -> null }). build()
155
161
}
156
162
}
157
163
@@ -341,4 +347,27 @@ class OsgiGraphQLHttpServletSpec extends Specification {
341
347
then :
342
348
0 * executionStrategy. getQueryExecutionStrategy()
343
349
}
350
+
351
+ def " instrumentation provider is bound and unbound" () {
352
+ setup :
353
+ def servlet = new OsgiGraphQLHttpServlet ()
354
+ def instrumentation = new SimpleInstrumentation ()
355
+ def instrumentationProvider = Mock (InstrumentationProvider )
356
+ instrumentationProvider. getInstrumentation() >> instrumentation
357
+ def request = GraphQLRequest . createIntrospectionRequest()
358
+ instrumentation. createState(_ as InstrumentationCreateStateParameters ) >> Mock (InstrumentationState )
359
+
360
+ when :
361
+ servlet. setInstrumentationProvider(instrumentationProvider)
362
+ def invocationInput = servlet. configuration. invocationInputFactory. create(request)
363
+ servlet. configuration. graphQLInvoker. query(invocationInput)
364
+
365
+ then :
366
+ noExceptionThrown()
367
+
368
+ when :
369
+ servlet. unsetInstrumentationProvider(instrumentationProvider)
370
+ then :
371
+ noExceptionThrown()
372
+ }
344
373
}
0 commit comments