I have set up a connection to a mongoDB collection using graphQL. Here is the data from the DB:
{
"_id" : ObjectId("59ee1be762494b1df1dfe30c"),
"itemId" : 1,
"item" : "texture",
"__v" : 0
}
{
"_id" : ObjectId("59ee1bee62494b1df1dfe30d"),
"itemId" : 1,
"item" : "pictures",
"__v" : 0
}
Running the query
{ todo(item: "texture"){ itemId, item } }
returns:
{
"data": {
"todo": [
{
"itemId": 1,
"item": "texture"
}
]
}
}
I am looking to find datasets that partially match a given string. For example, the string tur
should return both datasets: texture, pictures
My graphQL Schema is defined as follows:
var schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'RootQueryType',
fields: {
todo: {
type: new GraphQLList(todoType),
args: {
item: {
name: 'item',
type: new GraphQLNonNull(GraphQLString)
}
},
resolve: (root, {item}, source, fieldASTs) => {
var projections = getProjection(fieldASTs)
var foundItems = new Promise((resolve, reject) => {
ToDoMongo.find({item}, projections, (err, todos) => {
err ? reject(err) : resolve(todos)
})
})
return foundItems
}
}
}
})
})