I'm setting up a GraphQL server using the Apollo framework.
It will have an entity called Shelf. A Shelf has a shelfId and packages.
I need to be able to query for Shelves with the shelfId or packageCode.
My data source can handle both of these scenario's but I want to have 1 resolver called shelf for this.
Example
query getShelf(shelfId: "1") {
shelfId
}
or:
query getShelf(packageCode: "123") {
shelfId
}
How to can I define a type the checks if packageCode or shelfId is set?
- When
packageCodeis providedshelfIdis not required - When
shelfIdis providedpackageCodeis not required - When neither us provided either of them are required
The only options I think I have are:
- A) Create separate resolvers for each scenario
- B) Make them both optional and return an error from the resolver.
How would I proceed?