Skip to content

Commit fe8a5d4

Browse files
committed
Improved test and tweaked javadoc
1 parent 37a5375 commit fe8a5d4

2 files changed

Lines changed: 22 additions & 34 deletions

File tree

‎src/main/java/graphql/schema/DataFetchingFieldSelectionSet.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public interface DataFetchingFieldSelectionSet extends Supplier<Map<String, List
5858
* This will allow you to use '*', '**' and '?' as special matching characters such that "invoice/customer*" would
5959
* match an invoice field with child fields that start with 'customer'.
6060
*
61+
* @param fieldGlobPattern the glob pattern to match fields against
6162
* @return true if the selection set contains these fields
6263
*
6364
* @see java.nio.file.FileSystem#getPathMatcher(String)

‎src/test/groovy/graphql/schema/DataFetcherSelectionTest.groovy‎

Lines changed: 21 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,18 @@ class DataFetcherSelectionTest extends Specification {
4848
captureFieldArgs.add(arguments)
4949

5050
if (!selectionSet.isEmpty()) {
51-
String subSelection = captureSubSelection(selectionSet)
52-
def path = environment.getFieldTypeInfo().getPath().toString()
53-
captureMap.put(path, subSelection)
51+
for (String fieldName : selectionSet.keySet()) {
52+
String ast = captureFields(selectionSet.get(fieldName))
53+
captureMap.put(fieldName, ast)
54+
}
5455
}
5556

5657
return delegate.get(environment)
5758
}
5859

59-
String captureSubSelection(Map<String, List<Field>> fields) {
60-
return fields.values().stream().map({ f -> captureFields(f) }).collect(Collectors.joining("\n"))
61-
}
62-
6360
String captureFields(List<Field> fields) {
64-
return fields.stream().map({ f -> AstPrinter.printAst(f) }).collect(Collectors.joining("\n"))
61+
def collect = fields.stream().map({ f -> AstPrinter.printAst(f) }).collect(Collectors.joining(";"))
62+
return collect
6563
}
6664
}
6765

@@ -152,28 +150,19 @@ class DataFetcherSelectionTest extends Specification {
152150

153151
// captures each stage as it descends
154152
captureMap == [
155-
"/luke" : "name\n" +
156-
"friends {\n" +
157-
" name\n" +
158-
" friends {\n" +
159-
" name\n" +
160-
" }\n" +
161-
"}\n" +
162-
"name\n"+
163-
"homePlanet",
164-
165-
"/luke/friends": "name\n" +
166-
"friends {\n" +
153+
"appearsIn" : "appearsIn",
154+
"friends/friends/name": "name",
155+
"friends/friends" : "friends {\n" +
167156
" name\n" +
168157
"}",
169-
170-
"/leia" : "id\n" +
171-
"friends {\n" +
158+
"friends/name" : "name",
159+
"friends" : "friends {\n" +
172160
" name\n" +
173-
"}\n" +
174-
"appearsIn",
161+
"}",
162+
"homePlanet" : "homePlanet",
163+
"id" : "id",
164+
"name" : "name"
175165

176-
"/leia/friends": "name",
177166
]
178167
}
179168

@@ -199,15 +188,13 @@ class DataFetcherSelectionTest extends Specification {
199188
then:
200189

201190
captureMap == [
202-
"/luke" : "name\n" +
203-
"friends {\n" +
191+
"name" : "name",
192+
"friends" : "friends {\n" +
204193
" name\n" +
205-
"}\n" +
206-
"homePlanet",
207-
208-
"/luke/friends": "name"
194+
"}",
195+
"friends/name": "name",
196+
"homePlanet" : "homePlanet",
209197
]
210-
211198
}
212199

213200
def "#832 - field selection captures field arguments"() {
@@ -266,7 +253,7 @@ class DataFetcherSelectionTest extends Specification {
266253
locale : "AU"
267254
]
268255
],
269-
[name: [:], friends: [separationCount: 4]],
256+
[name: [:], friends: [separationCount: 4], "friends/id": [:]],
270257
[id: [:]]
271258
]
272259

0 commit comments

Comments
 (0)