FleekHQ / apollo-cursor-pagination

Relay's Connection implementation for Apollo Server GraphQL library
MIT License
61 stars 12 forks source link

missing FROM-clause entry for table: `last` arg replaces table with `last_subquery` #54

Open socialwyze-franklin opened 3 years ago

socialwyze-franklin commented 3 years ago

Offending line

I have an Objection QueryBuilder that produces the following SQL:

SELECT
    my_table.*
FROM
    my_table
    INNER JOIN other_table1 ON 1=1
    INNER JOIN other_table2 ON 1=1
WHERE
    other_table2.thing = ?

cursorPagination produces this SQL which results in Postgres returning the error missing FROM-clause entry for table "my_table"

SELECT
    * 
FROM
    (
    SELECT
        my_table.*,
    FROM
        my_table
      INNER JOIN other_table1 ON 1=1
    INNER JOIN other_table2 ON 1=1
  WHERE
      other_table2.thing = ?
    ORDER BY
        "id" DESC,
        "id" DESC 
        LIMIT $2 
    ) AS "last_subquery"
    INNER JOIN other_table1 ON 1=1
    INNER JOIN other_table2 ON 1=1
ORDER BY
    "id" ASC,
    "id" ASC