提交 1fc590ea 编写于 作者: B Bogdan Kobylynskyi

Populate field annotation for GraphQL input type #7

上级 41886052
...@@ -51,7 +51,7 @@ public class FieldDefinitionToDataModelMapper { ...@@ -51,7 +51,7 @@ public class FieldDefinitionToDataModelMapper {
operation.setName(fieldDef.getName()); operation.setName(fieldDef.getName());
operation.setType(GraphqlTypeToJavaTypeMapper.getJavaType(mappingConfig, fieldDef.getType(), fieldDef.getName(), parentTypeName)); operation.setType(GraphqlTypeToJavaTypeMapper.getJavaType(mappingConfig, fieldDef.getType(), fieldDef.getName(), parentTypeName));
operation.setAnnotations(GraphqlTypeToJavaTypeMapper.getAnnotations(mappingConfig, fieldDef.getType(), fieldDef.getName(), parentTypeName)); operation.setAnnotations(GraphqlTypeToJavaTypeMapper.getAnnotations(mappingConfig, fieldDef.getType(), fieldDef.getName(), parentTypeName));
operation.setParameters(InputValueDefinitionToParameterMapper.map(mappingConfig, fieldDef.getInputValueDefinitions())); operation.setParameters(InputValueDefinitionToParameterMapper.map(mappingConfig, fieldDef.getInputValueDefinitions(), fieldDef.getName()));
return operation; return operation;
} }
......
...@@ -23,10 +23,11 @@ class GraphqlTypeToJavaTypeMapper { ...@@ -23,10 +23,11 @@ class GraphqlTypeToJavaTypeMapper {
return parameter; return parameter;
} }
public static ParameterDefinition map(MappingConfig mappingConfig, InputValueDefinition inputValueDefinition) { public static ParameterDefinition map(MappingConfig mappingConfig, InputValueDefinition inputValueDefinition, String parentTypeName) {
ParameterDefinition parameter = new ParameterDefinition(); ParameterDefinition parameter = new ParameterDefinition();
parameter.setName(MapperUtils.capitalizeIfRestricted(inputValueDefinition.getName())); parameter.setName(MapperUtils.capitalizeIfRestricted(inputValueDefinition.getName()));
parameter.setType(getJavaType(mappingConfig, inputValueDefinition.getType())); parameter.setType(getJavaType(mappingConfig, inputValueDefinition.getType()));
parameter.setAnnotations(getAnnotations(mappingConfig, inputValueDefinition.getType(), inputValueDefinition.getName(), parentTypeName));
return parameter; return parameter;
} }
...@@ -69,7 +70,7 @@ class GraphqlTypeToJavaTypeMapper { ...@@ -69,7 +70,7 @@ class GraphqlTypeToJavaTypeMapper {
} }
static List<String> getAnnotations(MappingConfig mappingConfig, Type type, String name, String parentTypeName) { static List<String> getAnnotations(MappingConfig mappingConfig, Type type, String name, String parentTypeName) {
return getAnnotations(mappingConfig, type, name, parentTypeName, true); return getAnnotations(mappingConfig, type, name, parentTypeName, false);
} }
private static List<String> getAnnotations(MappingConfig mappingConfig, Type type, String name, String parentTypeName, private static List<String> getAnnotations(MappingConfig mappingConfig, Type type, String name, String parentTypeName,
......
...@@ -29,7 +29,7 @@ public class InputDefinitionToDataModelMapper { ...@@ -29,7 +29,7 @@ public class InputDefinitionToDataModelMapper {
dataModel.put(IMPORTS, MapperUtils.getImports(mappingConfig, packageName)); dataModel.put(IMPORTS, MapperUtils.getImports(mappingConfig, packageName));
dataModel.put(CLASS_NAME, MapperUtils.getClassNameWithPrefixAndSuffix(mappingConfig, typeDefinition)); dataModel.put(CLASS_NAME, MapperUtils.getClassNameWithPrefixAndSuffix(mappingConfig, typeDefinition));
dataModel.put(NAME, typeDefinition.getName()); dataModel.put(NAME, typeDefinition.getName());
dataModel.put(FIELDS, InputValueDefinitionToParameterMapper.map(mappingConfig, typeDefinition.getInputValueDefinitions())); dataModel.put(FIELDS, InputValueDefinitionToParameterMapper.map(mappingConfig, typeDefinition.getInputValueDefinitions(), typeDefinition.getName()));
return dataModel; return dataModel;
} }
......
...@@ -15,12 +15,12 @@ import java.util.stream.Collectors; ...@@ -15,12 +15,12 @@ import java.util.stream.Collectors;
*/ */
public class InputValueDefinitionToParameterMapper { public class InputValueDefinitionToParameterMapper {
public static List<ParameterDefinition> map(MappingConfig mappingConfig, List<InputValueDefinition> valueDefinitions) { public static List<ParameterDefinition> map(MappingConfig mappingConfig, List<InputValueDefinition> valueDefinitions, String parentTypeName) {
if (valueDefinitions == null) { if (valueDefinitions == null) {
return Collections.emptyList(); return Collections.emptyList();
} }
return valueDefinitions.stream() return valueDefinitions.stream()
.map(inputValueDefinition -> GraphqlTypeToJavaTypeMapper.map(mappingConfig, inputValueDefinition)) .map(inputValueDefinition -> GraphqlTypeToJavaTypeMapper.map(mappingConfig, inputValueDefinition, parentTypeName))
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
......
...@@ -75,8 +75,8 @@ class GraphqlCodegenGitHubTest { ...@@ -75,8 +75,8 @@ class GraphqlCodegenGitHubTest {
StringContains.containsString("public interface GithubAssigneeTO ")); StringContains.containsString("public interface GithubAssigneeTO "));
// verify proper class name for GraphQL input // verify proper class name for GraphQL input
assertThat(getGeneratedFileContent(files, "GithubChangeUserStatusInputTO.java"), assertEquals(Utils.getFileContent(new File("src/test/resources/expected-classes/GithubAcceptTopicSuggestionInputTO.java.txt").getPath()),
StringContains.containsString("public class GithubChangeUserStatusInputTO ")); getGeneratedFileContent(files, "GithubAcceptTopicSuggestionInputTO.java"));
// verify proper class name for GraphQL type and references to interfaces/types/unions for GraphQL type // verify proper class name for GraphQL type and references to interfaces/types/unions for GraphQL type
assertEquals(Utils.getFileContent(new File("src/test/resources/expected-classes/GithubCommitTO.java.txt").getPath()), assertEquals(Utils.getFileContent(new File("src/test/resources/expected-classes/GithubCommitTO.java.txt").getPath()),
......
package com.github.graphql;
import java.util.*;
public class GithubAcceptTopicSuggestionInputTO {
private String clientMutationId;
@javax.validation.constraints.NotNull
private String name;
@javax.validation.constraints.NotNull
private String repositoryId;
public GithubAcceptTopicSuggestionInputTO() {
}
public String getClientMutationId() {
return clientMutationId;
}
public void setClientMutationId(String clientMutationId) {
this.clientMutationId = clientMutationId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getRepositoryId() {
return repositoryId;
}
public void setRepositoryId(String repositoryId) {
this.repositoryId = repositoryId;
}
}
\ No newline at end of file
...@@ -9,19 +9,19 @@ schema { ...@@ -9,19 +9,19 @@ schema {
type Query { type Query {
# Version of the application. # Version of the application.
version: String version: String!
# List of events of a specified category. # List of events of a specified category.
eventsByCategoryAndStatus(categoryId: ID!, status: EventStatus): [Event] eventsByCategoryAndStatus(categoryId: ID!, status: EventStatus): [Event]!
# Single event by ID. # Single event by ID.
eventById(id: ID!): Event eventById(id: ID!): Event!
} }
type Mutation { type Mutation {
# Create a new event. # Create a new event.
createEvent(categoryId: String!, createEvent(categoryId: String!,
createdBy: String!): Event createdBy: String!): Event!
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册