Skip to content

Commit

Permalink
Merge pull request #215 from osher-sade/master
Browse files Browse the repository at this point in the history
fixed a bug that could cause directives to be built with synthetic fields
  • Loading branch information
yarinvak authored Jul 9, 2019
2 parents cfdba31 + e860593 commit e0c48a4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public DirectiveArgumentCreator(CommonPropertiesCreator commonPropertiesCreator,
this.container = container;
}


public GraphQLArgument getArgument(Field field, Class<?> containingClass) {
GraphQLArgument.Builder builder = newArgument()
.name(commonPropertiesCreator.getName(field))
Expand All @@ -60,6 +59,4 @@ private GraphQLInputType getType(Field field) {
return (GraphQLInputType) typeFunction.buildType(true, field.getType(),
field.getAnnotatedType(), container);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public DirectiveCreator(DirectiveArgumentCreator directiveArgumentCreator, Commo

public GraphQLDirective getDirective(Class<?> annotatedClass) {
GraphQLDirective.Builder builder = newDirective()
.name(commonPropertiesCreator.getName(annotatedClass))
.description(commonPropertiesCreator.getDescription(annotatedClass));
.name(commonPropertiesCreator.getName(annotatedClass))
.description(commonPropertiesCreator.getDescription(annotatedClass));
Introspection.DirectiveLocation[] validLocations = getValidLocations(annotatedClass);
if (validLocations == null || validLocations.length == 0) {
throw new GraphQLAnnotationsException("No valid locations defined on directive", null);
Expand All @@ -49,17 +49,16 @@ public GraphQLDirective getDirective(Class<?> annotatedClass) {
}

private void buildArguments(GraphQLDirective.Builder builder, Class<?> annotatedClass) {
Arrays.stream(annotatedClass.getDeclaredFields()).forEach(x ->
builder.argument(directiveArgumentCreator.getArgument(x, annotatedClass)));
Arrays.stream(annotatedClass.getDeclaredFields())
.filter(field -> !field.isSynthetic())
.forEach(field -> builder.argument(directiveArgumentCreator.getArgument(field, annotatedClass)));
}


private Introspection.DirectiveLocation[] getValidLocations(Class<?> annotatedClass) {
DirectiveLocations directiveLocationsAnnotation = annotatedClass.getAnnotation(DirectiveLocations.class);
if (directiveLocationsAnnotation != null) {
return directiveLocationsAnnotation.value();
}
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import java.util.Map;
import java.util.TreeMap;

public class ObjectUtil {
public class ObjectUtil {

public static Map<String, Field> getAllFields(Class c) {
Map<String, Field> fields;
Expand All @@ -30,7 +30,9 @@ public static Map<String, Field> getAllFields(Class c) {
}

for (Field f : c.getDeclaredFields()) {
fields.put(f.getName(), f);
if (!f.isSynthetic()) {
fields.put(f.getName(), f);
}
}

return fields;
Expand Down

0 comments on commit e0c48a4

Please sign in to comment.