graphql.language.SchemaDefinition Maven / Gradle / Ivy
package graphql.language;
import graphql.Internal;
import graphql.PublicApi;
import graphql.util.TraversalControl;
import graphql.util.TraverserContext;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import static graphql.language.NodeUtil.directivesByName;
@PublicApi
public class SchemaDefinition extends AbstractNode implements SDLDefinition {
private final List directives;
private final List operationTypeDefinitions;
@Internal
protected SchemaDefinition(List directives,
List operationTypeDefinitions,
SourceLocation sourceLocation,
List comments) {
super(sourceLocation, comments);
this.directives = directives;
this.operationTypeDefinitions = operationTypeDefinitions;
}
public List getDirectives() {
return new ArrayList<>(directives);
}
public Map getDirectivesByName() {
return directivesByName(directives);
}
public Directive getDirective(String directiveName) {
return getDirectivesByName().get(directiveName);
}
public List getOperationTypeDefinitions() {
return operationTypeDefinitions;
}
@Override
public List getChildren() {
List result = new ArrayList<>();
result.addAll(directives);
result.addAll(operationTypeDefinitions);
return result;
}
@Override
public boolean isEqualTo(Node o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
SchemaDefinition that = (SchemaDefinition) o;
return true;
}
@Override
public SchemaDefinition deepCopy() {
return new SchemaDefinition(deepCopy(directives), deepCopy(operationTypeDefinitions), getSourceLocation(), getComments());
}
@Override
public String toString() {
return "SchemaDefinition{" +
"directives=" + directives +
", operationTypeDefinitions=" + operationTypeDefinitions +
"}";
}
@Override
public TraversalControl accept(TraverserContext context, NodeVisitor visitor) {
return visitor.visitSchemaDefinition(this, context);
}
public SchemaDefinition transform(Consumer builderConsumer) {
Builder builder = new Builder(this);
builderConsumer.accept(builder);
return builder.build();
}
public static Builder newSchemaDefinition() {
return new Builder();
}
public static final class Builder implements NodeBuilder {
private SourceLocation sourceLocation;
private List comments = new ArrayList<>();
private List directives = new ArrayList<>();
private List operationTypeDefinitions = new ArrayList<>();
private Builder() {
}
private Builder(SchemaDefinition existing) {
this.sourceLocation = existing.getSourceLocation();
this.comments = existing.getComments();
this.directives = existing.getDirectives();
this.operationTypeDefinitions = existing.getOperationTypeDefinitions();
}
public Builder sourceLocation(SourceLocation sourceLocation) {
this.sourceLocation = sourceLocation;
return this;
}
public Builder comments(List comments) {
this.comments = comments;
return this;
}
public Builder directives(List directives) {
this.directives = directives;
return this;
}
public Builder directive(Directive directive) {
this.directives.add(directive);
return this;
}
public Builder operationTypeDefinitions(List operationTypeDefinitions) {
this.operationTypeDefinitions = operationTypeDefinitions;
return this;
}
public Builder operationTypeDefinition(OperationTypeDefinition operationTypeDefinitions) {
this.operationTypeDefinitions.add(operationTypeDefinitions);
return this;
}
public SchemaDefinition build() {
SchemaDefinition schemaDefinition = new SchemaDefinition(directives,
operationTypeDefinitions,
sourceLocation,
comments);
return schemaDefinition;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy