Skip to content

Commit f5aecfe

Browse files
authored
Fix invalid parameter names for extensions and customTypeMappings #964 (#979)
1 parent 5a2c5d5 commit f5aecfe

File tree

7 files changed

+62
-12
lines changed

7 files changed

+62
-12
lines changed

src/main/java/com/kobylynskyi/graphql/codegen/mapper/FieldDefinitionsToResolverDataModelMapper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@
2424
import java.util.Set;
2525
import java.util.stream.Collectors;
2626

27-
import static com.kobylynskyi.graphql.codegen.model.DataModelFields.INITIALIZE_NULLABLE_TYPES;
2827
import static com.kobylynskyi.graphql.codegen.model.DataModelFields.CLASS_NAME;
2928
import static com.kobylynskyi.graphql.codegen.model.DataModelFields.ENUM_IMPORT_IT_SELF_IN_SCALA;
3029
import static com.kobylynskyi.graphql.codegen.model.DataModelFields.GENERATED_ANNOTATION;
3130
import static com.kobylynskyi.graphql.codegen.model.DataModelFields.GENERATED_INFO;
3231
import static com.kobylynskyi.graphql.codegen.model.DataModelFields.GENERATE_MODEL_OPEN_CLASSES;
3332
import static com.kobylynskyi.graphql.codegen.model.DataModelFields.IMPLEMENTS;
3433
import static com.kobylynskyi.graphql.codegen.model.DataModelFields.IMPORTS;
34+
import static com.kobylynskyi.graphql.codegen.model.DataModelFields.INITIALIZE_NULLABLE_TYPES;
3535
import static com.kobylynskyi.graphql.codegen.model.DataModelFields.JAVA_DOC;
3636
import static com.kobylynskyi.graphql.codegen.model.DataModelFields.OPERATIONS;
3737
import static com.kobylynskyi.graphql.codegen.model.DataModelFields.PACKAGE;
@@ -225,7 +225,7 @@ private List<ParameterDefinition> getOperationParameters(MappingContext mappingC
225225
String parentObjectParamType = graphQLTypeMapper
226226
.getLanguageType(mappingContext, new TypeName(parentTypeName));
227227
String parentObjectParamName = dataModelMapper
228-
.capitalizeIfRestricted(mappingContext, Utils.unCapitalize(parentObjectParamType));
228+
.capitalizeIfRestricted(mappingContext, Utils.unCapitalize(parentTypeName));
229229
ParameterDefinition parameterDefinition = new ParameterDefinition();
230230
parameterDefinition.setType(parentObjectParamType);
231231
parameterDefinition.setName(parentObjectParamName);

src/test/java/com/kobylynskyi/graphql/codegen/GraphQLCodegenCustomScalarMappingTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,23 @@ void generate_CustomTypeMapping_ScalarOnQueryOnly() throws Exception {
7070
getFileByName(files, "ResponseContainingDate.java"));
7171
}
7272

73+
/**
74+
* See #964
75+
*/
76+
@Test
77+
void generate_CustomTypeMapping_ForExtensionProperty() throws Exception {
78+
mappingConfig.setGenerateExtensionFieldsResolvers(true);
79+
mappingConfig.setCustomTypesMapping(new HashMap<>(singletonMap("External", "com.example.External")));
80+
mappingConfig.setGenerateClient(false);
81+
82+
new JavaGraphQLCodegen(singletonList("src/test/resources/schemas/external-type-extend.graphqls"),
83+
outputBuildDir, mappingConfig, TestUtils.getStaticGeneratedInfo()).generate();
84+
85+
File[] files = Objects.requireNonNull(outputJavaClassesDir.listFiles());
86+
87+
assertSameTrimmedContent(
88+
new File("src/test/resources/expected-classes/custom-type/ExternalResolver.java.txt"),
89+
getFileByName(files, "ExternalResolver.java"));
90+
}
91+
7392
}

src/test/resources/expected-classes/AcceptTopicSuggestionPayloadResolver.java.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ package com.github.graphql;
1010
)
1111
public interface AcceptTopicSuggestionPayloadResolver {
1212

13-
GithubTopicTO topic(GithubAcceptTopicSuggestionPayloadTO githubAcceptTopicSuggestionPayloadTO, graphql.schema.DataFetchingEnvironment env) throws Exception;
13+
GithubTopicTO topic(GithubAcceptTopicSuggestionPayloadTO acceptTopicSuggestionPayload, graphql.schema.DataFetchingEnvironment env) throws Exception;
1414

1515
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.kobylynskyi.graphql.test1;
2+
3+
4+
/**
5+
* Resolver for External
6+
*/
7+
@javax.annotation.Generated(
8+
value = "com.kobylynskyi.graphql.codegen.GraphQLCodegen",
9+
date = "2020-12-31T23:59:59-0500"
10+
)
11+
public interface ExternalResolver {
12+
13+
int age(com.example.External external) throws Exception;
14+
15+
}

src/test/resources/expected-classes/kt/field-resolver/AcceptTopicSuggestionPayloadResolver.kt.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ package com.github.graphql
1111
interface AcceptTopicSuggestionPayloadResolver {
1212

1313
@Throws(Exception::class)
14-
fun topic(githubAcceptTopicSuggestionPayloadTO: GithubAcceptTopicSuggestionPayloadTO, env: graphql.schema.DataFetchingEnvironment): GithubTopicTO?
14+
fun topic(acceptTopicSuggestionPayload: GithubAcceptTopicSuggestionPayloadTO, env: graphql.schema.DataFetchingEnvironment): GithubTopicTO?
1515

1616
}

src/test/resources/expected-classes/parent-interfaces/EventResolver.java.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@ package com.kobylynskyi.graphql.interfaces;
1010
)
1111
public interface EventResolver extends graphql.kickstart.tools.GraphQLResolver<EventTO> {
1212

13-
String id(EventTO eventTO) throws Exception;
13+
String id(EventTO event) throws Exception;
1414

15-
String categoryId(EventTO eventTO) throws Exception;
15+
String categoryId(EventTO event) throws Exception;
1616

17-
java.util.List<EventPropertyTO> properties(EventTO eventTO) throws Exception;
17+
java.util.List<EventPropertyTO> properties(EventTO event) throws Exception;
1818

19-
EventStatusTO status(EventTO eventTO) throws Exception;
19+
EventStatusTO status(EventTO event) throws Exception;
2020

21-
String createdBy(EventTO eventTO) throws Exception;
21+
String createdBy(EventTO event) throws Exception;
2222

23-
String createdDateTime(EventTO eventTO) throws Exception;
23+
String createdDateTime(EventTO event) throws Exception;
2424

25-
Boolean active(EventTO eventTO) throws Exception;
25+
Boolean active(EventTO event) throws Exception;
2626

27-
Integer rating(EventTO eventTO) throws Exception;
27+
Integer rating(EventTO event) throws Exception;
2828

2929
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
schema {
2+
query: Query
3+
}
4+
5+
type Query {
6+
external(name: String!): External!
7+
}
8+
9+
# This is expected to be defined elsewhere and configured via a custom type mapping
10+
# type External {
11+
# name: String!
12+
# }
13+
14+
extend type External {
15+
age: Int!
16+
}

0 commit comments

Comments
 (0)