无法从父查询派生数据时,如何嵌套Graphql查询?

时间:2018-11-30 04:03:41

标签: graphql

我有电影模式

  type Movie {
    id: ID
    title: String
    watchedBy: [User]!
    watchedCount: Int
  }

解析器:

  Query: {
    listMovies: async (_, __, { dataSources }) => {
      return await dataSources.movieAPI.getAllMovies()
    },
  },
  Movie: {
    watchedBy: async (listMovie, __, { dataSources }) => {
      return await dataSources.userAPI.getWatchedByUsers(listMovie.id)
    }
  }

如果我想退回watchedCount怎么办?如何访问watchedBy,以便退回watchedBy.length?还是应该在前端计算watchedBy.length

0 个答案:

没有答案