edgedb / edgedb-js

The official TypeScript/JS client library and query builder for EdgeDB
https://edgedb.com
Apache License 2.0
514 stars 65 forks source link

Link properties in backlink. #399

Open izakfilmalter opened 2 years ago

izakfilmalter commented 2 years ago

Right now you can't get link properties from a backlink. This means you can't filter the backlink, or grab data from that edge. I am not sure if this an actual limitation of EdgeDB, or just a limitation of the library.

image

This leads to querres that look like this:

e.select(e.User, (x) => ({
  filter: e.op(x.id, '=', e.uuid(userId)),
  friends: (y) => ({
    filter: e.op(
      e.op(y['@status'], '=', e.Status.accepted),
      'and',
      e.op('exists', y.name),
    ),
  }),
  receivedFriends: e.select(x['<friends[is User]'], (y) => ({
    friends: (z) => ({
      filter: e.op(z.id, '=', e.uuid(userId)),
      '@status': true,
    }),
  })),
}))

You then have to filter this on the client side.

colinhacks commented 2 years ago

This is a tricky one. It's a limitation of EdgeQL currently, and I can't find a simpler workaround than the one you're currently using. I suspect you'd have an easier time using an intermediate table to represent friendships - link properties can be fiddly and they're subject to certain limitations (e.g. can't be required). I'll starting thinking about an API to make this better at the query builder level.

jaclarke commented 2 years ago

It's a limitation of EdgeQL currently

I thought linkprops on backlinks got fixed (https://github.com/edgedb/edgedb/pull/3841), or does this not work with how the qb generates queries?

izakfilmalter commented 2 years ago

Ya I have been thinking about dumping the ink properties because they aren't as real as other properties. I really like the idea of storing data on an edge and not having to deal with another id.