edgedb-js icon indicating copy to clipboard operation
edgedb-js copied to clipboard

Empty `e.params` generate an invalid query

Open scotttrinh opened this issue 1 year ago • 1 comments

Code The code causing the error.

export const homePublic = e.params({}, () => {
    return e.select({
        popularDishes: e.assert_exists(e.assert_single(e.select(
            e.GlobalState,
            () => ({
                popularDishes: true,
                limit: 1
            }),
        ))),
        posts: e.select(e.Post, () => ({
            imageUrl: true,
            roninId: true,
            imageWidth: true,
            imageHeight: true,
            imagePreviewBase64Hash: true,
        })),
    })
})
export type homePublicReturn = $infer<typeof homePublic>

Generated EdgeQL

Run the .toEdgeQL() method on your query and print the result. Then copy the generated query here.

WITH

SELECT (SELECT {
  single popularDishes := (
    std::assert_exists(std::assert_single((WITH
      __scope_0_defaultGlobalState := DETACHED default::GlobalState
    SELECT __scope_0_defaultGlobalState {
      popularDishes
    }
    LIMIT 1)))
  ),
  multi posts := (
    WITH
      __scope_1_defaultPost := DETACHED default::Post
    SELECT __scope_1_defaultPost {
      imageUrl,
      roninId,
      imageWidth,
      imageHeight,
      imagePreviewBase64Hash
    }
  )
}) public data
 GET / 200 in 95ms
 ⚠ Fast Refresh had to perform a full reload due to a runtime error.
 GET /favicon.ico 200 in 15ms
WITH

SELECT (SELECT {
  single popularDishes := (
    std::assert_exists(std::assert_single((WITH
      __scope_0_defaultGlobalState := DETACHED default::GlobalState
    SELECT __scope_0_defaultGlobalState {
      popularDishes
    }
    LIMIT 1)))
  ),
  multi posts := (
    WITH
      __scope_1_defaultPost := DETACHED default::Post
    SELECT __scope_1_defaultPost {
      imageUrl,
      roninId,
      imageWidth,
      imageHeight,
      imagePreviewBase64Hash
    }
  )
})

Notice the empty with.


We should either not allow constructing an empty params object, or detect this case and ignore the params.

scotttrinh avatar May 17 '24 16:05 scotttrinh

I would prefer if solution was detect this case and ignore the params. I would like to make all my queries look nearly identical. I often copy one query and just change the content inside, it's easy for me to just remove the params and not have to unwrap it too.

Assuming there is no perf impact.

nikivdev avatar May 17 '24 16:05 nikivdev