diff --git a/src/main/java/com/kobylynskyi/graphql/codegen/GraphQLCodegen.java b/src/main/java/com/kobylynskyi/graphql/codegen/GraphQLCodegen.java index 333a0bd03..ee6a820e6 100644 --- a/src/main/java/com/kobylynskyi/graphql/codegen/GraphQLCodegen.java +++ b/src/main/java/com/kobylynskyi/graphql/codegen/GraphQLCodegen.java @@ -146,9 +146,10 @@ private File generateInterface(ExtendedInterfaceTypeDefinition definition) { private List generateOperation(ExtendedObjectTypeDefinition definition) { List generatedFiles = new ArrayList<>(); + List fieldNames = definition.getFieldDefinitions().stream().map(FieldDefinition::getName).collect(toList()); if (Boolean.TRUE.equals(mappingConfig.getGenerateApis())) { for (ExtendedFieldDefinition operationDef : definition.getFieldDefinitions()) { - Map dataModel = FieldDefinitionsToResolverDataModelMapper.mapRootTypeField(mappingConfig, operationDef, definition.getName()); + Map dataModel = FieldDefinitionsToResolverDataModelMapper.mapRootTypeField(mappingConfig, operationDef, definition.getName(), fieldNames); generatedFiles.add(GraphQLCodegenFileCreator.generateFile(FreeMarkerTemplatesRegistry.operationsTemplate, dataModel, outputDir)); } // We need to generate a root object to workaround https://github.com/facebook/relay/issues/112 @@ -159,7 +160,7 @@ private List generateOperation(ExtendedObjectTypeDefinition definition) { if (Boolean.TRUE.equals(mappingConfig.getGenerateRequests())) { // generate request objects for graphql operations for (ExtendedFieldDefinition operationDef : definition.getFieldDefinitions()) { - Map requestDataModel = FieldDefinitionToRequestDataModelMapper.map(mappingConfig, operationDef, definition.getName()); + Map requestDataModel = FieldDefinitionToRequestDataModelMapper.map(mappingConfig, operationDef, definition.getName(), fieldNames); generatedFiles.add(GraphQLCodegenFileCreator.generateFile(FreeMarkerTemplatesRegistry.requestTemplate, requestDataModel, outputDir)); } } diff --git a/src/main/java/com/kobylynskyi/graphql/codegen/GraphQLCodegenFileCreator.java b/src/main/java/com/kobylynskyi/graphql/codegen/GraphQLCodegenFileCreator.java index 0d9855f48..46312cd49 100644 --- a/src/main/java/com/kobylynskyi/graphql/codegen/GraphQLCodegenFileCreator.java +++ b/src/main/java/com/kobylynskyi/graphql/codegen/GraphQLCodegenFileCreator.java @@ -42,7 +42,7 @@ static void prepareOutputDir(File outputDir) { private static File getFileTargetDirectory(Map dataModel, File outputDir) { File targetDir; Object packageName = dataModel.get(DataModelFields.PACKAGE); - if (packageName != null && !Utils.isBlank(packageName.toString())) { + if (packageName != null && Utils.isNotBlank(packageName.toString())) { targetDir = new File(outputDir, packageName.toString().replace(".", File.separator)); } else { targetDir = outputDir; diff --git a/src/main/java/com/kobylynskyi/graphql/codegen/mapper/FieldDefinitionToRequestDataModelMapper.java b/src/main/java/com/kobylynskyi/graphql/codegen/mapper/FieldDefinitionToRequestDataModelMapper.java index 3317a244f..e1fc99e58 100644 --- a/src/main/java/com/kobylynskyi/graphql/codegen/mapper/FieldDefinitionToRequestDataModelMapper.java +++ b/src/main/java/com/kobylynskyi/graphql/codegen/mapper/FieldDefinitionToRequestDataModelMapper.java @@ -3,9 +3,10 @@ import com.kobylynskyi.graphql.codegen.model.MappingConfig; import com.kobylynskyi.graphql.codegen.model.definitions.ExtendedFieldDefinition; import com.kobylynskyi.graphql.codegen.utils.Utils; -import graphql.language.FieldDefinition; +import java.util.Collections; import java.util.HashMap; +import java.util.List; import java.util.Map; import static com.kobylynskyi.graphql.codegen.model.DataModelFields.*; @@ -23,15 +24,17 @@ public class FieldDefinitionToRequestDataModelMapper { * @param mappingConfig Global mapping configuration * @param operationDef GraphQL operation definition * @param objectTypeName Object type (e.g.: "Query", "Mutation" or "Subscription") + * @param fieldNames Names of all fields inside the rootType. Used to detect duplicate * @return Freemarker data model of the GraphQL request */ public static Map map(MappingConfig mappingConfig, ExtendedFieldDefinition operationDef, - String objectTypeName) { + String objectTypeName, + List fieldNames) { Map dataModel = new HashMap<>(); // Request classes are sharing the package with the model classes, so no imports are needed dataModel.put(PACKAGE, MapperUtils.getModelPackageName(mappingConfig)); - dataModel.put(CLASS_NAME, getClassName(operationDef.getName(), objectTypeName, mappingConfig.getRequestSuffix())); + dataModel.put(CLASS_NAME, getClassName(operationDef, fieldNames, objectTypeName, mappingConfig.getRequestSuffix())); dataModel.put(JAVA_DOC, operationDef.getJavaDoc()); dataModel.put(OPERATION_NAME, operationDef.getName()); dataModel.put(OPERATION_TYPE, objectTypeName.toUpperCase()); @@ -45,14 +48,23 @@ public static Map map(MappingConfig mappingConfig, /** * Examples: + * - EventsByIdsQueryRequest * - EventsByCategoryQueryRequest * - CreateEventMutationRequest */ - private static String getClassName(String operationDefName, String objectType, String requestSuffix) { - if (Utils.isBlank(requestSuffix)) { - return Utils.capitalize(operationDefName) + objectType; - } else { - return Utils.capitalize(operationDefName) + objectType + requestSuffix; + private static String getClassName(ExtendedFieldDefinition operationDef, + List fieldNames, + String objectType, + String requestSuffix) { + StringBuilder classNameBuilder = new StringBuilder(); + classNameBuilder.append(Utils.capitalize(operationDef.getName())); + if (Collections.frequency(fieldNames, operationDef.getName()) > 1) { + classNameBuilder.append(MapperUtils.getClassNameSuffixWithInputValues(operationDef)); } + classNameBuilder.append(objectType); + if (Utils.isNotBlank(requestSuffix)) { + classNameBuilder.append(requestSuffix); + } + return classNameBuilder.toString(); } } diff --git a/src/main/java/com/kobylynskyi/graphql/codegen/mapper/FieldDefinitionsToResolverDataModelMapper.java b/src/main/java/com/kobylynskyi/graphql/codegen/mapper/FieldDefinitionsToResolverDataModelMapper.java index eb6cb5881..a8215474f 100644 --- a/src/main/java/com/kobylynskyi/graphql/codegen/mapper/FieldDefinitionsToResolverDataModelMapper.java +++ b/src/main/java/com/kobylynskyi/graphql/codegen/mapper/FieldDefinitionsToResolverDataModelMapper.java @@ -3,9 +3,10 @@ import com.kobylynskyi.graphql.codegen.model.MappingConfig; import com.kobylynskyi.graphql.codegen.model.OperationDefinition; import com.kobylynskyi.graphql.codegen.model.ParameterDefinition; -import com.kobylynskyi.graphql.codegen.model.definitions.ExtendedObjectTypeDefinition; import com.kobylynskyi.graphql.codegen.model.definitions.ExtendedFieldDefinition; +import com.kobylynskyi.graphql.codegen.model.definitions.ExtendedObjectTypeDefinition; import com.kobylynskyi.graphql.codegen.utils.Utils; +import graphql.language.InputValueDefinition; import graphql.language.TypeName; import java.util.*; @@ -43,13 +44,20 @@ public static Map mapToTypeResolver(MappingConfig mappingConfig, * @param mappingConfig Global mapping configuration * @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 Freemarker data model of the GraphQL field */ public static Map mapRootTypeField(MappingConfig mappingConfig, ExtendedFieldDefinition fieldDefinition, - String rootTypeName) { - // Examples: VersionQuery, CreateEventMutation (rootTypeName is "Query" or the likes) - String className = Utils.capitalize(fieldDefinition.getName()) + rootTypeName; + String rootTypeName, + List fieldNames) { + String fieldDefinitionName = fieldDefinition.getName(); + 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 fieldDefs = Collections.singletonList(fieldDefinition); return mapToResolverModel(mappingConfig, rootTypeName, className, fieldDefs, fieldDefinition.getJavaDoc()); } @@ -83,6 +91,7 @@ private static Map mapToResolverModel(MappingConfig mappingConfi dataModel.put(IMPORTS, imports); dataModel.put(CLASS_NAME, className); dataModel.put(OPERATIONS, operations); + dataModel.put(JAVA_DOC, javaDoc); return dataModel; } diff --git a/src/main/java/com/kobylynskyi/graphql/codegen/mapper/GraphqlTypeToJavaTypeMapper.java b/src/main/java/com/kobylynskyi/graphql/codegen/mapper/GraphqlTypeToJavaTypeMapper.java index a740d2ed3..c6af8d6e3 100644 --- a/src/main/java/com/kobylynskyi/graphql/codegen/mapper/GraphqlTypeToJavaTypeMapper.java +++ b/src/main/java/com/kobylynskyi/graphql/codegen/mapper/GraphqlTypeToJavaTypeMapper.java @@ -122,7 +122,7 @@ private static List getAnnotations(MappingConfig mappingConfig, String g List annotations = new ArrayList<>(); if (mandatory) { String modelValidationAnnotation = mappingConfig.getModelValidationAnnotation(); - if (!Utils.isBlank(modelValidationAnnotation)) { + if (Utils.isNotBlank(modelValidationAnnotation)) { annotations.add(modelValidationAnnotation); } } @@ -185,7 +185,7 @@ static String wrapIntoAsyncIfRequired(MappingConfig mappingConfig, String javaTy */ private static String wrapIntoSubscriptionIfRequired(MappingConfig mappingConfig, String javaTypeName, String parentTypeName) { if (parentTypeName.equalsIgnoreCase(GraphQLOperation.SUBSCRIPTION.name()) - && !Utils.isBlank(mappingConfig.getSubscriptionReturnType())) { + && Utils.isNotBlank(mappingConfig.getSubscriptionReturnType())) { return String.format("%s<%s>", mappingConfig.getSubscriptionReturnType(), javaTypeName); } return javaTypeName; diff --git a/src/main/java/com/kobylynskyi/graphql/codegen/mapper/MapperUtils.java b/src/main/java/com/kobylynskyi/graphql/codegen/mapper/MapperUtils.java index 21adeb700..7aae5eec1 100644 --- a/src/main/java/com/kobylynskyi/graphql/codegen/mapper/MapperUtils.java +++ b/src/main/java/com/kobylynskyi/graphql/codegen/mapper/MapperUtils.java @@ -2,12 +2,15 @@ import com.kobylynskyi.graphql.codegen.model.MappingConfig; import com.kobylynskyi.graphql.codegen.model.definitions.ExtendedDefinition; +import com.kobylynskyi.graphql.codegen.model.definitions.ExtendedFieldDefinition; import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLOperation; import com.kobylynskyi.graphql.codegen.utils.Utils; +import graphql.language.InputValueDefinition; import java.util.Arrays; import java.util.HashSet; import java.util.Set; +import java.util.StringJoiner; class MapperUtils { @@ -55,11 +58,11 @@ static String getClassNameWithPrefixAndSuffix(MappingConfig mappingConfig, */ static String getClassNameWithPrefixAndSuffix(MappingConfig mappingConfig, String definitionName) { StringBuilder classNameBuilder = new StringBuilder(); - if (!Utils.isBlank(mappingConfig.getModelNamePrefix())) { + if (Utils.isNotBlank(mappingConfig.getModelNamePrefix())) { classNameBuilder.append(mappingConfig.getModelNamePrefix()); } classNameBuilder.append(Utils.capitalize(definitionName)); - if (!Utils.isBlank(mappingConfig.getModelNameSuffix())) { + if (Utils.isNotBlank(mappingConfig.getModelNameSuffix())) { classNameBuilder.append(mappingConfig.getModelNameSuffix()); } return classNameBuilder.toString(); @@ -72,7 +75,7 @@ static String getClassNameWithPrefixAndSuffix(MappingConfig mappingConfig, Strin * @return api package name if present. Generic package name otherwise */ static String getApiPackageName(MappingConfig mappingConfig) { - if (!Utils.isBlank(mappingConfig.getApiPackageName())) { + if (Utils.isNotBlank(mappingConfig.getApiPackageName())) { return mappingConfig.getApiPackageName(); } else { return mappingConfig.getPackageName(); @@ -86,7 +89,7 @@ static String getApiPackageName(MappingConfig mappingConfig) { * @return model package name if present. Generic package name otherwise */ static String getModelPackageName(MappingConfig mappingConfig) { - if (!Utils.isBlank(mappingConfig.getModelPackageName())) { + if (Utils.isNotBlank(mappingConfig.getModelPackageName())) { return mappingConfig.getModelPackageName(); } else { return mappingConfig.getPackageName(); @@ -105,11 +108,11 @@ static String getModelPackageName(MappingConfig mappingConfig) { static Set getImports(MappingConfig mappingConfig, String packageName) { Set imports = new HashSet<>(); String modelPackageName = mappingConfig.getModelPackageName(); - if (!Utils.isBlank(modelPackageName) && !modelPackageName.equals(packageName)) { + if (Utils.isNotBlank(modelPackageName) && !modelPackageName.equals(packageName)) { imports.add(modelPackageName); } String genericPackageName = mappingConfig.getPackageName(); - if (!Utils.isBlank(genericPackageName) && !genericPackageName.equals(packageName)) { + if (Utils.isNotBlank(genericPackageName) && !genericPackageName.equals(packageName)) { imports.add(genericPackageName); } // not adding apiPackageName because it should not be imported in any other generated classes @@ -128,4 +131,26 @@ static boolean shouldUseAsyncMethods(MappingConfig mappingConfig, String typeNam return isAsyncApi && !GraphQLOperation.SUBSCRIPTION.name().equalsIgnoreCase(typeName); } + + /** + * Builds a className suffix based on the input values. + * Examples: + * 1. fieldDefinition has some input values: + * "ids" => "ByIds" + * "category", "status" => "ByCategoryAndStatus" + * + * @param fieldDefinition field definition that has some InputValueDefinitions + * @return className suffix based on the input values + */ + static String getClassNameSuffixWithInputValues(ExtendedFieldDefinition fieldDefinition) { + StringJoiner inputValueNamesJoiner = new StringJoiner("And"); + fieldDefinition.getInputValueDefinitions().stream() + .map(InputValueDefinition::getName).map(Utils::capitalize) + .forEach(inputValueNamesJoiner::add); + String inputValueNames = inputValueNamesJoiner.toString(); + if (inputValueNames.isEmpty()) { + return inputValueNames; + } + return "By" + inputValueNames; + } } diff --git a/src/main/java/com/kobylynskyi/graphql/codegen/utils/Utils.java b/src/main/java/com/kobylynskyi/graphql/codegen/utils/Utils.java index 608d54a7a..ac6c33c7f 100644 --- a/src/main/java/com/kobylynskyi/graphql/codegen/utils/Utils.java +++ b/src/main/java/com/kobylynskyi/graphql/codegen/utils/Utils.java @@ -58,22 +58,22 @@ public static String uncapitalize(String aString) { } /** - * Basically copy of org.apache.commons.lang3.StringUtils.isBlank(CharSequence cs) + * Inverted copy of org.apache.commons.lang3.StringUtils.isBlank(CharSequence cs) * * @param cs the CharSequence to check, may be null - * @return {@code true} if the CharSequence is null, empty or whitespace only + * @return {@code false} if the CharSequence is null, empty or whitespace only */ - public static boolean isBlank(CharSequence cs) { + public static boolean isNotBlank(CharSequence cs) { int strLen; if (cs == null || (strLen = cs.length()) == 0) { - return true; + return false; } for (int i = 0; i < strLen; i++) { if (!Character.isWhitespace(cs.charAt(i))) { - return false; + return true; } } - return true; + return false; } /** diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/GraphQLCodegenRequestTest.java b/src/test/java/com/kobylynskyi/graphql/codegen/GraphQLCodegenRequestTest.java index c8a162d7a..2044dba67 100644 --- a/src/test/java/com/kobylynskyi/graphql/codegen/GraphQLCodegenRequestTest.java +++ b/src/test/java/com/kobylynskyi/graphql/codegen/GraphQLCodegenRequestTest.java @@ -147,6 +147,20 @@ void generate_apiImportForModelClassesIfResolversExtensions() throws Exception { getGeneratedFile(files, "EventsByCategoryAndStatusQueryRequest.java")); } + @Test + void generate_QueriesWithSameName() throws Exception { + new GraphQLCodegen(singletonList("src/test/resources/schemas/queries-same-name.graphqls"), + outputBuildDir, mappingConfig).generate(); + + File[] files = Objects.requireNonNull(outputJavaClassesDir.listFiles()); + + assertSameTrimmedContent(new File("src/test/resources/expected-classes/request/ProductsByCategoryIdAndStatusQueryRequest.java.txt"), + getGeneratedFile(files, "ProductsByCategoryIdAndStatusQueryRequest.java")); + + assertSameTrimmedContent(new File("src/test/resources/expected-classes/request/ProductsByIdsQueryRequest.java.txt"), + getGeneratedFile(files, "ProductsByIdsQueryRequest.java")); + } + private static File getGeneratedFile(File[] files, String fileName) throws FileNotFoundException { return Arrays.stream(files) .filter(f -> f.getName().equalsIgnoreCase(fileName)) diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/GraphQLCodegenTest.java b/src/test/java/com/kobylynskyi/graphql/codegen/GraphQLCodegenTest.java index b3918b431..99960aaf7 100644 --- a/src/test/java/com/kobylynskyi/graphql/codegen/GraphQLCodegenTest.java +++ b/src/test/java/com/kobylynskyi/graphql/codegen/GraphQLCodegenTest.java @@ -424,6 +424,23 @@ void generate_deprecated() throws Exception { } } + @Test + void generate_QueriesWithSameName() throws Exception { + new GraphQLCodegen(singletonList("src/test/resources/schemas/queries-same-name.graphqls"), + outputBuildDir, mappingConfig).generate(); + + File[] files = Objects.requireNonNull(outputJavaClassesDir.listFiles()); + + assertEquals(Utils.getFileContent("src/test/resources/expected-classes/ProductsByCategoryIdAndStatusQuery.java.txt"), + Utils.getFileContent( + Arrays.stream(files).filter(f -> f.getName().equals("ProductsByCategoryIdAndStatusQuery.java")).map(File::getPath) + .findFirst().orElseThrow(FileNotFoundException::new))); + assertEquals(Utils.getFileContent("src/test/resources/expected-classes/ProductsByIdsQuery.java.txt"), + Utils.getFileContent( + Arrays.stream(files).filter(f -> f.getName().equals("ProductsByIdsQuery.java")).map(File::getPath) + .findFirst().orElseThrow(FileNotFoundException::new))); + } + private void assertFileContainsElements(File[] files, String fileName, String... elements) throws IOException { File file = getFile(files, fileName); diff --git a/src/test/resources/expected-classes/AcceptTopicSuggestionPayloadResolver.java.txt b/src/test/resources/expected-classes/AcceptTopicSuggestionPayloadResolver.java.txt index a98252a60..d2c01d5bc 100644 --- a/src/test/resources/expected-classes/AcceptTopicSuggestionPayloadResolver.java.txt +++ b/src/test/resources/expected-classes/AcceptTopicSuggestionPayloadResolver.java.txt @@ -1,6 +1,9 @@ package com.github.graphql; +/** + * Resolver for AcceptTopicSuggestionPayload + */ public interface AcceptTopicSuggestionPayloadResolver { GithubTopicTO topic(GithubAcceptTopicSuggestionPayloadTO githubAcceptTopicSuggestionPayloadTO, graphql.schema.DataFetchingEnvironment env) throws Exception; diff --git a/src/test/resources/expected-classes/CommentDeletedEventResolver.java.txt b/src/test/resources/expected-classes/CommentDeletedEventResolver.java.txt index 52aed8544..c165a040f 100644 --- a/src/test/resources/expected-classes/CommentDeletedEventResolver.java.txt +++ b/src/test/resources/expected-classes/CommentDeletedEventResolver.java.txt @@ -1,6 +1,9 @@ package com.github.graphql; +/** + * Resolver for CommentDeletedEvent + */ public interface CommentDeletedEventResolver { Actor actor(CommentDeletedEvent commentDeletedEvent) throws Exception; diff --git a/src/test/resources/expected-classes/CommitResolver.java.txt b/src/test/resources/expected-classes/CommitResolver.java.txt index 24a169b63..b964fafb5 100644 --- a/src/test/resources/expected-classes/CommitResolver.java.txt +++ b/src/test/resources/expected-classes/CommitResolver.java.txt @@ -1,6 +1,9 @@ package com.github.graphql; +/** + * Resolver for Commit + */ public interface CommitResolver { PullRequestConnection associatedPullRequests(Commit commit, String after, String before, Integer first, Integer last, PullRequestOrder orderBy, graphql.schema.DataFetchingEnvironment env) throws Exception; diff --git a/src/test/resources/expected-classes/CreateEventMutation.java.txt b/src/test/resources/expected-classes/CreateEventMutation.java.txt index d031880b2..f64b7948a 100644 --- a/src/test/resources/expected-classes/CreateEventMutation.java.txt +++ b/src/test/resources/expected-classes/CreateEventMutation.java.txt @@ -1,6 +1,9 @@ package com.kobylynskyi.graphql.test1; +/** + * Create a new event. + */ public interface CreateEventMutation { /** diff --git a/src/test/resources/expected-classes/EventByIdQuery.java.txt b/src/test/resources/expected-classes/EventByIdQuery.java.txt index 177cea85d..7136f9e4f 100644 --- a/src/test/resources/expected-classes/EventByIdQuery.java.txt +++ b/src/test/resources/expected-classes/EventByIdQuery.java.txt @@ -1,6 +1,9 @@ package com.kobylynskyi.graphql.test1; +/** + * Single event by ID. + */ public interface EventByIdQuery { /** diff --git a/src/test/resources/expected-classes/EventsByCategoryAndStatusQuery.java.txt b/src/test/resources/expected-classes/EventsByCategoryAndStatusQuery.java.txt index 2ee492e3a..d44e483ae 100644 --- a/src/test/resources/expected-classes/EventsByCategoryAndStatusQuery.java.txt +++ b/src/test/resources/expected-classes/EventsByCategoryAndStatusQuery.java.txt @@ -1,6 +1,9 @@ package com.kobylynskyi.graphql.test1; +/** + * List of events of a specified category. + */ public interface EventsByCategoryAndStatusQuery { /** diff --git a/src/test/resources/expected-classes/EventsByIdsQuery.java.txt b/src/test/resources/expected-classes/EventsByIdsQuery.java.txt index f86d9e30f..19860d0a6 100644 --- a/src/test/resources/expected-classes/EventsByIdsQuery.java.txt +++ b/src/test/resources/expected-classes/EventsByIdsQuery.java.txt @@ -1,6 +1,9 @@ package com.kobylynskyi.graphql.test1; +/** + * Events by IDs. + */ public interface EventsByIdsQuery { /** diff --git a/src/test/resources/expected-classes/EventsCreatedSubscription.java.txt b/src/test/resources/expected-classes/EventsCreatedSubscription.java.txt index cb79dbfb1..ce7ea2538 100644 --- a/src/test/resources/expected-classes/EventsCreatedSubscription.java.txt +++ b/src/test/resources/expected-classes/EventsCreatedSubscription.java.txt @@ -1,6 +1,9 @@ package com.kobylynskyi.graphql.test1; +/** + * Subscribe to events + */ public interface EventsCreatedSubscription { /** diff --git a/src/test/resources/expected-classes/ProductsByCategoryIdAndStatusQuery.java.txt b/src/test/resources/expected-classes/ProductsByCategoryIdAndStatusQuery.java.txt new file mode 100644 index 000000000..0ba1a7ea9 --- /dev/null +++ b/src/test/resources/expected-classes/ProductsByCategoryIdAndStatusQuery.java.txt @@ -0,0 +1,8 @@ +package com.kobylynskyi.graphql.test1; + + +public interface ProductsByCategoryIdAndStatusQuery { + + java.util.Collection products(String categoryId, String status) throws Exception; + +} \ No newline at end of file diff --git a/src/test/resources/expected-classes/ProductsByIdsQuery.java.txt b/src/test/resources/expected-classes/ProductsByIdsQuery.java.txt new file mode 100644 index 000000000..5e34f64f3 --- /dev/null +++ b/src/test/resources/expected-classes/ProductsByIdsQuery.java.txt @@ -0,0 +1,8 @@ +package com.kobylynskyi.graphql.test1; + + +public interface ProductsByIdsQuery { + + java.util.Collection products(java.util.Collection ids) throws Exception; + +} \ No newline at end of file diff --git a/src/test/resources/expected-classes/VersionQuery.java.txt b/src/test/resources/expected-classes/VersionQuery.java.txt index 1393022a2..b6446a105 100644 --- a/src/test/resources/expected-classes/VersionQuery.java.txt +++ b/src/test/resources/expected-classes/VersionQuery.java.txt @@ -1,6 +1,9 @@ package com.kobylynskyi.graphql.test1; +/** + * Version of the application. + */ public interface VersionQuery { /** diff --git a/src/test/resources/expected-classes/extend-with-resolvers/EventResolver.java.txt b/src/test/resources/expected-classes/extend-with-resolvers/EventResolver.java.txt index 3abb25911..a2bf37a55 100644 --- a/src/test/resources/expected-classes/extend-with-resolvers/EventResolver.java.txt +++ b/src/test/resources/expected-classes/extend-with-resolvers/EventResolver.java.txt @@ -1,3 +1,6 @@ +/** + * Resolver for Event + */ public interface EventResolver { /** diff --git a/src/test/resources/expected-classes/extend-with-resolvers/NodeResolver.java.txt b/src/test/resources/expected-classes/extend-with-resolvers/NodeResolver.java.txt index 0e93ba841..7d51d75bb 100644 --- a/src/test/resources/expected-classes/extend-with-resolvers/NodeResolver.java.txt +++ b/src/test/resources/expected-classes/extend-with-resolvers/NodeResolver.java.txt @@ -1,3 +1,6 @@ +/** + * Resolver for Node + */ public interface NodeResolver { String createdBy(Node node) throws Exception; diff --git a/src/test/resources/expected-classes/extend-with-resolvers/Query.java.txt b/src/test/resources/expected-classes/extend-with-resolvers/Query.java.txt index 6fd0095b2..40cb8c3b4 100644 --- a/src/test/resources/expected-classes/extend-with-resolvers/Query.java.txt +++ b/src/test/resources/expected-classes/extend-with-resolvers/Query.java.txt @@ -1,3 +1,7 @@ +/** + * Queries related to events + * Queries related to assets + */ public interface Query { @javax.validation.constraints.NotNull diff --git a/src/test/resources/expected-classes/extend/Query.java.txt b/src/test/resources/expected-classes/extend/Query.java.txt index 6fd0095b2..40cb8c3b4 100644 --- a/src/test/resources/expected-classes/extend/Query.java.txt +++ b/src/test/resources/expected-classes/extend/Query.java.txt @@ -1,3 +1,7 @@ +/** + * Queries related to events + * Queries related to assets + */ public interface Query { @javax.validation.constraints.NotNull diff --git a/src/test/resources/expected-classes/request/ProductsByCategoryIdAndStatusQueryRequest.java.txt b/src/test/resources/expected-classes/request/ProductsByCategoryIdAndStatusQueryRequest.java.txt new file mode 100644 index 000000000..e30b1d5e3 --- /dev/null +++ b/src/test/resources/expected-classes/request/ProductsByCategoryIdAndStatusQueryRequest.java.txt @@ -0,0 +1,74 @@ +package com.github.graphql; + +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLOperation; +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLOperationRequest; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Objects; + +public class ProductsByCategoryIdAndStatusQueryRequest implements GraphQLOperationRequest { + + private static final GraphQLOperation OPERATION_TYPE = GraphQLOperation.QUERY; + private static final String OPERATION_NAME = "products"; + + private Map input = new LinkedHashMap<>(); + + public ProductsByCategoryIdAndStatusQueryRequest() { + } + + public void setCategoryId(String categoryId) { + this.input.put("categoryId", categoryId); + } + + public void setStatus(String status) { + this.input.put("status", status); + } + + @Override + public GraphQLOperation getOperationType() { + return OPERATION_TYPE; + } + + @Override + public String getOperationName() { + return OPERATION_NAME; + } + + @Override + public Map getInput() { + return input; + } + + @Override + public String toString() { + return Objects.toString(input); + } + + public static class Builder { + + private String categoryId; + private String status; + + public Builder() { + } + + public Builder setCategoryId(String categoryId) { + this.categoryId = categoryId; + return this; + } + + public Builder setStatus(String status) { + this.status = status; + return this; + } + + + public ProductsByCategoryIdAndStatusQueryRequest build() { + ProductsByCategoryIdAndStatusQueryRequest obj = new ProductsByCategoryIdAndStatusQueryRequest(); + obj.setCategoryId(categoryId); + obj.setStatus(status); + return obj; + } + + } +} diff --git a/src/test/resources/expected-classes/request/ProductsByIdsQueryRequest.java.txt b/src/test/resources/expected-classes/request/ProductsByIdsQueryRequest.java.txt new file mode 100644 index 000000000..647dd9eae --- /dev/null +++ b/src/test/resources/expected-classes/request/ProductsByIdsQueryRequest.java.txt @@ -0,0 +1,63 @@ +package com.github.graphql; + +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLOperation; +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLOperationRequest; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Objects; + +public class ProductsByIdsQueryRequest implements GraphQLOperationRequest { + + private static final GraphQLOperation OPERATION_TYPE = GraphQLOperation.QUERY; + private static final String OPERATION_NAME = "products"; + + private Map input = new LinkedHashMap<>(); + + public ProductsByIdsQueryRequest() { + } + + public void setIds(java.util.Collection ids) { + this.input.put("ids", ids); + } + + @Override + public GraphQLOperation getOperationType() { + return OPERATION_TYPE; + } + + @Override + public String getOperationName() { + return OPERATION_NAME; + } + + @Override + public Map getInput() { + return input; + } + + @Override + public String toString() { + return Objects.toString(input); + } + + public static class Builder { + + private java.util.Collection ids; + + public Builder() { + } + + public Builder setIds(java.util.Collection ids) { + this.ids = ids; + return this; + } + + + public ProductsByIdsQueryRequest build() { + ProductsByIdsQueryRequest obj = new ProductsByIdsQueryRequest(); + obj.setIds(ids); + return obj; + } + + } +} diff --git a/src/test/resources/schemas/empty-types-with-extend.graphqls b/src/test/resources/schemas/empty-types-with-extend.graphqls index 0ddacf3d5..e3b21e9a2 100644 --- a/src/test/resources/schemas/empty-types-with-extend.graphqls +++ b/src/test/resources/schemas/empty-types-with-extend.graphqls @@ -23,6 +23,7 @@ union PinnableItem +# Queries related to events extend type Query { events: [Event!] } @@ -55,6 +56,7 @@ scalar DateTime +# Queries related to assets extend type Query { assets: [Asset!] } diff --git a/src/test/resources/schemas/queries-same-name.graphqls b/src/test/resources/schemas/queries-same-name.graphqls new file mode 100644 index 000000000..fcbfc97cf --- /dev/null +++ b/src/test/resources/schemas/queries-same-name.graphqls @@ -0,0 +1,13 @@ +schema { + query: Query + mutation: Mutation +} + +type Query { + products(categoryId: ID!, status: String!): [Product] + products(ids: [ID!]!): [Product] +} + +type Product { + id: ID +} \ No newline at end of file