graphql-java-annotations icon indicating copy to clipboard operation
graphql-java-annotations copied to clipboard

MethodDataFetcher should allow ObjectMapper.convert() for buildArg

Open shevek opened this issue 4 years ago • 2 comments

The implementation of buildArg() isn't very strong, and is somewhat brittle if e.g. a constructor parameter doesn't match an item in the GraphQL schema. We should be permitted to just use Jackson's ObjectMapper.convert() to build the arguments somehow, instead of using buildArg().

shevek avatar Oct 29 '19 22:10 shevek

Strongly agree

FLXT-Qi avatar Mar 05 '20 09:03 FLXT-Qi

Maybe another way would be:

Instead of looking for a constructor that exactly matches the schema use a NoArgsConstructor and then populate the fields (or only do this as fallback).

My use case:


public interface Pattern {
    @GraphQLID
    @GraphQLField
    @GraphQLNonNull
    public String getName();
}

@Setter
@Getter
public abstract class PatternBaseType implements Pattern  {

    @GraphQLID
    @GraphQLField
    @GraphQLNonNull
    public String name;
}


@Data
public class SpecialPattern extends PatternBaseType implements Pattern {
    @GraphQLField
    public Double width;
}

public class Mutations {
    @GraphQLField
    @GraphQLNonNull
    public static SpecialPattern createSpecialPattern(SpecialPattern blueprint) {
        return ...
    }
}

Now SpecialPattern needs a Constructor that takes in the name and the width as parameter otherwise the object is not constructed correctly.

So I guess my question is why does buildArg only consider the constructor and not the JavaObjects fields?

freelancer1845 avatar Mar 03 '21 11:03 freelancer1845

Hi @shevek , @FLXT-Qi , @freelancer1845

We're helping with project maintenance and reviewing the list of opened PRs and Issues.

This issue was created quite a while ago, we were wondering if you were still interested in the outcome, please let us know if this is the case.

Without an answer by October 1st, 2023, this issue will be closed as "inactive" (and can always be re-opened later on if needed).

Thanks,

Fgerthoffert avatar Aug 25 '23 08:08 Fgerthoffert