使用列表字段在 graphql 解析器中执行查找操作

Doing a find operation in graphql resolver with a list field

我有一个从后端发送的列表。我正在尝试使用另一个数据源进行查找

Field: (request, _, { dataSources: { dataSource} }) => 
    dataSource.find({ id: request.ListField }),

我确实尝试在其中使用 for each 循环,但返回的是空值。

        Field: (request, _, { dataSources: { xDataSource} }) => { 
        const ids = request.ListField ;
        ListField .forEach(element => {
           return dataSource.find({ id: element })});
    },

find方法接受一个id并发送一个get请求

我认为你的语法 ListField .forEach(element =>... 不对。应该是ids.forEach(element =>...