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

Empty e.params generate an invalid query #1024

Open
scotttrinh opened this issue May 17, 2024 · 1 comment
Open

Empty e.params generate an invalid query #1024

scotttrinh opened this issue May 17, 2024 · 1 comment

Comments

@scotttrinh
Copy link
Collaborator

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.

@nikitavoloboev
Copy link

nikitavoloboev commented May 17, 2024

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.

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

2 participants