Skip to content

Commit f8baa94

Browse files
authored
Generate annotations for mutation and query parameters #602 (#603)
1 parent 1034c48 commit f8baa94

36 files changed

+127
-125
lines changed

src/main/resources/templates/java-lang/javaClassGraphqlOperations.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public interface ${className}<#if implements?has_content> extends <#list impleme
3535
<#list operation.annotations as annotation>
3636
@${annotation}
3737
</#list>
38-
${operation.type} ${operation.name}(<#list operation.parameters as param>${param.type} ${param.name}<#if param_has_next>, </#if></#list>)<#if operation.throwsException> throws Exception</#if>;
38+
${operation.type} ${operation.name}(<#list operation.parameters as param><#list param.annotations as paramAnnotation>@${paramAnnotation}<#if param.annotations?has_content> </#if></#list>${param.type} ${param.name}<#if param_has_next>, </#if></#list>)<#if operation.throwsException> throws Exception</#if>;
3939

4040
</#list>
4141
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ void generate_Directives() throws Exception {
208208
"float={{float?toArrayOfStrings}}, " +
209209
"int={{int}}, " +
210210
"n={{n?toString}})"));
211+
directiveAnnotationsMapping.put("valid", singletonList("@javax.validation.Valid"));
211212
mappingConfig.setDirectiveAnnotationsMapping(directiveAnnotationsMapping);
212213

213214
new JavaGraphQLCodegen(singletonList("src/test/resources/schemas/test.graphqls"),

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ public interface CommitResolver {
1414

1515
@javax.validation.constraints.NotNull
1616
@com.fasterxml.jackson.databind.annotation.JsonDeserialize(using = com.example.json.DateTimeScalarDeserializer.class)
17-
Blame blame(Commit commit, String path, graphql.schema.DataFetchingEnvironment env) throws Exception;
17+
Blame blame(Commit commit, @javax.validation.constraints.NotNull String path, graphql.schema.DataFetchingEnvironment env) throws Exception;
1818

1919
@javax.validation.constraints.NotNull
2020
CommitCommentConnection comments(Commit commit, String after, String before, Integer first, Integer last, graphql.schema.DataFetchingEnvironment env) throws Exception;
2121

22-
DeploymentConnection deployments(Commit commit, String after, String before, java.util.List<String> environments, Integer first, Integer last, DeploymentOrder orderBy, graphql.schema.DataFetchingEnvironment env) throws Exception;
22+
DeploymentConnection deployments(Commit commit, String after, String before, @javax.validation.constraints.NotNull java.util.List<String> environments, Integer first, Integer last, DeploymentOrder orderBy, graphql.schema.DataFetchingEnvironment env) throws Exception;
2323

2424
@javax.validation.constraints.NotNull
2525
CommitHistoryConnection history(Commit commit, String after, CommitAuthor author, String before, Integer first, Integer last, String path, String since, String until, graphql.schema.DataFetchingEnvironment env) throws Exception;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ public interface CreateEventMutationResolver {
1414
* Create a new event.
1515
*/
1616
@javax.validation.constraints.NotNull
17-
Event createEvent(String categoryId, String createdBy) throws Exception;
17+
Event createEvent(@javax.validation.constraints.NotNull String categoryId, String createdBy) throws Exception;
1818

1919
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ public interface EventByIdQueryResolver {
1414
* Single event by ID.
1515
*/
1616
@javax.validation.constraints.NotNull
17-
Event eventById(String id) throws Exception;
17+
Event eventById(@javax.validation.constraints.NotNull String id) throws Exception;
1818

1919
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ public interface EventsByCategoryAndStatusQueryResolver {
1414
* List of events of a specified category.
1515
*/
1616
@javax.validation.constraints.NotNull
17-
java.util.List<Event> eventsByCategoryAndStatus(String categoryId, EventStatus status) throws Exception;
17+
java.util.List<Event> eventsByCategoryAndStatus(@javax.validation.constraints.NotNull String categoryId, EventStatus status) throws Exception;
1818

1919
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ public interface EventsByIdsQueryResolver {
1414
* Events by IDs.
1515
*/
1616
@javax.validation.constraints.NotNull
17-
java.util.List<Event> eventsByIds(java.util.List<String> ids) throws Exception;
17+
java.util.List<Event> eventsByIds(@javax.validation.constraints.NotNull java.util.List<String> ids) throws Exception;
1818

1919
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ public interface MutationResolver {
1111
* Create a new event.
1212
*/
1313
@javax.validation.constraints.NotNull
14-
Event createEvent(String categoryId, String createdBy) throws Exception;
14+
Event createEvent(@javax.validation.constraints.NotNull String categoryId, String createdBy) throws Exception;
1515

1616
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ package com.kobylynskyi.graphql.test1;
77
)
88
public interface ProductsByCategoryIdAndStatusQueryResolver {
99

10-
java.util.List<Product> products(String categoryId, String status) throws Exception;
10+
java.util.List<Product> products(@javax.validation.constraints.NotNull String categoryId, @javax.validation.constraints.NotNull String status) throws Exception;
1111

1212
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ package com.kobylynskyi.graphql.test1;
77
)
88
public interface ProductsByIdsQueryResolver {
99

10-
java.util.List<Product> products(java.util.List<String> ids) throws Exception;
10+
java.util.List<Product> products(@javax.validation.constraints.NotNull java.util.List<String> ids) throws Exception;
1111

1212
}

0 commit comments

Comments
 (0)