templates.javaClassGraphqlRequest.ftl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of graphql-java-codegen Show documentation
Show all versions of graphql-java-codegen Show documentation
Java Code Generator based on GraphQL schema
The newest version!
<#if package?has_content>
package ${package};
#if>
import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLOperation;
import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLOperationRequest;
import java.util.LinkedHashMap;
import java.util.Map;
<#if toString || equalsAndHashCode>
import java.util.Objects;
#if>
<#if javaDoc?has_content>
/**
<#list javaDoc as javaDocLine>
* ${javaDocLine}
#list>
*/
#if>
<#if generatedInfo.getGeneratedType()?has_content>
@${generatedInfo.getGeneratedType()}(
value = "com.kobylynskyi.graphql.codegen.GraphQLCodegen",
date = "${generatedInfo.getDateTime()}"
)
#if>
<#list annotations as annotation>
@${annotation}
#list>
public class ${className} implements GraphQLOperationRequest {
private static final GraphQLOperation OPERATION_TYPE = GraphQLOperation.${operationType};
private static final String OPERATION_NAME = "${operationName}";
private Map input = new LinkedHashMap<>();
public ${className}() {
}
<#if fields?has_content>
<#list fields as field>
<#if field.javaDoc?has_content>
/**
<#list field.javaDoc as javaDocLine>
* ${javaDocLine}
#list>
*/
#if>
<#if field.deprecated>
@Deprecated
#if>
public void set${field.name?cap_first}(${field.type} ${field.name}) {
this.input.put("${field.originalName}", ${field.name});
}
#list>
#if>
@Override
public GraphQLOperation getOperationType() {
return OPERATION_TYPE;
}
@Override
public String getOperationName() {
return OPERATION_NAME;
}
@Override
public Map getInput() {
return input;
}
<#if equalsAndHashCode>
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
final ${className} that = (${className}) obj;
return Objects.equals(getOperationType(), that.getOperationType()) &&
Objects.equals(getOperationName(), that.getOperationName()) &&
Objects.equals(input, that.input);
}
@Override
public int hashCode() {
return Objects.hash(getOperationType(), getOperationName(), input);
}
#if>
<#if toString>
@Override
public String toString() {
return Objects.toString(input);
}
#if>
<#if builder>
public static class Builder {
<#if fields?has_content>
<#list fields as field>
private ${field.type} ${field.name}<#if field.defaultValue?has_content> = ${field.defaultValue}#if>;
#list>
#if>
public Builder() {
}
<#if fields?has_content>
<#list fields as field>
<#if field.javaDoc?has_content>
/**
<#list field.javaDoc as javaDocLine>
* ${javaDocLine}
#list>
*/
#if>
<#if field.deprecated>
@Deprecated
#if>
public Builder set${field.name?cap_first}(${field.type} ${field.name}) {
this.${field.name} = ${field.name};
return this;
}
#list>
#if>
public ${className} build() {
${className} obj = new ${className}();
<#if fields?has_content>
<#list fields as field>
obj.set${field.name?cap_first}(${field.name});
#list>
#if>
return obj;
}
}
#if>
}