diff --git a/src/main/java/graphql/execution/incremental/DeferredExecutionSupport.java b/src/main/java/graphql/execution/incremental/DeferredExecutionSupport.java index 1689afa684..9e24ec2103 100644 --- a/src/main/java/graphql/execution/incremental/DeferredExecutionSupport.java +++ b/src/main/java/graphql/execution/incremental/DeferredExecutionSupport.java @@ -132,7 +132,7 @@ private Supplier fields = new LinkedHashMap<>(); - fields.put(currentField.getName(), currentField); + fields.put(currentField.getResultKey(), currentField); ExecutionStrategyParameters callParameters = parameters.transform(builder -> { @@ -140,7 +140,7 @@ private Supplier child chain - it's a new start effectively } ); @@ -151,7 +151,7 @@ private Supplier FpKit.interThreadMemoize(() -> { @@ -165,7 +165,7 @@ private Supplier - new DeferredFragmentCall.FieldWithExecutionResult(currentField.getName(), executionResult) + new DeferredFragmentCall.FieldWithExecutionResult(currentField.getResultKey(), executionResult) ); } ) diff --git a/src/main/java/graphql/execution/incremental/DeferredFragmentCall.java b/src/main/java/graphql/execution/incremental/DeferredFragmentCall.java index be28fb9e90..79b9496fd1 100644 --- a/src/main/java/graphql/execution/incremental/DeferredFragmentCall.java +++ b/src/main/java/graphql/execution/incremental/DeferredFragmentCall.java @@ -107,7 +107,7 @@ private DeferPayload transformToDeferredPayload(List f ImmutableList.Builder errorsBuilder = ImmutableList.builder(); fieldWithExecutionResults.forEach(entry -> { - dataMap.put(entry.fieldName, entry.executionResult.getData()); + dataMap.put(entry.resultKey, entry.executionResult.getData()); errorsBuilder.addAll(entry.executionResult.getErrors()); }); @@ -120,11 +120,11 @@ private DeferPayload transformToDeferredPayload(List f } public static class FieldWithExecutionResult { - private final String fieldName; + private final String resultKey; private final ExecutionResult executionResult; - public FieldWithExecutionResult(String fieldName, ExecutionResult executionResult) { - this.fieldName = fieldName; + public FieldWithExecutionResult(String resultKey, ExecutionResult executionResult) { + this.resultKey = resultKey; this.executionResult = executionResult; } diff --git a/src/test/groovy/graphql/execution/incremental/DeferExecutionSupportIntegrationTest.groovy b/src/test/groovy/graphql/execution/incremental/DeferExecutionSupportIntegrationTest.groovy index c805132853..46a0756c6a 100644 --- a/src/test/groovy/graphql/execution/incremental/DeferExecutionSupportIntegrationTest.groovy +++ b/src/test/groovy/graphql/execution/incremental/DeferExecutionSupportIntegrationTest.groovy @@ -29,6 +29,7 @@ class DeferExecutionSupportIntegrationTest extends Specification { type Query { post : Post posts: [Post] + postById(id: ID!): Post hello: String item(type: String!): Item } @@ -135,6 +136,9 @@ class DeferExecutionSupportIntegrationTest extends Specification { [id: "1002"], [id: "1003"] ])) + .dataFetcher("postById", (env) -> { + return [id: env.getArgument("id")] + }) .dataFetcher("hello", resolve("world")) .dataFetcher("item", resolveItem()) ) @@ -201,6 +205,109 @@ class DeferExecutionSupportIntegrationTest extends Specification { ] } + def "defer with aliased fields"() { + def query = ''' + query { + postAlias: post { + idAlias: id + ... @defer { + summaryAlias: summary + } + } + } + ''' + + when: + IncrementalExecutionResult initialResult = executeQuery(query) + + then: + initialResult.toSpecification() == [ + data : [postAlias: [idAlias: "1001"]], + hasNext: true + ] + + when: + def incrementalResults = getIncrementalResults(initialResult) + + then: + incrementalResults == [ + [ + hasNext : false, + incremental: [ + [ + path: ["postAlias"], + data: [summaryAlias: "A summary"] + ] + ] + ] + ] + } + + def "aliased fields with different parameters"() { + def query = ''' + query { + postById(id: "1") { + id + } + ... @defer { + post2: postById(id: "2") { + id2: id + } + } + ... @defer { + post3: postById(id: "3") { + ... @defer { + id3: id + } + } + } + } + ''' + + when: + IncrementalExecutionResult initialResult = executeQuery(query) + + then: + initialResult.toSpecification() == [ + data : [postById: [id: "1"]], + hasNext: true + ] + + when: + def incrementalResults = getIncrementalResults(initialResult) + + then: + incrementalResults == [ + [ + hasNext : true, + incremental: [ + [ + path: [], + data: [post2: [id2: "2"]] + ] + ] + ], + [ + hasNext : true, + incremental: [ + [ + path: [], + data: [post3: [:]] + ] + ] + ], + [ + hasNext : false, + incremental: [ + [ + path: ["post3"], + data: [id3: "3"] + ] + ] + ] + ] + } + def "defer on interface field"() { def query = """ query {