I'm trying to specify a GraphQL schema with a type that has various fields, and also allows you to tack on an OR: [...] recursively with the same arguments.  I've got it working like this
input BookFilters {
  _id: String
  title: String
  title_contains: String
  title_startsWith: String
  title_endsWith: String
  OR: [BookFilters]
}
type Query {
   allBooks(_id: String
     title: String
     title_contains: String
     title_startsWith: String
     title_endsWith: String
     OR: [BookFilters]
   ): [Book]
}
which works great, and this query
{
  allBooks(title_endsWith: "1", OR: [{ title: "2" }, {title:"3"}, {OR: [{title_contains: "Q"}, {OR:[{title:"Q"}]}]}]) {
    _id
    title
  }
}
goes through just fine.
My question is, is there some way to remove the duplication? Ideally I'd love it if
type Query {
   allBooks(...BookFilters): [Book]
}
was valid, but it doesn't appear to be.
Edit - A comment brought up fragments. They can only be declared off of a type, right? So I'd still have a make a new type that lists all my query arguments, and then make a fragment off of it, re-listing all the fields?
Even if that's not so, GraphQL still doesn't seem to like spreading on input arguments.
fragment BookFiltersFragment on BookFilters {
    _id
}
type Query {
   allBooks(...BookFiltersFragment): [Book]
}
which errors out on the ...
For the benefit of anyone winding up here, it looks like this is impossible, at least according to an Apollo dev.
https://twitter.com/stubailo/status/914997054098759680
https://twitter.com/stubailo/status/914997127356366848
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With