提交 7d3f79ba 编写于 作者: B Bogdan Kobylynskyi

Introduce apiNamePrefix and apiNameSuffix config options #136 (#166)

上级 25aa7108
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
| `generateDataFetchingEnvironmentArgumentInApis` | Boolean | False | If true, then `graphql.schema.DataFetchingEnvironment env` will be added as a last argument to all methods of root type resolvers and field resolvers. | | `generateDataFetchingEnvironmentArgumentInApis` | Boolean | False | If true, then `graphql.schema.DataFetchingEnvironment env` will be added as a last argument to all methods of root type resolvers and field resolvers. |
| `generateEqualsAndHashCode` | Boolean | False | Specifies whether generated model classes should have equals and hashCode methods defined. | | `generateEqualsAndHashCode` | Boolean | False | Specifies whether generated model classes should have equals and hashCode methods defined. |
| `generateToString` | Boolean | False | Specifies whether generated model classes should have toString method defined. | | `generateToString` | Boolean | False | Specifies whether generated model classes should have toString method defined. |
| `apiNamePrefix` | String | Empty | Sets the prefix for GraphQL api classes (query, mutation, subscription). |
| `apiNameSuffix` | String | Resolver | Sets the suffix for GraphQL api classes (query, mutation, subscription). |
| `modelNamePrefix` | String | Empty | Sets the prefix for GraphQL model classes (type, input, interface, enum, union). | | `modelNamePrefix` | String | Empty | Sets the prefix for GraphQL model classes (type, input, interface, enum, union). |
| `modelNameSuffix` | String | Empty | Sets the suffix for GraphQL model classes (type, input, interface, enum, union). | | `modelNameSuffix` | String | Empty | Sets the suffix for GraphQL model classes (type, input, interface, enum, union). |
| `modelValidationAnnotation` | String | @javax.validation.<br>constraints.NotNull | Annotation for mandatory (NonNull) fields. Can be null/empty. | | `modelValidationAnnotation` | String | @javax.validation.<br>constraints.NotNull | Annotation for mandatory (NonNull) fields. Can be null/empty. |
......
package io.github.kobylynskyi.order.graphql.resolvers; package io.github.kobylynskyi.order.graphql.resolvers;
import graphql.kickstart.tools.GraphQLMutationResolver; import graphql.kickstart.tools.GraphQLMutationResolver;
import io.github.kobylynskyi.order.graphql.api.Mutation; import io.github.kobylynskyi.order.graphql.api.AddProductToOrderMutationResolver;
import io.github.kobylynskyi.order.graphql.api.CreateMutationResolver;
import io.github.kobylynskyi.order.graphql.mappers.OrderMapper; import io.github.kobylynskyi.order.graphql.mappers.OrderMapper;
import io.github.kobylynskyi.order.graphql.model.OrderTO; import io.github.kobylynskyi.order.graphql.model.OrderTO;
import io.github.kobylynskyi.order.service.OrderService; import io.github.kobylynskyi.order.service.OrderService;
...@@ -9,7 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -9,7 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@Component @Component
public class MutationsResolver implements Mutation, GraphQLMutationResolver { public class MutationsResolver implements CreateMutationResolver, AddProductToOrderMutationResolver, GraphQLMutationResolver {
@Autowired @Autowired
private OrderService service; private OrderService service;
......
package io.github.kobylynskyi.order.graphql.resolvers; package io.github.kobylynskyi.order.graphql.resolvers;
import graphql.kickstart.tools.GraphQLQueryResolver; import graphql.kickstart.tools.GraphQLQueryResolver;
import io.github.kobylynskyi.order.graphql.api.Query; import io.github.kobylynskyi.order.graphql.api.OrderByIdQueryResolver;
import io.github.kobylynskyi.order.graphql.api.OrdersQueryResolver;
import io.github.kobylynskyi.order.graphql.mappers.OrderMapper; import io.github.kobylynskyi.order.graphql.mappers.OrderMapper;
import io.github.kobylynskyi.order.graphql.model.OrderTO; import io.github.kobylynskyi.order.graphql.model.OrderTO;
import io.github.kobylynskyi.order.model.OrderNotFoundException; import io.github.kobylynskyi.order.model.OrderNotFoundException;
...@@ -14,7 +15,7 @@ import java.util.Collection; ...@@ -14,7 +15,7 @@ import java.util.Collection;
import static java.util.stream.Collectors.toList; import static java.util.stream.Collectors.toList;
@Component @Component
public class QueriesResolver implements Query, GraphQLQueryResolver { public class QueriesResolver implements OrdersQueryResolver, OrderByIdQueryResolver, GraphQLQueryResolver {
@Autowired @Autowired
private OrderService service; private OrderService service;
......
package io.github.kobylynskyi.product.graphql.resolvers; package io.github.kobylynskyi.product.graphql.resolvers;
import io.github.kobylynskyi.product.graphql.api.Mutation; import io.github.kobylynskyi.product.graphql.api.CreateMutationResolver;
import io.github.kobylynskyi.product.graphql.mappers.ProductMapper; import io.github.kobylynskyi.product.graphql.mappers.ProductMapper;
import io.github.kobylynskyi.product.graphql.model.ProductInputTO; import io.github.kobylynskyi.product.graphql.model.ProductInputTO;
import io.github.kobylynskyi.product.graphql.model.ProductTO; import io.github.kobylynskyi.product.graphql.model.ProductTO;
...@@ -10,7 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -10,7 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@Component @Component
public class MutationsResolver implements Mutation { public class MutationsResolver implements CreateMutationResolver {
@Autowired @Autowired
private ProductService service; private ProductService service;
......
package io.github.kobylynskyi.product.graphql.resolvers; package io.github.kobylynskyi.product.graphql.resolvers;
import io.github.kobylynskyi.product.graphql.api.Query; import io.github.kobylynskyi.product.graphql.api.ProductByIdQueryResolver;
import io.github.kobylynskyi.product.graphql.api.ProductsByIdsQueryResolver;
import io.github.kobylynskyi.product.graphql.api.ProductsQueryResolver;
import io.github.kobylynskyi.product.graphql.mappers.ProductMapper; import io.github.kobylynskyi.product.graphql.mappers.ProductMapper;
import io.github.kobylynskyi.product.graphql.model.ProductTO; import io.github.kobylynskyi.product.graphql.model.ProductTO;
import io.github.kobylynskyi.product.service.ProductService; import io.github.kobylynskyi.product.service.ProductService;
...@@ -12,7 +14,7 @@ import java.util.Collection; ...@@ -12,7 +14,7 @@ import java.util.Collection;
import static java.util.stream.Collectors.toList; import static java.util.stream.Collectors.toList;
@Component @Component
public class QueriesResolver implements Query { public class QueriesResolver implements ProductsQueryResolver, ProductsByIdsQueryResolver, ProductByIdQueryResolver {
@Autowired @Autowired
private ProductService service; private ProductService service;
......
...@@ -33,6 +33,8 @@ public class GraphQLCodegenGradleTask extends DefaultTask implements GraphQLCode ...@@ -33,6 +33,8 @@ public class GraphQLCodegenGradleTask extends DefaultTask implements GraphQLCode
private Map<String, String> customAnnotationsMapping = new HashMap<>(); private Map<String, String> customAnnotationsMapping = new HashMap<>();
private String packageName; private String packageName;
private String apiPackageName; private String apiPackageName;
private String apiNamePrefix;
private String apiNameSuffix;
private String modelPackageName; private String modelPackageName;
private String modelNamePrefix; private String modelNamePrefix;
private String modelNameSuffix; private String modelNameSuffix;
...@@ -73,6 +75,8 @@ public class GraphQLCodegenGradleTask extends DefaultTask implements GraphQLCode ...@@ -73,6 +75,8 @@ public class GraphQLCodegenGradleTask extends DefaultTask implements GraphQLCode
MappingConfig mappingConfig = new MappingConfig(); MappingConfig mappingConfig = new MappingConfig();
mappingConfig.setPackageName(packageName); mappingConfig.setPackageName(packageName);
mappingConfig.setCustomTypesMapping(customTypesMapping); mappingConfig.setCustomTypesMapping(customTypesMapping);
mappingConfig.setApiNameSuffix(apiNameSuffix);
mappingConfig.setApiNamePrefix(apiNamePrefix);
mappingConfig.setModelNamePrefix(modelNamePrefix); mappingConfig.setModelNamePrefix(modelNamePrefix);
mappingConfig.setModelNameSuffix(modelNameSuffix); mappingConfig.setModelNameSuffix(modelNameSuffix);
mappingConfig.setApiPackageName(apiPackageName); mappingConfig.setApiPackageName(apiPackageName);
...@@ -232,6 +236,28 @@ public class GraphQLCodegenGradleTask extends DefaultTask implements GraphQLCode ...@@ -232,6 +236,28 @@ public class GraphQLCodegenGradleTask extends DefaultTask implements GraphQLCode
this.apiPackageName = apiPackageName; this.apiPackageName = apiPackageName;
} }
@Input
@Optional
@Override
public String getApiNamePrefix() {
return apiNamePrefix;
}
public void setApiNamePrefix(String apiNamePrefix) {
this.apiNamePrefix = apiNamePrefix;
}
@Input
@Optional
@Override
public String getApiNameSuffix() {
return apiNameSuffix;
}
public void setApiNameSuffix(String apiNameSuffix) {
this.apiNameSuffix = apiNameSuffix;
}
@Input @Input
@Optional @Optional
@Override @Override
......
package io.github.kobylynskyi.order.graphql.resolvers; package io.github.kobylynskyi.order.graphql.resolvers;
import graphql.kickstart.tools.GraphQLMutationResolver; import graphql.kickstart.tools.GraphQLMutationResolver;
import io.github.kobylynskyi.order.graphql.api.Mutation; import io.github.kobylynskyi.order.graphql.api.AddProductToOrderMutationResolver;
import io.github.kobylynskyi.order.graphql.api.CreateMutationResolver;
import io.github.kobylynskyi.order.graphql.mappers.OrderMapper; import io.github.kobylynskyi.order.graphql.mappers.OrderMapper;
import io.github.kobylynskyi.order.graphql.model.OrderTO; import io.github.kobylynskyi.order.graphql.model.OrderTO;
import io.github.kobylynskyi.order.service.OrderService; import io.github.kobylynskyi.order.service.OrderService;
...@@ -9,7 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -9,7 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@Component @Component
public class MutationsResolver implements Mutation, GraphQLMutationResolver { public class MutationsResolver implements CreateMutationResolver, AddProductToOrderMutationResolver, GraphQLMutationResolver {
@Autowired @Autowired
private OrderService service; private OrderService service;
......
package io.github.kobylynskyi.order.graphql.resolvers; package io.github.kobylynskyi.order.graphql.resolvers;
import graphql.kickstart.tools.GraphQLQueryResolver; import graphql.kickstart.tools.GraphQLQueryResolver;
import io.github.kobylynskyi.order.graphql.api.Query; import io.github.kobylynskyi.order.graphql.api.OrderByIdQueryResolver;
import io.github.kobylynskyi.order.graphql.api.OrdersQueryResolver;
import io.github.kobylynskyi.order.graphql.mappers.OrderMapper; import io.github.kobylynskyi.order.graphql.mappers.OrderMapper;
import io.github.kobylynskyi.order.graphql.model.OrderTO; import io.github.kobylynskyi.order.graphql.model.OrderTO;
import io.github.kobylynskyi.order.model.OrderNotFoundException; import io.github.kobylynskyi.order.model.OrderNotFoundException;
...@@ -14,7 +15,7 @@ import java.util.Collection; ...@@ -14,7 +15,7 @@ import java.util.Collection;
import static java.util.stream.Collectors.toList; import static java.util.stream.Collectors.toList;
@Component @Component
public class QueriesResolver implements Query, GraphQLQueryResolver { public class QueriesResolver implements OrdersQueryResolver, OrderByIdQueryResolver, GraphQLQueryResolver {
@Autowired @Autowired
private OrderService service; private OrderService service;
......
package io.github.kobylynskyi.product.graphql.resolvers; package io.github.kobylynskyi.product.graphql.resolvers;
import io.github.kobylynskyi.product.graphql.api.Mutation; import io.github.kobylynskyi.product.graphql.api.CreateMutationResolver;
import io.github.kobylynskyi.product.graphql.mappers.ProductMapper; import io.github.kobylynskyi.product.graphql.mappers.ProductMapper;
import io.github.kobylynskyi.product.graphql.model.ProductInputTO; import io.github.kobylynskyi.product.graphql.model.ProductInputTO;
import io.github.kobylynskyi.product.graphql.model.ProductTO; import io.github.kobylynskyi.product.graphql.model.ProductTO;
...@@ -10,7 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -10,7 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@Component @Component
public class MutationsResolver implements Mutation { public class MutationsResolver implements CreateMutationResolver {
@Autowired @Autowired
private ProductService service; private ProductService service;
......
package io.github.kobylynskyi.product.graphql.resolvers; package io.github.kobylynskyi.product.graphql.resolvers;
import io.github.kobylynskyi.product.graphql.api.Query; import io.github.kobylynskyi.product.graphql.api.ProductByIdQueryResolver;
import io.github.kobylynskyi.product.graphql.api.ProductsByIdsQueryResolver;
import io.github.kobylynskyi.product.graphql.api.ProductsQueryResolver;
import io.github.kobylynskyi.product.graphql.mappers.ProductMapper; import io.github.kobylynskyi.product.graphql.mappers.ProductMapper;
import io.github.kobylynskyi.product.graphql.model.ProductTO; import io.github.kobylynskyi.product.graphql.model.ProductTO;
import io.github.kobylynskyi.product.service.ProductService; import io.github.kobylynskyi.product.service.ProductService;
...@@ -12,7 +14,7 @@ import java.util.Collection; ...@@ -12,7 +14,7 @@ import java.util.Collection;
import static java.util.stream.Collectors.toList; import static java.util.stream.Collectors.toList;
@Component @Component
public class QueriesResolver implements Query { public class QueriesResolver implements ProductsQueryResolver, ProductsByIdsQueryResolver, ProductByIdQueryResolver {
@Autowired @Autowired
private ProductService service; private ProductService service;
......
...@@ -63,6 +63,12 @@ public class GraphQLCodegenMojo extends AbstractMojo implements GraphQLCodegenCo ...@@ -63,6 +63,12 @@ public class GraphQLCodegenMojo extends AbstractMojo implements GraphQLCodegenCo
@Parameter @Parameter
private String apiPackageName; private String apiPackageName;
@Parameter
private String apiNamePrefix;
@Parameter(defaultValue = MappingConfigConstants.DEFAULT_API_NAME_SUFFIX)
private String apiNameSuffix;
@Parameter @Parameter
private String modelPackageName; private String modelPackageName;
...@@ -138,6 +144,8 @@ public class GraphQLCodegenMojo extends AbstractMojo implements GraphQLCodegenCo ...@@ -138,6 +144,8 @@ public class GraphQLCodegenMojo extends AbstractMojo implements GraphQLCodegenCo
MappingConfig mappingConfig = new MappingConfig(); MappingConfig mappingConfig = new MappingConfig();
mappingConfig.setPackageName(packageName); mappingConfig.setPackageName(packageName);
mappingConfig.setCustomTypesMapping(customTypesMapping != null ? customTypesMapping : new HashMap<>()); mappingConfig.setCustomTypesMapping(customTypesMapping != null ? customTypesMapping : new HashMap<>());
mappingConfig.setApiNameSuffix(apiNameSuffix);
mappingConfig.setApiNamePrefix(apiNamePrefix);
mappingConfig.setModelNamePrefix(modelNamePrefix); mappingConfig.setModelNamePrefix(modelNamePrefix);
mappingConfig.setModelNameSuffix(modelNameSuffix); mappingConfig.setModelNameSuffix(modelNameSuffix);
mappingConfig.setApiPackageName(apiPackageName); mappingConfig.setApiPackageName(apiPackageName);
...@@ -264,6 +272,24 @@ public class GraphQLCodegenMojo extends AbstractMojo implements GraphQLCodegenCo ...@@ -264,6 +272,24 @@ public class GraphQLCodegenMojo extends AbstractMojo implements GraphQLCodegenCo
this.apiPackageName = apiPackageName; this.apiPackageName = apiPackageName;
} }
@Override
public String getApiNamePrefix() {
return apiNamePrefix;
}
public void setApiNamePrefix(String apiNamePrefix) {
this.apiNamePrefix = apiNamePrefix;
}
@Override
public String getApiNameSuffix() {
return apiNameSuffix;
}
public void setApiNameSuffix(String apiNameSuffix) {
this.apiNameSuffix = apiNameSuffix;
}
@Override @Override
public String getModelPackageName() { public String getModelPackageName() {
return modelPackageName; return modelPackageName;
......
...@@ -96,6 +96,9 @@ public class GraphQLCodegen { ...@@ -96,6 +96,9 @@ public class GraphQLCodegen {
if (mappingConfig.getGenerateApis() == null) { if (mappingConfig.getGenerateApis() == null) {
mappingConfig.setGenerateApis(MappingConfigConstants.DEFAULT_GENERATE_APIS); mappingConfig.setGenerateApis(MappingConfigConstants.DEFAULT_GENERATE_APIS);
} }
if (mappingConfig.getApiNameSuffix() == null) {
mappingConfig.setApiNameSuffix(MappingConfigConstants.DEFAULT_API_NAME_SUFFIX);
}
if (mappingConfig.getGenerateAsyncApi() == null) { if (mappingConfig.getGenerateAsyncApi() == null) {
mappingConfig.setGenerateAsyncApi(MappingConfigConstants.DEFAULT_GENERATE_ASYNC_APIS); mappingConfig.setGenerateAsyncApi(MappingConfigConstants.DEFAULT_GENERATE_ASYNC_APIS);
} }
......
...@@ -60,7 +60,7 @@ public class DefaultValueMapper { ...@@ -60,7 +60,7 @@ public class DefaultValueMapper {
private static String mapEnum(MappingContext mappingContext, Type<?> graphQLType, EnumValue defaultValue) { private static String mapEnum(MappingContext mappingContext, Type<?> graphQLType, EnumValue defaultValue) {
if (graphQLType instanceof TypeName) { if (graphQLType instanceof TypeName) {
String typeName = ((TypeName) graphQLType).getName(); String typeName = ((TypeName) graphQLType).getName();
typeName = MapperUtils.getClassNameWithPrefixAndSuffix(mappingContext, typeName); typeName = MapperUtils.getModelClassNameWithPrefixAndSuffix(mappingContext, typeName);
return typeName + "." + defaultValue.getName(); return typeName + "." + defaultValue.getName();
} }
if (graphQLType instanceof NonNullType) { if (graphQLType instanceof NonNullType) {
......
...@@ -40,7 +40,7 @@ public class EnumDefinitionToDataModelMapper { ...@@ -40,7 +40,7 @@ public class EnumDefinitionToDataModelMapper {
Map<String, Object> dataModel = new HashMap<>(); Map<String, Object> dataModel = new HashMap<>();
// type/enum/input/interface/union classes do not require any imports // type/enum/input/interface/union classes do not require any imports
dataModel.put(PACKAGE, MapperUtils.getModelPackageName(mappingContext)); dataModel.put(PACKAGE, MapperUtils.getModelPackageName(mappingContext));
dataModel.put(CLASS_NAME, MapperUtils.getClassNameWithPrefixAndSuffix(mappingContext, definition)); dataModel.put(CLASS_NAME, MapperUtils.getModelClassNameWithPrefixAndSuffix(mappingContext, definition));
dataModel.put(IMPLEMENTS, getUnionInterfaces(mappingContext, definition)); dataModel.put(IMPLEMENTS, getUnionInterfaces(mappingContext, definition));
dataModel.put(JAVA_DOC, definition.getJavaDoc()); dataModel.put(JAVA_DOC, definition.getJavaDoc());
dataModel.put(FIELDS, map(definition.getValueDefinitions())); dataModel.put(FIELDS, map(definition.getValueDefinitions()));
...@@ -53,7 +53,7 @@ public class EnumDefinitionToDataModelMapper { ...@@ -53,7 +53,7 @@ public class EnumDefinitionToDataModelMapper {
.stream() .stream()
.filter(union -> union.isDefinitionPartOfUnion(definition)) .filter(union -> union.isDefinitionPartOfUnion(definition))
.map(ExtendedUnionTypeDefinition::getName) .map(ExtendedUnionTypeDefinition::getName)
.map(unionName -> MapperUtils.getClassNameWithPrefixAndSuffix(mappingContext, unionName)) .map(unionName -> MapperUtils.getModelClassNameWithPrefixAndSuffix(mappingContext, unionName))
.collect(Collectors.toSet()); .collect(Collectors.toSet());
} }
......
...@@ -9,10 +9,20 @@ import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLOperation; ...@@ -9,10 +9,20 @@ import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLOperation;
import com.kobylynskyi.graphql.codegen.utils.Utils; import com.kobylynskyi.graphql.codegen.utils.Utils;
import graphql.language.TypeName; import graphql.language.TypeName;
import java.util.*; import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static com.kobylynskyi.graphql.codegen.model.DataModelFields.*; import static com.kobylynskyi.graphql.codegen.model.DataModelFields.CLASS_NAME;
import static com.kobylynskyi.graphql.codegen.model.DataModelFields.IMPLEMENTS;
import static com.kobylynskyi.graphql.codegen.model.DataModelFields.IMPORTS;
import static com.kobylynskyi.graphql.codegen.model.DataModelFields.JAVA_DOC;
import static com.kobylynskyi.graphql.codegen.model.DataModelFields.OPERATIONS;
import static com.kobylynskyi.graphql.codegen.model.DataModelFields.PACKAGE;
import static com.kobylynskyi.graphql.codegen.model.MappingConfigConstants.PARENT_INTERFACE_TYPE_PLACEHOLDER; import static com.kobylynskyi.graphql.codegen.model.MappingConfigConstants.PARENT_INTERFACE_TYPE_PLACEHOLDER;
import static java.util.Collections.emptyList; import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList; import static java.util.Collections.singletonList;
...@@ -53,13 +63,7 @@ public class FieldDefinitionsToResolverDataModelMapper { ...@@ -53,13 +63,7 @@ public class FieldDefinitionsToResolverDataModelMapper {
ExtendedFieldDefinition fieldDefinition, ExtendedFieldDefinition fieldDefinition,
String rootTypeName, String rootTypeName,
List<String> fieldNames) { List<String> fieldNames) {
String fieldDefinitionName = fieldDefinition.getName(); String className = MapperUtils.getApiClassNameWithPrefixAndSuffix(mappingContext, fieldDefinition, rootTypeName, fieldNames);
if (Collections.frequency(fieldNames, fieldDefinitionName) > 1) {
// Examples: EventsByIdsQuery, EventsByCategoryAndStatusQuery
fieldDefinitionName += MapperUtils.getClassNameSuffixWithInputValues(fieldDefinition);
}
// Examples: CreateEventMutation, EventsQuery, EventsByIdsQuery (rootTypeName is "Query" or the likes)
String className = Utils.capitalize(fieldDefinitionName) + rootTypeName;
List<ExtendedFieldDefinition> fieldDefs = Collections.singletonList(fieldDefinition); List<ExtendedFieldDefinition> fieldDefs = Collections.singletonList(fieldDefinition);
return mapToResolverModel(mappingContext, rootTypeName, className, fieldDefs, fieldDefinition.getJavaDoc(), return mapToResolverModel(mappingContext, rootTypeName, className, fieldDefs, fieldDefinition.getJavaDoc(),
getParentInterface(mappingContext, rootTypeName)); getParentInterface(mappingContext, rootTypeName));
...@@ -74,12 +78,11 @@ public class FieldDefinitionsToResolverDataModelMapper { ...@@ -74,12 +78,11 @@ public class FieldDefinitionsToResolverDataModelMapper {
*/ */
public static Map<String, Object> mapRootTypeFields(MappingContext mappingContext, public static Map<String, Object> mapRootTypeFields(MappingContext mappingContext,
ExtendedObjectTypeDefinition definition) { ExtendedObjectTypeDefinition definition) {
String parentTypeName = definition.getName(); String className = MapperUtils.getApiClassNameWithPrefixAndSuffix(mappingContext, definition);
String className = Utils.capitalize(parentTypeName);
// For root types like "Query", we create resolvers for all fields // For root types like "Query", we create resolvers for all fields
return mapToResolverModel(mappingContext, parentTypeName, className, return mapToResolverModel(mappingContext, definition.getName(), className,
definition.getFieldDefinitions(), definition.getJavaDoc(), definition.getFieldDefinitions(), definition.getJavaDoc(),
getParentInterface(mappingContext, parentTypeName)); getParentInterface(mappingContext, definition.getName()));
} }
private static Map<String, Object> mapToResolverModel(MappingContext mappingContext, String parentTypeName, private static Map<String, Object> mapToResolverModel(MappingContext mappingContext, String parentTypeName,
...@@ -183,7 +186,7 @@ public class FieldDefinitionsToResolverDataModelMapper { ...@@ -183,7 +186,7 @@ public class FieldDefinitionsToResolverDataModelMapper {
} }
return mappingContext.getResolverParentInterface() return mappingContext.getResolverParentInterface()
.replace(PARENT_INTERFACE_TYPE_PLACEHOLDER, .replace(PARENT_INTERFACE_TYPE_PLACEHOLDER,
MapperUtils.getClassNameWithPrefixAndSuffix(mappingContext, typeName)); MapperUtils.getModelClassNameWithPrefixAndSuffix(mappingContext, typeName));
} }
} }
...@@ -100,7 +100,7 @@ class GraphqlTypeToJavaTypeMapper { ...@@ -100,7 +100,7 @@ class GraphqlTypeToJavaTypeMapper {
} else if (customTypesMapping.containsKey(graphQLType)) { } else if (customTypesMapping.containsKey(graphQLType)) {
javaTypeName = customTypesMapping.get(graphQLType); javaTypeName = customTypesMapping.get(graphQLType);
} else { } else {
javaTypeName = MapperUtils.getClassNameWithPrefixAndSuffix(mappingContext, graphQLType); javaTypeName = MapperUtils.getModelClassNameWithPrefixAndSuffix(mappingContext, graphQLType);
} }
return new NamedDefinition(javaTypeName, mappingContext.getInterfaceNames().contains(graphQLType)); return new NamedDefinition(javaTypeName, mappingContext.getInterfaceNames().contains(graphQLType));
} }
......
...@@ -26,7 +26,7 @@ public class InputDefinitionToDataModelMapper { ...@@ -26,7 +26,7 @@ public class InputDefinitionToDataModelMapper {
Map<String, Object> dataModel = new HashMap<>(); Map<String, Object> dataModel = new HashMap<>();
// type/enum/input/interface/union classes do not require any imports // type/enum/input/interface/union classes do not require any imports
dataModel.put(PACKAGE, MapperUtils.getModelPackageName(mappingContext)); dataModel.put(PACKAGE, MapperUtils.getModelPackageName(mappingContext));
dataModel.put(CLASS_NAME, MapperUtils.getClassNameWithPrefixAndSuffix(mappingContext, definition)); dataModel.put(CLASS_NAME, MapperUtils.getModelClassNameWithPrefixAndSuffix(mappingContext, definition));
dataModel.put(JAVA_DOC, definition.getJavaDoc()); dataModel.put(JAVA_DOC, definition.getJavaDoc());
dataModel.put(NAME, definition.getName()); dataModel.put(NAME, definition.getName());
dataModel.put(FIELDS, InputValueDefinitionToParameterMapper.map(mappingContext, definition.getValueDefinitions(), definition.getName())); dataModel.put(FIELDS, InputValueDefinitionToParameterMapper.map(mappingContext, definition.getValueDefinitions(), definition.getName()));
......
...@@ -26,7 +26,7 @@ public class InterfaceDefinitionToDataModelMapper { ...@@ -26,7 +26,7 @@ public class InterfaceDefinitionToDataModelMapper {
Map<String, Object> dataModel = new HashMap<>(); Map<String, Object> dataModel = new HashMap<>();
// type/enum/input/interface/union classes do not require any imports // type/enum/input/interface/union classes do not require any imports
dataModel.put(PACKAGE, MapperUtils.getModelPackageName(mappingContext)); dataModel.put(PACKAGE, MapperUtils.getModelPackageName(mappingContext));
dataModel.put(CLASS_NAME, MapperUtils.getClassNameWithPrefixAndSuffix(mappingContext, definition)); dataModel.put(CLASS_NAME, MapperUtils.getModelClassNameWithPrefixAndSuffix(mappingContext, definition));
dataModel.put(JAVA_DOC, definition.getJavaDoc()); dataModel.put(JAVA_DOC, definition.getJavaDoc());
dataModel.put(FIELDS, FieldDefinitionToParameterMapper.mapFields( dataModel.put(FIELDS, FieldDefinitionToParameterMapper.mapFields(
mappingContext, definition.getFieldDefinitions(), definition.getName())); mappingContext, definition.getFieldDefinitions(), definition.getName()));
......
...@@ -45,25 +45,25 @@ class MapperUtils { ...@@ -45,25 +45,25 @@ class MapperUtils {
} }
/** /**
* Generates a class name including prefix and suffix (if any) * Generates a model class name including prefix and suffix (if any)
* *
* @param mappingContext Global mapping context * @param mappingContext Global mapping context
* @param extendedDefinition GraphQL extended definition * @param extendedDefinition GraphQL extended definition
* @return Class name of GraphQL node * @return Class name of GraphQL model node
*/ */
static String getClassNameWithPrefixAndSuffix(MappingContext mappingContext, static String getModelClassNameWithPrefixAndSuffix(MappingContext mappingContext,
ExtendedDefinition<?, ?> extendedDefinition) { ExtendedDefinition<?, ?> extendedDefinition) {
return getClassNameWithPrefixAndSuffix(mappingContext, extendedDefinition.getName()); return getModelClassNameWithPrefixAndSuffix(mappingContext, extendedDefinition.getName());
} }
/** /**
* Generates a class name including prefix and suffix (if any) * Generates a model class name including prefix and suffix (if any)
* *
* @param mappingContext Global mapping context * @param mappingContext Global mapping context
* @param definitionName GraphQL node name * @param definitionName GraphQL node name
* @return Class name of GraphQL node * @return Class name of GraphQL model node
*/ */
static String getClassNameWithPrefixAndSuffix(MappingContext mappingContext, String definitionName) { static String getModelClassNameWithPrefixAndSuffix(MappingContext mappingContext, String definitionName) {
StringBuilder classNameBuilder = new StringBuilder(); StringBuilder classNameBuilder = new StringBuilder();
if (Utils.isNotBlank(mappingContext.getModelNamePrefix())) { if (Utils.isNotBlank(mappingContext.getModelNamePrefix())) {
classNameBuilder.append(mappingContext.getModelNamePrefix()); classNameBuilder.append(mappingContext.getModelNamePrefix());
...@@ -75,6 +75,59 @@ class MapperUtils { ...@@ -75,6 +75,59 @@ class MapperUtils {
return classNameBuilder.toString(); return classNameBuilder.toString();
} }
/**
* Generates an api class name including prefix and suffix (if any)
* Examples: CreateEventMutationResolver, EventsQueryResolver, EventsByIdsQueryResolver (rootTypeName is "Query" or the likes)
*
* @param mappingContext Global mapping context
* @param fieldDefinition GraphQL field definition
* @param rootTypeName Object type (e.g.: "Query", "Mutation" or "Subscription")
* @param fieldNames Names of all fields inside the rootType. Used to detect duplicate
* @return Class name of GraphQL api node
*/
static String getApiClassNameWithPrefixAndSuffix(MappingContext mappingContext,
ExtendedFieldDefinition fieldDefinition,
String rootTypeName,
List<String> fieldNames) {
StringBuilder classNameBuilder = new StringBuilder();
if (Utils.isNotBlank(mappingContext.getApiNamePrefix())) {
classNameBuilder.append(mappingContext.getApiNamePrefix());
}
classNameBuilder.append(Utils.capitalize(fieldDefinition.getName()));
if (Collections.frequency(fieldNames, fieldDefinition.getName()) > 1) {
// Examples: EventsByIdsQuery, EventsByCategoryAndStatusQuery
classNameBuilder.append(MapperUtils.getClassNameSuffixWithInputValues(fieldDefinition));
}
if (Utils.isNotBlank(rootTypeName)) {
classNameBuilder.append(rootTypeName);
}
if (Utils.isNotBlank(mappingContext.getApiNameSuffix())) {
classNameBuilder.append(mappingContext.getApiNameSuffix());
}
return classNameBuilder.toString();
}
/**
* Generates an api class name including prefix and suffix (if any)
* Examples: MutationResolver, QueryResolver, etc
*
* @param mappingContext Global mapping context
* @param definition GraphQL object definition of a root type like Query
* @return Class name of GraphQL api node
*/
static String getApiClassNameWithPrefixAndSuffix(MappingContext mappingContext,
ExtendedObjectTypeDefinition definition) {
StringBuilder classNameBuilder = new StringBuilder();
if (Utils.isNotBlank(mappingContext.getApiNamePrefix())) {
classNameBuilder.append(mappingContext.getApiNamePrefix());
}
classNameBuilder.append(Utils.capitalize(definition.getName()));
if (Utils.isNotBlank(mappingContext.getApiNameSuffix())) {
classNameBuilder.append(mappingContext.getApiNameSuffix());
}
return classNameBuilder.toString();
}
/** /**
* Generates a class name for ParametrizedInput * Generates a class name for ParametrizedInput
* *
......
...@@ -47,7 +47,7 @@ public class TypeDefinitionToDataModelMapper { ...@@ -47,7 +47,7 @@ public class TypeDefinitionToDataModelMapper {
Map<String, Object> dataModel = new HashMap<>(); Map<String, Object> dataModel = new HashMap<>();
// type/enum/input/interface/union classes do not require any imports // type/enum/input/interface/union classes do not require any imports
dataModel.put(PACKAGE, MapperUtils.getModelPackageName(mappingContext)); dataModel.put(PACKAGE, MapperUtils.getModelPackageName(mappingContext));
dataModel.put(CLASS_NAME, MapperUtils.getClassNameWithPrefixAndSuffix(mappingContext, definition)); dataModel.put(CLASS_NAME, MapperUtils.getModelClassNameWithPrefixAndSuffix(mappingContext, definition));
dataModel.put(JAVA_DOC, definition.getJavaDoc()); dataModel.put(JAVA_DOC, definition.getJavaDoc());
dataModel.put(IMPLEMENTS, getInterfaces(mappingContext, definition)); dataModel.put(IMPLEMENTS, getInterfaces(mappingContext, definition));
dataModel.put(FIELDS, getFields(mappingContext, definition, document)); dataModel.put(FIELDS, getFields(mappingContext, definition, document));
...@@ -107,7 +107,7 @@ public class TypeDefinitionToDataModelMapper { ...@@ -107,7 +107,7 @@ public class TypeDefinitionToDataModelMapper {
.stream() .stream()
.filter(union -> union.isDefinitionPartOfUnion(definition)) .filter(union -> union.isDefinitionPartOfUnion(definition))
.map(ExtendedUnionTypeDefinition::getName) .map(ExtendedUnionTypeDefinition::getName)
.map(unionName -> MapperUtils.getClassNameWithPrefixAndSuffix(mappingContext, unionName)) .map(unionName -> MapperUtils.getModelClassNameWithPrefixAndSuffix(mappingContext, unionName))
.collect(Collectors.toList()); .collect(Collectors.toList());
Set<String> interfaceNames = definition.getImplements() Set<String> interfaceNames = definition.getImplements()
.stream() .stream()
......
...@@ -26,7 +26,7 @@ public class UnionDefinitionToDataModelMapper { ...@@ -26,7 +26,7 @@ public class UnionDefinitionToDataModelMapper {
Map<String, Object> dataModel = new HashMap<>(); Map<String, Object> dataModel = new HashMap<>();
// type/enum/input/interface/union classes do not require any imports // type/enum/input/interface/union classes do not require any imports
dataModel.put(PACKAGE, MapperUtils.getModelPackageName(mappingContext)); dataModel.put(PACKAGE, MapperUtils.getModelPackageName(mappingContext));
dataModel.put(CLASS_NAME, MapperUtils.getClassNameWithPrefixAndSuffix(mappingContext, definition)); dataModel.put(CLASS_NAME, MapperUtils.getModelClassNameWithPrefixAndSuffix(mappingContext, definition));
dataModel.put(JAVA_DOC, definition.getJavaDoc()); dataModel.put(JAVA_DOC, definition.getJavaDoc());
return dataModel; return dataModel;
} }
......
...@@ -73,10 +73,24 @@ public interface GraphQLCodegenConfiguration { ...@@ -73,10 +73,24 @@ public interface GraphQLCodegenConfiguration {
/** /**
* Sets the suffix for GraphQL model classes (type, input, interface, enum, union). * Sets the suffix for GraphQL model classes (type, input, interface, enum, union).
* *
* @return The prefix for GraphQL model classes. * @return The suffix for GraphQL model classes.
*/ */
String getModelNameSuffix(); String getModelNameSuffix();
/**
* Sets the prefix for GraphQL api classes (query, mutation, subscription).
*
* @return The prefix for GraphQL api classes.
*/
String getApiNamePrefix();
/**
* Sets the suffix for GraphQL api classes (query, mutation, subscription).
*
* @return The suffix for GraphQL api classes.
*/
String getApiNameSuffix();
/** /**
* Annotation for mandatory (NonNull) fields. Can be null/empty. * Annotation for mandatory (NonNull) fields. Can be null/empty.
* *
......
...@@ -24,6 +24,8 @@ public class MappingConfig implements GraphQLCodegenConfiguration, Combinable<Ma ...@@ -24,6 +24,8 @@ public class MappingConfig implements GraphQLCodegenConfiguration, Combinable<Ma
private String modelPackageName; private String modelPackageName;
private String modelNamePrefix; private String modelNamePrefix;
private String modelNameSuffix; private String modelNameSuffix;
private String apiNamePrefix;
private String apiNameSuffix;
private String modelValidationAnnotation; private String modelValidationAnnotation;
private String subscriptionReturnType; private String subscriptionReturnType;
private Boolean generateBuilder; private Boolean generateBuilder;
...@@ -68,6 +70,8 @@ public class MappingConfig implements GraphQLCodegenConfiguration, Combinable<Ma ...@@ -68,6 +70,8 @@ public class MappingConfig implements GraphQLCodegenConfiguration, Combinable<Ma
this.modelPackageName = source.modelPackageName != null ? source.modelPackageName : this.modelPackageName; this.modelPackageName = source.modelPackageName != null ? source.modelPackageName : this.modelPackageName;
this.modelNamePrefix = source.modelNamePrefix != null ? source.modelNamePrefix : this.modelNamePrefix; this.modelNamePrefix = source.modelNamePrefix != null ? source.modelNamePrefix : this.modelNamePrefix;
this.modelNameSuffix = source.modelNameSuffix != null ? source.modelNameSuffix : this.modelNameSuffix; this.modelNameSuffix = source.modelNameSuffix != null ? source.modelNameSuffix : this.modelNameSuffix;
this.apiNamePrefix = source.apiNamePrefix != null ? source.apiNamePrefix : this.apiNamePrefix;
this.apiNameSuffix = source.apiNameSuffix != null ? source.apiNameSuffix : this.apiNameSuffix;
this.modelValidationAnnotation = source.modelValidationAnnotation != null ? source.modelValidationAnnotation : this.modelValidationAnnotation; this.modelValidationAnnotation = source.modelValidationAnnotation != null ? source.modelValidationAnnotation : this.modelValidationAnnotation;
this.subscriptionReturnType = source.subscriptionReturnType != null ? source.subscriptionReturnType : this.subscriptionReturnType; this.subscriptionReturnType = source.subscriptionReturnType != null ? source.subscriptionReturnType : this.subscriptionReturnType;
this.generateBuilder = source.generateBuilder != null ? source.generateBuilder : this.generateBuilder; this.generateBuilder = source.generateBuilder != null ? source.generateBuilder : this.generateBuilder;
......
...@@ -6,6 +6,7 @@ public class MappingConfigConstants { ...@@ -6,6 +6,7 @@ public class MappingConfigConstants {
public static final String PARENT_INTERFACE_TYPE_PLACEHOLDER = "{{TYPE}}"; public static final String PARENT_INTERFACE_TYPE_PLACEHOLDER = "{{TYPE}}";
public static final boolean DEFAULT_GENERATE_APIS = true; public static final boolean DEFAULT_GENERATE_APIS = true;
public static final String DEFAULT_GENERATE_APIS_STRING = "true"; public static final String DEFAULT_GENERATE_APIS_STRING = "true";
public static final String DEFAULT_API_NAME_SUFFIX = "Resolver";
public static final boolean DEFAULT_GENERATE_ASYNC_APIS = false; public static final boolean DEFAULT_GENERATE_ASYNC_APIS = false;
public static final String DEFAULT_GENERATE_ASYNC_APIS_STRING = "false"; public static final String DEFAULT_GENERATE_ASYNC_APIS_STRING = "false";
public static final boolean DEFAULT_BUILDER = true; public static final boolean DEFAULT_BUILDER = true;
......
...@@ -54,6 +54,16 @@ public class MappingContext implements GraphQLCodegenConfiguration { ...@@ -54,6 +54,16 @@ public class MappingContext implements GraphQLCodegenConfiguration {
return config.getModelNameSuffix(); return config.getModelNameSuffix();
} }
@Override
public String getApiNamePrefix() {
return config.getApiNamePrefix();
}
@Override
public String getApiNameSuffix() {
return config.getApiNameSuffix();
}
@Override @Override
public String getModelValidationAnnotation() { public String getModelValidationAnnotation() {
return config.getModelValidationAnnotation(); return config.getModelValidationAnnotation();
......
...@@ -43,9 +43,9 @@ class GraphQLCodegenExtendTest { ...@@ -43,9 +43,9 @@ class GraphQLCodegenExtendTest {
File[] files = Objects.requireNonNull(outputJavaClassesDir.listFiles()); File[] files = Objects.requireNonNull(outputJavaClassesDir.listFiles());
Set<String> generatedFileNames = Arrays.stream(files).map(File::getName).collect(toSet()); Set<String> generatedFileNames = Arrays.stream(files).map(File::getName).collect(toSet());
assertEquals(new HashSet<>(asList("Mutation.java", "Query.java", assertEquals(new HashSet<>(asList("MutationResolver.java", "QueryResolver.java",
"EventsQuery.java", "AssetsQuery.java", "EventsQueryResolver.java", "AssetsQueryResolver.java",
"CreateEventMutation.java", "CreateAssetMutation.java", "CreateEventMutationResolver.java", "CreateAssetMutationResolver.java",
"Event.java", "Asset.java", "EventInput.java", "AssetInput.java", "Event.java", "Asset.java", "EventInput.java", "AssetInput.java",
"Node.java", "Status.java", "PinnableItem.java")), generatedFileNames); "Node.java", "Status.java", "PinnableItem.java")), generatedFileNames);
...@@ -61,8 +61,8 @@ class GraphQLCodegenExtendTest { ...@@ -61,8 +61,8 @@ class GraphQLCodegenExtendTest {
schemaFinder.setIncludePattern("only-extend-queries.*\\.graphqls"); schemaFinder.setIncludePattern("only-extend-queries.*\\.graphqls");
new GraphQLCodegen(schemaFinder.findSchemas(), outputBuildDir, mappingConfig).generate(); new GraphQLCodegen(schemaFinder.findSchemas(), outputBuildDir, mappingConfig).generate();
assertEquals(new HashSet<>(asList("Subscription.java", "UserQuery.java", "User.java", assertEquals(new HashSet<>(asList("SubscriptionResolver.java", "UserQueryResolver.java", "User.java",
"UsersCreatedSubscription.java", "CreateUserMutation.java", "Mutation.java", "Query.java", "UsersCreatedSubscriptionResolver.java", "CreateUserMutationResolver.java", "MutationResolver.java", "QueryResolver.java",
"UserInput.java")), Arrays.stream(Objects.requireNonNull(outputJavaClassesDir.listFiles())) "UserInput.java")), Arrays.stream(Objects.requireNonNull(outputJavaClassesDir.listFiles()))
.map(File::getName).collect(toSet())); .map(File::getName).collect(toSet()));
} }
...@@ -74,10 +74,10 @@ class GraphQLCodegenExtendTest { ...@@ -74,10 +74,10 @@ class GraphQLCodegenExtendTest {
File[] files = Objects.requireNonNull(outputJavaClassesDir.listFiles()); File[] files = Objects.requireNonNull(outputJavaClassesDir.listFiles());
Set<String> generatedFileNames = Arrays.stream(files).map(File::getName).collect(toSet()); Set<String> generatedFileNames = Arrays.stream(files).map(File::getName).collect(toSet());
assertEquals(new HashSet<>(asList("Mutation.java", "Query.java", assertEquals(new HashSet<>(asList("MutationResolver.java", "QueryResolver.java",
"EventsQuery.java", "AssetsQuery.java", "EventsQueryResolver.java", "AssetsQueryResolver.java",
"EventResolver.java", "NodeResolver.java", "EventResolver.java", "NodeResolver.java",
"CreateEventMutation.java", "CreateAssetMutation.java", "CreateEventMutationResolver.java", "CreateAssetMutationResolver.java",
"Event.java", "Asset.java", "EventInput.java", "AssetInput.java", "Event.java", "Asset.java", "EventInput.java", "AssetInput.java",
"Node.java", "Status.java", "PinnableItem.java")), generatedFileNames); "Node.java", "Status.java", "PinnableItem.java")), generatedFileNames);
...@@ -96,9 +96,9 @@ class GraphQLCodegenExtendTest { ...@@ -96,9 +96,9 @@ class GraphQLCodegenExtendTest {
File[] files = Objects.requireNonNull(outputJavaClassesDir.listFiles()); File[] files = Objects.requireNonNull(outputJavaClassesDir.listFiles());
Set<String> generatedFileNames = Arrays.stream(files).map(File::getName).collect(toSet()); Set<String> generatedFileNames = Arrays.stream(files).map(File::getName).collect(toSet());
assertEquals(new HashSet<>(asList("Mutation.java", "Query.java", assertEquals(new HashSet<>(asList("MutationResolver.java", "QueryResolver.java",
"EventsQuery.java", "AssetsQuery.java", "EventsQueryResolver.java", "AssetsQueryResolver.java",
"CreateEventMutation.java", "CreateAssetMutation.java", "CreateEventMutationResolver.java", "CreateAssetMutationResolver.java",
"Event.java", "Asset.java", "EventInput.java", "AssetInput.java", "Event.java", "Asset.java", "EventInput.java", "AssetInput.java",
"Node.java", "Status.java", "PinnableItem.java")), generatedFileNames); "Node.java", "Status.java", "PinnableItem.java")), generatedFileNames);
...@@ -133,9 +133,9 @@ class GraphQLCodegenExtendTest { ...@@ -133,9 +133,9 @@ class GraphQLCodegenExtendTest {
File[] files = Objects.requireNonNull(outputJavaClassesDir.listFiles()); File[] files = Objects.requireNonNull(outputJavaClassesDir.listFiles());
Set<String> generatedFileNames = Arrays.stream(files).map(File::getName).collect(toSet()); Set<String> generatedFileNames = Arrays.stream(files).map(File::getName).collect(toSet());
assertEquals(new HashSet<>(asList("Mutation.java", "Query.java", assertEquals(new HashSet<>(asList("MutationResolver.java", "QueryResolver.java",
"EventsQuery.java", "AssetsQuery.java", "EventsQueryResolver.java", "AssetsQueryResolver.java",
"CreateEventMutation.java", "CreateAssetMutation.java", "CreateEventMutationResolver.java", "CreateAssetMutationResolver.java",
"Event.java", "Asset.java", "EventInput.java", "AssetInput.java", "Event.java", "Asset.java", "EventInput.java", "AssetInput.java",
"Node.java", "Status.java", "PinnableItem.java")), generatedFileNames); "Node.java", "Status.java", "PinnableItem.java")), generatedFileNames);
......
...@@ -46,23 +46,23 @@ class GraphQLCodegenParentInterfacesTest { ...@@ -46,23 +46,23 @@ class GraphQLCodegenParentInterfacesTest {
File[] files = Objects.requireNonNull(outputJavaClassesDir.listFiles()); File[] files = Objects.requireNonNull(outputJavaClassesDir.listFiles());
assertSameTrimmedContent( assertSameTrimmedContent(
new File("src/test/resources/expected-classes/parent-interfaces/Query.java.txt"), new File("src/test/resources/expected-classes/parent-interfaces/QueryResolver.java.txt"),
getFileByName(files, "Query.java")); getFileByName(files, "QueryResolver.java"));
assertSameTrimmedContent( assertSameTrimmedContent(
new File("src/test/resources/expected-classes/parent-interfaces/Mutation.java.txt"), new File("src/test/resources/expected-classes/parent-interfaces/MutationResolver.java.txt"),
getFileByName(files, "Mutation.java")); getFileByName(files, "MutationResolver.java"));
assertSameTrimmedContent( assertSameTrimmedContent(
new File("src/test/resources/expected-classes/parent-interfaces/Subscription.java.txt"), new File("src/test/resources/expected-classes/parent-interfaces/SubscriptionResolver.java.txt"),
getFileByName(files, "Subscription.java")); getFileByName(files, "SubscriptionResolver.java"));
assertSameTrimmedContent( assertSameTrimmedContent(
new File("src/test/resources/expected-classes/parent-interfaces/VersionQuery.java.txt"), new File("src/test/resources/expected-classes/parent-interfaces/VersionQueryResolver.java.txt"),
getFileByName(files, "VersionQuery.java")); getFileByName(files, "VersionQueryResolver.java"));
assertSameTrimmedContent( assertSameTrimmedContent(
new File("src/test/resources/expected-classes/parent-interfaces/CreateEventMutation.java.txt"), new File("src/test/resources/expected-classes/parent-interfaces/CreateEventMutationResolver.java.txt"),
getFileByName(files, "CreateEventMutation.java")); getFileByName(files, "CreateEventMutationResolver.java"));
assertSameTrimmedContent( assertSameTrimmedContent(
new File("src/test/resources/expected-classes/parent-interfaces/EventsCreatedSubscription.java.txt"), new File("src/test/resources/expected-classes/parent-interfaces/EventsCreatedSubscriptionResolver.java.txt"),
getFileByName(files, "EventsCreatedSubscription.java")); getFileByName(files, "EventsCreatedSubscriptionResolver.java"));
assertSameTrimmedContent( assertSameTrimmedContent(
new File("src/test/resources/expected-classes/parent-interfaces/EventResolver.java.txt"), new File("src/test/resources/expected-classes/parent-interfaces/EventResolver.java.txt"),
getFileByName(files, "EventResolver.java")); getFileByName(files, "EventResolver.java"));
......
...@@ -61,10 +61,10 @@ class GraphQLCodegenTest { ...@@ -61,10 +61,10 @@ class GraphQLCodegenTest {
File[] files = Objects.requireNonNull(outputJavaClassesDir.listFiles()); File[] files = Objects.requireNonNull(outputJavaClassesDir.listFiles());
List<String> generatedFileNames = Arrays.stream(files).map(File::getName).sorted().collect(toList()); List<String> generatedFileNames = Arrays.stream(files).map(File::getName).sorted().collect(toList());
assertEquals(Arrays.asList( assertEquals(Arrays.asList(
"CreateEventMutation.java", "Event.java", "EventByIdQuery.java", "EventProperty.java", "CreateEventMutationResolver.java", "Event.java", "EventByIdQueryResolver.java", "EventProperty.java",
"EventStatus.java", "EventsByCategoryAndStatusQuery.java", "EventsByIdsQuery.java", "EventStatus.java", "EventsByCategoryAndStatusQueryResolver.java", "EventsByIdsQueryResolver.java",
"EventsCreatedSubscription.java", "Mutation.java", "Query.java", "Subscription.java", "EventsCreatedSubscriptionResolver.java", "MutationResolver.java", "QueryResolver.java", "SubscriptionResolver.java",
"VersionQuery.java"), generatedFileNames); "VersionQueryResolver.java"), generatedFileNames);
for (File file : files) { for (File file : files) {
File expected = new File(String.format("src/test/resources/expected-classes/%s.txt", file.getName())); File expected = new File(String.format("src/test/resources/expected-classes/%s.txt", file.getName()));
...@@ -178,7 +178,7 @@ class GraphQLCodegenTest { ...@@ -178,7 +178,7 @@ class GraphQLCodegenTest {
File[] files = Objects.requireNonNull(outputJavaClassesDir.listFiles()); File[] files = Objects.requireNonNull(outputJavaClassesDir.listFiles());
assertFileContainsElements(files, "EventsCreatedSubscription.java", assertFileContainsElements(files, "EventsCreatedSubscriptionResolver.java",
"org.reactivestreams.Publisher<java.util.Collection<Event>> eventsCreated() throws Exception;"); "org.reactivestreams.Publisher<java.util.Collection<Event>> eventsCreated() throws Exception;");
} }
...@@ -204,9 +204,9 @@ class GraphQLCodegenTest { ...@@ -204,9 +204,9 @@ class GraphQLCodegenTest {
File[] apiFiles = Objects.requireNonNull(new File(outputJavaClassesDir, "api").listFiles()); File[] apiFiles = Objects.requireNonNull(new File(outputJavaClassesDir, "api").listFiles());
List<String> generatedApiFileNames = Arrays.stream(apiFiles).map(File::getName).sorted().collect(toList()); List<String> generatedApiFileNames = Arrays.stream(apiFiles).map(File::getName).sorted().collect(toList());
assertEquals(Arrays.asList("CreateEventMutation.java", "EventByIdQuery.java", assertEquals(Arrays.asList("CreateEventMutationResolver.java", "EventByIdQueryResolver.java",
"EventsByCategoryAndStatusQuery.java", "EventsByIdsQuery.java", "EventsCreatedSubscription.java", "Mutation.java", "Query.java", "EventsByCategoryAndStatusQueryResolver.java", "EventsByIdsQueryResolver.java", "EventsCreatedSubscriptionResolver.java", "MutationResolver.java", "QueryResolver.java",
"Subscription.java", "VersionQuery.java"), generatedApiFileNames); "SubscriptionResolver.java", "VersionQueryResolver.java"), generatedApiFileNames);
for (File apiFile : apiFiles) { for (File apiFile : apiFiles) {
assertThat(Utils.getFileContent(apiFile.getPath()), assertThat(Utils.getFileContent(apiFile.getPath()),
...@@ -300,10 +300,10 @@ class GraphQLCodegenTest { ...@@ -300,10 +300,10 @@ class GraphQLCodegenTest {
File[] files = Objects.requireNonNull(outputBuildDir.listFiles()); File[] files = Objects.requireNonNull(outputBuildDir.listFiles());
assertEquals(2, files.length); assertEquals(2, files.length);
assertSameTrimmedContent(new File("src/test/resources/expected-classes/EmptyMutation.java.txt"), assertSameTrimmedContent(new File("src/test/resources/expected-classes/EmptyMutationResolver.java.txt"),
getFileByName(files, "Mutation.java")); getFileByName(files, "MutationResolver.java"));
assertSameTrimmedContent(new File("src/test/resources/expected-classes/EmptyQuery.java.txt"), assertSameTrimmedContent(new File("src/test/resources/expected-classes/EmptyQueryResolver.java.txt"),
getFileByName(files, "Query.java")); getFileByName(files, "QueryResolver.java"));
} }
@Test @Test
...@@ -331,7 +331,7 @@ class GraphQLCodegenTest { ...@@ -331,7 +331,7 @@ class GraphQLCodegenTest {
generator.generate(); generator.generate();
File[] files = Objects.requireNonNull(outputJavaClassesDir.listFiles()); File[] files = Objects.requireNonNull(outputJavaClassesDir.listFiles());
assertFileContainsElements(files, "VersionQuery.java", "String version()"); assertFileContainsElements(files, "VersionQueryResolver.java", "String version()");
} }
@Test @Test
...@@ -341,13 +341,13 @@ class GraphQLCodegenTest { ...@@ -341,13 +341,13 @@ class GraphQLCodegenTest {
File[] files = Objects.requireNonNull(outputJavaClassesDir.listFiles()); File[] files = Objects.requireNonNull(outputJavaClassesDir.listFiles());
assertFileContainsElements(files, "VersionQuery.java", assertFileContainsElements(files, "VersionQueryResolver.java",
"java.util.concurrent.CompletableFuture<String> version()"); "java.util.concurrent.CompletableFuture<String> version()");
assertFileContainsElements(files, "EventsByCategoryAndStatusQuery.java", assertFileContainsElements(files, "EventsByCategoryAndStatusQueryResolver.java",
"java.util.concurrent.CompletableFuture<java.util.Collection<Event>> eventsByCategoryAndStatus("); "java.util.concurrent.CompletableFuture<java.util.Collection<Event>> eventsByCategoryAndStatus(");
assertFileContainsElements(files, "EventByIdQuery.java", assertFileContainsElements(files, "EventByIdQueryResolver.java",
"java.util.concurrent.CompletableFuture<Event> eventById("); "java.util.concurrent.CompletableFuture<Event> eventById(");
} }
...@@ -358,7 +358,7 @@ class GraphQLCodegenTest { ...@@ -358,7 +358,7 @@ class GraphQLCodegenTest {
File[] files = Objects.requireNonNull(outputJavaClassesDir.listFiles()); File[] files = Objects.requireNonNull(outputJavaClassesDir.listFiles());
assertFileContainsElements(files, "CreateEventMutation.java", assertFileContainsElements(files, "CreateEventMutationResolver.java",
"java.util.concurrent.CompletableFuture<Event> createEvent("); "java.util.concurrent.CompletableFuture<Event> createEvent(");
} }
...@@ -369,8 +369,8 @@ class GraphQLCodegenTest { ...@@ -369,8 +369,8 @@ class GraphQLCodegenTest {
File[] files = Objects.requireNonNull(outputJavaClassesDir.listFiles()); File[] files = Objects.requireNonNull(outputJavaClassesDir.listFiles());
List<String> generatedFileNames = Arrays.stream(files).map(File::getName).sorted().collect(toList()); List<String> generatedFileNames = Arrays.stream(files).map(File::getName).sorted().collect(toList());
assertEquals(Arrays.asList("CreateEventMutation.java", "Event.java", "EventInput.java", "EventsQuery.java", assertEquals(Arrays.asList("CreateEventMutationResolver.java", "Event.java", "EventInput.java", "EventsQueryResolver.java",
"Mutation.java", "Node.java", "PinnableItem.java", "Query.java", "Status.java"), generatedFileNames); "MutationResolver.java", "Node.java", "PinnableItem.java", "QueryResolver.java", "Status.java"), generatedFileNames);
for (File file : files) { for (File file : files) {
assertSameTrimmedContent( assertSameTrimmedContent(
...@@ -386,11 +386,11 @@ class GraphQLCodegenTest { ...@@ -386,11 +386,11 @@ class GraphQLCodegenTest {
File[] files = Objects.requireNonNull(outputJavaClassesDir.listFiles()); File[] files = Objects.requireNonNull(outputJavaClassesDir.listFiles());
assertSameTrimmedContent(new File("src/test/resources/expected-classes/ProductsByCategoryIdAndStatusQuery.java.txt"), assertSameTrimmedContent(new File("src/test/resources/expected-classes/ProductsByCategoryIdAndStatusQueryResolver.java.txt"),
getFileByName(files, "ProductsByCategoryIdAndStatusQuery.java")); getFileByName(files, "ProductsByCategoryIdAndStatusQueryResolver.java"));
assertSameTrimmedContent(new File("src/test/resources/expected-classes/ProductsByIdsQuery.java.txt"), assertSameTrimmedContent(new File("src/test/resources/expected-classes/ProductsByIdsQueryResolver.java.txt"),
getFileByName(files, "ProductsByIdsQuery.java")); getFileByName(files, "ProductsByIdsQueryResolver.java"));
} }
@Test @Test
......
...@@ -4,7 +4,7 @@ package com.kobylynskyi.graphql.test1; ...@@ -4,7 +4,7 @@ package com.kobylynskyi.graphql.test1;
/** /**
* Create a new event. * Create a new event.
*/ */
public interface CreateEventMutation { public interface CreateEventMutationResolver {
/** /**
* Create a new event. * Create a new event.
......
public interface Mutation {
}
\ No newline at end of file
public interface MutationResolver {
}
\ No newline at end of file
public interface Query {
}
\ No newline at end of file
public interface QueryResolver {
}
\ No newline at end of file
...@@ -4,7 +4,7 @@ package com.kobylynskyi.graphql.test1; ...@@ -4,7 +4,7 @@ package com.kobylynskyi.graphql.test1;
/** /**
* Single event by ID. * Single event by ID.
*/ */
public interface EventByIdQuery { public interface EventByIdQueryResolver {
/** /**
* Single event by ID. * Single event by ID.
......
...@@ -4,7 +4,7 @@ package com.kobylynskyi.graphql.test1; ...@@ -4,7 +4,7 @@ package com.kobylynskyi.graphql.test1;
/** /**
* List of events of a specified category. * List of events of a specified category.
*/ */
public interface EventsByCategoryAndStatusQuery { public interface EventsByCategoryAndStatusQueryResolver {
/** /**
* List of events of a specified category. * List of events of a specified category.
......
...@@ -4,7 +4,7 @@ package com.kobylynskyi.graphql.test1; ...@@ -4,7 +4,7 @@ package com.kobylynskyi.graphql.test1;
/** /**
* Events by IDs. * Events by IDs.
*/ */
public interface EventsByIdsQuery { public interface EventsByIdsQueryResolver {
/** /**
* Events by IDs. * Events by IDs.
......
...@@ -4,7 +4,7 @@ package com.kobylynskyi.graphql.test1; ...@@ -4,7 +4,7 @@ package com.kobylynskyi.graphql.test1;
/** /**
* Subscribe to events * Subscribe to events
*/ */
public interface EventsCreatedSubscription { public interface EventsCreatedSubscriptionResolver {
/** /**
* Subscribe to events * Subscribe to events
......
package com.kobylynskyi.graphql.test1; package com.kobylynskyi.graphql.test1;
public interface Mutation { public interface MutationResolver {
/** /**
* Create a new event. * Create a new event.
......
package com.kobylynskyi.graphql.test1; package com.kobylynskyi.graphql.test1;
public interface ProductsByCategoryIdAndStatusQuery { public interface ProductsByCategoryIdAndStatusQueryResolver {
java.util.Collection<Product> products(String categoryId, String status) throws Exception; java.util.Collection<Product> products(String categoryId, String status) throws Exception;
......
package com.kobylynskyi.graphql.test1; package com.kobylynskyi.graphql.test1;
public interface ProductsByIdsQuery { public interface ProductsByIdsQueryResolver {
java.util.Collection<Product> products(java.util.Collection<String> ids) throws Exception; java.util.Collection<Product> products(java.util.Collection<String> ids) throws Exception;
......
package com.kobylynskyi.graphql.test1; package com.kobylynskyi.graphql.test1;
public interface Query { public interface QueryResolver {
/** /**
* Version of the application. * Version of the application.
......
package com.kobylynskyi.graphql.test1; package com.kobylynskyi.graphql.test1;
public interface Subscription { public interface SubscriptionResolver {
/** /**
* Subscribe to events * Subscribe to events
......
...@@ -4,7 +4,7 @@ package com.kobylynskyi.graphql.test1; ...@@ -4,7 +4,7 @@ package com.kobylynskyi.graphql.test1;
/** /**
* Version of the application. * Version of the application.
*/ */
public interface VersionQuery { public interface VersionQueryResolver {
/** /**
* Version of the application. * Version of the application.
......
package com.kobylynskyi.graphql.test1; package com.kobylynskyi.graphql.test1;
public interface CreateEventMutation { public interface CreateEventMutationResolver {
@Deprecated @Deprecated
@javax.validation.constraints.NotNull @javax.validation.constraints.NotNull
......
package com.kobylynskyi.graphql.test1; package com.kobylynskyi.graphql.test1;
public interface EventsQuery { public interface EventsQueryResolver {
@Deprecated @Deprecated
@javax.validation.constraints.NotNull @javax.validation.constraints.NotNull
......
package com.kobylynskyi.graphql.test1; package com.kobylynskyi.graphql.test1;
public interface Mutation { public interface MutationResolver {
@Deprecated @Deprecated
@javax.validation.constraints.NotNull @javax.validation.constraints.NotNull
......
package com.kobylynskyi.graphql.test1; package com.kobylynskyi.graphql.test1;
public interface Query { public interface QueryResolver {
@Deprecated @Deprecated
@javax.validation.constraints.NotNull @javax.validation.constraints.NotNull
......
public interface AssetsQuery { public interface AssetsQueryResolver {
@javax.validation.constraints.NotNull @javax.validation.constraints.NotNull
java.util.Collection<Asset> assets() throws Exception; java.util.Collection<Asset> assets() throws Exception;
......
public interface CreateAssetMutation { public interface CreateAssetMutationResolver {
@javax.validation.constraints.NotNull @javax.validation.constraints.NotNull
Asset createAsset(AssetInput input) throws Exception; Asset createAsset(AssetInput input) throws Exception;
......
public interface CreateEventMutation { public interface CreateEventMutationResolver {
@javax.validation.constraints.NotNull @javax.validation.constraints.NotNull
Event createEvent(EventInput input) throws Exception; Event createEvent(EventInput input) throws Exception;
......
public interface EventsQuery { public interface EventsQueryResolver {
@javax.validation.constraints.NotNull @javax.validation.constraints.NotNull
java.util.Collection<Event> events() throws Exception; java.util.Collection<Event> events() throws Exception;
......
public interface Mutation { public interface MutationResolver {
@javax.validation.constraints.NotNull @javax.validation.constraints.NotNull
Event createEvent(EventInput input) throws Exception; Event createEvent(EventInput input) throws Exception;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* Queries related to events * Queries related to events
* Queries related to assets * Queries related to assets
*/ */
public interface Query { public interface QueryResolver {
@javax.validation.constraints.NotNull @javax.validation.constraints.NotNull
java.util.Collection<Event> events() throws Exception; java.util.Collection<Event> events() throws Exception;
......
public interface AssetsQuery { public interface AssetsQueryResolver {
@javax.validation.constraints.NotNull @javax.validation.constraints.NotNull
java.util.Collection<Asset> assets() throws Exception; java.util.Collection<Asset> assets() throws Exception;
......
public interface CreateAssetMutation { public interface CreateAssetMutationResolver {
@javax.validation.constraints.NotNull @javax.validation.constraints.NotNull
Asset createAsset(AssetInput input) throws Exception; Asset createAsset(AssetInput input) throws Exception;
......
public interface CreateEventMutation { public interface CreateEventMutationResolver {
@javax.validation.constraints.NotNull @javax.validation.constraints.NotNull
Event createEvent(EventInput input) throws Exception; Event createEvent(EventInput input) throws Exception;
......
public interface EventsQuery { public interface EventsQueryResolver {
@javax.validation.constraints.NotNull @javax.validation.constraints.NotNull
java.util.Collection<Event> events() throws Exception; java.util.Collection<Event> events() throws Exception;
......
public interface Mutation { public interface MutationResolver {
@javax.validation.constraints.NotNull @javax.validation.constraints.NotNull
Event createEvent(EventInput input) throws Exception; Event createEvent(EventInput input) throws Exception;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* Queries related to events * Queries related to events
* Queries related to assets * Queries related to assets
*/ */
public interface Query { public interface QueryResolver {
@javax.validation.constraints.NotNull @javax.validation.constraints.NotNull
java.util.Collection<Event> events() throws Exception; java.util.Collection<Event> events() throws Exception;
......
...@@ -4,7 +4,7 @@ package com.kobylynskyi.graphql.interfaces; ...@@ -4,7 +4,7 @@ package com.kobylynskyi.graphql.interfaces;
/** /**
* Create a new event. * Create a new event.
*/ */
public interface CreateEventMutation extends graphql.kickstart.tools.GraphQLMutationResolver { public interface CreateEventMutationResolver extends graphql.kickstart.tools.GraphQLMutationResolver {
/** /**
* Create a new event. * Create a new event.
......
...@@ -4,7 +4,7 @@ package com.kobylynskyi.graphql.interfaces; ...@@ -4,7 +4,7 @@ package com.kobylynskyi.graphql.interfaces;
/** /**
* Subscribe to events * Subscribe to events
*/ */
public interface EventsCreatedSubscription extends graphql.kickstart.tools.GraphQLSubscriptionResolver { public interface EventsCreatedSubscriptionResolver extends graphql.kickstart.tools.GraphQLSubscriptionResolver {
/** /**
* Subscribe to events * Subscribe to events
......
package com.kobylynskyi.graphql.interfaces; package com.kobylynskyi.graphql.interfaces;
public interface Mutation extends graphql.kickstart.tools.GraphQLMutationResolver { public interface MutationResolver extends graphql.kickstart.tools.GraphQLMutationResolver {
/** /**
* Create a new event. * Create a new event.
......
package com.kobylynskyi.graphql.interfaces; package com.kobylynskyi.graphql.interfaces;
public interface Query extends graphql.kickstart.tools.GraphQLQueryResolver { public interface QueryResolver extends graphql.kickstart.tools.GraphQLQueryResolver {
/** /**
* Version of the application. * Version of the application.
......
package com.kobylynskyi.graphql.interfaces; package com.kobylynskyi.graphql.interfaces;
public interface Subscription extends graphql.kickstart.tools.GraphQLSubscriptionResolver { public interface SubscriptionResolver extends graphql.kickstart.tools.GraphQLSubscriptionResolver {
/** /**
* Subscribe to events * Subscribe to events
......
...@@ -4,7 +4,7 @@ package com.kobylynskyi.graphql.interfaces; ...@@ -4,7 +4,7 @@ package com.kobylynskyi.graphql.interfaces;
/** /**
* Version of the application. * Version of the application.
*/ */
public interface VersionQuery extends graphql.kickstart.tools.GraphQLQueryResolver { public interface VersionQueryResolver extends graphql.kickstart.tools.GraphQLQueryResolver {
/** /**
* Version of the application. * Version of the application.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册