I have a basic Java entity class.
public class Result {
String resultTitle;
String resultDecription;
}
This class is returned in a GraphQL query
@GraphQLQuery(name = "getResult")
public Result getResult() {
Result result = //get result, e.g. from DB
return result;
}
This works fine so far. Now I want to return one additional attribute in the GraphQL query. But that additonal attribute is very costly to calculate. So I only want to return it, when the GraphQL client actually requests it in his query like so:
query { getResult() { resultTitle resultDecription } }
<== do not execute the costly calculationquery { getResult() { resultTitle resultDecription costlyAdditionalProp } }
<== DO execute the costly calculationCan this be done with graphql-spqr?
Oh, that was actually quite simple. Just needed to dig up the right example from the graphql-spqr-examples.
@GraphQLQuery(name = "costlyAdditionalProp ")
public Long getCostlyAdditionalProp (@GraphQLContext Result result) {
return calculationService.doCalculation(result);
}