I have a big dataset I am experimenting with. I am trying to conditionally include nested objects. My client query:
query getAllAlbums ($fetchPhotos: Boolean!){
albums{
id
title
tags{
...Tag
weight
}
carouselItems{
id,
mediaUrl
}
photos @include(if: $fetchPhotos){
...Photo
}
}
}
For my first attempt at implementing on the server side, I added it to the schema:
type Album @include{
id: String
title: String
tags: [Tag]
photos: [Photo] @include(if: fetchPhotos)
carouselItems: [Photo]
}
I am getting validation errors:
Error: Directive "@include" may not be used on OBJECT.
Directive "@include" argument "if" of type "Boolean!" is required, but it was not provided.
Directive "@include" may not be used on FIELD_DEFINITION.
Okay, I can't use it on the schema, so what is left? The resolvers? It isn't in the arguments...
How do I implement this? The apollographql documentation says they support it, but no examples were given for these.