Search code examples
javascriptgraphqlapollo

Doing a find operation in graphql resolver with a list field


I have a list that is being sent from my backend. I am trying to do a lookup using another datasource

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

I did try using a for each loop inside this like but I am getting nulls returned.

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

The find method takes in a id and sends a get request


Solution

  • I think your syntax ListField .forEach(element =>... is not right. It should be ids.forEach(element =>...