Skip to content

Commit f4939e3

Browse files
committed
Added more tests cases to QueryDirectivesIntegrationTest.groovy
1 parent 641bea4 commit f4939e3

1 file changed

Lines changed: 51 additions & 4 deletions

File tree

src/test/groovy/graphql/execution/directives/QueryDirectivesIntegrationTest.groovy

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package graphql.execution.directives
22

3-
import com.google.common.collect.ImmutableList
3+
44
import graphql.GraphQL
55
import graphql.TestUtil
6-
import graphql.execution.CoercedVariables
76
import graphql.execution.RawVariables
8-
import graphql.normalized.ExecutableNormalizedField
7+
import graphql.language.IntValue
98
import graphql.normalized.ExecutableNormalizedOperationFactory
9+
import graphql.normalized.NormalizedInputValue
1010
import graphql.schema.DataFetcher
1111
import graphql.schema.FieldCoordinates
1212
import spock.lang.Specification
@@ -155,6 +155,53 @@ class QueryDirectivesIntegrationTest extends Specification {
155155

156156
def reviewField = eno.getCoordinatesToNormalizedFields().get(FieldCoordinates.coordinates("Book", "review"))
157157
def reviewQueryDirectives = eno.getQueryDirectives(reviewField[0])
158-
!reviewQueryDirectives.immediateAppliedDirectivesByName.isEmpty()
158+
def reviewImmediateDirectivesMap = reviewQueryDirectives.immediateAppliedDirectivesByName
159+
def argInputValues = simplifiedInputValuesWithState(reviewImmediateDirectivesMap)
160+
argInputValues == [
161+
timeout: [
162+
[timeout: [[afterMillis: 5]]], [timeout: [[afterMillis: 28]]], [timeout: [[afterMillis: 10]]]
163+
],
164+
cached : [
165+
[cached: [[forMillis: 5]]], [cached: [[forMillis: 10]]]
166+
]
167+
]
168+
169+
// normalised values are AST values
170+
def normalizedValues = simplifiedNormalizedValues(reviewQueryDirectives.getNormalizedInputValueByImmediateAppliedDirectives())
171+
normalizedValues == [
172+
timeout: [
173+
[afterMillis: 5], [afterMillis: 28], [afterMillis: 10]],
174+
cached : [
175+
[forMillis: 5], [forMillis: 10]]
176+
]
177+
178+
}
179+
180+
def simplifiedInputValuesWithState(Map<String, List<QueryAppliedDirective>> mapOfDirectives) {
181+
def simpleMap = [:]
182+
mapOfDirectives.forEach { k, listOfDirectives ->
183+
184+
def dirVals = listOfDirectives.collect { qd ->
185+
def argVals = qd.getArguments().collect { arg ->
186+
def argValue = arg.getArgumentValue()
187+
return [(arg.name): argValue?.value]
188+
}
189+
return [(qd.name): argVals]
190+
}
191+
simpleMap[k] = dirVals
192+
}
193+
return simpleMap
194+
}
195+
196+
def simplifiedNormalizedValues(Map<QueryAppliedDirective, Map<String, NormalizedInputValue>> mapOfDirectives) {
197+
Map<String, List<Map<String, Integer>>> simpleMap = new LinkedHashMap<>()
198+
mapOfDirectives.forEach { qd, argMap ->
199+
def argVals = argMap.collect { entry ->
200+
def argValueAst = entry.value?.value as IntValue // just assume INtValue for these tests
201+
return [(entry.key): argValueAst?.value?.toInteger()]
202+
}
203+
simpleMap.computeIfAbsent(qd.name, { _ -> [] }).addAll(argVals)
204+
}
205+
return simpleMap
159206
}
160207
}

0 commit comments

Comments
 (0)