Distelli/graphql-apigen

NPE in MethodDataFetcher

Closed this issue · 2 comments

Hello

i've a POJO like this.

class Test {
  private String namedProperty;

  public Test(String namedProperty) {
    this.namedProperty = namedProperty;
  }

  public String getNamedProperty() {
    return this.namedProperty;
  }
}

and i define a GraphQL field

...
	.field(GraphQLFieldDefinition.newFieldDefinition()
                    .type(Scalars.GraphQLInt)
                    .name("named_property")
                    .dataFetcher(new MethodDataFetcher(
    	                    "namedProperty",
    	                    null,
    	                    _impl.orElse(null)))
    	                .build())
...

_impl is the TestClass.

and i get this error.

java.lang.NullPointerException
	at com.distelli.graphql.MethodDataFetcher.getMethodViaGetter(MethodDataFetcher.java:54) ~[graphql-apigen-deps-3.0.0.jar:?]
	at com.distelli.graphql.MethodDataFetcher.get(MethodDataFetcher.java:43) ~[graphql-apigen-deps-3.0.0.jar:?]

is it possible to have a fieldname, different from the POJO ?

Thanks
Marcel

With my pullRequest it's possibile to give the name of the GraphQL field

.field(GraphQLFieldDefinition.newFieldDefinition()
                    .type(Scalars.GraphQLInt)
                    .name("named_property")
                    .dataFetcher(new MethodDataFetcher(
    	                    "namedProperty",
    	                    null,
    	                    _impl.orElse(null),
                            "named_property"))
    	                .build())

Thanks for the PR, I've accepted your change.