|
1 | 1 | package graphql.execution.directives |
2 | 2 |
|
3 | | -import com.google.common.collect.ImmutableList |
| 3 | + |
4 | 4 | import graphql.GraphQL |
5 | 5 | import graphql.TestUtil |
6 | | -import graphql.execution.CoercedVariables |
7 | 6 | import graphql.execution.RawVariables |
8 | | -import graphql.normalized.ExecutableNormalizedField |
| 7 | +import graphql.language.IntValue |
9 | 8 | import graphql.normalized.ExecutableNormalizedOperationFactory |
| 9 | +import graphql.normalized.NormalizedInputValue |
10 | 10 | import graphql.schema.DataFetcher |
11 | 11 | import graphql.schema.FieldCoordinates |
12 | 12 | import spock.lang.Specification |
@@ -155,6 +155,53 @@ class QueryDirectivesIntegrationTest extends Specification { |
155 | 155 |
|
156 | 156 | def reviewField = eno.getCoordinatesToNormalizedFields().get(FieldCoordinates.coordinates("Book", "review")) |
157 | 157 | 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 |
159 | 206 | } |
160 | 207 | } |
0 commit comments