【发布时间】:2021-03-08 22:29:51
【问题描述】:
我有一个正在试验的大型数据集。我正在尝试有条件地包含嵌套对象。 我的客户查询:
query getAllAlbums ($fetchPhotos: Boolean!){
albums{
id
title
tags{
...Tag
weight
}
carouselItems{
id,
mediaUrl
}
photos @include(if: $fetchPhotos){
...Photo
}
}
}
在我第一次尝试在服务器端实现时,我将它添加到架构中:
type Album @include{
id: String
title: String
tags: [Tag]
photos: [Photo] @include(if: fetchPhotos)
carouselItems: [Photo]
}
我收到验证错误:
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.
好的,我不能在架构上使用它,那么还剩下什么?解析器?它不在论点中......
我该如何实现呢? apollographql 文档说他们支持它,但没有给出这些示例。
【问题讨论】: