com.kobylynskyi.graphql.codegen.mapper.InputDefinitionToDataModelMapper 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!
package com.kobylynskyi.graphql.codegen.mapper;
import com.kobylynskyi.graphql.codegen.model.MappingContext;
import com.kobylynskyi.graphql.codegen.model.definitions.ExtendedInputObjectTypeDefinition;
import java.util.HashMap;
import java.util.Map;
import static com.kobylynskyi.graphql.codegen.model.DataModelFields.ANNOTATIONS;
import static com.kobylynskyi.graphql.codegen.model.DataModelFields.BUILDER;
import static com.kobylynskyi.graphql.codegen.model.DataModelFields.CLASS_NAME;
import static com.kobylynskyi.graphql.codegen.model.DataModelFields.EQUALS_AND_HASH_CODE;
import static com.kobylynskyi.graphql.codegen.model.DataModelFields.FIELDS;
import static com.kobylynskyi.graphql.codegen.model.DataModelFields.GENERATED_INFO;
import static com.kobylynskyi.graphql.codegen.model.DataModelFields.IMMUTABLE_MODELS;
import static com.kobylynskyi.graphql.codegen.model.DataModelFields.JAVA_DOC;
import static com.kobylynskyi.graphql.codegen.model.DataModelFields.NAME;
import static com.kobylynskyi.graphql.codegen.model.DataModelFields.PACKAGE;
import static com.kobylynskyi.graphql.codegen.model.DataModelFields.TO_STRING;
import static com.kobylynskyi.graphql.codegen.model.DataModelFields.TO_STRING_FOR_REQUEST;
/**
* Map input type definition to a Freemarker data model
*
* @author kobylynskyi
*/
public class InputDefinitionToDataModelMapper {
private InputDefinitionToDataModelMapper() {
}
/**
* Map input type definition to a Freemarker data model
*
* @param mappingContext Global mapping context
* @param definition Definition of input type including base definition and its extensions
* @return Freemarker data model of the GraphQL type
*/
public static Map map(MappingContext mappingContext, ExtendedInputObjectTypeDefinition definition) {
Map dataModel = new HashMap<>();
// type/enum/input/interface/union classes do not require any imports
dataModel.put(PACKAGE, MapperUtils.getModelPackageName(mappingContext));
dataModel.put(CLASS_NAME, MapperUtils.getModelClassNameWithPrefixAndSuffix(mappingContext, definition));
dataModel.put(JAVA_DOC, definition.getJavaDoc());
dataModel.put(NAME, definition.getName());
dataModel.put(FIELDS, InputValueDefinitionToParameterMapper.map(mappingContext, definition.getValueDefinitions(), definition.getName()));
dataModel.put(ANNOTATIONS, GraphqlTypeToJavaTypeMapper.getAnnotations(mappingContext, definition));
dataModel.put(BUILDER, mappingContext.getGenerateBuilder());
dataModel.put(EQUALS_AND_HASH_CODE, mappingContext.getGenerateEqualsAndHashCode());
dataModel.put(IMMUTABLE_MODELS, mappingContext.getGenerateImmutableModels());
dataModel.put(TO_STRING, mappingContext.getGenerateToString());
dataModel.put(TO_STRING_FOR_REQUEST, mappingContext.getGenerateClient());
dataModel.put(GENERATED_INFO, mappingContext.getGeneratedInformation());
return dataModel;
}
}