Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Returning ref from route results in incomplete response #226

Open
jameslaneconkling opened this issue Sep 22, 2019 · 0 comments
Open

Returning ref from route results in incomplete response #226

jameslaneconkling opened this issue Sep 22, 2019 · 0 comments

Comments

@jameslaneconkling
Copy link

Specifically, returning a ref with a path shorter than the route path results in incomplete response. E.g.

const BaseRouter = Router.createClass([{
    route: 'people[{keys}].name',
    get([_, ids]: [string, string[]]) {
      return ids.map((id) => {
        if (/^!/.test(id)) {
          return {
            path: ['people', id],
            value: { $type: 'ref', value: ['vip', id] }
          }
        }

        return {
          path: ['people', id],
          value: 'some name'
        }
      })
    }
  }, {
    route: 'vip[{keys}].name',
    get([_, ids]: [string, string[]]) {
      return ids.map((id) => ({
        path: ['vip', id, 'name'],
        value: 'special person name'
      }))
    }
}])
// GET ?method=get&paths=[["people", "abc", "name"]]
{
    "jsonGraph": {
        "people": {
            "abc": "some name"
        }
    }
}

// GET ?method=get&paths=[["people", "!abc", "name"]]
{
    "jsonGraph": {
        "people": {
            "!abc": {
                "$type": "ref",
                "value": [
                    "vip",
                    "!abc"
                ]
            }
        },
        "vip": {
            "!abc": {
                "name": {
                    "$type": "atom"
                }
            }
        }
    }
}

In the above case, when matching on ['people', ids, 'name'] but returning a ref from ['people', id] to ['vip', id], the router does not follow up with a call for ['vip', id, 'name']. This is a trivial example, but the general use case of being able to say X is actually Y when asking for a property on X is quite useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant