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}: *