【发布时间】:2018-08-10 01:46:54
【问题描述】:
我希望创建一个 GraphQL 查询,它可以根据变量“类型”(一个字符串)选择性地添加/删除字段:
query ResultsPage($casetype: String!)
根据Directives 上的引用,您可以对@include 或@skip 某些字段使用布尔值:
query Hero($episode: Episode, $withFriends: Boolean!) {
hero(episode: $episode) {
name
friends @include(if: $withFriends) {
name
}
}
}
我怎样才能对这个字符串值做类似的事情?即,如果$casetype = "foo",则仅包含friends 字段。 GraphQL 可以做到这一点吗?
谢谢!
【问题讨论】:
标签: graphql graphql-js relay gatsby