如何在graphql Apollo中的客户端描述复杂的响应对象

时间:2020-08-13 21:14:10

标签: graphql apollo

我在服务器和客户端上使用graphql apollo。 服务器具有一个变异,该变异返回一个非常复杂的对象,该对象具有嵌套关系等。 the complex graphql mutation response type

那么如何在客户端进行描述?

我试图像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,
        }
      }
    }
  }
`;

也许有人可以提出一些建议/想法,如何处理? 谢谢你的帮助

0 个答案:

没有答案