3 个级别的 Graphql Nest 解析器

问题描述

我在使用嵌套解析器最佳实践时遇到问题

这是一个游戏,用户拥有国家的一部分,有一个城市列表,在这个城市有一个房子列表

{ user: { countries :[{ cities : [{ house : [] }] }] }}

我想做这个 GQL 查询

query getHouseByUser {
  user {
   countries {
    cities {
     house {
     name
     }
  }
  }
  }
}

这是我的 Apollo 解析器

const  Resolvers = {
  User: {
    countries: () => {
      try {
        const countries = await getCountries();
        return countries;
      } catch (error) {
        throw new ApolloError(error);
      }
    },},Countries: {
    cities: async () => {
      try {
        const cities = await getCitiesByCountry()
        return cities;
      } catch (error) {
        throw new ApolloError(error);
      }
    },

我的问题是如何解析 house 字段以获取我的房子,关于拆分解析器的最佳实践是什么? 我不想有很多嵌套的解析器

感谢您的帮助

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)