我正在创建一个投票应用程序,其中包含可以投票的民意调查。我目前坚持投票进行投票(基本上是投票)。
(长话短说:民意调查可以从主商店访问,但观众的民意调查和投票可以直接由他(作为字段)访问。投票也可以从民商店访问,但民意调查&# 39;投票也可以直接访问。
query {
store {
polls { //poll connection
edges {
node { //poll
votes { //vote connection
...
}
}
}
}
votes { //vote connection
edges {
node { //vote
...
}
}
}
}
viewer {
polls { //poll connection
edges {
node { //poll
votes { //vote connection
...
}
}
}
}
votes { //vote connection
edges {
node { //vote
...
}
}
}
}
}
这个复杂的架构让我对如何定义胖查询感到困惑,因为它应该定义所有可能正在改变的内容。
所以我的问题是如何在我的胖查询中表达这一点,这是否足够?
getFatQuery() {
return Relay.QL`
fragment on CreateVoteMutation {
voteEdge,
viewer{
polls,
voteCount
votes,
},
store{
polls,
voteCount,
votes,
}
}
`;
}
或者我应该以某种方式在民意调查中包括投票?
getFatQuery() {
return Relay.QL`
fragment on CreateVoteMutation {
voteEdge,
viewer{
polls{
edges{
node{
voteCount,
votes
}
}
},
voteCount
votes,
},
store{
polls{
edges{
node{
voteCount,
votes
}
}
},
voteCount,
votes,
}
}
`;
}
谢谢!
答案 0 :(得分:1)
看起来你有正确的想法。在Relay中定义FatQuery时,您应该尽可能保持返回字段的最佳状态,因为这是GraphQL的好处(您不需要返回比在客户端中使用的更多)。所以你的FatQuery应该是这样的:
getFatQuery() {
return Relay.QL`
fragment on CreateVoteMutation {
voteEdge,
viewer{
polls { // this is most likely a GraphQL object type, so you'll need a sub-selection, but you don't necessarily need to return all the Votes again since you do that later
name
timestamp
}
voteCount // scalar integer
votes { // again, here you'll need to return a sub-selection since Votes is a GraphQL object type
name
timestamp
}
},
store{
polls { // this is most likely a GraphQL object type, so you'll need a sub-selection, but you don't necessarily need to return all the Votes again since you do that later
name
timestamp
}
voteCount // scalar integer
votes { // again, here you'll need to return a sub-selection since Votes is a GraphQL object type
name
timestamp
}
}
}
`;
}
我们的想法是,您可以在技术上再次将votes
作为polls
的子选项返回;但是,没有必要,因为你已经回到了观众面前。这将为您提供系统中的totalCount和所有投票。如果你想通过民意调查来过滤投票和投票,那么你可以做相反的事情,看起来像这样:
getFatQuery() {
return Relay.QL`
fragment on CreateVoteMutation {
voteEdge,
viewer{
polls { // this is most likely a GraphQL object type, so you'll need a sub-selection, but you don't necessarily need to return all the Votes again since you do that later
name
timestamp
voteCount // scalar integer
votes { // again, here you'll need to return a sub-selection since Votes is a GraphQL object type
name
timestamp
}
}
},
store{
polls { // this is most likely a GraphQL object type, so you'll need a sub-selection, but you don't necessarily need to return all the Votes again since you do that later
name
timestamp
voteCount // scalar integer
votes { // again, here you'll need to return a sub-selection since Votes is a GraphQL object type
name
timestamp
}
}
}
}
`;
}
希望这有帮助!