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
12 changes: 0 additions & 12 deletions src/main/java/graphql/language/AbstractNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,4 @@ protected <V extends Node> List<V> deepCopy(List<? extends Node> list) {
}
return list.stream().map(Node::deepCopy).map(node -> (V) node).collect(Collectors.toList());
}

//TODO: Implement really in each Node
@Override
public ChildrenContainer getNamedChildren() {
return null;
}

//TODO: Implement really in each Node
@Override
public T withNewChildren(ChildrenContainer newChildren) {
return null;
}
}
27 changes: 17 additions & 10 deletions src/main/java/graphql/language/Argument.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
@PublicApi
public class Argument extends AbstractNode<Argument> implements NamedNode<Argument> {

private String name;
private Value value;
private final String name;
private final Value value;

private static final String CHILD_VALUE = "value";

@Internal
protected Argument(String name, Value value, SourceLocation sourceLocation, List<Comment> comments) {
Expand Down Expand Up @@ -42,21 +44,26 @@ public Value getValue() {
return value;
}

public void setName(String name) {
this.name = name;
}

public void setValue(Value value) {
this.value = value;
}

@Override
public List<Node> getChildren() {
List<Node> result = new ArrayList<>();
result.add(value);
return result;
}

@Override
public ChildrenContainer getNamedChildren() {
return ChildrenContainer.newChildrenContainer()
.child(CHILD_VALUE, value)
.build();
}

@Override
public Argument withNewChildren(ChildrenContainer newChildren) {
return transform(builder -> builder
.value(newChildren.getSingleValueOrNull(CHILD_VALUE))
);
}

@Override
public boolean isEqualTo(Node o) {
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/graphql/language/ArrayValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class ArrayValue extends AbstractNode<ArrayValue> implements Value<ArrayV

private final List<Value> values = new ArrayList<>();

private static final String CHILD_VALUES = "values";

@Internal
protected ArrayValue(List<Value> values, SourceLocation sourceLocation, List<Comment> comments) {
super(sourceLocation, comments);
Expand All @@ -40,6 +42,20 @@ public List<Node> getChildren() {
return new ArrayList<>(values);
}

@Override
public ChildrenContainer getNamedChildren() {
return ChildrenContainer.newChildrenContainer()
.children(CHILD_VALUES, values)
.build();
}

@Override
public ArrayValue withNewChildren(ChildrenContainer newChildren) {
return transform(builder -> builder
.values(newChildren.getList(CHILD_VALUES))
);
}

@Override
public boolean isEqualTo(Node o) {
if (this == o) return true;
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/graphql/language/BooleanValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@ public List<Node> getChildren() {
return new ArrayList<>();
}

@Override
public ChildrenContainer getNamedChildren() {
return ChildrenContainer.newChildrenContainer().build();
}

@Override
public BooleanValue withNewChildren(ChildrenContainer newChildren) {
if (!newChildren.isEmpty()) {
throw new IllegalArgumentException("Cannot pass non-empty newChildren to Node that doesn't hold children");
}

return this;
}

@Override
public boolean isEqualTo(Node o) {
if (this == o) return true;
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/graphql/language/ChildrenContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ public ChildrenContainer transform(Consumer<Builder> builderConsumer) {
return builder.build();
}

public boolean isEmpty() {
return this.children.isEmpty();
}

public static class Builder {
private final Map<String, List<Node>> children = new LinkedHashMap<>();

Expand Down
16 changes: 16 additions & 0 deletions src/main/java/graphql/language/Directive.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class Directive extends AbstractNode<Directive> implements NamedNode<Dire
private final String name;
private final List<Argument> arguments = new ArrayList<>();

private static final String CHILD_ARGUMENTS = "arguments";

@Internal
protected Directive(String name, List<Argument> arguments, SourceLocation sourceLocation, List<Comment> comments) {
super(sourceLocation, comments);
Expand Down Expand Up @@ -64,6 +66,20 @@ public List<Node> getChildren() {
return new ArrayList<>(arguments);
}

@Override
public ChildrenContainer getNamedChildren() {
return ChildrenContainer.newChildrenContainer()
.children(CHILD_ARGUMENTS, arguments)
.build();
}

@Override
public Directive withNewChildren(ChildrenContainer newChildren) {
return transform(builder -> builder
.arguments(newChildren.getList(CHILD_ARGUMENTS))
);
}

@Override
public boolean isEqualTo(Node o) {
if (this == o) return true;
Expand Down
33 changes: 25 additions & 8 deletions src/main/java/graphql/language/DirectiveDefinition.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,24 @@
@PublicApi
public class DirectiveDefinition extends AbstractNode<DirectiveDefinition> implements SDLDefinition<DirectiveDefinition>, NamedNode<DirectiveDefinition> {
private final String name;
private Description description;
private final Description description;
private final List<InputValueDefinition> inputValueDefinitions;
private final List<DirectiveLocation> directiveLocations;

private static final String CHILD_INPUT_VALUE_DEFINITIONS = "inputValueDefinitions";
private static final String CHILD_DIRECTIVE_LOCATION = "directiveLocation";

@Internal
protected DirectiveDefinition(String name,
Description description,
List<InputValueDefinition> inputValueDefinitions,
List<DirectiveLocation> directiveLocations,
SourceLocation sourceLocation,
List<Comment> comments
) {
super(sourceLocation, comments);
this.name = name;
this.description = description;
this.inputValueDefinitions = inputValueDefinitions;
this.directiveLocations = directiveLocations;
}
Expand All @@ -34,7 +39,7 @@ protected DirectiveDefinition(String name,
* alternative to using a Builder for convenience
*/
public DirectiveDefinition(String name) {
this(name, new ArrayList<>(), new ArrayList<>(), null, new ArrayList<>());
this(name, null, new ArrayList<>(), new ArrayList<>(), null, new ArrayList<>());
}

@Override
Expand All @@ -46,10 +51,6 @@ public Description getDescription() {
return description;
}

public void setDescription(Description description) {
this.description = description;
}

public List<InputValueDefinition> getInputValueDefinitions() {
return new ArrayList<>(inputValueDefinitions);
}
Expand All @@ -66,6 +67,22 @@ public List<Node> getChildren() {
return result;
}

@Override
public ChildrenContainer getNamedChildren() {
return ChildrenContainer.newChildrenContainer()
.children(CHILD_INPUT_VALUE_DEFINITIONS, inputValueDefinitions)
.children(CHILD_DIRECTIVE_LOCATION, directiveLocations)
.build();
}

@Override
public DirectiveDefinition withNewChildren(ChildrenContainer newChildren) {
return transform(builder -> builder
.inputValueDefinitions(newChildren.getList(CHILD_INPUT_VALUE_DEFINITIONS))
.directiveLocations(newChildren.getList(CHILD_DIRECTIVE_LOCATION))
);
}

@Override
public boolean isEqualTo(Node o) {
if (this == o) return true;
Expand All @@ -79,6 +96,7 @@ public boolean isEqualTo(Node o) {
@Override
public DirectiveDefinition deepCopy() {
return new DirectiveDefinition(name,
description,
deepCopy(inputValueDefinitions),
deepCopy(directiveLocations),
getSourceLocation(),
Expand Down Expand Up @@ -170,8 +188,7 @@ public Builder directiveLocation(DirectiveLocation directiveLocation) {
}

public DirectiveDefinition build() {
DirectiveDefinition directiveDefinition = new DirectiveDefinition(name, inputValueDefinitions, directiveLocations, sourceLocation, comments);
directiveDefinition.setDescription(description);
DirectiveDefinition directiveDefinition = new DirectiveDefinition(name, description, inputValueDefinitions, directiveLocations, sourceLocation, comments);
return directiveDefinition;
}
}
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/graphql/language/DirectiveLocation.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,20 @@ public List<Node> getChildren() {
return new ArrayList<>();
}

@Override
public ChildrenContainer getNamedChildren() {
return ChildrenContainer.newChildrenContainer().build();
}

@Override
public DirectiveLocation withNewChildren(ChildrenContainer newChildren) {
if (!newChildren.isEmpty()) {
throw new IllegalArgumentException("Cannot pass non-empty newChildren to Node that doesn't hold children");
}

return this;
}

@Override
public boolean isEqualTo(Node o) {
if (this == o) return true;
Expand Down
16 changes: 15 additions & 1 deletion src/main/java/graphql/language/Document.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class Document extends AbstractNode<Document> {

private final List<Definition> definitions;

private static final String CHILD_DEFINITIONS = "definitions";

@Internal
protected Document(List<Definition> definitions, SourceLocation sourceLocation, List<Comment> comments) {
super(sourceLocation, comments);
Expand All @@ -32,12 +34,24 @@ public List<Definition> getDefinitions() {
return definitions;
}


@Override
public List<Node> getChildren() {
return new ArrayList<>(definitions);
}

@Override
public ChildrenContainer getNamedChildren() {
return ChildrenContainer.newChildrenContainer()
.children(CHILD_DEFINITIONS, definitions)
.build();
}

@Override
public Document withNewChildren(ChildrenContainer newChildren) {
return transform(builder -> builder
.definitions(newChildren.getList(CHILD_DEFINITIONS))
);
}

@Override
public boolean isEqualTo(Node o) {
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/graphql/language/EnumTypeDefinition.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public class EnumTypeDefinition extends AbstractNode<EnumTypeDefinition> impleme
private final List<EnumValueDefinition> enumValueDefinitions;
private final List<Directive> directives;

private static final String CHILD_ENUM_VALUE_DEFINITIONS = "enumValueDefinitions";
private static final String CHILD_DIRECTIVES = "directives";

@Internal
protected EnumTypeDefinition(String name,
List<EnumValueDefinition> enumValueDefinitions,
Expand Down Expand Up @@ -63,6 +66,22 @@ public List<Node> getChildren() {
return result;
}

@Override
public ChildrenContainer getNamedChildren() {
return ChildrenContainer.newChildrenContainer()
.children(CHILD_ENUM_VALUE_DEFINITIONS, enumValueDefinitions)
.children(CHILD_DIRECTIVES, directives)
.build();
}

@Override
public EnumTypeDefinition withNewChildren(ChildrenContainer newChildren) {
return transform(builder -> builder
.enumValueDefinitions(newChildren.getList(CHILD_ENUM_VALUE_DEFINITIONS))
.directives(newChildren.getList(CHILD_DIRECTIVES))
);
}

@Override
public boolean isEqualTo(Node o) {
if (this == o) return true;
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/graphql/language/EnumValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ public List<Node> getChildren() {
return new ArrayList<>();
}

@Override
public ChildrenContainer getNamedChildren() {
return ChildrenContainer.newChildrenContainer().build();
}

@Override
public EnumValue withNewChildren(ChildrenContainer newChildren) {
if (!newChildren.isEmpty()) {
throw new IllegalArgumentException("Cannot pass non-empty newChildren to Node that doesn't hold children");
}

return this;
}

@Override
public boolean isEqualTo(Node o) {
if (this == o) return true;
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/graphql/language/EnumValueDefinition.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class EnumValueDefinition extends AbstractNode<EnumValueDefinition> imple
private final Description description;
private final List<Directive> directives;

private static final String CHILD_DIRECTIVES = "directives";

@Internal
protected EnumValueDefinition(String name,
Expand Down Expand Up @@ -64,6 +65,20 @@ public List<Node> getChildren() {
return result;
}

@Override
public ChildrenContainer getNamedChildren() {
return ChildrenContainer.newChildrenContainer()
.children(CHILD_DIRECTIVES, directives)
.build();
}

@Override
public EnumValueDefinition withNewChildren(ChildrenContainer newChildren) {
return transform(builder -> builder
.directives(newChildren.getList(CHILD_DIRECTIVES))
);
}

@Override
public boolean isEqualTo(Node o) {
if (this == o) return true;
Expand Down
Loading