So I'm trying to figure out how to return an array of strings in GraphQL. Basically I have a to-do list with dependencies, so for each item there's a list of things that other item relies on by ID. I'm a little new to all this, but I've done a lot of searching on the GraphQL docs and on here and haven't found anything yet, so apologies in advance if this is a dumb question. I'm using lodash in the resolve function.
// dummy data
var todos = [
{ name: 'Repair Driveway', dependencies: ['2' ,'3'], id: '1' },
{ name: 'Research driveway repair', dependencies: [], id: '2' },
{ name: 'Buy driveway repair tools', dependencies: ['2'], id: '3' },
{ name: 'Get groceries', dependencies: [], id: '4'}
];
const TodoType = new GraphQLObjectType({
name: 'Todo',
fields: () => ({
id: { type: GraphQLID },
name: { type: GraphQLString },
deadline: { type: GraphQLDateTime },
dependencies: { type: } // This is where I'm not sure what to do.
})
});
const RootQuery = new GraphQLObjectType({
name: 'RootQueryType',
fields: {
todo: {
type: TodoType,
args: { id: { type: GraphQLID } },
resolve(parent, args){
console.log("Queried:" );
return _.find(todos, { id: args.id });
}
}
}
})