'GraphQL query with nested query passing parameters to non scalar type arguments

I have a current Query type defined like this:

type BoxItems {
  total: Number,
  boxItems: [BoxItem]
}
type Box {
     boxItemUuid: UUID!
     boxItems:(page: Number, pageSize: Number): BoxItems
}
extend Query {
   boxes(input: SomeInputType): [Box]
   boxItems(boxItemUuid: UUID!, page: Number, pageSize: Number): BoxItems
}

Which is then called by client like:

query BoxesQuery($input: SomeInputType){
  boxes(input:$input){
   boxItems:(pageSize:1){
     total
  }
 }
}

In this case a boxItems resolver function is still able to access boxItemUuid in the args object. My question is what if I decide to create input types for my boxItems Query type. For instance, lets say boxItemUuid was now defined in FilterInfo type

 boxItems(pageInfo: PageInfo, filter: FilterInfo): BoxItems

How would I go about defining the query client BoxesQuery, to pass boxItemUuid as a field on the FilterInfo type? Is this even possible? Is it bad practice for query types to include non scalar type parameters?



Solution 1:[1]

I didn't realize the resolver handler, which was not included in my question was checking parent, and args object for a particular parameter. So the answer here is to grab parameter from parent object

 resolver(parent, args, context){
  const boxItemUuid = parent.boxItemUuid || args.boxItemUuid;
}

Sources

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

Source: Stack Overflow

Solution Source
Solution 1 Mike Lunn