edgedb / edgedb-js

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

Unable to query link properties from a backlink #428

Open mrmntte opened 2 years ago

mrmntte commented 2 years ago

Code The code causing the error.

        e.select(e.User, user => ({
          id: true,
          following: e.select(user['<_followers'].is(e.Group), group => {
            return {
              name: group._name,
              note: group['@_note'], // 🚨 throws "Cannot read properties of undefined (reading '__kind__')"
              // '@_note': true, // 🚨 throws "cannot select link property '@_note' on an object (default::Group)"
            }
          }),
        }))

Schema

  type User {
    required property _email -> str {
      constraint exclusive;
    }
  }

  type Group {
    required property _name -> str {
      constraint exclusive;
    }
    multi link _followers -> User {
      property _note -> str;
      property _followedAt -> datetime {
        default := datetime_current();
      };
    }
  }

Generated EdgeQL The query cannot be generated with the link properties, but WITHOUT them the result of .toEdgeQL is:

WITH
  __scope_0_User := DETACHED default::User
SELECT __scope_0_User {
  id,
  multi following := (
    WITH
      __scope_1_Group := __scope_0_User.<_followers[IS default::Group]
    SELECT __scope_1_Group {
      single name := __scope_1_Group._name
    }
  )
}

Desired behavior

Get the same results as this query.

select User { id, followers := .<_followers[is Group] { name := ._name, note := @_note } }

Versions:

izakfilmalter commented 2 years ago

Have the same issue. Would love to see this resolved.