graphql - 如何在 graphql Apollo 中描述客户端的复杂响应对象
问题描述
我在服务器和客户端使用 graphql apollo。服务器有一个突变,它返回一个非常复杂的对象,该对象具有嵌套关系等。
那么如何在客户端进行描述呢?
我试图明确地描述像 grapqhl 需要的每个字段,但它非常累人和丑陋。此外,模式上的字段具有链接关系,我不知道如何在 graphql 响应中描述它。我不确定在这种情况下碎片是否可以帮助我。
export const CREATE_COMMUNITY_MUTATION = gql`
mutation CreateCommunity($data: CreateCommunityInput!) {
createCommunity(data: $data) {
id,
name,
about,
owner {
id,
email,
bio,
firstName,
lastName,
profileUrl,
locale,
username,
account,
timeBasedFeed,
scoreBasedFeed,
},
color,
pictureUrl,
timeBasedFeed,
scoreBasedFeed,
topics {
id,
name,
image,
timeBasedFeed,
storeBasedFeed,
aliases,
parents,
allAncestors
},
members {
edges {
cursor,
node {
id,
email,
bio,
firstName,
lastName,
profileUrl,
locale,
username,
account,
timeBasedFeed,
scoreBasedFeed,
}
},
totalCount,
pageInfo {
startCursor
endCursor
hasNextPage
hasPreviousPage
count
},
}
blockedUsers {
edges {
cursor,
node {
id,
email,
bio,
firstName,
lastName,
profileUrl,
locale,
username,
account,
timeBasedFeed,
scoreBasedFeed,
}
},
totalCount,
pageInfo {
startCursor
endCursor
hasNextPage
hasPreviousPage
count
},
},
admins {
users {
id,
email,
bio,
firstName,
lastName,
profileUrl,
locale,
username,
account,
timeBasedFeed,
scoreBasedFeed,
}
},
moderators {
users {
id,
email,
bio,
firstName,
lastName,
profileUrl,
locale,
username,
account,
timeBasedFeed,
scoreBasedFeed,
}
}
}
}
`;
也许有人可以提出一些建议/想法如何处理它?谢谢你的帮助
解决方案
推荐阅读
- reactjs - 在开发工作时,React 路线在 heroku 上未经授权
- r - 如何使用 poly R 函数更改 for 循环中的多项式阶数?
- php - 我想使用 foreach 循环 php 中的 ajax 获取单击行的 UID,但获取所有 UID
- flutter - 我对 Flutter 说错误:控制器的长度属性不匹配
- javascript - 如何在 JavaScript 或 jQuery 中 1 秒后删除一个类?
- elixir - 使用 File.stream 的图像大小差异
- python - python quad:对一个变量进行积分,同时将其他变量视为常量?
- entity-framework - 将 dotnet-ef 与 docker 和 asp.net core 3.1 一起使用
- c++ - 有没有办法一次声明多个相同类型的对象,并通过一个表达式立即用相同的右值初始化它们?
- node.js - Raspberry pi 零 w 上的 Puppeteer