diff --git a/CHANGELOG.md b/CHANGELOG.md
index 99faee6e2..28d327e14 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,9 +12,9 @@ Whether the application uses the _graphql_, the _generateClientCode_ or the _gen
# Not released yet
-
Both modes:
-* Issue #166 : Corrected an issue that prevents to request data when GraphQL field's name are java reserved keywords
+* Issue #166: Corrected an issue that prevents to request data when GraphQL field's name are java reserved keywords
+* Issue #164: the descriptions from the GraphQL schema is now included in the java comments for objects, fields, union...
# 1.18.8
diff --git a/graphql-maven-plugin-logic/src/main/java/com/graphql_java_generator/plugin/DocumentParser.java b/graphql-maven-plugin-logic/src/main/java/com/graphql_java_generator/plugin/DocumentParser.java
index 2847c6f96..b421c4789 100644
--- a/graphql-maven-plugin-logic/src/main/java/com/graphql_java_generator/plugin/DocumentParser.java
+++ b/graphql-maven-plugin-logic/src/main/java/com/graphql_java_generator/plugin/DocumentParser.java
@@ -25,6 +25,7 @@
import com.graphql_java_generator.plugin.conf.GraphQLConfiguration;
import com.graphql_java_generator.plugin.generate_schema.GenerateGraphQLSchemaDocumentParser;
import com.graphql_java_generator.plugin.language.AppliedDirective;
+import com.graphql_java_generator.plugin.language.Description;
import com.graphql_java_generator.plugin.language.Directive;
import com.graphql_java_generator.plugin.language.DirectiveLocation;
import com.graphql_java_generator.plugin.language.EnumValue;
@@ -482,9 +483,14 @@ public Directive readDirectiveDefinition(DirectiveDefinition node) {
directive.setArguments(node.getInputValueDefinitions().stream().map(this::readFieldTypeDefinition)
.collect(Collectors.toList()));
- // Let's store its comments
+ // Let's store its comments,
directive.setComments(node.getComments());
+ // its description,
+ if (node.getDescription() != null) {
+ directive.setDescription(getDescription(node.getDescription()));
+ }
+
// and all its locations
for (graphql.language.DirectiveLocation dl : node.getDirectiveLocations()) {
DirectiveLocation dirLoc = DirectiveLocation.valueOf(DirectiveLocation.class, dl.getName());
@@ -676,6 +682,11 @@ private ObjectType addObjectTypeDefinition(final ObjectType objectType, ObjectTy
objectType.getComments()
.addAll(node.getComments().stream().map(c -> c.getContent()).collect(Collectors.toList()));
+ // and its description,
+ if (node.getDescription() != null) {
+ objectType.setDescription(getDescription(node.getDescription()));
+ }
+
// Let's read all the interfaces this object implements
for (graphql.language.Type type : node.getImplements()) {
if (type instanceof TypeName) {
@@ -710,6 +721,11 @@ ObjectType readInputType(ObjectType objectType, InputObjectTypeDefinition node)
objectType.getComments()
.addAll(node.getComments().stream().map(c -> c.getContent()).collect(Collectors.toList()));
+ // and its description,
+ if (node.getDescription() != null) {
+ objectType.setDescription(getDescription(node.getDescription()));
+ }
+
// Let's read all its fields
for (InputValueDefinition def : node.getInputValueDefinitions()) {
FieldImpl field = readFieldTypeDefinition(def);
@@ -742,6 +758,11 @@ InterfaceType readInterfaceType(InterfaceTypeDefinition node) {
// Let's store its comments
interfaceType.setComments(node.getComments());
+ // and its description,
+ if (node.getDescription() != null) {
+ interfaceType.setDescription(getDescription(node.getDescription()));
+ }
+
// Let's read all its fields
interfaceType.setFields(node.getFieldDefinitions().stream().map(def -> readField(def, interfaceType))
.collect(Collectors.toList()));
@@ -773,6 +794,11 @@ UnionType readUnionType(UnionType unionType, UnionTypeDefinition node) {
unionType.getComments()
.addAll(node.getComments().stream().map(c -> c.getContent()).collect(Collectors.toList()));
+ // and its description,
+ if (node.getDescription() != null) {
+ unionType.setDescription(getDescription(node.getDescription()));
+ }
+
for (graphql.language.Type> memberType : node.getMemberTypes()) {
String memberTypeName = (String) graphqlUtils.invokeMethod("getName", memberType);
@@ -834,6 +860,11 @@ CustomScalarType readCustomScalarType(ScalarTypeDefinition node) {
// Let's store its comments
customScalarType.setComments(node.getComments());
+ // and its description,
+ if (node.getDescription() != null) {
+ customScalarType.setDescription(getDescription(node.getDescription()));
+ }
+
return customScalarType;
}
@@ -853,6 +884,11 @@ public EnumType readEnumType(EnumType enumType, EnumTypeDefinition node) {
enumType.getComments()
.addAll(node.getComments().stream().map(c -> c.getContent()).collect(Collectors.toList()));
+ // and its description,
+ if (node.getDescription() != null) {
+ enumType.setDescription(getDescription(node.getDescription()));
+ }
+
for (EnumValueDefinition enumValDef : node.getEnumValueDefinitions()) {
EnumValue val = EnumValueImpl.builder().name(enumValDef.getName())
.appliedDirectives(readAppliedDirectives(enumValDef.getDirectives())).build();
@@ -883,6 +919,11 @@ Field readField(FieldDefinition fieldDef, Type owningType) {
// Let's store its comments
field.setComments(fieldDef.getComments());
+ // and its description
+ if (fieldDef.getDescription() != null) {
+ field.setDescription(getDescription(fieldDef.getDescription()));
+ }
+
return field;
}
@@ -1043,4 +1084,14 @@ protected String getUtilPackageName() {
return ((GenerateCodeCommonConfiguration) configuration).getPackageName();
}
+ /**
+ * Returns an instance of {@link Description} based on the given String, or null of this string is null
+ *
+ * @param description
+ * @return
+ */
+ private Description getDescription(graphql.language.Description description) {
+ return (description == null) ? null : new Description(description);
+ }
+
}
\ No newline at end of file
diff --git a/graphql-maven-plugin-logic/src/main/java/com/graphql_java_generator/plugin/language/DataFetcher.java b/graphql-maven-plugin-logic/src/main/java/com/graphql_java_generator/plugin/language/DataFetcher.java
index 72ecf9ddb..a3318c32f 100644
--- a/graphql-maven-plugin-logic/src/main/java/com/graphql_java_generator/plugin/language/DataFetcher.java
+++ b/graphql-maven-plugin-logic/src/main/java/com/graphql_java_generator/plugin/language/DataFetcher.java
@@ -69,7 +69,7 @@ default public String getJavaName() {
public DataFetchersDelegate getDataFetcherDelegate();
/**
- * Retrieves the origin of this {@link DataFetcher}, that is: the name of the object which contains the field to
+ * Retrieves the origin of this {@link DataFetcher}, that is: the name of the object which contains the fields to
* fetch.
* There are two kinds of {@link DataFetcher}:
*
diff --git a/graphql-maven-plugin-logic/src/main/java/com/graphql_java_generator/plugin/language/Description.java b/graphql-maven-plugin-logic/src/main/java/com/graphql_java_generator/plugin/language/Description.java
new file mode 100644
index 000000000..30b9d79b5
--- /dev/null
+++ b/graphql-maven-plugin-logic/src/main/java/com/graphql_java_generator/plugin/language/Description.java
@@ -0,0 +1,65 @@
+/**
+ *
+ */
+package com.graphql_java_generator.plugin.language;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * This class matches the description of a GraphQL item, as described in the GraphQL schema. It allows several
+ * capabilities for use in the template, for code or schema generation
+ *
+ * @author etienne-sf
+ */
+public class Description {
+
+ /** The description as it has been read from the source GraphQL schema */
+ final graphql.language.Description description;
+
+ /** The decomposition of the description in lines, without the EOL character(s) */
+ List lines = null;
+
+ public Description(graphql.language.Description description2) {
+ this.description = description2;
+ }
+
+ /**
+ * Returns the content of the description
+ *
+ * @return
+ */
+ public String getContent() {
+ return description.getContent();
+ }
+
+ public boolean isMultiLine() {
+ return description.isMultiLine();
+ }
+
+ /**
+ * Returns an array of the lines of this description. This array contains at least one item.
+ *
+ * @return
+ */
+ public List getLines() {
+ if (lines == null) {
+ if (description.isMultiLine()) {
+ try (BufferedReader sr = new BufferedReader(new StringReader(description.getContent()))) {
+ lines = sr.lines().collect(Collectors.toList());
+ } catch (IOException e) {
+ throw new RuntimeException(e.getMessage(), e);
+ }
+ } else {
+ lines = new ArrayList(1);
+ lines.add(description.getContent());
+ }
+ }
+ return lines;
+ }
+
+}
diff --git a/graphql-maven-plugin-logic/src/main/java/com/graphql_java_generator/plugin/language/Directive.java b/graphql-maven-plugin-logic/src/main/java/com/graphql_java_generator/plugin/language/Directive.java
index ceb64d541..942007f2c 100644
--- a/graphql-maven-plugin-logic/src/main/java/com/graphql_java_generator/plugin/language/Directive.java
+++ b/graphql-maven-plugin-logic/src/main/java/com/graphql_java_generator/plugin/language/Directive.java
@@ -18,9 +18,12 @@ public interface Directive {
/** A directive may have arguments. An argument is actually a field. */
public List getArguments();
- /** Returns the comments that have been found for this object, in the provided GraphQL schema */
+ /** Returns the comments that have been found before this object, in the provided GraphQL schema */
public List getComments();
+ /** Returns the description for this object, in the provided GraphQL schema */
+ public Description getDescription();
+
/** Returns the list of location that this directive may have */
public List getDirectiveLocations();
diff --git a/graphql-maven-plugin-logic/src/main/java/com/graphql_java_generator/plugin/language/Field.java b/graphql-maven-plugin-logic/src/main/java/com/graphql_java_generator/plugin/language/Field.java
index 4dc910fed..e6ee19478 100644
--- a/graphql-maven-plugin-logic/src/main/java/com/graphql_java_generator/plugin/language/Field.java
+++ b/graphql-maven-plugin-logic/src/main/java/com/graphql_java_generator/plugin/language/Field.java
@@ -201,9 +201,12 @@ default public Set getFieldJavaFullClassnamesFromImplementedInterface()
*/
public String getAnnotation();
- /** Returns the comments that have been found for this object, in the provided GraphQL schema */
+ /** Returns the comments that have been found before this object, in the provided GraphQL schema */
public List getComments();
+ /** Returns the description for this object, in the provided GraphQL schema */
+ public Description getDescription();
+
/**
* Convert the given name, which is supposed to be in camel case (for instance: thisIsCamelCase) to a pascal case
* string (for instance: ThisIsCamelCase).
diff --git a/graphql-maven-plugin-logic/src/main/java/com/graphql_java_generator/plugin/language/Type.java b/graphql-maven-plugin-logic/src/main/java/com/graphql_java_generator/plugin/language/Type.java
index d18934124..00b0d2888 100644
--- a/graphql-maven-plugin-logic/src/main/java/com/graphql_java_generator/plugin/language/Type.java
+++ b/graphql-maven-plugin-logic/src/main/java/com/graphql_java_generator/plugin/language/Type.java
@@ -129,9 +129,12 @@ default public String getTargetFileName(String fileType) {
*/
public void addAnnotation(String annotationToAdd, boolean replace);
- /** Returns the comments that have been found for this object, in the provided GraphQL schema */
+ /** Returns the comments that have been found before this object, in the provided GraphQL schema */
public List getComments();
+ /** Returns the description for this object, in the provided GraphQL schema */
+ public Description getDescription();
+
/**
* The GraphQlType for this type
*
diff --git a/graphql-maven-plugin-logic/src/main/java/com/graphql_java_generator/plugin/language/impl/AbstractType.java b/graphql-maven-plugin-logic/src/main/java/com/graphql_java_generator/plugin/language/impl/AbstractType.java
index 790121238..26b65d8cb 100644
--- a/graphql-maven-plugin-logic/src/main/java/com/graphql_java_generator/plugin/language/impl/AbstractType.java
+++ b/graphql-maven-plugin-logic/src/main/java/com/graphql_java_generator/plugin/language/impl/AbstractType.java
@@ -12,6 +12,7 @@
import com.graphql_java_generator.plugin.conf.CommonConfiguration;
import com.graphql_java_generator.plugin.conf.GraphQLConfiguration;
import com.graphql_java_generator.plugin.language.AppliedDirective;
+import com.graphql_java_generator.plugin.language.Description;
import com.graphql_java_generator.plugin.language.Field;
import com.graphql_java_generator.plugin.language.Type;
import com.graphql_java_generator.util.GraphqlUtils;
@@ -53,9 +54,12 @@ public abstract class AbstractType implements Type {
/** All directives that have been defined in the GraphQL schema for this type */
private List appliedDirectives = new ArrayList<>();
- /** The comments that have been found for this object, in the provided GraphQL schema */
+ /** The comments that have been found before this type, in the provided GraphQL schema */
private List comments = new ArrayList<>();
+ /** The description of this type, in the provided GraphQL schema */
+ private Description description = null;
+
/** The GraphQL type for this type */
final private GraphQlType graphQlType;
@@ -89,18 +93,19 @@ public String getClassSimpleName() {
return getJavaName();
}
- @Override
- public String getJavaName() {
- // Optionally add a prefix and/or suffix to the name
- String name = Stream.of(getPrefix(), getName(), getSuffix())
- .filter(Objects::nonNull).collect(Collectors.joining());
+ @Override
+ public String getJavaName() {
+ // Optionally add a prefix and/or suffix to the name
+ String name = Stream.of(getPrefix(), getName(), getSuffix()).filter(Objects::nonNull)
+ .collect(Collectors.joining());
return GraphqlUtils.graphqlUtils.getJavaName(name);
- }
+ }
protected String getPrefix() {
return "";
}
+
protected String getSuffix() {
return "";
}
diff --git a/graphql-maven-plugin-logic/src/main/java/com/graphql_java_generator/plugin/language/impl/DirectiveImpl.java b/graphql-maven-plugin-logic/src/main/java/com/graphql_java_generator/plugin/language/impl/DirectiveImpl.java
index 29536c249..5238d0f19 100644
--- a/graphql-maven-plugin-logic/src/main/java/com/graphql_java_generator/plugin/language/impl/DirectiveImpl.java
+++ b/graphql-maven-plugin-logic/src/main/java/com/graphql_java_generator/plugin/language/impl/DirectiveImpl.java
@@ -6,6 +6,7 @@
import java.util.ArrayList;
import java.util.List;
+import com.graphql_java_generator.plugin.language.Description;
import com.graphql_java_generator.plugin.language.Directive;
import com.graphql_java_generator.plugin.language.DirectiveLocation;
import com.graphql_java_generator.plugin.language.Field;
@@ -29,9 +30,12 @@ public class DirectiveImpl implements Directive {
/** Returns the list of location that this directive may have */
private List directiveLocations = new ArrayList<>();
- /** The comments that have been found for this object, in the provided GraphQL schema */
+ /** The comments that have been found before this object, in the provided GraphQL schema */
private List comments = new ArrayList<>();
+ /** The description of this directive, in the provided GraphQL schema */
+ private Description description = null;
+
/**
* True if this directive is a standard GraphQL directive, or if it has been defined in the GraphQL schema. Default
* value is false (non standard)
diff --git a/graphql-maven-plugin-logic/src/main/java/com/graphql_java_generator/plugin/language/impl/FieldImpl.java b/graphql-maven-plugin-logic/src/main/java/com/graphql_java_generator/plugin/language/impl/FieldImpl.java
index 6c7745e6e..fe79783cc 100644
--- a/graphql-maven-plugin-logic/src/main/java/com/graphql_java_generator/plugin/language/impl/FieldImpl.java
+++ b/graphql-maven-plugin-logic/src/main/java/com/graphql_java_generator/plugin/language/impl/FieldImpl.java
@@ -9,6 +9,7 @@
import com.graphql_java_generator.plugin.DocumentParser;
import com.graphql_java_generator.plugin.generate_code.GenerateCodeDocumentParser;
import com.graphql_java_generator.plugin.language.AppliedDirective;
+import com.graphql_java_generator.plugin.language.Description;
import com.graphql_java_generator.plugin.language.Field;
import com.graphql_java_generator.plugin.language.FieldTypeAST;
import com.graphql_java_generator.plugin.language.Relation;
@@ -84,10 +85,13 @@ public class FieldImpl implements Field {
@Builder.Default
private List appliedDirectives = new ArrayList<>();
- /** The comments that have been found for this field, in the provided GraphQL schema */
+ /** The comments that have been found before this field, in the provided GraphQL schema */
@Builder.Default
private List comments = new ArrayList<>();
+ /** The description of this field, in the provided GraphQL schema */
+ private Description description;
+
@Override
public Type getType() {
return documentParser.getType(getGraphQLTypeSimpleName());
diff --git a/graphql-maven-plugin-logic/src/main/resources/templates/client_query_mutation_executor.vm.java b/graphql-maven-plugin-logic/src/main/resources/templates/client_query_mutation_executor.vm.java
index d929a39bf..34bf2106f 100644
--- a/graphql-maven-plugin-logic/src/main/resources/templates/client_query_mutation_executor.vm.java
+++ b/graphql-maven-plugin-logic/src/main/resources/templates/client_query_mutation_executor.vm.java
@@ -72,10 +72,10 @@
/**
-#foreach ($comment in $object.comments)
- * $comment
+#if ($object.description)
+#foreach ($line in $object.description.lines)
+ * ${line}
#end
-#if ($object.comments.size() > 0)
*
#end
* This class contains the methods that allows the execution of the queries or mutations that are defined in the ${object.name} of the GraphQL schema.
@@ -399,13 +399,14 @@ public GraphQLRequest getGraphQLRequest(String fullRequest) throws GraphQLReques
}
#foreach ($field in $object.fields)
- /**
#foreach ($comment in $field.comments)
- * ${field.content}
+ // $comment
#end
-#if ($field.comments.size() > 0)
- *
+ /**
+#foreach ($line in $field.description.lines)
+ * $line
#end
+ *
* This method executes a partial query against the GraphQL server. That is, the query that is one of the queries
* defined in the GraphQL query object. The queryResponseDef contains the part of the query that is
* after the query name.
@@ -458,13 +459,14 @@ public GraphQLRequest getGraphQLRequest(String fullRequest) throws GraphQLReques
return ${field.javaName}(objectResponse#inputValues(), parameters);
}
- /**
#foreach ($comment in $field.comments)
- * ${field.content}
+ // $comment
#end
-#if ($field.comments.size() > 0)
- *
+ /**
+#foreach ($line in $field.description.lines)
+ * $line
#end
+ *
* This method executes a partial query against the GraphQL server. That is, the query that is one of the queries
* defined in the GraphQL query object. The queryResponseDef contains the part of the query that is
* after the query name.
@@ -514,13 +516,14 @@ public GraphQLRequest getGraphQLRequest(String fullRequest) throws GraphQLReques
return ${field.javaName}WithBindValues(objectResponse#inputValues(), graphqlClientUtils.generatesBindVariableValuesMap(paramsAndValues));
}
- /**
#foreach ($comment in $field.comments)
- * ${field.content}
+ // $comment
#end
-#if ($field.comments.size() > 0)
- *
+ /**
+#foreach ($line in $field.description.lines)
+ * $line
#end
+ *
* This method is expected by the graphql-java framework. It will be called when this query is called. It offers a
* logging of the call (if in debug mode), or of the call and its parameters (if in trace mode).
* This method is valid for queries/mutations/subscriptions which don't have bind variables, as there is no
@@ -591,13 +594,14 @@ public GraphQLRequest getGraphQLRequest(String fullRequest) throws GraphQLReques
return ret.get${field.pascalCaseName}();
}
- /**
#foreach ($comment in $field.comments)
- * ${field.content}
+ // $comment
#end
-#if ($field.comments.size() > 0)
- *
+ /**
+#foreach ($line in $field.description.lines)
+ * $line
#end
+ *
* This method is expected by the graphql-java framework. It will be called when this query is called. It offers a
* logging of the call (if in debug mode), or of the call and its parameters (if in trace mode).
* This method is valid for queries/mutations/subscriptions which don't have bind variables, as there is no
@@ -679,13 +683,14 @@ public GraphQLRequest getGraphQLRequest(String fullRequest) throws GraphQLReques
return ret.get${field.pascalCaseName}();
}
- /**
#foreach ($comment in $field.comments)
- * ${field.content}
+ // $comment
#end
-#if ($field.comments.size() > 0)
- *
+ /**
+#foreach ($line in $field.description.lines)
+ * $line
#end
+ *
* Get the {@link com.graphql_java_generator.client.request.Builder} for the ${field.type.classSimpleName}, as expected by the ${field.name} query.
*
* @return
@@ -700,13 +705,14 @@ public GraphQLRequest getGraphQLRequest(String fullRequest) throws GraphQLReques
}
- /**
#foreach ($comment in $field.comments)
- * ${field.content}
+ // $comment
#end
-#if ($field.comments.size() > 0)
- *
+ /**
+#foreach ($line in $field.description.lines)
+ * $line
#end
+ *
* Get the {@link GraphQLRequest} for the ${field.name} $type, created with the given Partial request.
*
* @param partialRequest
diff --git a/graphql-maven-plugin-logic/src/main/resources/templates/client_query_mutation_type.vm.java b/graphql-maven-plugin-logic/src/main/resources/templates/client_query_mutation_type.vm.java
index b674cee9c..4d86ec1a4 100644
--- a/graphql-maven-plugin-logic/src/main/resources/templates/client_query_mutation_type.vm.java
+++ b/graphql-maven-plugin-logic/src/main/resources/templates/client_query_mutation_type.vm.java
@@ -52,8 +52,10 @@
import com.graphql_java_generator.client.GraphqlClientUtils;
/**
-#foreach ($comment in $object.comments)
- * $comment
+#if ($object.description)
+#foreach ($line in $object.description.lines)
+ * ${line}
+#end
#end
#if ($object.comments.size() > 0)
*
@@ -214,7 +216,14 @@ public GraphQLRequest getGraphQLRequest(String fullRequest) throws GraphQLReques
}
#foreach ($field in $object.fields)
+#foreach ($comment in $field.comments)
+ // $comment
+#end
/**
+#foreach ($line in $field.description.lines)
+ * $line
+#end
+ *
* This method is deprecated: please use {@link ${object.classSimpleName}Executor} class instead of this class, to execute this method.
* It is maintained to keep existing code compatible with the generated code. It will be removed in 2.0 version.
*/
@@ -231,7 +240,14 @@ public GraphQLRequest getGraphQLRequest(String fullRequest) throws GraphQLReques
return super.${field.javaName}WithBindValues(queryResponseDef#inputValues(), parameters);
}
+#foreach ($comment in $field.comments)
+ // $comment
+#end
/**
+#foreach ($line in $field.description.lines)
+ * $line
+#end
+ *
* This method is deprecated: please use {@link ${object.classSimpleName}Executor} class instead of this class, to execute this method.
* It is maintained to keep existing code compatible with the generated code. It will be removed in 2.0 version.
*/
@@ -248,7 +264,14 @@ public GraphQLRequest getGraphQLRequest(String fullRequest) throws GraphQLReques
return super.${field.javaName}(queryResponseDef#inputValues(), paramsAndValues);
}
+#foreach ($comment in $field.comments)
+ // $comment
+#end
/**
+#foreach ($line in $field.description.lines)
+ * $line
+#end
+ *
* This method is deprecated: please use {@link ${object.classSimpleName}Executor} class instead of this class, to execute this method.
* It is maintained to keep existing code compatible with the generated code. It will be removed in 2.0 version.
*/
@@ -265,7 +288,14 @@ public GraphQLRequest getGraphQLRequest(String fullRequest) throws GraphQLReques
return super.${field.javaName}WithBindValues(objectResponse#inputValues(), parameters);
}
+#foreach ($comment in $field.comments)
+ // $comment
+#end
/**
+#foreach ($line in $field.description.lines)
+ * $line
+#end
+ *
* This method is deprecated: please use {@link ${object.classSimpleName}Executor} class instead of this class, to execute this method.
* It is maintained to keep existing code compatible with the generated code. It will be removed in 2.0 version.
*/
@@ -282,7 +312,14 @@ public GraphQLRequest getGraphQLRequest(String fullRequest) throws GraphQLReques
return super.${field.javaName}(objectResponse#inputValues(), paramsAndValues);
}
+#foreach ($comment in $field.comments)
+ // $comment
+#end
/**
+#foreach ($line in $field.description.lines)
+ * $line
+#end
+ *
* This method is deprecated: please use {@link ${object.classSimpleName}Executor} class instead of this class, to execute this method.
* It is maintained to keep existing code compatible with the generated code. It will be removed in 2.0 version.
*/
@@ -291,8 +328,14 @@ public GraphQLRequest getGraphQLRequest(String fullRequest) throws GraphQLReques
return super.get${field.pascalCaseName}ResponseBuilder();
}
-
+#foreach ($comment in $field.comments)
+ // $comment
+#end
/**
+#foreach ($line in $field.description.lines)
+ * $line
+#end
+ *
* This method is deprecated: please use {@link ${object.classSimpleName}Executor} class instead of this class, to execute this method.
* It is maintained to keep existing code compatible with the generated code. It will be removed in 2.0 version.
*/
diff --git a/graphql-maven-plugin-logic/src/main/resources/templates/client_subscription_executor.vm.java b/graphql-maven-plugin-logic/src/main/resources/templates/client_subscription_executor.vm.java
index ca0e9ce14..a5aa090cd 100644
--- a/graphql-maven-plugin-logic/src/main/resources/templates/client_subscription_executor.vm.java
+++ b/graphql-maven-plugin-logic/src/main/resources/templates/client_subscription_executor.vm.java
@@ -69,12 +69,12 @@
/**
-#foreach ($comment in $object.comments)
- * $comment
+#if ($object.description)
+#foreach ($line in $object.description.lines)
+ * ${line}
#end
-#if ($object.comments.size() > 0)
- *
#end
+ *
* This class contains the methods that allows the execution of the subscriptions that are defined in the ${object.name} of the GraphQL schema.
* These methods allows:
*
@@ -439,13 +439,14 @@ public GraphQLRequest getGraphQLRequest(String fullRequest) throws GraphQLReques
#foreach ($field in $object.fields)
#if ($field.name != "__typename")
- /**
#foreach ($comment in $field.comments)
- * ${field.content}
+ // $comment
#end
-#if ($field.comments.size() > 0)
- *
+ /**
+#foreach ($line in $field.description.lines)
+ * $line
#end
+ *
* This method registers a subscription, by executing a direct partial request against the GraphQL server. This
* subscription is one of the fields defined in the GraphQL subscription object. The queryResponseDef contains the
* part of the subscription that is after the subscription name (see the sample below), for instance
@@ -513,13 +514,14 @@ public GraphQLRequest getGraphQLRequest(String fullRequest) throws GraphQLReques
return ${field.javaName}(objectResponse, subscriptionCallback#inputValues(), parameters);
}
- /**
#foreach ($comment in $field.comments)
- * ${field.content}
+ // $comment
#end
-#if ($field.comments.size() > 0)
- *
+ /**
+#foreach ($line in $field.description.lines)
+ * $line
#end
+ *
* This method registers a subscription, by executing a direct partial request against the GraphQL server. This
* subscription is one of the fields defined in the GraphQL subscription object. The queryResponseDef contains the
* part of the subscription that is after the subscription name (see the sample below), for instance
@@ -584,13 +586,14 @@ public GraphQLRequest getGraphQLRequest(String fullRequest) throws GraphQLReques
return ${field.javaName}WithBindValues(objectResponse, subscriptionCallback#inputValues(), graphqlClientUtils.generatesBindVariableValuesMap(paramsAndValues));
}
- /**
#foreach ($comment in $field.comments)
- * ${field.content}
+ // $comment
#end
-#if ($field.comments.size() > 0)
- *
+ /**
+#foreach ($line in $field.description.lines)
+ * $line
#end
+ *
* This method registers a subscription, by executing a direct partial request against the GraphQL server. This
* subscription is one of the fields defined in the GraphQL subscription object. The queryResponseDef contains the
* part of the subscription that is after the subscription name (see the sample below), for instance
@@ -673,13 +676,14 @@ public GraphQLRequest getGraphQLRequest(String fullRequest) throws GraphQLReques
return graphQLConfiguration${springBeanSuffix}.getQueryExecutor().execute(objectResponse, parameters,#if($field.fieldTypeAST.listDepth>0) (SubscriptionCallback) (Object)#end subscriptionCallback, ${object.classFullName}.class, #if($field.fieldTypeAST.listDepth>0)List#else${field.javaTypeFullClassname}#end.class);
}
- /**
#foreach ($comment in $field.comments)
- * ${field.content}
+ // $comment
#end
-#if ($field.comments.size() > 0)
- *
+ /**
+#foreach ($line in $field.description.lines)
+ * $line
#end
+ *
* This method registers a subscription, by executing a direct partial request against the GraphQL server. This
* subscription is one of the fields defined in the GraphQL subscription object. The queryResponseDef contains the
* part of the subscription that is after the subscription name (see the sample below), for instance
@@ -775,13 +779,14 @@ public GraphQLRequest getGraphQLRequest(String fullRequest) throws GraphQLReques
return graphQLConfiguration${springBeanSuffix}.getQueryExecutor().execute(objectResponse, parameters, #if($field.fieldTypeAST.listDepth>0) (SubscriptionCallback) (Object)#end subscriptionCallback, ${object.classFullName}.class, #if($field.fieldTypeAST.listDepth>0)List#else${field.javaTypeFullClassname}#end.class);
}
- /**
#foreach ($comment in $field.comments)
- * ${field.content}
+ // $comment
#end
-#if ($field.comments.size() > 0)
- *
+ /**
+#foreach ($line in $field.description.lines)
+ * $line
#end
+ *
* Get the {@link com.graphql_java_generator.client.request.Builder} for the ${field.type.classSimpleName}, as expected by the ${field.name} subscription.
*
* @return
@@ -795,14 +800,14 @@ public GraphQLRequest getGraphQLRequest(String fullRequest) throws GraphQLReques
);
}
-
- /**
#foreach ($comment in $field.comments)
- * ${field.content}
+ // $comment
#end
-#if ($field.comments.size() > 0)
- *
+ /**
+#foreach ($line in $field.description.lines)
+ * $line
#end
+ *
* Get the {@link GraphQLRequest} for the ${field.name} $type, created with the given Partial request.
*
* @param partialRequest
diff --git a/graphql-maven-plugin-logic/src/main/resources/templates/client_subscription_type.vm.java b/graphql-maven-plugin-logic/src/main/resources/templates/client_subscription_type.vm.java
index 7bc227cd7..a4d2cbb3d 100644
--- a/graphql-maven-plugin-logic/src/main/resources/templates/client_subscription_type.vm.java
+++ b/graphql-maven-plugin-logic/src/main/resources/templates/client_subscription_type.vm.java
@@ -59,13 +59,12 @@
import com.graphql_java_generator.client.SubscriptionClient;
/**
-#foreach ($comment in $object.comments)
- * $comment
+#if ($object.description)
+#foreach ($line in $object.description.lines)
+ * ${line}
#end
-#if ($object.comments.size() > 0)
- *
- *
#end
+ *
* This class contains the response for a full request. See the
* plugin web site
* for more information on full and partial requests.
@@ -164,7 +163,14 @@ public T getExtensionsField(String key, Class t) throws JsonProcessingExc
#foreach ($field in $object.fields)
#if ($field.name != "__typename")
+#foreach ($comment in $field.comments)
+ // $comment
+#end
/**
+#foreach ($line in $field.description.lines)
+ * $line
+#end
+ *
* This method is deprecated: please use {@link ${object.classSimpleName}Executor} class instead of this class, to execute this method.
* It is maintained to keep existing code compatible with the generated code. It will be removed in 2.0 version.
*/
@@ -178,7 +184,14 @@ public T getExtensionsField(String key, Class t) throws JsonProcessingExc
return super.${field.javaName}WithBindValues(queryResponseDef, subscriptionCallback #inputValues(), parameters);
}
+#foreach ($comment in $field.comments)
+ // $comment
+#end
/**
+#foreach ($line in $field.description.lines)
+ * $line
+#end
+ *
* This method is deprecated: please use {@link ${object.classSimpleName}Executor} class instead of this class, to execute this method.
* It is maintained to keep existing code compatible with the generated code. It will be removed in 2.0 version.
*/
@@ -191,7 +204,14 @@ public T getExtensionsField(String key, Class t) throws JsonProcessingExc
return super.${field.javaName}(queryResponseDef, subscriptionCallback #inputValues(), paramsAndValues);
}
+#foreach ($comment in $field.comments)
+ // $comment
+#end
/**
+#foreach ($line in $field.description.lines)
+ * $line
+#end
+ *
* This method is deprecated: please use {@link ${object.classSimpleName}Executor} class instead of this class, to execute this method.
* It is maintained to keep existing code compatible with the generated code. It will be removed in 2.0 version.
*/
@@ -204,7 +224,14 @@ public T getExtensionsField(String key, Class t) throws JsonProcessingExc
return super.${field.javaName}WithBindValues(objectResponse, subscriptionCallback #inputValues(), parameters);
}
+#foreach ($comment in $field.comments)
+ // $comment
+#end
/**
+#foreach ($line in $field.description.lines)
+ * $line
+#end
+ *
* This method is deprecated: please use {@link ${object.classSimpleName}Executor} class instead of this class, to execute this method.
* It is maintained to keep existing code compatible with the generated code. It will be removed in 2.0 version.
*/
@@ -217,7 +244,14 @@ public T getExtensionsField(String key, Class t) throws JsonProcessingExc
return super.${field.javaName}(objectResponse, subscriptionCallback #inputValues(), paramsAndValues);
}
+#foreach ($comment in $field.comments)
+ // $comment
+#end
/**
+#foreach ($line in $field.description.lines)
+ * $line
+#end
+ *
* This method is deprecated: please use {@link ${object.classSimpleName}Executor} class instead of this class, to execute this method.
* It is maintained to keep existing code compatible with the generated code. It will be removed in 2.0 version.
*/
@@ -227,7 +261,14 @@ public T getExtensionsField(String key, Class t) throws JsonProcessingExc
}
+#foreach ($comment in $field.comments)
+ // $comment
+#end
/**
+#foreach ($line in $field.description.lines)
+ * $line
+#end
+ *
* This method is deprecated: please use {@link ${object.classSimpleName}Executor} class instead of this class, to execute this method.
* It is maintained to keep existing code compatible with the generated code. It will be removed in 2.0 version.
*/
diff --git a/graphql-maven-plugin-logic/src/main/resources/templates/enum_type.vm.java b/graphql-maven-plugin-logic/src/main/resources/templates/enum_type.vm.java
index 60a4d0e65..81fd58f01 100644
--- a/graphql-maven-plugin-logic/src/main/resources/templates/enum_type.vm.java
+++ b/graphql-maven-plugin-logic/src/main/resources/templates/enum_type.vm.java
@@ -7,13 +7,12 @@
import com.graphql_java_generator.annotation.GraphQLEnumType;
/**
-#foreach ($comment in $object.comments)
- * $comment
+#if ($object.description)
+#foreach ($line in $object.description.lines)
+ * ${line}
#end
-#if ($object.comments.size() > 0)
- *
- *
#end
+ *
* @author generated by graphql-java-generator
* @see https://github.com/graphql-java-generator/graphql-java-generator
*/
diff --git a/graphql-maven-plugin-logic/src/main/resources/templates/generateRelaySchema.vm.graphqls b/graphql-maven-plugin-logic/src/main/resources/templates/generateRelaySchema.vm.graphqls
index 666de88e4..795d2c961 100644
--- a/graphql-maven-plugin-logic/src/main/resources/templates/generateRelaySchema.vm.graphqls
+++ b/graphql-maven-plugin-logic/src/main/resources/templates/generateRelaySchema.vm.graphqls
@@ -1,3 +1,7 @@
+##
+## There is an issue in the way the description is written for fields. The writing of the field's description lacks the starting tabulation
+#set ($tab=" ")
+##
######################################################################################################################################################
##
## The "objectFields" macro generates the list of fields for an ObjectType or for an InterfaceType
@@ -13,6 +17,18 @@
#foreach ($comment in $field.comments)
#$comment
#end
+#if ($field.description)
+#if ($field.description.multiLine)
+#set ($appendDoubleQuotes=true)
+#foreach ($line in $field.description.lines)
+$tab#if($appendDoubleQuotes)"""#end${line}
+#set ($appendDoubleQuotes=false)
+#end
+ """
+#else
+ "${field.description.content}"
+#end
+#end
##
## To make this template readable, the parameters are written one per line. Which means that the way the field
## is written depends on whether this field has or doesn't have input parameters
@@ -81,12 +97,39 @@ $argName: ${graphqlUtils.getValueAsText($appliedDir.argumentValues[$argName])}#i
#end
#end
##
+######################################################################################################################################################
+##
+## The "writeDescription" macro generates the given description, in a mono or multine format, or do nothing if it is null.
+##
+## parameters:
+## 1) description: the description to generate
+##
+######
+#macro (writeDescription $description)
+##
+#if ($description)
+## Ok, the description is not null. Let's manage it
+##
+#if ($description.multiLine)
+#set ($appendDoubleQuotes=true)
+#foreach ($line in $description.lines)
+#if($appendDoubleQuotes)"""#end$line
+#set ($appendDoubleQuotes=false)
+#end
+"""
+#else
+"${description.content}"
+#end
+##
+#end
+#end
###############################################################################################################
################ Scalar Extensions (of standard GraphQL scalars) #############################################
###############################################################################################################
#foreach ($scalar in $scalars)
#if ($scalar.class.name != "com.graphql_java_generator.plugin.language.impl.CustomScalarType")
## This scalar is a standard scalar type. It may have been extended with a directive
+#writeDescription($scalar.description)
#if ($scalar.appliedDirectives.size() > 0)
extend scalar ${scalar.name}#implementedDirective($scalar.appliedDirectives)$space
#end
@@ -101,6 +144,7 @@ extend scalar ${scalar.name}#implementedDirective($scalar.appliedDirectives)$spa
#foreach ($comment in $customScalar.comments)
#$comment
#end
+#writeDescription($customScalar.description)
scalar ${customScalar.name}#implementedDirective($customScalar.appliedDirectives)$space
#end
@@ -112,6 +156,7 @@ scalar ${customScalar.name}#implementedDirective($customScalar.appliedDirectives
#foreach ($comment in $enum.comments)
#$comment
#end
+#writeDescription($enum.description)
enum ${enum.name}#implementedDirective($enum.appliedDirectives) {
#foreach ($value in $enum.values)
${value.name}#implementedDirective($value.appliedDirectives)$space
@@ -127,6 +172,7 @@ enum ${enum.name}#implementedDirective($enum.appliedDirectives) {
#foreach ($comment in $directive.comments)
#$comment
#end
+#writeDescription($directive.description)
#if (! $directive.standard)
directive @${directive.name} #if ($directive.arguments.size() > 0)(
#else $space
@@ -165,6 +211,7 @@ schema#implementedDirective($schemaDirectives) {
#foreach ($comment in $union.comments)
#$comment
#end
+#writeDescription($union.description)
union ${union.name}#implementedDirective($union.appliedDirectives)$space
= #foreach ($type in $union.memberTypes)${type.name}#if($foreach.hasNext) | #end#end
@@ -177,6 +224,7 @@ union ${union.name}#implementedDirective($union.appliedDirectives)$space
#foreach ($comment in $interface.comments)
#$comment
#end
+#writeDescription($interface.description)
interface ${interface.name}#implements($interface.implementz)#implementedDirective($interface.appliedDirectives) {
#objectFields($interface.fields)
}
@@ -190,6 +238,7 @@ interface ${interface.name}#implements($interface.implementz)#implementedDirecti
#foreach ($comment in $objectType.comments)
#$comment
#end
+#writeDescription($objectType.description)
#if($objectType.inputType)input#{else}type#end ${objectType.name}#implements($objectType.implementz)#implementedDirective($objectType.appliedDirectives) {
#objectFields($objectType.fields)
}
diff --git a/graphql-maven-plugin-logic/src/main/resources/templates/interface_type.vm.java b/graphql-maven-plugin-logic/src/main/resources/templates/interface_type.vm.java
index e342d2767..6938cfae2 100644
--- a/graphql-maven-plugin-logic/src/main/resources/templates/interface_type.vm.java
+++ b/graphql-maven-plugin-logic/src/main/resources/templates/interface_type.vm.java
@@ -6,13 +6,12 @@
#end
/**
-#foreach ($comment in $object.comments)
- * $comment
+#if ($object.description)
+#foreach ($line in $object.description.lines)
+ * ${line}
#end
-#if ($object.comments.size() > 0)
- *
- *
#end
+ *
* @author generated by graphql-java-generator
* @see https://github.com/graphql-java-generator/graphql-java-generator
*/
diff --git a/graphql-maven-plugin-logic/src/main/resources/templates/object_content.vm.java b/graphql-maven-plugin-logic/src/main/resources/templates/object_content.vm.java
index 4b975cd8f..405f89c1d 100644
--- a/graphql-maven-plugin-logic/src/main/resources/templates/object_content.vm.java
+++ b/graphql-maven-plugin-logic/src/main/resources/templates/object_content.vm.java
@@ -19,13 +19,14 @@
}
#foreach ($field in $object.fields)
-#if ($field.comments.size() > 0)
- /**
-#end
#foreach ($comment in $field.comments)
- * $comment
+ // $comment
+#end
+#if ($field.description)
+ /**
+#foreach ($line in $field.description.lines)
+ * $line
#end
-#if ($field.comments.size() > 0)
*/
#end
${field.annotation}
@@ -41,27 +42,29 @@
####################################################################################################################################################
#if ($field.fieldJavaFullClassnamesFromImplementedInterface.size() == 0)
##
-#if ($field.comments.size() > 0)
- /**
-#end
#foreach ($comment in $field.comments)
- * $comment
+ // $comment
#end
-#if ($field.comments.size() > 0)
- */
+#if ($field.description)
+ /**
+#foreach ($line in $field.description.lines)
+ * $line
+#end
+ */
#end
public void set${field.pascalCaseName}(${field.javaTypeFullClassname} ${field.javaName}) {
this.${field.javaName} = ${field.javaName};
}
-#if ($field.comments.size() > 0)
- /**
-#end
#foreach ($comment in $field.comments)
- * $comment
+ // $comment
#end
-#if ($field.comments.size() > 0)
- */
+#if ($field.description)
+ /**
+#foreach ($line in $field.description.lines)
+ * $line
+#end
+ */
#end
public ${field.javaTypeFullClassname} get${field.pascalCaseName}() {
return ${field.javaName};
@@ -77,11 +80,16 @@
## The field inherited from an interface field, and the field's type has been narrowed (it's not the type defined in the interface, but a subclass or subinterface of it)
## See IFoo and TFoo sample in the allGraphQLCases schema, used to check the #114 issue (search for 114 in allGraphQLCases.graphqls)
- /**
#foreach ($comment in $field.comments)
- * $comment
+ // $comment
+#end
+#if ($field.description)
+ /**
+#foreach ($line in $field.description.lines)
+ * $line
+#end
+ */
#end
- */
@Override
#if ($field.javaType.startsWith("List<"))
@SuppressWarnings("unchecked")
@@ -114,7 +122,14 @@
#if (!$field.fieldJavaFullClassnamesFromImplementedInterface.contains($field.javaTypeFullClassname))
+#foreach ($comment in $field.comments)
+ // $comment
+#end
/**
+#foreach ($line in $field.description.lines)
+ * $line
+#end
+ *
* As the type declared in the class is not inherited from one of the implemented interfaces, we need a dedicated setter.
#if ($field.javaType.startsWith("List<"))
*
@@ -214,11 +229,16 @@
#end
#end
- /**
#foreach ($comment in $field.comments)
- * $comment
+ // $comment
+#end
+#if ($field.description)
+ /**
+#foreach ($line in $field.description.lines)
+ * $line
+#end
+ */
#end
- */
#if (!$field.javaType.startsWith("List<"))
@Override
#end
@@ -293,11 +313,22 @@ public String toString() {
#foreach ($field in $object.fields)
#if(${field.javaName} != '__typename')
+#foreach ($comment in $field.comments)
+ // $comment
+#end
+#if ($field.description)
+ /**
+#foreach ($line in $field.description.lines)
+ * $line
+#end
+ */
+#end
public#if($targetFileName=="Builder") _Builder#else Builder#end with${field.pascalCaseName}(${field.javaTypeFullClassname} ${field.javaName}) {
this.${field.javaName} = ${field.javaName};
return this;
}
#end
+
#end
public ${targetFileName} build() {
diff --git a/graphql-maven-plugin-logic/src/main/resources/templates/object_type.vm.java b/graphql-maven-plugin-logic/src/main/resources/templates/object_type.vm.java
index 55bcf4d4d..d95370d15 100644
--- a/graphql-maven-plugin-logic/src/main/resources/templates/object_type.vm.java
+++ b/graphql-maven-plugin-logic/src/main/resources/templates/object_type.vm.java
@@ -19,8 +19,10 @@
#end
/**
-#foreach ($comment in $object.comments)
- * $comment
+#if ($object.description)
+#foreach ($line in $object.description.lines)
+ * ${line}
+#end
#end
*
* @author generated by graphql-java-generator
diff --git a/graphql-maven-plugin-logic/src/main/resources/templates/server_GraphQLDataFetchersDelegate.vm.java b/graphql-maven-plugin-logic/src/main/resources/templates/server_GraphQLDataFetchersDelegate.vm.java
index 240b2a494..efcfbff54 100644
--- a/graphql-maven-plugin-logic/src/main/resources/templates/server_GraphQLDataFetchersDelegate.vm.java
+++ b/graphql-maven-plugin-logic/src/main/resources/templates/server_GraphQLDataFetchersDelegate.vm.java
@@ -18,6 +18,14 @@
#end
/**
+#if ($dataFetcherDelegate.type.description)
+ * Description for the ${dataFetcherDelegate.type.name} type:
+#foreach ($line in $dataFetcherDelegate.type.description.lines)
+ * ${line}
+#end
+ *
+#end
+ *
* @author generated by graphql-java-generator
* @see https://github.com/graphql-java-generator/graphql-java-generator
*/
@@ -32,6 +40,14 @@ public interface ${dataFetcherDelegate.pascalCaseName} {
## If this dataFetcher is a completableFuture, we add a DataLoader parameter
#if ($dataFetcher.completableFuture)
/**
+#if ($dataFetcher.field.description)
+ * Description for the ${dataFetcher.field.name} field:
+#foreach ($line in $dataFetcher.field.description.lines)
+ * ${line}
+#end
+ *
+ *
+#end
* This method loads the data for ${dataFetcher.field.owningType.name}.${dataFetcher.field.name}.
*
* For optimization, this method returns a CompletableFuture. This allows to use
@@ -80,6 +96,14 @@ public interface ${dataFetcherDelegate.pascalCaseName} {
#end ## #if (${dataFetcher.completableFuture})
/**
+#if ($dataFetcher.field.description)
+ * Description for the ${dataFetcher.field.name} field:
+#foreach ($line in $dataFetcher.field.description.lines)
+ * ${line}
+#end
+ *
+ *
+#end
* This method loads the data for ${dataFetcher.field.owningType.name}.${dataFetcher.field.name}.
*
*
@@ -121,6 +145,14 @@ public interface ${dataFetcherDelegate.pascalCaseName} {
#end
#foreach ($batchLoader in $dataFetcherDelegate.batchLoaders)
/**
+#if ($dataFetcher.field.description)
+ * Description for the ${dataFetcher.field.name} field:
+#foreach ($line in $dataFetcher.field.description.lines)
+ * ${line}
+#end
+ *
+ *
+#end
* This method loads a list of ${dataFetcher.field.name}, based on the list of id to be fetched. This method is used by
* graphql-java java-dataloader to highly optimize the
* number of requests to the server, when recursing down through the object associations.
@@ -153,6 +185,14 @@ public interface ${dataFetcherDelegate.pascalCaseName} {
}
/**
+#if ($dataFetcher.field.description)
+ * Description for the ${dataFetcher.field.name} field:
+#foreach ($line in $dataFetcher.field.description.lines)
+ * ${line}
+#end
+ *
+ *
+#end
* This method loads a list of ${dataFetcher.field.name}, based on the list of id to be fetched. This method is used by
* graphql-java java-dataloader to highly optimize the
* number of requests to the server, when recursing down through the object associations.
diff --git a/graphql-maven-plugin-logic/src/main/resources/templates/union_type.vm.java b/graphql-maven-plugin-logic/src/main/resources/templates/union_type.vm.java
index 5cfb1b4c7..e24262cc8 100644
--- a/graphql-maven-plugin-logic/src/main/resources/templates/union_type.vm.java
+++ b/graphql-maven-plugin-logic/src/main/resources/templates/union_type.vm.java
@@ -7,6 +7,12 @@
/**
+#if ($object.description)
+#foreach ($line in $object.description.lines)
+ * ${line}
+#end
+#end
+ *
* @author generated by graphql-java-generator
* @see https://github.com/graphql-java-generator/graphql-java-generator
*/
diff --git a/graphql-maven-plugin-logic/src/test/java/com/graphql_java_generator/plugin/generate_schema/GenerateGraphQLSchemaTest.java b/graphql-maven-plugin-logic/src/test/java/com/graphql_java_generator/plugin/generate_schema/GenerateGraphQLSchemaTest.java
index 37ebf9d15..32e7fa659 100644
--- a/graphql-maven-plugin-logic/src/test/java/com/graphql_java_generator/plugin/generate_schema/GenerateGraphQLSchemaTest.java
+++ b/graphql-maven-plugin-logic/src/test/java/com/graphql_java_generator/plugin/generate_schema/GenerateGraphQLSchemaTest.java
@@ -19,8 +19,13 @@
import com.graphql_java_generator.plugin.DocumentParser;
import com.graphql_java_generator.plugin.ResourceSchemaStringProvider;
import com.graphql_java_generator.plugin.conf.GenerateGraphQLSchemaConfiguration;
+import com.graphql_java_generator.plugin.language.Description;
import com.graphql_java_generator.plugin.language.Type;
+import com.graphql_java_generator.plugin.language.impl.CustomScalarType;
+import com.graphql_java_generator.plugin.language.impl.DirectiveImpl;
+import com.graphql_java_generator.plugin.language.impl.EnumType;
import com.graphql_java_generator.plugin.language.impl.FieldImpl;
+import com.graphql_java_generator.plugin.language.impl.InterfaceType;
import com.graphql_java_generator.plugin.language.impl.ObjectType;
import com.graphql_java_generator.plugin.language.impl.UnionType;
import com.graphql_java_generator.plugin.test.helper.DeepComparator;
@@ -69,11 +74,18 @@ void setUp() {
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////// Id fields //////////////////////////////////////////////////////////////////////////
+ deepComparator.addIdField(CustomScalarType.class, "name");
+ deepComparator.addIdField(DirectiveImpl.class, "name");
+ deepComparator.addIdField(EnumType.class, "name");
+ deepComparator.addIdField(InterfaceType.class, "name");
deepComparator.addIdField(ObjectType.class, "name");
+ deepComparator.addIdField(UnionType.class, "name");
+ deepComparator.addIdField(FieldImpl.class, "name");
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////// Ignored fields //////////////////////////////////////////////////////////////////////////
deepComparator.addIgnoredFields(FieldImpl.class, "documentParser");
+ deepComparator.addIgnoredFields(Description.class, "content");
deepComparator.addIgnoredFields(DocumentParser.class, "schemaDirectives");
deepComparator.addIgnoredFields(GenerateGraphQLSchemaDocumentParser.class, "configuration");
deepComparator.addIgnoredFields(GenerateGraphQLSchemaDocumentParser.class, "graphqlUtils");
@@ -152,8 +164,8 @@ void testGenerateRelaySchema_forum() throws IOException {
* - Load the generated schema in a target {@link DocumentParser}
* - Deep compare the source and the target {@link DocumentParser} with a generic tool
*
- * Doing this insure that the code is stable even if the {@link DocumentParser} implementation changes. And as this
- * implementation is heavily tested, we an consider that it is complete, out of some known and documented
+ * Doing this insures that the code is stable even if the {@link DocumentParser} implementation changes. And as this
+ * implementation is heavily tested, we can consider that it is complete, out of some known and documented
* limitations
*
* @param sourceSpringConfClass
diff --git a/graphql-maven-plugin-logic/src/test/java/com/graphql_java_generator/plugin/test/helper/DeepComparator.java b/graphql-maven-plugin-logic/src/test/java/com/graphql_java_generator/plugin/test/helper/DeepComparator.java
index 0fbb0b852..dc5dcc8aa 100644
--- a/graphql-maven-plugin-logic/src/test/java/com/graphql_java_generator/plugin/test/helper/DeepComparator.java
+++ b/graphql-maven-plugin-logic/src/test/java/com/graphql_java_generator/plugin/test/helper/DeepComparator.java
@@ -491,15 +491,41 @@ List compareNonOrderedCollection(Collection> o1, Collection> o2,
// Let's look for all items in o1 that doesn't exist in o2
if (nbMaxDifferences > 0) {
for (Object item1 : o1) {
- // Each item of o1 must exist in o2.
boolean found = false;
+ String idField = idFields.get(item1.getClass());
+
+ // Each item of o1 must exist in o2.
for (Object item2 : o2) {
+
+ // o1 and o2 are of the same class, and this class is identified by an id field. If the value of
+ // their id fields is the same, then we consider that they are the same object.
+ if (item2.getClass() == item1.getClass() && idField != null) {
+ Object id1 = graphqlUtils.invokeGetter(item1, idField);
+ Object id2 = graphqlUtils.invokeGetter(item2, idField);
+ if (compare(id1, id2)) {
+ // The two id fields are identical. These object are "the same", but may differ on secondary
+ // attributes. Let's check that (doing this allows to have a specific difference's message,
+ // which is important to understand which differences have been found)
+ List diffs = differences(item1, item2, nbMaxDifferences,
+ path + "[" + id1 + "]");
+ if (diffs.size() > 0) {
+ differences.addAll(diffs);
+ }
+
+ found = true;
+ break;
+ }
+ }
+
+ // Otherwise, we just compare them to check if they are identical
if (compare(item1, item2)) {
found = true;
break;
}
}
+ // Once here, the o1 object has been found in the second list ... or not
+
if (!found) {
// Too bad, item1 was not found in o2.
differences.add(new Difference(path, DifferenceType.VALUE, item1, null,
@@ -517,8 +543,17 @@ List compareNonOrderedCollection(Collection> o1, Collection> o2,
if (nbMaxDifferences > 0) {
for (Object item2 : o2) {
boolean found = false;
+ String idField = idFields.get(item2.getClass());
+
for (Object item1 : o1) {
- if (compare(item1, item2)) {
+ // o1 and o2 are of the same class, and this class is identified by an id field. If the value of
+ // their id fields is the same, then we consider that they are the same object.
+ if (item2.getClass() == item1.getClass() && idField != null) {
+ // It is the same object. The comparison has already been done in the previous loop. So we're
+ // done for item1.
+ found = true;
+ break;
+ } else if (compare(item1, item2)) {
found = true;
break;
}
diff --git a/graphql-maven-plugin-logic/src/test/java/com/graphql_java_generator/plugin/test/helper/DeepComparatorTest.java b/graphql-maven-plugin-logic/src/test/java/com/graphql_java_generator/plugin/test/helper/DeepComparatorTest.java
index 8ab9150dd..d3a1655fd 100644
--- a/graphql-maven-plugin-logic/src/test/java/com/graphql_java_generator/plugin/test/helper/DeepComparatorTest.java
+++ b/graphql-maven-plugin-logic/src/test/java/com/graphql_java_generator/plugin/test/helper/DeepComparatorTest.java
@@ -75,6 +75,47 @@ public Long getL() {
public String getIgnored() {
return ignored;
}
+
+ @Override
+ public String toString() {
+ return ComparisonObject.class.getSimpleName() + "(id=" + id + ",name=" + name + ",ignored=" + ignored + ")";
+ }
+ }
+
+ public class ComparisonObjectWithStringId {
+ String id;
+ String name;
+ String description;
+ String ignored;
+
+ public ComparisonObjectWithStringId(String id, String name, String description, String ignored) {
+ this.id = id;
+ this.name = name;
+ this.description = description;
+ this.ignored = ignored;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public String getIgnored() {
+ return ignored;
+ }
+
+ @Override
+ public String toString() {
+ return ComparisonObjectWithStringId.class.getSimpleName() + "(id=" + id + ",name=" + name + ",description="
+ + description + ",ignored=" + ignored + ")";
+ }
}
public enum TestEnum {
@@ -108,8 +149,11 @@ public Cycler getCycler() {
public void beforeEach() {
deepComparator = new DeepComparator();
- // deepComparator.addComparedClass(ComparisonObject.class);
+ deepComparator.addIdField(ComparisonObject.class, "id");
+ deepComparator.addIdField(ComparisonObjectWithStringId.class, "id");
+
deepComparator.addIgnoredFields(ComparisonObject.class, "ignored");
+ deepComparator.addIgnoredFields(ComparisonObjectWithStringId.class, "ignored");
// To break the cycle where comparing ComparisonSuperClass.comp cycle with the Comparison class, we define a
// specific comparison rule:
@@ -457,7 +501,6 @@ void test_differencesObjects_withIdField() {
int i = 0;
// The if field of ComparisonObject is marked as id. So these objects should be matched, and as their attributes
// are different, the path for the found differences should be /ComparisonObject(id:1)
- deepComparator.addIdField(ComparisonObject.class, "id");
ComparisonObject o1 = new ComparisonObject(1, "o1", 100L, "ignored 1");
ComparisonObject o1bis = new ComparisonObject(1, "o2", 200L, "ignored 2");
@@ -480,6 +523,36 @@ void test_differencesObjects_withIdField() {
assertEquals(o1bis.l, d.value2);
}
+ @Test
+ @Execution(ExecutionMode.CONCURRENT)
+ void test_differencesListObjects_withIdField() {
+ // Preparation
+ Difference d;
+ int i = 0;
+ // The if field of ComparisonObject is marked as id. So these objects should be matched, and as their attributes
+ // are different, the path for the found differences should be /ComparisonObject(id:1)
+ ComparisonObjectWithStringId o1 = new ComparisonObjectWithStringId("1", "o1", "description 1", "ignored 1");
+ ComparisonObjectWithStringId o2 = new ComparisonObjectWithStringId("2", "o2", "description 2", "ignored 2");
+ ComparisonObjectWithStringId o1bis = new ComparisonObjectWithStringId("1", "o1", "not description 1",
+ "ignored diff 1");
+ ComparisonObjectWithStringId o2bis = new ComparisonObjectWithStringId("2", "o2", "description 2",
+ "ignored diff 2");
+ List list1 = Arrays.asList(o1, o2);
+ List list2 = Arrays.asList(o2bis, o1bis);
+
+ // Go, go, go
+ List differences = deepComparator.differences(list1, list2, Integer.MAX_VALUE);
+
+ // Verification
+ assertEquals(1, differences.size());
+
+ d = differences.get(i++);
+ assertEquals(DeepComparator.DifferenceType.VALUE, d.type);
+ assertEquals("[1]/ComparisonObjectWithStringId(id:1)/description", d.path);
+ assertEquals("description 1", d.value1);
+ assertEquals("not description 1", d.value2);
+ }
+
@Test
@Execution(ExecutionMode.CONCURRENT)
void test_ObjectsWithDiffInSuperClassFields() {
@@ -512,7 +585,7 @@ void test_ObjectsWithDiffInSuperClassFields() {
assertEquals(1, differences.size());
d = differences.get(i++);
assertEquals(DeepComparator.DifferenceType.VALUE, d.type);
- assertEquals("/comp/id", d.path);
+ assertEquals("/ComparisonObject(id:1)/comp/id", d.path);
assertEquals(o1.comp.id, d.value1);
assertEquals(o2.comp.id, d.value2);
}
diff --git a/graphql-maven-plugin-samples/graphql-maven-plugin-samples-allGraphQLCases-client/src/graphqls/allGraphQLCases/allGraphQLCases.graphqls b/graphql-maven-plugin-samples/graphql-maven-plugin-samples-allGraphQLCases-client/src/graphqls/allGraphQLCases/allGraphQLCases.graphqls
index 0877a89da..a8c2c887d 100644
--- a/graphql-maven-plugin-samples/graphql-maven-plugin-samples-allGraphQLCases-client/src/graphqls/allGraphQLCases/allGraphQLCases.graphqls
+++ b/graphql-maven-plugin-samples/graphql-maven-plugin-samples-allGraphQLCases-client/src/graphqls/allGraphQLCases/allGraphQLCases.graphqls
@@ -3,7 +3,7 @@ scalar Date
# Directive commented, as with graphql-java 15.0, they can't be applied to a Scalar that is the type of a directive definition's argument
# (see issue 2055)
-# The DateTime uses the ExtendedScalars#DateTime implementation, provided by graphql-java (in the graphql-java-extended-scalars)
+""" The DateTime uses the ExtendedScalars#DateTime implementation, provided by graphql-java (in the graphql-java-extended-scalars) """
scalar DateTime
scalar Long
@@ -11,7 +11,7 @@ scalar Long
directive @IDScalarDirective
on SCALAR
-# A comment, to check that comments are properly managed when writing the generated schema
+# No description is allowed here (only a comment)
extend scalar ID @IDScalarDirective
directive @RelayConnection
@@ -29,13 +29,21 @@ on
schema @testDirective(value:"on Schema") {
- #A comment on the query
+ """ A description on the query """
query: MyQueryType
mutation: AnotherMutationType
# The subscription is defined in the 'extend schema', here below
}
+"""
+This is a description to describe the type MyQueryType
+on two lines
+"""
type MyQueryType {
+ """
+ This is a description to describe the field withoutParameters
+ on two lines
+ """
withoutParameters: [Character]!
withOneOptionalParam(character: CharacterInput): Character
withOneMandatoryParam(character: CharacterInput!): Character
@@ -44,36 +52,48 @@ type MyQueryType {
withEnum(episode: Episode! = NEWHOPE): Character
withListOfList(matrix: [[Float]]!): AllFieldCases
+ """
################################################################################
# withList return a list of Characters, matching the given list of CharacterInput.
# The name of the first Character returned is replaced by the given firstName.
- # All ids are generated
+ # All ids are generated
+ """
withList(firstName: String!, characters: [CharacterInput!]!): [Character]
+ """
################################################################################
# Complementary tests with the AllFieldCases Object
+ """
allFieldCases(input: AllFieldCasesInput): AllFieldCases
+ """
################################################################################
# Test for unions
+ """
unionTest(human1: HumanInput, human2: HumanInput, droid1: DroidInput, droid2: DroidInput): [AnyCharacter!]!
+ """
################################################################################
# error always returns an error! (used to check the error management)
+ """
error(errorLabel: String!): Character!
- # Check for GraphQL identifier that are java keywords
+ """ Check for GraphQL identifier that are java keywords """
aBreak: break
################################################################################
# queries to check directive behavior
+ """
# Returns the value, and potentially the anotherValue of the @testDirective directive set on the directiveOnQuery query.
# List is null if the directive is not present.
+ """
directiveOnQuery(uppercase: Boolean): [String]!
+ """
# Returns the value, and potentially the anotherValue of the @testDirective directive set on the @directiveOnQuery.
# List is null if the directive is not present.
+ """
directiveOnField: Character!
@@ -85,17 +105,23 @@ type MyQueryType {
################################################################################
# queries created to test some issues
- #issue53 is about custom scalars as parameter for a query/mutation/subscription, that was not properly serialized/deserialized
+ """
+ #issue53 is about custom scalars as parameter for a query/mutation/subscription,
+ that was not properly serialized/deserialized
+ """
issue53(date: Date!): Date!
- #issue82 is about hard coded values as parameters. Other types are tests with other queries, but there was no method with a simple float parameter
+ """
+ #issue82 is about hard coded values as parameters. Other types are tests with other queries,
+ but there was no method with a simple float parameter
+ """
issue82Float(aFloat: Float!): Float!
issue82ID(aID: ID!): ID!
- # test for issue #128 (compilation error when a Query returns a type 'Client')
+ """ test for issue #128 (compilation error when a Query returns a type 'Client') """
issue128: Client
- # test for issue #139 (use of java reserved keyword)
+ """ test for issue #139 (use of java reserved keyword) """
enumWithReservedJavaKeywordAsValues: EnumWithReservedJavaKeywordAsValues
listOfEnumWithReservedJavaKeywordAsValues(
param1: EnumWithReservedJavaKeywordAsValues=abstract,
@@ -131,45 +157,49 @@ type MyQueryType {
volatile: String
while: String
- # test for issue #140 (error for type that implements multiple interfaces)
+ """ test for issue #140 (error for type that implements multiple interfaces) """
foo140: Foo140
}
+" A mono line description for AnotherMutationType "
type AnotherMutationType {
createHuman(human: HumanInput!): Human!
createAllFieldCases(input: AllFieldCasesInput!): AllFieldCases!
- # Tests for issue 51
+ " Tests for issue 51 "
deleteSnacks(id: [ID]) : Boolean
- # test for issue #139 (use of java reserved keyword)
+ """ test for issue #139 (use of java reserved keyword) """
if: String
implements: String
}
+"A mono line description for TheSubscriptionType"
type TheSubscriptionType {
- # Will be notified for each Human added to this Episode
+ """ Will be notified for each Human added to this Episode """
subscribeNewHumanForEpisode(episode: Episode!): Human!
- # Issue 54
+ """ Issue 54 """
subscribeToAList: [Int]!
subscribeToAListOfScalars: [Date]
- # issue53 is about custom scalars as parameter for a query/mutation/subscription, that was not properly serialized/deserialized
+ """ issue53 is about custom scalars as parameter for a query/mutation/subscription, that was not properly serialized/deserialized """
issue53(date: Date!): Date!
- # Some subscriptions to test all kind of input parameters (to check proper serialization and deserialization)
+ """ Some subscriptions to test all kind of input parameters (to check proper serialization and deserialization) """
allGraphQLCasesInput(input: AllFieldCasesInput!): AllFieldCases!
allGraphQLCasesParam(id: String!, name: String!, age: Long!, integer: Int!, date: Date!, dates: [Date]!, matrix: [[Float]]!, oneWithoutIdSubtype: AllFieldCasesWithoutIdSubtypeInput!, listWithoutIdSubtype: [AllFieldCasesWithoutIdSubtypeInput!]!): AllFieldCases!
- # A dummy subscription, that allows to test errors (and other strange behavior), and their return to the subscription's client
+ """
+ A dummy subscription, that allows to test errors (and other strange behavior), and their return to the subscription's client
+ """
subscriptionTest(param: SubscriptionTestParam!): String!
- # Issue 122: Check Subscription behavior when notification response is null
+ """ Issue 122: Check Subscription behavior when notification response is null """
subscriptionWithNullResponse: String
- # test for issue #139 (use of java reserved keyword)
+ """ test for issue #139 (use of java reserved keyword) """
enumWithReservedJavaKeywordAsValues: EnumWithReservedJavaKeywordAsValues
listOfEnumWithReservedJavaKeywordAsValues: [EnumWithReservedJavaKeywordAsValues]
if: String
@@ -233,8 +263,10 @@ enum Unit {
}
-# This type is a clone of the InterfaceAllFieldCases interface.
-# Both should contains all possible combinations of parameters, data type, list, mandatory field or items...
+"""
+This type is a clone of the InterfaceAllFieldCases interface.
+Both should contains all possible combinations of parameters, data type, list, mandatory field or items...
+"""
type AllFieldCases implements WithID @testDirective(value:"on Object") @anotherTestDirective {
id: ID! @testDirective(value:"on Field")
name: String!
@@ -287,8 +319,10 @@ type AllFieldCases implements WithID @testDirective(value:"on Object") @anotherT
]): AllFieldCases!
}
-# This interface is a clone of the AllFieldCases type.
-# Both should contains all possible combinations of parameters, data type, list, mandatory field or items...
+"""
+This interface is a clone of the AllFieldCases type.
+Both should contains all possible combinations of parameters, data type, list, mandatory field or items...
+"""
interface AllFieldCasesInterface {
id: ID!
name: String!
@@ -306,7 +340,7 @@ interface AllFieldCasesInterface {
listWithoutIdSubTypes(nbItems: Int!, input: FieldParameterInput, textToAppendToTheForname: String): [AllFieldCasesWithoutIdSubtype]
}
-# A concrete class that just implements the above interface
+""" A concrete class that just implements the above interface """
type AllFieldCasesInterfaceType implements AllFieldCasesInterface & WithID {
id: ID!
name: String!
@@ -416,7 +450,7 @@ input DroidInput {
##############################################################################################################
-# A test directive, that can be added anywhere
+""" A test directive, that can be added anywhere """
directive @testDirective(
value: String! = "A value to test default values"
anotherValue: String = null
@@ -435,7 +469,7 @@ directive @testDirective(
# TypeSystemDirectiveLocation
SCHEMA | SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
-# Another test directive, to check that two directives can be added
+""" Another test directive, to check that two directives can be added """
directive @anotherTestDirective
on
# ExecutableDirectiveLocation
@@ -559,21 +593,26 @@ type TBar2 implements IBar2 & IBar1 {
id: ID
}
-# TFoo1 is the basic test case, for issue #114
+""" TFoo1 is the basic test case, for issue #114 """
type TFoo1 implements IFoo1 {
id: ID
- # The 'bar' field is a valid GraphQL field.
- # But before correction of the issue #114, the generated Java code would not compile, as the TBar is a concrete class that implements IBar
- # (and not IBar itself as declared in IFoo)
+
+ """
+ The 'bar' field is a valid GraphQL field.
+ But before correction of the issue #114, the generated Java code would not compile, as the TBar is a concrete class that implements IBar
+ (and not IBar itself as declared in IFoo)
+ """
bar: TBar1
}
-# TFoo12 is a more complex one, with more than one interface implemented
+""" TFoo12 is a more complex one, with more than one interface implemented """
type TFoo12 implements IFoo1 & IFoo2 {
id: ID
- # The 'bar' field is a valid GraphQL field.
- # But before correction of the issue #114, the generated Java code would not compile, as the TBar is a concrete class that implements IBar
- # (and not IBar itself as declared in IFoo)
+ """
+ The 'bar' field is a valid GraphQL field.
+ But before correction of the issue #114, the generated Java code would not compile, as the TBar is a concrete class that implements IBar
+ (and not IBar itself as declared in IFoo)
+ """
bar: TBar12
}
@@ -758,22 +797,30 @@ type ReservedJavaKeywordAsObjectField {
while: Human
}
+"""
#############################
-# test for issue #166:
-# This class contains fields that are Java reserved words. A query allows to check that mapping properly occurs on both client and server side.
+test for issue #166:
+This class contains fields that are Java reserved words. A query allows to check that mapping properly occurs on both client and server side.
+"""
type ReservedJavaKeywordAllFieldCases {
- # A field with a java reserved name which is an enum
+ """ A field with a java reserved name which is an enum """
if: Unit
- # A field with a _non_ java reserved name which is an interface (to check standard behavior)
+
+ """ A field with a _non_ java reserved name which is an interface (to check standard behavior) """
nonJavaKeywordField: WithID
- # A field with a java reserved name which is an interface
+
+ """ A field with a java reserved name which is an interface """
implements: WithID
- # A field with a java reserved name which is a scalar (standard)
+
+ """ A field with a java reserved name which is a scalar (standard) """
import: String
- # A field with a java reserved name which is a scalar (custom)
+
+ """ A field with a java reserved name which is a scalar (custom) """
instanceof: Date
- # A field with a java reserved name which is an object type
+
+ """ A field with a java reserved name which is an object type """
int: Human
- # A field with a java reserved name which is a union
+
+ """ A field with a java reserved name which is a union """
interface: AnyCharacter
}
\ No newline at end of file