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

Correctly handle NativeQueries in Relationships #27

Merged
merged 2 commits into from
Nov 27, 2024
Merged

Conversation

codedmart
Copy link
Contributor

I am not a jooq expert, but this works from my tests. Current problem is you can not use Native Queries in relationships and/or predicates. This fixes by finding all NativeQueries and generating CTE's if there are any.

query MyQuery {
  profileInfos(where: {profileInfoUrls: {rowId: {_eq: 71}}}) {
    name
    id
    profileInfoUrls {
      url
      rowId
      tableId
    }
  }
}
with
  "ProfileInfoUrls" as (
    select * from urls where tableId = 7
  )
select json_arrayagg(json_object(key 'rows' value (
  select json_arrayagg(json_object(
    key 'name' value "name",
    key 'id' value "id",
    key 'profileInfoUrls' value coalesce(
      (
        select json_object(key 'rows' value (
          select json_arrayagg(json_object(
            key 'url' value "url",
            key 'rowId' value "rowId",
            key 'tableId' value "tableId"
          ))
          from (
            select "ProfileInfoUrls".*
            from "ProfileInfoUrls"
            where "profileInfos"."id" = "ProfileInfoUrls"."rowId"
          ) "ProfileInfoUrls"
        ))
      ),
      json_object(key 'rows' value json_array())
    )
  ))
  from (
    select "A.profileInfos".*
    from "A.profileInfos"
    where exists (
      select 1 "one"
      from "ProfileInfoUrls"
      where (
        "ProfileInfoUrls"."rowId" = 71
        and "A"."profileInfos"."id" = "ProfileInfoUrls"."rowId"
      )
    )
  ) "profileInfos"
)))

Copy link
Collaborator

@gneeri gneeri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of the questions are cosmetic, but there is a substantive question concerning withStep

@codedmart codedmart merged commit dd079eb into main Nov 27, 2024
@codedmart codedmart deleted the codedmart/ctes-nq branch November 27, 2024 20:46
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

Successfully merging this pull request may close these issues.

2 participants