Falcor Router not resolving $ref

205 views Asked by At

I've got the following paths defined on my router:

getProjectById[{keys:ids}][{keys:props}]
projects[{ranges:ranges}][{keys:props}]

On client I'm able to successfully retrieve individual projects with the following query:

model.get(
   ['getProjectById', 'ffd38a56-cca2-11e5-9e6a-695c9890612f', 'name'],
   ['getProjectById', 'ffd38a55-cca2-11e5-9e6a-695c9890612f', 'name']).then((data) => {
  console.log('valid json response ->', data);
 });

The 'projects' route returns a reference to each individual project, yet when I make the following request I get undefined as my response:

model.get(['projects', { from: 0, to: 2}, ['name', 'overview']]).then((data) => {
    console.log('response is undefined ->', data);
});

The server endpoint returns a promise, when that finally resolves it contains the following array of paths:

[
    { path: ['projects', 0], value: { $ref(['getProjectById', 'ffd38a56-cca2-11e5-9e6a-695c9890612f'] }},
    { path: ['projects', 1], value: { $ref(['getProjectById', 'ffd38a55-cca2-11e5-9e6a-695c9890612f'] }},
    { path: ['projects', 2 ], value : { $atom(undefined) }
]

According to the docs, this should perform a secondary hit on 'getProjectById' route passing in the array of identifiers, but this never gets triggered.

1

There are 1 answers

0
PrzeoR On

I had similar problem, maybe it will help.

I will give an example, how I've solved it in the past:

route: 'articlesById[{keys}]["_id","title"]',

First route, that contains the $ref (not working):

route: 'articles[{integers}]["title"]',
get: (pathSet) => {
  // striped

  let articleRef = $ref(['articlesById', currentMongoID]);

  return {
    path: ['articles', index],
    value: articleRef
  };
}
FIX:

Delete the ["title"] from the articles route, so the new working is code:

route: 'articles[{integers}]',
get: (pathSet) => {
  // striped

  let articleRef = $ref(['articlesById', currentMongoID]);

  return {
    path: ['articles', index],
    value: articleRef
  };
}

As you can see I've deleted the ["title"] above... you must also make sure that in the articlesById, you have this "title" in place when returning the data so:

{
    route: 'articlesById[{keys}]["_id","title"]',
  // striped
  articleResObj.title = "WE HAVE TITLE HERE"; // make sure of this when returning
  results.push({
    path: ['articlesById', currentIdString],
    value: articleResObj
  });