Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions src/main/java/graphql/language/DirectivesContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,16 @@ public interface DirectivesContainer<T extends DirectivesContainer> extends Node
*

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We no longer have default methods - but rather a memory efficient DirectivesHolder helper

* @return a map of all directives by directive name
*/
default Map<String, List<Directive>> getDirectivesByName() {
return ImmutableMap.copyOf(allDirectivesByName(getDirectives()));

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was terribly memory inefficient

}
Map<String, List<Directive>> getDirectivesByName();

/**
* Returns all of the directives with the provided name, including repeatable and non repeatable directives.
* Returns all the directives with the provided name, including repeatable and non repeatable directives.
*
* @param directiveName the name of the directives to retrieve
*
* @return the directives or empty list if there is not one with that name
*/
default List<Directive> getDirectives(String directiveName) {
return getDirectivesByName().getOrDefault(directiveName, emptyList());

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was terribly memory inefficient

}
List<Directive> getDirectives(String directiveName);

/**
* This returns true if the AST node contains one or more directives by the specified name
Expand All @@ -56,7 +52,5 @@ default List<Directive> getDirectives(String directiveName) {
*
* @return true if the AST node contains one or more directives by the specified name
*/
default boolean hasDirective(String directiveName) {
return !getDirectives(directiveName).isEmpty();

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was terribly memory inefficient

}
boolean hasDirective(String directiveName);
}
27 changes: 21 additions & 6 deletions src/main/java/graphql/language/EnumTypeDefinition.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
public class EnumTypeDefinition extends AbstractDescribedNode<EnumTypeDefinition> implements TypeDefinition<EnumTypeDefinition>, DirectivesContainer<EnumTypeDefinition>, NamedNode<EnumTypeDefinition> {
private final String name;
private final ImmutableList<EnumValueDefinition> enumValueDefinitions;
private final ImmutableList<Directive> directives;
private final NodeUtil.DirectivesHolder directives;

public static final String CHILD_ENUM_VALUE_DEFINITIONS = "enumValueDefinitions";
public static final String CHILD_DIRECTIVES = "directives";
Expand All @@ -38,7 +38,7 @@ protected EnumTypeDefinition(String name,
IgnoredChars ignoredChars, Map<String, String> additionalData) {
super(sourceLocation, comments, ignoredChars, additionalData, description);
this.name = name;
this.directives = ImmutableKit.nonNullCopyOf(directives);
this.directives = NodeUtil.DirectivesHolder.of(directives);
this.enumValueDefinitions = ImmutableKit.nonNullCopyOf(enumValueDefinitions);
}

Expand All @@ -57,7 +57,22 @@ public List<EnumValueDefinition> getEnumValueDefinitions() {

@Override
public List<Directive> getDirectives() {
return directives;
return directives.getDirectives();
}

@Override
public Map<String, List<Directive>> getDirectivesByName() {
return directives.getDirectivesByName();
}

@Override
public List<Directive> getDirectives(String directiveName) {
return directives.getDirectives(directiveName);
}

@Override
public boolean hasDirective(String directiveName) {
return directives.hasDirective(directiveName);
}

@Override
Expand All @@ -69,15 +84,15 @@ public String getName() {
public List<Node> getChildren() {
List<Node> result = new ArrayList<>();
result.addAll(enumValueDefinitions);
result.addAll(directives);
result.addAll(directives.getDirectives());
return result;
}

@Override
public NodeChildrenContainer getNamedChildren() {
return newNodeChildrenContainer()
.children(CHILD_ENUM_VALUE_DEFINITIONS, enumValueDefinitions)
.children(CHILD_DIRECTIVES, directives)
.children(CHILD_DIRECTIVES, directives.getDirectives())
.build();
}

Expand Down Expand Up @@ -107,7 +122,7 @@ public boolean isEqualTo(Node o) {
public EnumTypeDefinition deepCopy() {
return new EnumTypeDefinition(name,
deepCopy(enumValueDefinitions),
deepCopy(directives),
deepCopy(directives.getDirectives()),
description,
getSourceLocation(),
getComments(),
Expand Down
28 changes: 21 additions & 7 deletions src/main/java/graphql/language/EnumValueDefinition.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@
import static graphql.Assert.assertNotNull;
import static graphql.collect.ImmutableKit.emptyList;
import static graphql.collect.ImmutableKit.emptyMap;
import static graphql.collect.ImmutableKit.nonNullCopyOf;
import static graphql.language.NodeChildrenContainer.newNodeChildrenContainer;

@PublicApi
public class EnumValueDefinition extends AbstractDescribedNode<EnumValueDefinition> implements DirectivesContainer<EnumValueDefinition>, NamedNode<EnumValueDefinition> {
private final String name;
private final ImmutableList<Directive> directives;
private final NodeUtil.DirectivesHolder directives;

public static final String CHILD_DIRECTIVES = "directives";

Expand All @@ -36,7 +35,7 @@ protected EnumValueDefinition(String name,
IgnoredChars ignoredChars, Map<String, String> additionalData) {
super(sourceLocation, comments, ignoredChars, additionalData, description);
this.name = name;
this.directives = nonNullCopyOf(directives);
this.directives = NodeUtil.DirectivesHolder.of(directives);
}

/**
Expand Down Expand Up @@ -65,18 +64,33 @@ public String getName() {

@Override
public List<Directive> getDirectives() {
return directives;
return directives.getDirectives();
}

@Override
public Map<String, List<Directive>> getDirectivesByName() {
return directives.getDirectivesByName();
}

@Override
public List<Directive> getDirectives(String directiveName) {
return directives.getDirectives(directiveName);
}

@Override
public boolean hasDirective(String directiveName) {
return directives.hasDirective(directiveName);
}

@Override
public List<Node> getChildren() {
return ImmutableList.copyOf(directives);
return ImmutableList.copyOf(directives.getDirectives());
}

@Override
public NodeChildrenContainer getNamedChildren() {
return newNodeChildrenContainer()
.children(CHILD_DIRECTIVES, directives)
.children(CHILD_DIRECTIVES, directives.getDirectives())
.build();
}

Expand Down Expand Up @@ -104,7 +118,7 @@ public boolean isEqualTo(Node o) {

@Override
public EnumValueDefinition deepCopy() {
return new EnumValueDefinition(name, deepCopy(directives), description, getSourceLocation(), getComments(), getIgnoredChars(), getAdditionalData());
return new EnumValueDefinition(name, deepCopy(directives.getDirectives()), description, getSourceLocation(), getComments(), getIgnoredChars(), getAdditionalData());
}

@Override
Expand Down
27 changes: 21 additions & 6 deletions src/main/java/graphql/language/Field.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class Field extends AbstractNode<Field> implements Selection<Field>, Sele
private final String name;
private final String alias;
private final ImmutableList<Argument> arguments;
private final ImmutableList<Directive> directives;
private final NodeUtil.DirectivesHolder directives;
private final SelectionSet selectionSet;

public static final String CHILD_ARGUMENTS = "arguments";
Expand All @@ -54,7 +54,7 @@ protected Field(String name,
this.name = name == null ? null : Interning.intern(name);
this.alias = alias;
this.arguments = ImmutableList.copyOf(arguments);
this.directives = ImmutableList.copyOf(directives);
this.directives = NodeUtil.DirectivesHolder.of(directives);
this.selectionSet = selectionSet;
}

Expand Down Expand Up @@ -103,7 +103,7 @@ public Field(String name, SelectionSet selectionSet) {
public List<Node> getChildren() {
List<Node> result = new ArrayList<>();
result.addAll(arguments);
result.addAll(directives);
result.addAll(directives.getDirectives());
if (selectionSet != null) {
result.add(selectionSet);
}
Expand All @@ -114,7 +114,7 @@ public List<Node> getChildren() {
public NodeChildrenContainer getNamedChildren() {
return NodeChildrenContainer.newNodeChildrenContainer()
.children(CHILD_ARGUMENTS, arguments)
.children(CHILD_DIRECTIVES, directives)
.children(CHILD_DIRECTIVES, directives.getDirectives())
.child(CHILD_SELECTION_SET, selectionSet)
.build();
}
Expand Down Expand Up @@ -147,7 +147,22 @@ public List<Argument> getArguments() {

@Override
public List<Directive> getDirectives() {
return directives;
return directives.getDirectives();
}

@Override
public Map<String, List<Directive>> getDirectivesByName() {
return directives.getDirectivesByName();
}

@Override
public List<Directive> getDirectives(String directiveName) {
return directives.getDirectives(directiveName);
}

@Override
public boolean hasDirective(String directiveName) {
return directives.hasDirective(directiveName);
}

@Override
Expand Down Expand Up @@ -175,7 +190,7 @@ public Field deepCopy() {
return new Field(name,
alias,
deepCopy(arguments),
deepCopy(directives),
deepCopy(directives.getDirectives()),
deepCopy(selectionSet),
getSourceLocation(),
getComments(),
Expand Down
27 changes: 21 additions & 6 deletions src/main/java/graphql/language/FieldDefinition.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class FieldDefinition extends AbstractDescribedNode<FieldDefinition> impl
private final String name;
private final Type type;
private final ImmutableList<InputValueDefinition> inputValueDefinitions;
private final ImmutableList<Directive> directives;
private final NodeUtil.DirectivesHolder directives;

public static final String CHILD_TYPE = "type";
public static final String CHILD_INPUT_VALUE_DEFINITION = "inputValueDefinition";
Expand All @@ -45,7 +45,7 @@ protected FieldDefinition(String name,
this.name = name;
this.type = type;
this.inputValueDefinitions = ImmutableList.copyOf(inputValueDefinitions);
this.directives = ImmutableList.copyOf(directives);
this.directives = NodeUtil.DirectivesHolder.of(directives);
}

public FieldDefinition(String name,
Expand All @@ -68,15 +68,30 @@ public List<InputValueDefinition> getInputValueDefinitions() {

@Override
public List<Directive> getDirectives() {
return directives;
return directives.getDirectives();
}

@Override
public Map<String, List<Directive>> getDirectivesByName() {
return directives.getDirectivesByName();
}

@Override
public List<Directive> getDirectives(String directiveName) {
return directives.getDirectives(directiveName);
}

@Override
public boolean hasDirective(String directiveName) {
return directives.hasDirective(directiveName);
}

@Override
public List<Node> getChildren() {
List<Node> result = new ArrayList<>();
result.add(type);
result.addAll(inputValueDefinitions);
result.addAll(directives);
result.addAll(directives.getDirectives());
return result;
}

Expand All @@ -85,7 +100,7 @@ public NodeChildrenContainer getNamedChildren() {
return newNodeChildrenContainer()
.child(CHILD_TYPE, type)
.children(CHILD_INPUT_VALUE_DEFINITION, inputValueDefinitions)
.children(CHILD_DIRECTIVES, directives)
.children(CHILD_DIRECTIVES, directives.getDirectives())
.build();
}

Expand Down Expand Up @@ -117,7 +132,7 @@ public FieldDefinition deepCopy() {
return new FieldDefinition(name,
deepCopy(type),
deepCopy(inputValueDefinitions),
deepCopy(directives),
deepCopy(directives.getDirectives()),
description,
getSourceLocation(),
getComments(),
Expand Down
26 changes: 20 additions & 6 deletions src/main/java/graphql/language/FragmentDefinition.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class FragmentDefinition extends AbstractNode<FragmentDefinition> impleme

private final String name;
private final TypeName typeCondition;
private final ImmutableList<Directive> directives;
private final NodeUtil.DirectivesHolder directives;
private final SelectionSet selectionSet;

public static final String CHILD_TYPE_CONDITION = "typeCondition";
Expand All @@ -46,7 +46,7 @@ protected FragmentDefinition(String name,
super(sourceLocation, comments, ignoredChars, additionalData);
this.name = name;
this.typeCondition = typeCondition;
this.directives = ImmutableList.copyOf(directives);
this.directives = NodeUtil.DirectivesHolder.of(directives);
this.selectionSet = selectionSet;
}

Expand All @@ -62,9 +62,23 @@ public TypeName getTypeCondition() {

@Override
public List<Directive> getDirectives() {
return directives;
return directives.getDirectives();
}

@Override
public Map<String, List<Directive>> getDirectivesByName() {
return directives.getDirectivesByName();
}

@Override
public List<Directive> getDirectives(String directiveName) {
return directives.getDirectives(directiveName);
}

@Override
public boolean hasDirective(String directiveName) {
return directives.hasDirective(directiveName);
}

@Override
public SelectionSet getSelectionSet() {
Expand All @@ -75,7 +89,7 @@ public SelectionSet getSelectionSet() {
public List<Node> getChildren() {
List<Node> result = new ArrayList<>();
result.add(typeCondition);
result.addAll(directives);
result.addAll(directives.getDirectives());
result.add(selectionSet);
return result;
}
Expand All @@ -84,7 +98,7 @@ public List<Node> getChildren() {
public NodeChildrenContainer getNamedChildren() {
return newNodeChildrenContainer()
.child(CHILD_TYPE_CONDITION, typeCondition)
.children(CHILD_DIRECTIVES, directives)
.children(CHILD_DIRECTIVES, directives.getDirectives())
.child(CHILD_SELECTION_SET, selectionSet)
.build();
}
Expand Down Expand Up @@ -116,7 +130,7 @@ public boolean isEqualTo(Node o) {
public FragmentDefinition deepCopy() {
return new FragmentDefinition(name,
deepCopy(typeCondition),
deepCopy(directives),
deepCopy(directives.getDirectives()),
deepCopy(selectionSet),
getSourceLocation(),
getComments(),
Expand Down
Loading