falcor-router
falcor-router copied to clipboard
combining data fetch queries - bug?
from Netflix/falcor#289
the falcor-router-demo was a huge help for me getting a working server up, I was having trouble before using the example from the falcor repo readme, I'm guessing it's a bit out of date. I got a basic server going and connecting to a mysql db, but I haven't been able to figure out how to combine fields so they can make a single sql request.
I remember from older examples/screencasts I watched that all the fields would come in to the get function in the router, and could then be combined into a query, but now it seems it is calling a separate get function for each field, which makes combining them more difficult.
I thought maybe a solution with combining promises would work, but it seems like it would be needlessly complicated and I am probably just missing something.
In any case I think the falcor-router-demo repo could do with another router function to demonstrate how this should be done, assuming it still can be.
after talking to jafar on the phone it became apparent this might be a bug with the router
here's the route code I was testing:
{
route: "recipesById[{integers:recipeIds}]['title','url_title']",
get: function (pathSet) {
console.log((new Date()).getTime(), pathSet);
/*var key = pathSet[2];
var stuff = [];
_.each(pathSet.recipeIds, function(id) {
stuff.push(dbquery('SELECT '+key+' from km.recipes where id='+id).then(function(data) {
var rows = data[0];
return {
path: ['recipesById', id, key],
value: rows[0][key]
};
}));
});
return Q.all(stuff);*/
}
}
on the client side:
model.get('recipesById[1..10]["title","url_title"]').then(/* ... */);
log output from the get function on the server happens twice, once for each field
1435606139423 [ 'recipesById', [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ], 'title', recipeIds: [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ] ]
1435606139497 [ 'recipesById', [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ], 'url_title', recipeIds: [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ] ]
falcor-router at 7b2b28 falcor-restify at e97e5c falcor at c8dbdd falcor-path-syntax at 60253d
Hello!
It turns out this is a problem with our collapsing algo. We are working on solving this and when we do we will pull it out of falcor and use it throughout our packages.