Skip to content

Commit b9b0f54

Browse files
WIP: attempt of getting rid of the NormalizedDeferExecutionFactory
WIP WIP
1 parent 6446ad4 commit b9b0f54

8 files changed

Lines changed: 160 additions & 95 deletions

src/main/java/graphql/normalized/ENFMerger.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
package graphql.normalized;
22

3-
import com.google.common.collect.Multimap;
43
import graphql.Internal;
54
import graphql.introspection.Introspection;
65
import graphql.language.Argument;
76
import graphql.language.AstComparator;
8-
import graphql.normalized.incremental.DeferDeclaration;
97
import graphql.schema.GraphQLInterfaceType;
108
import graphql.schema.GraphQLObjectType;
119
import graphql.schema.GraphQLSchema;
@@ -25,7 +23,7 @@ public static void merge(
2523
ExecutableNormalizedField parent,
2624
List<ExecutableNormalizedField> childrenWithSameResultKey,
2725
GraphQLSchema schema,
28-
Multimap<ExecutableNormalizedField, DeferDeclaration> normalizedFieldToDeferExecution
26+
boolean deferSupport
2927
) {
3028
// they have all the same result key
3129
// we can only merge the fields if they have the same field name + arguments + all children are the same
@@ -74,9 +72,20 @@ && isFieldInSharedInterface(field, fieldInGroup, schema)
7472
while (iterator.hasNext()) {
7573
ExecutableNormalizedField next = iterator.next();
7674
// Move defer executions from removed field into the merged field's entry
77-
normalizedFieldToDeferExecution.putAll(first, normalizedFieldToDeferExecution.get(next));
75+
// normalizedFieldToDeferExecution.putAll(first, normalizedFieldToDeferExecution.get(next));
76+
if (deferSupport) {
77+
first.getDeferExecutions().forEach(deferDeclarationFirst -> {
78+
next.getDeferExecutions().forEach(deferDeclarationNext -> {
79+
if (Objects.equals(deferDeclarationFirst.getLabel(), deferDeclarationNext.getLabel())
80+
&& mergedObjects.containsAll(deferDeclarationNext.getObjectTypeNames())
81+
) {
82+
deferDeclarationFirst.addObjectTypes(deferDeclarationNext.getObjectTypes());
83+
}
84+
});
85+
});
86+
}
7887
parent.getChildren().remove(next);
79-
normalizedFieldToDeferExecution.removeAll(next);
88+
// normalizedFieldToDeferExecution.removeAll(next);
8089
}
8190
first.setObjectTypeNames(mergedObjects);
8291
}

src/main/java/graphql/normalized/ExecutableNormalizedField.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import graphql.collect.ImmutableKit;
1212
import graphql.introspection.Introspection;
1313
import graphql.language.Argument;
14+
import graphql.normalized.incremental.DeferDeclaration;
1415
import graphql.normalized.incremental.NormalizedDeferExecution;
1516
import graphql.schema.GraphQLFieldDefinition;
1617
import graphql.schema.GraphQLInterfaceType;
@@ -67,7 +68,7 @@ public class ExecutableNormalizedField {
6768
private final int level;
6869

6970
// Mutable List on purpose: it is modified after creation
70-
private final LinkedHashSet<NormalizedDeferExecution> deferExecutions;
71+
private final LinkedHashSet<DeferDeclaration> deferExecutions;
7172

7273
private ExecutableNormalizedField(Builder builder) {
7374
this.alias = builder.alias;
@@ -263,11 +264,16 @@ public void clearChildren() {
263264
}
264265

265266
@Internal
266-
public void setDeferExecutions(Collection<NormalizedDeferExecution> deferExecutions) {
267+
public void setDeferExecutions(Collection<DeferDeclaration> deferExecutions) {
267268
this.deferExecutions.clear();
268269
this.deferExecutions.addAll(deferExecutions);
269270
}
270271

272+
@Internal
273+
public void addDeferExecutions(Collection<DeferDeclaration> deferDeclarations) {
274+
this.deferExecutions.addAll(deferDeclarations);
275+
}
276+
271277
/**
272278
* All merged fields have the same name so this is the name of the {@link ExecutableNormalizedField}.
273279
* <p>
@@ -475,7 +481,7 @@ public ExecutableNormalizedField getParent() {
475481

476482
// TODO: Javadoc
477483
@ExperimentalApi
478-
public LinkedHashSet<NormalizedDeferExecution> getDeferExecutions() {
484+
public LinkedHashSet<DeferDeclaration> getDeferExecutions() {
479485
return deferExecutions;
480486
}
481487

@@ -606,7 +612,7 @@ public static class Builder {
606612
private LinkedHashMap<String, Object> resolvedArguments = new LinkedHashMap<>();
607613
private ImmutableList<Argument> astArguments = ImmutableKit.emptyList();
608614

609-
private LinkedHashSet<NormalizedDeferExecution> deferExecutions = new LinkedHashSet<>();
615+
private LinkedHashSet<DeferDeclaration> deferExecutions = new LinkedHashSet<>();
610616

611617
private Builder() {
612618
}
@@ -677,7 +683,7 @@ public Builder parent(ExecutableNormalizedField parent) {
677683
return this;
678684
}
679685

680-
public Builder deferExecutions(LinkedHashSet<NormalizedDeferExecution> deferExecutions) {
686+
public Builder deferExecutions(LinkedHashSet<DeferDeclaration> deferExecutions) {
681687
this.deferExecutions = deferExecutions;
682688
return this;
683689
}

0 commit comments

Comments
 (0)