Skip to content

Should allow for specialized constructor @GraphQLDataFetcher #39

@crazyfrozenpenguin

Description

@crazyfrozenpenguin

I've noticed that GraphQL will, for fields starting with "is" (e.g. isAvailable), set the DataFetcher to FieldDataFetcher as opposed to PropertyDataFetcher.

Native boolean fields starting by "isXxxx" are allowed to have a getter method of the same name as defined in the Java Beans spec section 8.3.2:

   public boolean is<PropertyName>();

The same is not necessarily true for Boolean object types.

Although it is discussible if such fields should be using FieldDataFetcher by default, the graphql-java-annotations should allow graphql fields to be easily overwritten by another DataFetcher basic type.

The current case generates a FieldDataFetcher by default:

  @ApiModelProperty(value = "")
  @GraphQLField
  var isAvailable: Boolean? = null

But instead I would like it to use the PropertyDataFetcher:

  @ApiModelProperty(value = "")
  @GraphQLField
  @GraphQLDataFetcher(PropertyDataFetcher::class)
  var isAvailable: Boolean? = null

And this code fails to compile because PropertyDataFetcher annotation does not have a public default constructor. To get around it I had to specialize the PropertyDataFetcher for that specific field and it can become quite repetitive having to do the same for other similar fields.

Instead, it would be nice to allow to pass argument for a given specialized constructor as in:

  @GraphQLDataFetcher(value=PropertyDataFetcher::class, args="isAvailable")
  public Boolean isAvailable = null

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions