首页 > 解决方案 > 在 Apollo 客户端缓存中展平对象

问题描述

所以我是阿波罗客户端的新手并尝试连接它所以我想了解如何在缓存中的查询中展平嵌套对象我的代码看起来像 获取所有用户的查询

export const GET_USERS = gql`
  query User {
    users {
      id
      username
      email
      role {
        __typename
        name
      }
    }
  }

我的索引

const cache = new InMemoryCache({
  typePolicies: {
    Users: {
      
    },
  },
});

我需要的输出就像

[{
      id
      username
      email
      roleName
}]

标签: graphqlapolloapollo-client

解决方案


推荐阅读