Skip to content

Commit bbe573a

Browse files
Fix one more bug caused by improper usage of field.getName
1 parent fc0a73e commit bbe573a

2 files changed

Lines changed: 72 additions & 3 deletions

File tree

src/main/java/graphql/execution/incremental/DeferredExecutionSupport.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,15 @@ private Supplier<CompletableFuture<DeferredFragmentCall.FieldWithExecutionResult
132132
DeferredCallContext deferredCallContext
133133
) {
134134
Map<String, MergedField> fields = new LinkedHashMap<>();
135-
fields.put(currentField.getName(), currentField);
135+
fields.put(currentField.getResultKey(), currentField);
136136

137137
ExecutionStrategyParameters callParameters = parameters.transform(builder ->
138138
{
139139
MergedSelectionSet mergedSelectionSet = MergedSelectionSet.newMergedSelectionSet().subFields(fields).build();
140140
builder.deferredCallContext(deferredCallContext)
141141
.field(currentField)
142142
.fields(mergedSelectionSet)
143-
.path(parameters.getPath().segment(currentField.getName()))
143+
.path(parameters.getPath().segment(currentField.getResultKey()))
144144
.parent(null); // this is a break in the parent -> child chain - it's a new start effectively
145145
}
146146
);
@@ -151,7 +151,7 @@ private Supplier<CompletableFuture<DeferredFragmentCall.FieldWithExecutionResult
151151
instrumentation.beginDeferredField(executionContext.getInstrumentationState());
152152

153153
return dfCache.computeIfAbsent(
154-
currentField.getName(),
154+
currentField.getResultKey(),
155155
// The same field can be associated with multiple defer executions, so
156156
// we memoize the field resolution to avoid multiple calls to the same data fetcher
157157
key -> FpKit.interThreadMemoize(() -> {

src/test/groovy/graphql/execution/incremental/DeferExecutionSupportIntegrationTest.groovy

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class DeferExecutionSupportIntegrationTest extends Specification {
2929
type Query {
3030
post : Post
3131
posts: [Post]
32+
postById(id: ID!): Post
3233
hello: String
3334
item(type: String!): Item
3435
}
@@ -135,6 +136,9 @@ class DeferExecutionSupportIntegrationTest extends Specification {
135136
[id: "1002"],
136137
[id: "1003"]
137138
]))
139+
.dataFetcher("postById", (env) -> {
140+
return [id: env.getArgument("id")]
141+
})
138142
.dataFetcher("hello", resolve("world"))
139143
.dataFetcher("item", resolveItem())
140144
)
@@ -239,6 +243,71 @@ class DeferExecutionSupportIntegrationTest extends Specification {
239243
]
240244
}
241245

246+
def "aliased fields with different parameters"() {
247+
def query = '''
248+
query {
249+
postById(id: "1") {
250+
id
251+
}
252+
... @defer {
253+
post2: postById(id: "2") {
254+
id2: id
255+
}
256+
}
257+
... @defer {
258+
post3: postById(id: "3") {
259+
... @defer {
260+
id3: id
261+
}
262+
}
263+
}
264+
}
265+
'''
266+
267+
when:
268+
IncrementalExecutionResult initialResult = executeQuery(query)
269+
270+
then:
271+
initialResult.toSpecification() == [
272+
data : [postById: [id: "1"]],
273+
hasNext: true
274+
]
275+
276+
when:
277+
def incrementalResults = getIncrementalResults(initialResult)
278+
279+
then:
280+
incrementalResults == [
281+
[
282+
hasNext : true,
283+
incremental: [
284+
[
285+
path: [],
286+
data: [post2: [id2: "2"]]
287+
]
288+
]
289+
],
290+
[
291+
hasNext : true,
292+
incremental: [
293+
[
294+
path: [],
295+
data: [post3: [:]]
296+
]
297+
]
298+
],
299+
[
300+
hasNext : false,
301+
incremental: [
302+
[
303+
path: ["post3"],
304+
data: [id3: "3"]
305+
]
306+
]
307+
]
308+
]
309+
}
310+
242311
def "defer on interface field"() {
243312
def query = """
244313
query {

0 commit comments

Comments
 (0)