graphql.schema.GraphQLArgument Maven / Gradle / Ivy
The newest version!
package graphql.schema;
import graphql.language.InputValueDefinition;
import java.util.Map;
import static graphql.Assert.assertNotNull;
import static graphql.Assert.assertValidName;
public class GraphQLArgument {
private final String name;
private final String description;
private GraphQLInputType type;
private final Object defaultValue;
private final InputValueDefinition definition;
public GraphQLArgument(String name, String description, GraphQLInputType type, Object defaultValue) {
this(name, description, type, defaultValue, null);
}
public GraphQLArgument(String name, GraphQLInputType type) {
this(name, null, type, null, null);
}
public GraphQLArgument(String name, String description, GraphQLInputType type, Object defaultValue, InputValueDefinition definition) {
assertValidName(name);
assertNotNull(type, "type can't be null");
this.name = name;
this.description = description;
this.type = type;
this.defaultValue = defaultValue;
this.definition = definition;
}
void replaceTypeReferences(Map typeMap) {
type = (GraphQLInputType) new SchemaUtil().resolveTypeReference(type, typeMap);
}
public String getName() {
return name;
}
public GraphQLInputType getType() {
return type;
}
public Object getDefaultValue() {
return defaultValue;
}
public String getDescription() {
return description;
}
public InputValueDefinition getDefinition() {
return definition;
}
public static Builder newArgument() {
return new Builder();
}
public static class Builder {
private String name;
private GraphQLInputType type;
private Object defaultValue;
private String description;
private InputValueDefinition definition;
public Builder name(String name) {
this.name = name;
return this;
}
public Builder description(String description) {
this.description = description;
return this;
}
public Builder definition(InputValueDefinition definition) {
this.definition = definition;
return this;
}
public Builder type(GraphQLInputType type) {
this.type = type;
return this;
}
public Builder defaultValue(Object defaultValue) {
this.defaultValue = defaultValue;
return this;
}
public GraphQLArgument build() {
return new GraphQLArgument(name, description, type, defaultValue, definition);
}
}
}