首页 > 解决方案 > 如何在 graphql Apollo 中描述客户端的复杂响应对象

问题描述

我在服务器和客户端使用 graphql apollo。服务器有一个突变,它返回一个非常复杂的对象,该对象具有嵌套关系等。 复杂的graphql突变响应类型

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

我试图明确地描述像 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,
        }
      }
    }
  }
`;

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

标签: graphqlapollo

解决方案


推荐阅读