未验证 提交 dee019ba 编写于 作者: B Bogdan Kobylynskyi 提交者: GitHub

Merge pull request #18 from kobylynskyi/feature/subscription-return-type

Subscription methods with custom return type #14
......@@ -26,6 +26,7 @@ Please refer to:
| modelValidationAnnotation | String | @javax.validation.<br>constraints.NotNull | Annotation for mandatory (NonNull) fields. Can be null/empty. |
| 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). |
| subscriptionReturnType | String | Empty | Return type for subscription methods. For example: `org.reactivestreams.Publisher`, `io.reactivex.Observable`, etc. |
| 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. |
......
......@@ -49,7 +49,8 @@ public class FieldDefinitionToDataModelMapper {
static OperationDefinition mapFieldDefinition(MappingConfig mappingConfig, FieldDefinition fieldDef, String parentTypeName) {
OperationDefinition operation = new OperationDefinition();
operation.setName(fieldDef.getName());
operation.setType(GraphqlTypeToJavaTypeMapper.getJavaType(mappingConfig, fieldDef.getType(), fieldDef.getName(), parentTypeName));
String javaType = GraphqlTypeToJavaTypeMapper.getJavaType(mappingConfig, fieldDef.getType(), fieldDef.getName(), parentTypeName);
operation.setType(GraphqlTypeToJavaTypeMapper.wrapIntoSubscriptionIfRequired(mappingConfig, javaType, parentTypeName));
operation.setAnnotations(GraphqlTypeToJavaTypeMapper.getAnnotations(mappingConfig, fieldDef.getType(), fieldDef.getName(), parentTypeName));
operation.setParameters(InputValueDefinitionToParameterMapper.map(mappingConfig, fieldDef.getInputValueDefinitions(), fieldDef.getName()));
return operation;
......
package com.kobylynskyi.graphql.codegen.mapper;
import static graphql.language.OperationDefinition.*;
import com.kobylynskyi.graphql.codegen.model.MappingConfig;
import com.kobylynskyi.graphql.codegen.model.ParameterDefinition;
import graphql.language.*;
......@@ -16,7 +18,7 @@ import java.util.Map;
class GraphqlTypeToJavaTypeMapper {
/**
* Map GraphQL's FieldDefinition to a Freemarker-understandable format of operation
* Map GraphQL's FieldDefinition to a Freemarker-understandable format of parameter
*
* @param mappingConfig Global mapping configuration
* @param fieldDef GraphQL field definition
......@@ -62,19 +64,19 @@ class GraphqlTypeToJavaTypeMapper {
* Convert GraphQL type to a corresponding Java type
*
* @param mappingConfig Global mapping configuration
* @param graphlType GraphQL type
* @param graphqlType GraphQL type
* @param name GraphQL type name
* @param parentTypeName Name of the parent type
* @return Corresponding Java type
*/
static String getJavaType(MappingConfig mappingConfig, Type graphlType, String name, String parentTypeName) {
if (graphlType instanceof TypeName) {
return getJavaType(mappingConfig, ((TypeName) graphlType).getName(), name, parentTypeName);
} else if (graphlType instanceof ListType) {
String mappedCollectionType = getJavaType(mappingConfig, ((ListType) graphlType).getType(), name, parentTypeName);
static String getJavaType(MappingConfig mappingConfig, Type graphqlType, String name, String parentTypeName) {
if (graphqlType instanceof TypeName) {
return getJavaType(mappingConfig, ((TypeName) graphqlType).getName(), name, parentTypeName);
} else if (graphqlType instanceof ListType) {
String mappedCollectionType = getJavaType(mappingConfig, ((ListType) graphqlType).getType(), name, parentTypeName);
return wrapIntoJavaCollection(mappedCollectionType);
} else if (graphlType instanceof NonNullType) {
return getJavaType(mappingConfig, ((NonNullType) graphlType).getType(), name, parentTypeName);
} else if (graphqlType instanceof NonNullType) {
return getJavaType(mappingConfig, ((NonNullType) graphqlType).getType(), name, parentTypeName);
}
return null;
}
......@@ -156,4 +158,13 @@ class GraphqlTypeToJavaTypeMapper {
return String.format("Collection<%s>", type);
}
static String wrapIntoSubscriptionIfRequired(MappingConfig mappingConfig, String javaTypeName, String parentTypeName) {
if (parentTypeName.equalsIgnoreCase(Operation.SUBSCRIPTION.name())
&& mappingConfig.getSubscriptionReturnType() != null
&& !mappingConfig.getSubscriptionReturnType().trim().isEmpty()) {
return String.format("%s<%s>", mappingConfig.getSubscriptionReturnType(), javaTypeName);
}
return javaTypeName;
}
}
......@@ -36,6 +36,7 @@ public class MappingConfig implements Combinable<MappingConfig> {
private String modelNamePrefix;
private String modelNameSuffix;
private String modelValidationAnnotation;
private String subscriptionReturnType;
private Boolean generateEqualsAndHashCode;
private Boolean generateToString;
......@@ -77,6 +78,7 @@ public class MappingConfig implements Combinable<MappingConfig> {
this.modelNamePrefix = source.modelNamePrefix != null ? source.modelNamePrefix : this.modelNamePrefix;
this.modelNameSuffix = source.modelNameSuffix != null ? source.modelNameSuffix : this.modelNameSuffix;
this.modelValidationAnnotation = source.modelValidationAnnotation != null ? source.modelValidationAnnotation : this.modelValidationAnnotation;
this.subscriptionReturnType = source.subscriptionReturnType != null ? source.subscriptionReturnType : this.subscriptionReturnType;
this.generateEqualsAndHashCode = source.generateEqualsAndHashCode != null ? source.generateEqualsAndHashCode : this.generateEqualsAndHashCode;
this.generateToString = source.generateToString != null ? source.generateToString : this.generateToString;
}
......
package com.kobylynskyi.graphql.codegen;
import com.kobylynskyi.graphql.codegen.model.MappingConfig;
import com.kobylynskyi.graphql.codegen.utils.Utils;
import static java.util.stream.Collectors.toList;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.fail;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.NoSuchFileException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import org.hamcrest.core.StringContains;
import org.hamcrest.core.StringStartsWith;
import org.junit.jupiter.api.AfterEach;
......@@ -9,17 +24,8 @@ import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.NoSuchFileException;
import java.util.*;
import static java.util.stream.Collectors.toList;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.fail;
import com.kobylynskyi.graphql.codegen.model.MappingConfig;
import com.kobylynskyi.graphql.codegen.utils.Utils;
class GraphqlCodegenTest {
......@@ -39,7 +45,7 @@ class GraphqlCodegenTest {
@AfterEach
void cleanup() throws IOException {
Utils.deleteDir(new File("build/generated"));
//Utils.deleteDir(new File("build/generated"));
}
@Test
......@@ -48,19 +54,16 @@ class GraphqlCodegenTest {
File[] files = Objects.requireNonNull(outputJavaClassesDir.listFiles());
List<String> generatedFileNames = Arrays.stream(files).map(File::getName).sorted().collect(toList());
assertEquals(Arrays.asList("CreateEventMutation.java", "Event.java", "EventByIdQuery.java",
"EventProperty.java", "EventStatus.java", "EventsByCategoryAndStatusQuery.java",
"Mutation.java", "Query.java", "VersionQuery.java"),
generatedFileNames);
Arrays.stream(files).forEach(file -> {
try {
File expected = new File(String.format("src/test/resources/expected-classes/%s.txt", file.getName()));
assertEquals(Utils.getFileContent(expected.getPath()), Utils.getFileContent(file.getPath()));
} catch (IOException e) {
fail(e);
}
});
assertEquals(
Arrays.asList("CreateEventMutation.java", "Event.java", "EventByIdQuery.java",
"EventProperty.java", "EventStatus.java", "EventsByCategoryAndStatusQuery.java",
"EventsCreatedSubscription.java", "Mutation.java", "Query.java", "Subscription.java",
"VersionQuery.java"), generatedFileNames);
for (File file : files) {
File expected = new File(String.format("src/test/resources/expected-classes/%s.txt", file.getName()));
assertEquals(Utils.getFileContent(expected.getPath()), Utils.getFileContent(file.getPath()));
}
}
@Test
......@@ -70,17 +73,17 @@ class GraphqlCodegenTest {
generator.generate();
File[] files = Objects.requireNonNull(outputJavaClassesDir.listFiles());
File eventFile = Arrays.stream(files)
.filter(file -> file.getName().equalsIgnoreCase("Event.java"))
.findFirst().orElseThrow(FileNotFoundException::new);
File eventFile = Arrays.stream(files).filter(file -> file.getName().equalsIgnoreCase("Event.java")).findFirst()
.orElseThrow(FileNotFoundException::new);
assertThat(Utils.getFileContent(eventFile.getPath()), StringContains.containsString("java.util.Date createdDateTime;"));
assertThat(Utils.getFileContent(eventFile.getPath()),
StringContains.containsString("java.util.Date createdDateTime;"));
}
@Test
void generate_CustomMappings_Nested() throws Exception {
mappingConfig.setCustomTypesMapping(new HashMap<>(
Collections.singletonMap("EventProperty.intVal", "java.math.BigInteger")));
mappingConfig.setCustomTypesMapping(
new HashMap<>(Collections.singletonMap("EventProperty.intVal", "java.math.BigInteger")));
generator.generate();
......@@ -88,15 +91,13 @@ class GraphqlCodegenTest {
// As per mapping, only EventProperty.intVal should be mapped to java.math.BigInteger
File eventPropertyFile = Arrays.stream(files)
.filter(file -> file.getName().equalsIgnoreCase("EventProperty.java"))
.findFirst().orElseThrow(FileNotFoundException::new);
.filter(file -> file.getName().equalsIgnoreCase("EventProperty.java")).findFirst()
.orElseThrow(FileNotFoundException::new);
assertThat(Utils.getFileContent(eventPropertyFile.getPath()),
StringContains.containsString("private java.math.BigInteger intVal;"));
File eventFile = Arrays.stream(files)
.filter(file -> file.getName().equalsIgnoreCase("Event.java"))
.findFirst().orElseThrow(FileNotFoundException::new);
assertThat(Utils.getFileContent(eventFile.getPath()),
StringContains.containsString("private Integer rating;"));
File eventFile = Arrays.stream(files).filter(file -> file.getName().equalsIgnoreCase("Event.java")).findFirst()
.orElseThrow(FileNotFoundException::new);
assertThat(Utils.getFileContent(eventFile.getPath()), StringContains.containsString("private Integer rating;"));
}
@Test
......@@ -105,9 +106,8 @@ class GraphqlCodegenTest {
generator.generate();
File[] files = Objects.requireNonNull(outputJavaClassesDir.listFiles());
File eventFile = Arrays.stream(files)
.filter(file -> file.getName().equalsIgnoreCase("Event.java"))
.findFirst().orElseThrow(FileNotFoundException::new);
File eventFile = Arrays.stream(files).filter(file -> file.getName().equalsIgnoreCase("Event.java")).findFirst()
.orElseThrow(FileNotFoundException::new);
assertThat(Utils.getFileContent(eventFile.getPath()), StringContains.containsString("String createdDateTime;"));
}
......@@ -118,47 +118,59 @@ class GraphqlCodegenTest {
generator.generate();
File[] files = Objects.requireNonNull(outputJavaClassesDir.listFiles());
File eventFile = Arrays.stream(files)
.filter(file -> file.getName().equalsIgnoreCase("Event.java"))
.findFirst().orElseThrow(FileNotFoundException::new);
File eventFile = Arrays.stream(files).filter(file -> file.getName().equalsIgnoreCase("Event.java")).findFirst()
.orElseThrow(FileNotFoundException::new);
assertThat(Utils.getFileContent(eventFile.getPath()), StringContains.containsString("String createdDateTime;"));
}
@Test
void generate_CustomAnnotationMappings() throws Exception {
mappingConfig.setCustomTypesMapping(new HashMap<>(Collections.singletonMap(
"Event.createdDateTime", "org.joda.time.DateTime")));
mappingConfig.setCustomTypesMapping(
new HashMap<>(Collections.singletonMap("Event.createdDateTime", "org.joda.time.DateTime")));
mappingConfig.setCustomAnnotationsMapping(new HashMap<>(Collections.singletonMap(
"Event.createdDateTime", "com.fasterxml.jackson.databind.annotation.JsonDeserialize(using = com.example.json.DateTimeScalarDeserializer.class)")));
mappingConfig.setCustomAnnotationsMapping(new HashMap<>(Collections.singletonMap("Event.createdDateTime",
"com.fasterxml.jackson.databind.annotation.JsonDeserialize(using = com.example.json.DateTimeScalarDeserializer.class)")));
generator.generate();
File eventFile = Arrays.stream(Objects.requireNonNull(outputJavaClassesDir.listFiles()))
.filter(file -> file.getName().equalsIgnoreCase("Event.java"))
.findFirst().orElseThrow(FileNotFoundException::new);
assertThat(Utils.getFileContent(eventFile.getPath()),
StringContains.containsString("@com.fasterxml.jackson.databind.annotation.JsonDeserialize(using = com.example.json.DateTimeScalarDeserializer.class)" +
System.lineSeparator() + " private org.joda.time.DateTime createdDateTime;"));
.filter(file -> file.getName().equalsIgnoreCase("Event.java")).findFirst()
.orElseThrow(FileNotFoundException::new);
assertThat(Utils.getFileContent(eventFile.getPath()), StringContains.containsString(
"@com.fasterxml.jackson.databind.annotation.JsonDeserialize(using = com.example.json.DateTimeScalarDeserializer.class)"
+ System.lineSeparator() + " private org.joda.time.DateTime createdDateTime;"));
}
@Test
void generate_CustomAnnotationMappings_FieldType() throws Exception {
mappingConfig.setCustomTypesMapping(new HashMap<>(Collections.singletonMap(
"DateTime", "org.joda.time.DateTime")));
mappingConfig
.setCustomTypesMapping(new HashMap<>(Collections.singletonMap("DateTime", "org.joda.time.DateTime")));
mappingConfig.setCustomAnnotationsMapping(new HashMap<>(Collections.singletonMap(
"Event.createdDateTime", "com.fasterxml.jackson.databind.annotation.JsonDeserialize(using = com.example.json.DateTimeScalarDeserializer.class)")));
mappingConfig.setCustomAnnotationsMapping(new HashMap<>(Collections.singletonMap("Event.createdDateTime",
"com.fasterxml.jackson.databind.annotation.JsonDeserialize(using = com.example.json.DateTimeScalarDeserializer.class)")));
generator.generate();
File eventFile = Arrays.stream(Objects.requireNonNull(outputJavaClassesDir.listFiles()))
.filter(file -> file.getName().equalsIgnoreCase("Event.java"))
.findFirst().orElseThrow(FileNotFoundException::new);
assertThat(Utils.getFileContent(eventFile.getPath()),
StringContains.containsString("@com.fasterxml.jackson.databind.annotation.JsonDeserialize(using = com.example.json.DateTimeScalarDeserializer.class)" +
System.lineSeparator() + " private org.joda.time.DateTime createdDateTime;"));
.filter(file -> file.getName().equalsIgnoreCase("Event.java")).findFirst()
.orElseThrow(FileNotFoundException::new);
assertThat(Utils.getFileContent(eventFile.getPath()), StringContains.containsString(
"@com.fasterxml.jackson.databind.annotation.JsonDeserialize(using = com.example.json.DateTimeScalarDeserializer.class)"
+ System.lineSeparator() + " private org.joda.time.DateTime createdDateTime;"));
}
@Test
void generate_CustomSubscriptionReturnType() throws Exception {
mappingConfig.setSubscriptionReturnType("org.reactivestreams.Publisher");
generator.generate();
File eventFile = Arrays.stream(Objects.requireNonNull(outputJavaClassesDir.listFiles()))
.filter(file -> file.getName().equalsIgnoreCase("EventsCreatedSubscription.java")).findFirst()
.orElseThrow(FileNotFoundException::new);
assertThat(Utils.getFileContent(eventFile.getPath()), StringContains.containsString(
"org.reactivestreams.Publisher<Collection<Event>> eventsCreated() throws Exception;"));
}
@Test
......@@ -167,14 +179,11 @@ class GraphqlCodegenTest {
generator.generate();
File[] files = Objects.requireNonNull(outputBuildDir.listFiles());
File eventFile = Arrays.stream(files)
.filter(file -> file.getName().equalsIgnoreCase("Event.java"))
.findFirst().orElseThrow(FileNotFoundException::new);
File eventFile = Arrays.stream(files).filter(file -> file.getName().equalsIgnoreCase("Event.java")).findFirst()
.orElseThrow(FileNotFoundException::new);
assertThat(Utils.getFileContent(eventFile.getPath()),
StringStartsWith.startsWith("import java.util.*;" +
System.lineSeparator() + System.lineSeparator() +
"public class Event {"));
assertThat(Utils.getFileContent(eventFile.getPath()), StringStartsWith.startsWith(
"import java.util.*;" + System.lineSeparator() + System.lineSeparator() + "public class Event {"));
}
@Test
......@@ -183,12 +192,11 @@ class GraphqlCodegenTest {
mappingConfig.setApiPackageName("com.kobylynskyi.graphql.test1.api");
generator.generate();
File[] apiFiles = Objects.requireNonNull(new File(outputJavaClassesDir, "api").listFiles());
List<String> generatedApiFileNames = Arrays.stream(apiFiles).map(File::getName).sorted().collect(toList());
assertEquals(Arrays.asList("CreateEventMutation.java", "EventByIdQuery.java",
"EventsByCategoryAndStatusQuery.java", "Mutation.java", "Query.java", "VersionQuery.java"),
generatedApiFileNames);
"EventsByCategoryAndStatusQuery.java", "EventsCreatedSubscription.java", "Mutation.java", "Query.java",
"Subscription.java", "VersionQuery.java"), generatedApiFileNames);
Arrays.stream(apiFiles).forEach(file -> {
try {
assertThat(Utils.getFileContent(file.getPath()),
......@@ -200,8 +208,7 @@ class GraphqlCodegenTest {
File[] modelFiles = Objects.requireNonNull(new File(outputJavaClassesDir, "model").listFiles());
List<String> generatedModelFileNames = Arrays.stream(modelFiles).map(File::getName).sorted().collect(toList());
assertEquals(Arrays.asList("Event.java", "EventProperty.java", "EventStatus.java"),
generatedModelFileNames);
assertEquals(Arrays.asList("Event.java", "EventProperty.java", "EventStatus.java"), generatedModelFileNames);
Arrays.stream(modelFiles).forEach(file -> {
try {
assertThat(Utils.getFileContent(file.getPath()),
......@@ -226,22 +233,21 @@ class GraphqlCodegenTest {
if (eventFile.getName().endsWith("TO.java")) {
String content = Utils.getFileContent(eventFile.getPath());
if (content.contains("public interface ") || content.contains("public enum ")) {
continue;
}
if (content.contains("public interface ") || content.contains("public enum ")) {
continue;
}
assertThat(content,
StringContains.containsString("public boolean equals(Object obj)"));
assertThat(content, StringContains.containsString("public boolean equals(Object obj)"));
assertThat(content,
StringContains.containsString("public int hashCode()"));
assertThat(content, StringContains.containsString("public int hashCode()"));
}
}
assertEquals(Utils.getFileContent("src/test/resources/expected-classes/EventPropertyTO_withEqualsAndHashCode.java.txt"),
Utils.getFileContent(Arrays.stream(files)
.filter(f -> f.getName().equals("EventPropertyTO.java"))
.map(File::getPath).findFirst().orElseThrow(FileNotFoundException::new)));
assertEquals(Utils.getFileContent(
"src/test/resources/expected-classes/EventPropertyTO_withEqualsAndHashCode.java.txt"),
Utils.getFileContent(
Arrays.stream(files).filter(f -> f.getName().equals("EventPropertyTO.java")).map(File::getPath)
.findFirst().orElseThrow(FileNotFoundException::new)));
}
@Test
......@@ -262,8 +268,7 @@ class GraphqlCodegenTest {
continue;
}
assertThat(content,
StringContains.containsString("public String toString()"));
assertThat(content, StringContains.containsString("public String toString()"));
}
}
}
......@@ -281,9 +286,7 @@ class GraphqlCodegenTest {
void generate_WrongSchema() {
generator.setSchemas(Collections.singletonList("src/test/resources/schemas/wrong.graphqls"));
Assertions.assertThrows(NoSuchFileException.class, () -> {
generator.generate();
});
Assertions.assertThrows(NoSuchFileException.class, () -> generator.generate());
}
@Test
......@@ -295,13 +298,13 @@ class GraphqlCodegenTest {
File[] files = Objects.requireNonNull(outputBuildDir.listFiles());
assertEquals(2, files.length);
assertEquals(Utils.getFileContent("src/test/resources/expected-classes/EmptyMutation.java.txt"),
Utils.getFileContent(Arrays.stream(files)
.filter(f -> f.getName().equals("Mutation.java"))
.map(File::getPath).findFirst().orElseThrow(FileNotFoundException::new)));
Utils.getFileContent(
Arrays.stream(files).filter(f -> f.getName().equals("Mutation.java")).map(File::getPath)
.findFirst().orElseThrow(FileNotFoundException::new)));
assertEquals(Utils.getFileContent("src/test/resources/expected-classes/EmptyQuery.java.txt"),
Utils.getFileContent(Arrays.stream(files)
.filter(f -> f.getName().equals("Query.java"))
.map(File::getPath).findFirst().orElseThrow(FileNotFoundException::new)));
Utils.getFileContent(
Arrays.stream(files).filter(f -> f.getName().equals("Query.java")).map(File::getPath)
.findFirst().orElseThrow(FileNotFoundException::new)));
}
@Test
......
package com.kobylynskyi.graphql.codegen.model;
import static java.util.Arrays.asList;
import static java.util.Collections.singletonMap;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
......@@ -9,7 +8,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.AbstractMap;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.stream.Collectors;
......@@ -19,7 +17,7 @@ import org.junit.jupiter.api.Test;
class MappingConfigTest {
@Test
public void combineDefaultWithNull() {
void combineDefaultWithNull() {
MappingConfig mappingConfig = buildEmptyMappingConfig();
mappingConfig.combine(null);
......@@ -68,6 +66,7 @@ class MappingConfigTest {
assertEquals("ModelPackageName", mappingConfig.getModelPackageName());
assertEquals("ModelValidationAnnotation", mappingConfig.getModelValidationAnnotation());
assertEquals("PackageName", mappingConfig.getPackageName());
assertEquals("SubscriptionsReturnType", mappingConfig.getSubscriptionReturnType());
}
@Test
......@@ -88,6 +87,7 @@ class MappingConfigTest {
assertEquals("ModelPackageName2", mappingConfig.getModelPackageName());
assertEquals("ModelValidationAnnotation2", mappingConfig.getModelValidationAnnotation());
assertEquals("PackageName2", mappingConfig.getPackageName());
assertEquals("SubscriptionsReturnType2", mappingConfig.getSubscriptionReturnType());
}
private static Map<String, String> hashMap(AbstractMap.SimpleEntry<String, String>... entries) {
......@@ -108,6 +108,7 @@ class MappingConfigTest {
config.setModelPackageName("ModelPackageName");
config.setModelValidationAnnotation("ModelValidationAnnotation");
config.setPackageName("PackageName");
config.setSubscriptionReturnType("SubscriptionsReturnType");
return config;
}
......@@ -124,6 +125,7 @@ class MappingConfigTest {
config.setModelPackageName("ModelPackageName2");
config.setModelValidationAnnotation("ModelValidationAnnotation2");
config.setPackageName("PackageName2");
config.setSubscriptionReturnType("SubscriptionsReturnType2");
return config;
}
......
package com.kobylynskyi.graphql.test1;
import java.util.*;
public interface EventsCreatedSubscription {
@javax.validation.constraints.NotNull
Collection<Event> eventsCreated() throws Exception;
}
\ No newline at end of file
package com.kobylynskyi.graphql.test1;
import java.util.*;
public interface Subscription {
@javax.validation.constraints.NotNull
Collection<Event> eventsCreated() throws Exception;
}
\ No newline at end of file
......@@ -5,6 +5,9 @@ schema {
# The mutation root.
mutation: Mutation
# The subscription root.
subscription: Subscription
}
type Query {
......@@ -23,6 +26,11 @@ type Mutation {
createEvent(categoryId: String!, createdBy: String!): Event! @auth(role:"admin")
}
type Subscription {
# Subscribe to events
eventsCreated: [Event!]!
}
# An event that describes a thing that happens
type Event {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册