Skip to content

Commit

Permalink
WIP: attempt of getting rid of the NormalizedDeferExecutionFactory
Browse files Browse the repository at this point in the history
WIP

WIP
  • Loading branch information
felipe-gdr-atlassian committed Jan 9, 2024
1 parent 6446ad4 commit b9b0f54
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 95 deletions.
19 changes: 14 additions & 5 deletions src/main/java/graphql/normalized/ENFMerger.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package graphql.normalized;

import com.google.common.collect.Multimap;
import graphql.Internal;
import graphql.introspection.Introspection;
import graphql.language.Argument;
import graphql.language.AstComparator;
import graphql.normalized.incremental.DeferDeclaration;
import graphql.schema.GraphQLInterfaceType;
import graphql.schema.GraphQLObjectType;
import graphql.schema.GraphQLSchema;
Expand All @@ -25,7 +23,7 @@ public static void merge(
ExecutableNormalizedField parent,
List<ExecutableNormalizedField> childrenWithSameResultKey,
GraphQLSchema schema,
Multimap<ExecutableNormalizedField, DeferDeclaration> normalizedFieldToDeferExecution
boolean deferSupport
) {
// they have all the same result key
// we can only merge the fields if they have the same field name + arguments + all children are the same
Expand Down Expand Up @@ -74,9 +72,20 @@ && isFieldInSharedInterface(field, fieldInGroup, schema)
while (iterator.hasNext()) {
ExecutableNormalizedField next = iterator.next();
// Move defer executions from removed field into the merged field's entry
normalizedFieldToDeferExecution.putAll(first, normalizedFieldToDeferExecution.get(next));
// normalizedFieldToDeferExecution.putAll(first, normalizedFieldToDeferExecution.get(next));
if (deferSupport) {
first.getDeferExecutions().forEach(deferDeclarationFirst -> {
next.getDeferExecutions().forEach(deferDeclarationNext -> {
if (Objects.equals(deferDeclarationFirst.getLabel(), deferDeclarationNext.getLabel())
&& mergedObjects.containsAll(deferDeclarationNext.getObjectTypeNames())
) {
deferDeclarationFirst.addObjectTypes(deferDeclarationNext.getObjectTypes());
}
});
});
}
parent.getChildren().remove(next);
normalizedFieldToDeferExecution.removeAll(next);
// normalizedFieldToDeferExecution.removeAll(next);
}
first.setObjectTypeNames(mergedObjects);
}
Expand Down
16 changes: 11 additions & 5 deletions src/main/java/graphql/normalized/ExecutableNormalizedField.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import graphql.collect.ImmutableKit;
import graphql.introspection.Introspection;
import graphql.language.Argument;
import graphql.normalized.incremental.DeferDeclaration;
import graphql.normalized.incremental.NormalizedDeferExecution;
import graphql.schema.GraphQLFieldDefinition;
import graphql.schema.GraphQLInterfaceType;
Expand Down Expand Up @@ -67,7 +68,7 @@ public class ExecutableNormalizedField {
private final int level;

// Mutable List on purpose: it is modified after creation
private final LinkedHashSet<NormalizedDeferExecution> deferExecutions;
private final LinkedHashSet<DeferDeclaration> deferExecutions;

private ExecutableNormalizedField(Builder builder) {
this.alias = builder.alias;
Expand Down Expand Up @@ -263,11 +264,16 @@ public void clearChildren() {
}

@Internal
public void setDeferExecutions(Collection<NormalizedDeferExecution> deferExecutions) {
public void setDeferExecutions(Collection<DeferDeclaration> deferExecutions) {
this.deferExecutions.clear();
this.deferExecutions.addAll(deferExecutions);
}

@Internal
public void addDeferExecutions(Collection<DeferDeclaration> deferDeclarations) {
this.deferExecutions.addAll(deferDeclarations);
}

/**
* All merged fields have the same name so this is the name of the {@link ExecutableNormalizedField}.
* <p>
Expand Down Expand Up @@ -475,7 +481,7 @@ public ExecutableNormalizedField getParent() {

// TODO: Javadoc
@ExperimentalApi
public LinkedHashSet<NormalizedDeferExecution> getDeferExecutions() {
public LinkedHashSet<DeferDeclaration> getDeferExecutions() {
return deferExecutions;
}

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

private LinkedHashSet<NormalizedDeferExecution> deferExecutions = new LinkedHashSet<>();
private LinkedHashSet<DeferDeclaration> deferExecutions = new LinkedHashSet<>();

private Builder() {
}
Expand Down Expand Up @@ -677,7 +683,7 @@ public Builder parent(ExecutableNormalizedField parent) {
return this;
}

public Builder deferExecutions(LinkedHashSet<NormalizedDeferExecution> deferExecutions) {
public Builder deferExecutions(LinkedHashSet<DeferDeclaration> deferExecutions) {
this.deferExecutions = deferExecutions;
return this;
}
Expand Down

0 comments on commit b9b0f54

Please sign in to comment.