'java GraphQL filtering parent data in child resolver

Working with graphql java. I have schema like :

type Deal {
  id: Int!,
  type: Type,
  instruments: [Instrument]
  #.. other fields
}

type Instrument {
  id: Int!,
  name: String,
  legs: [Leg],
  #.. other fields

}
type Leg {
  id: Int!
  payments: [Payment],
  #.. other fields
}

type Payment {
  id: Int!,
  amount: Boolean!,
  account: Int!
  #.. other fields
}

The requirement is to fetch deal related payments with given filter criteria. the criteria contains fields from parents as well as child objects. The query looks like

type Query {
  dealPayments(filter: Filter):[Deal]
}

input Filter {
  type: Type, //field on Deal
  amountGreaterThan: Integer //field on Payment
  account: Integer //field on Payment
  # other conditions
}

I want to implement my resolvers in a way that enables me to retrieve all Deals which have payment account as given account.

query AllDealsforAccount($filter : {"account" = 123}) {
   Deal {
     id 
     instruments  {
       id
       legs {
         id
         payments (account: 123){
           id
           account
         }
       }
     }
   }
}

Now applying the corresponding criteria in child resolvers - the child object(payment) becomes null, but deal is still in the response. ** How to filter the parent deals based on child resolver? **

Any help would be appreciated. TIA



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source