Did you look into implementing a GraphQLResolver as explained for the BookResolver in this link ?
If you read the above link, you should be able to write something like this:
public class AccountResolver implements GraphQLResolver<Account> {
public Collection<AccountTransaction> accountTransactions(Account account,Boolean annualFee) {
// put your business logic here that will call your jparepository
// for a given account
}
}
As for your java DTO, you should have something like this:
public class Account {
private String accountNumber;
private String openDate;
private String type;
private String transactionMonths;
private String productType;
// Don't specify a field for your list of transactions here, it should
// resolved by our AccountResolver
public Account(String accountNumber, String openDate, String type, String transactionMonths, String productType) {
this.accountNumber = accountNumber;
this.openDate = openDate;
this.type = type;
this.transactionMonths = transactionMonths;
this.productType = productType;
}
public String getAccountNumber() {
return accountNumber;
}
public String getOpenDate() {
return openDate;
}
public String getType() {
return type;
}
public String getTransactionMonths() {
return transactionMonths;
}
public String getProductType() {
return productType;
}
}
Let me explain a bit more the code concerning the resolver above:
- You create a new resolver for your Account DTO;
- It has one method with the exact same signature as your GraphQL field in Account, that is: accountTransactions, returning a collection of AccountTransaction.
As for the Java DTO:
- It specify all the fields of your GraphQL type but NOT the field you want your resolver to resolve.
SpringBoot GraphQL will autowire the resolver, and it will be called if the client asked for details on the account and its transactions.
Assuming that you have defined a GraphQL query called accounts that returns all accounts, the following GraphQL query would be valid:
{
accounts {
accountNumber
accountTransactions {
amount
date
annualFee
}
}
}