All Downloads are FREE. Search and download functionalities are using the official Maven repository.

templates.javaClassGraphqlOperationDefaultImplements.ftl Maven / Gradle / Ivy

The newest version!
<#if package?has_content>
package ${package};


import com.kobylynskyi.graphql.codegen.extension.GrowingIOConfig;
import com.kobylynskyi.graphql.codegen.extension.utils.JavaCollectionUtils;
import com.kobylynskyi.graphql.codegen.extension.utils.OkHttpUtils;
import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLRequest;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
<#list imports as import>
<#if import?has_content>
import ${import}.*;



<#if javaDoc?has_content>
/**
<#list javaDoc as javaDocLine>
 * ${javaDocLine}

 */

<#if generatedInfo.getGeneratedType()?has_content>
@${generatedInfo.getGeneratedType()}(
    value = "com.kobylynskyi.graphql.codegen.GraphQLCodegen",
    date = "${generatedInfo.getDateTime()}"
)

final public class ${className} implements ${className?substring(defaultResolverImplPrefix?length, className?length)} {

    private GrowingIOConfig growingIOConfig;

    public ${className}(GrowingIOConfig growingIOConfig) {
        this.growingIOConfig = growingIOConfig;
    }

    private ${className}() {}

<#list operations as operation>
<#if operation.javaDoc?has_content>
    /**
    <#list operation.javaDoc as javaDocLine>
     * ${javaDocLine}
    
     */

<#if operation.deprecated>
    @Deprecated

<#list operation.annotations as annotation>
    @${annotation}

    @Override
    public ${operation.type} ${operation.name}(<#list operation.parameters as param>${param.type} ${param.name}<#if param_has_next>, ) throws Exception {
        ${operateNameRequestName} request = new ${operateNameRequestName}();
        <#if operation.parameters?? && (operation.parameters?size > 0) >
        List keys = Arrays.asList(<#list operation.parameters as param>"${param.originalName}"<#if param_has_next>, );
        List values = Arrays.asList(<#list operation.parameters as param>${param.name}<#if param_has_next>, );
        Map parameters = JavaCollectionUtils.listToMap(keys, values);
        request.getInput().putAll(parameters);
        
        <#if operateNameProjectionName?has_content>
        ${operateNameProjectionName} projection = new ${operateNameProjectionName}().all$(growingIOConfig.getResponseProjectionMaxDepth());
        GraphQLRequest graphQLRequest = new GraphQLRequest(request, projection);
        <#else>
        GraphQLRequest graphQLRequest = new GraphQLRequest(request, null);
        
        ${operateNameResponseName} result = OkHttpUtils.executeGraphQLRemote(growingIOConfig, graphQLRequest, ${operateNameResponseName}.class);
        return result.${operation.name}();
    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy