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

query builder: variables are generated in the wrong scope #925

Open mrmntte opened 6 months ago

mrmntte commented 6 months ago

Code The code causing the error.

      const listQuery = e.select(e.User, () => ({
        limit: 10, // ⚠️ without this the query is generated correctly
      }))
      const resolverQuery = e.with([listQuery], e.select({
        edges: e.select(listQuery, (scope) => ({
          cursor: scope.id,
          node: e.select(scope, {
            id: true,
            handle: true
          })
        }))
      }))

Generated EdgeQL

WITH
  __withVar_3 := (
    WITH
      __scope_2_defaultUser := DETACHED default::User
    SELECT __scope_2_defaultUser {
      id
    }
    LIMIT __withVar_4
  )
SELECT {
  multi edges := (
    WITH
      __withVar_4 := 10,
      __scope_0_defaultUser := __withVar_3
    SELECT __scope_0_defaultUser {
      single cursor := __scope_0_defaultUser.id,
      single node := (
        WITH
          __scope_1_defaultUser := __scope_0_defaultUser
        SELECT __scope_1_defaultUser {
          id,
          handle
        }
      )
    }
  )
}

*Error:

InvalidReferenceError: object type or alias 'default::__withVar_4' does not exist
" 8 |     LIMIT __withVar_4",
 "  |           ^^^^^^^^^^^",

Versions:

awerlogus commented 6 months ago

Duplicate of https://github.com/edgedb/edgedb-js/issues/808