Netflix/falcor

Cannot read property $type of undefined at pathValueMerge

gijun19 opened this issue · 2 comments

I'm getting the error:

TypeError: Cannot read property '$type' of undefined

Here's the code I have that prepares the JSON that I'm returning to the client.

const falcor = require("falcor");
const FalcorRouter = require("falcor-router");
const request = require("request-promise");
const _ = require("lodash");

class ItemsRouter extends FalcorRouter.createClass([
  {
    route: 'items["id", "title"]',
    async get(pathSet) {
      try {
        if (this.headers.authorization === null) {
          throw new Error("Not authorized.");
        }
        const config = {
          uri: "http://localhost:8080/api",
          headers: this.headers
        };
        const response = await request(config);
        const attributes = pathSet[1];
        const items = JSON.parse(response)["content"];
        let itemsById = {};

        // Prepare JSON Graph.
        items.forEach(item => {
          itemsById[item.id] = _.pick(item, attributes);
        });

        const json = {
          itemsById,
          item: items.map(item => {
            return {
              $type: "ref",
              path: ["itemsById", item.id],
              value: ["itemsById", item.id]
            };
          })
        };

        return json;
      } catch (error) {
        throw new Error(error);
      }
    }
  }
]) {
  constructor(headers) {
    super();
    this.headers = headers;
  }
}

module.exports = ItemsRouter;

Is there anything glaringly wrong with this approach that makes this error happen?

Maybe related to this issue?
Issue

Are you able to create a full standalone repo where I can reproduce the issue?

@danielparkk Are you still encountering this issue? Which version of Falcor are you using?