Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ default List<String> getAnnotations(MappingContext mappingContext, Type<?> type,
default List<String> getAnnotations(MappingContext mappingContext, ExtendedDefinition<?, ?> extendedDefinition) {
NamedNode def = extendedDefinition != null ? extendedDefinition.getDefinition() : null;
return getAnnotations(mappingContext, extendedDefinition.getName(), extendedDefinition.getName(), null,
Collections.emptyList(), false, def);
extendedDefinition.getDirectives(), false, def);
}

default List<String> getAnnotations(MappingContext mappingContext, String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,26 @@ public List<String> getDirectiveNames() {
return directives;
}

/**
* Return all directives for this definition
*
* @return list of directive names
*/
public List<Directive> getDirectives() {
List<Directive> directives = new ArrayList<>();
if (this.definition instanceof DirectivesContainer) {
List<Directive> definitionDirectives = ((DirectivesContainer<?>) this.definition).getDirectives();
if (!Utils.isEmpty(definitionDirectives)) {
directives.addAll(definitionDirectives);
}
this.extensions.stream().filter(Objects::nonNull)
.map(DirectivesContainer.class::cast)
.map(DirectivesContainer::getDirectives).filter(Objects::nonNull)
.forEach(ds -> ds.forEach(d -> directives.add(((Directive) d))));
}
return directives;
}

public T getDefinition() {
return definition;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ void generate_Directives() throws Exception {
"int={{int}}, " +
"n={{n?toString}})"));
directiveAnnotationsMapping.put("valid", singletonList("@javax.validation.Valid"));
directiveAnnotationsMapping.put("customResolver", singletonList("@com.example.CustomAnnotation"));
mappingConfig.setDirectiveAnnotationsMapping(directiveAnnotationsMapping);

new JavaGraphQLCodegen(singletonList("src/test/resources/schemas/test.graphqls"),
Expand All @@ -221,6 +222,9 @@ void generate_Directives() throws Exception {
assertSameTrimmedContent(
new File("src/test/resources/expected-classes/annotation/MutationResolver.java.txt"),
getFileByName(files, "MutationResolver.java"));
assertSameTrimmedContent(
new File("src/test/resources/expected-classes/annotation/EventProperty.java.txt"),
getFileByName(files, "EventProperty.java"));
}

}
192 changes: 192 additions & 0 deletions src/test/resources/expected-classes/annotation/EventProperty.java.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
package com.kobylynskyi.graphql.test1;


/**
* An event property have all possible types
*/
@javax.annotation.Generated(
value = "com.kobylynskyi.graphql.codegen.GraphQLCodegen",
date = "2020-12-31T23:59:59-0500"
)
@com.example.CustomAnnotation
public class EventProperty implements java.io.Serializable {

private Double floatVal;
private Boolean booleanVal;
private int intVal;
private java.util.List<Integer> intVals;
private String stringVal;
private java.util.List<EventProperty> child;
private Event parent;

public EventProperty() {
}

public EventProperty(Double floatVal, Boolean booleanVal, int intVal, java.util.List<Integer> intVals, String stringVal, java.util.List<EventProperty> child, Event parent) {
this.floatVal = floatVal;
this.booleanVal = booleanVal;
this.intVal = intVal;
this.intVals = intVals;
this.stringVal = stringVal;
this.child = child;
this.parent = parent;
}

/**
* Float property
* with multiline comment
*/
public Double getFloatVal() {
return floatVal;
}
/**
* Float property
* with multiline comment
*/
public void setFloatVal(Double floatVal) {
this.floatVal = floatVal;
}

public Boolean getBooleanVal() {
return booleanVal;
}
public void setBooleanVal(Boolean booleanVal) {
this.booleanVal = booleanVal;
}

public int getIntVal() {
return intVal;
}
public void setIntVal(int intVal) {
this.intVal = intVal;
}

/**
* primitive should not be generated
*/
public java.util.List<Integer> getIntVals() {
return intVals;
}
/**
* primitive should not be generated
*/
public void setIntVals(java.util.List<Integer> intVals) {
this.intVals = intVals;
}

/**
* String comment
*/
public String getStringVal() {
return stringVal;
}
/**
* String comment
*/
public void setStringVal(String stringVal) {
this.stringVal = stringVal;
}

/**
* Properties
*/
public java.util.List<EventProperty> getChild() {
return child;
}
/**
* Properties
*/
public void setChild(java.util.List<EventProperty> child) {
this.child = child;
}

/**
* Parent event of the property
*/
public Event getParent() {
return parent;
}
/**
* Parent event of the property
*/
public void setParent(Event parent) {
this.parent = parent;
}



public static EventProperty.Builder builder() {
return new EventProperty.Builder();
}

public static class Builder {

private Double floatVal;
private Boolean booleanVal;
private int intVal;
private java.util.List<Integer> intVals;
private String stringVal;
private java.util.List<EventProperty> child;
private Event parent;

public Builder() {
}

/**
* Float property
* with multiline comment
*/
public Builder setFloatVal(Double floatVal) {
this.floatVal = floatVal;
return this;
}

public Builder setBooleanVal(Boolean booleanVal) {
this.booleanVal = booleanVal;
return this;
}

public Builder setIntVal(int intVal) {
this.intVal = intVal;
return this;
}

/**
* primitive should not be generated
*/
public Builder setIntVals(java.util.List<Integer> intVals) {
this.intVals = intVals;
return this;
}

/**
* String comment
*/
public Builder setStringVal(String stringVal) {
this.stringVal = stringVal;
return this;
}

/**
* Properties
*/
public Builder setChild(java.util.List<EventProperty> child) {
this.child = child;
return this;
}

/**
* Parent event of the property
*/
public Builder setParent(Event parent) {
this.parent = parent;
return this;
}


public EventProperty build() {
return new EventProperty(floatVal, booleanVal, intVal, intVals, stringVal, child, parent);
}

}
}