com.kobylynskyi.graphql.codegen.mapper.UnionDefinitionToDataModelMapper 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.ExtendedUnionTypeDefinition;
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.CLASS_NAME;
import static com.kobylynskyi.graphql.codegen.model.DataModelFields.GENERATED_INFO;
import static com.kobylynskyi.graphql.codegen.model.DataModelFields.JAVA_DOC;
import static com.kobylynskyi.graphql.codegen.model.DataModelFields.PACKAGE;
/**
* Map union definition to a Freemarker data model
*
* @author kobylynskyi
*/
public class UnionDefinitionToDataModelMapper {
private UnionDefinitionToDataModelMapper() {
}
/**
* Map union definition to a Freemarker data model
*
* @param mappingContext Global mapping context
* @param definition Definition of union type including base definition and its extensions
* @return Freemarker data model of the GraphQL union
*/
public static Map map(MappingContext mappingContext, ExtendedUnionTypeDefinition 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(ANNOTATIONS, GraphqlTypeToJavaTypeMapper.getAnnotations(mappingContext, definition));
dataModel.put(JAVA_DOC, definition.getJavaDoc());
dataModel.put(GENERATED_INFO, mappingContext.getGeneratedInformation());
return dataModel;
}
}