I am new to GraphQL and not really sure if this problem is my lack of JavaScript knowledge or GraphQL.
My GraphQL queries an external service and when the response is a scalar json object everything works great. The problem comes when the external service returns an array of json.
This works for a single json result:
const transform = (json) => {
return {
id: json.id,
fullname: json.fullName,
email: json.email
}
But for an array like this the mapping code is inadequate.
[{id:...fullname:...email:...},{id:...etc},{id:...etc}]
Now I can detect that the return is an array and I can loop through the array just not sure how to map into a GraphQLList.
So after Googling I found GraphQLList but it doesn't work either.
...snip from Schema...
UserData: {
type: GraphQLLIst(UserType),
same mapping code as above.
message": "Expected Iterable, but did not find one for field RootQueryType.investorData.
But I'm confused because the console log clearly shows a json array?
GraphQLSchema
const RootQueryType = new GraphQLObjectType({
name: 'RootQueryType',
fields:{
investorData: {
type: new GraphQLList(UserType),
description: 'Get investors by id',
args:{key: {type: GraphQLString} },
resolve: resolveInvestorData
}
}
}
})
investorDatafield?