Distelli / graphql-apigen

Generate Java APIs with GraphQL Schemas
Apache License 2.0
66 stars 20 forks source link

NPE in MethodDataFetcher #24

Closed a-marcel closed 7 years ago

a-marcel commented 7 years ago

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

a-marcel commented 7 years ago

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())
brimworks commented 7 years ago

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