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

Problems with knex using postgres driver #20

Open
jtiala opened this issue Aug 16, 2019 · 3 comments
Open

Problems with knex using postgres driver #20

jtiala opened this issue Aug 16, 2019 · 3 comments

Comments

@jtiala
Copy link
Contributor

jtiala commented Aug 16, 2019

I encountered some problems while trying to use this library with apollo-server setup using PostgreSQL as database and knex. My setup doesn't use objection ORM, it just calls knex queries straight from the resolver.

I forked the library and added posgres driver to isolate the issue from my setup. I created a new table, cities, since my initial problem was concerning a calculated column, which shows distance between coordinates in the database compared to coordinates in the query.

Most of the added code is here. The file contains detailed comments on the problem. I also added notes to the readme on how to run dockerized posgres to test this on. By the way, this can not be tested on sqlite since it doesn't have the necessary math functions to calculate distances.

I encountered two problems.

  1. .groupBy('id') is needed when selecting the columns using .select(). Even though the exact same query is generated with .select(['*']) and omitting the select altogether. When driving the sqlite driver, this problem doesn't occur. See implementation2 in the file linked before.
  2. When adding the custom column to the select array, it works fine when using only first pagination parameter. The column appears in the results and results can be sorted based on the calculated column. Using anything else than first breaks the query. See implementation3.

Any idea what might be causing this?

If you would like to include the test cases in the repo, I can clean them up and do a PR. There are no tests tho, didn't have time to setup postgres tests. I also added some general notes on the readme, feel free to copy them if you feel so :)

@jtiala
Copy link
Contributor Author

jtiala commented Aug 16, 2019

Another example here, playground available here, try this query:

query {
  restaurants(
    first: 10
    lat: 65.012643
    lng: 25.471445
    orderBy: "distance"
    orderDirection: asc
  ) {
    totalCount
    edges {
      cursor
      node {
        id
        distance
      }
    }
  }
}

Change first to last and it goes boom.

steerio added a commit to steerio/apollo-cursor-pagination that referenced this issue Dec 24, 2019
@sammarks
Copy link
Contributor

sammarks commented Sep 7, 2020

@jtiala I've submitted a few PRs that might fix the issues you mentioned above since these issues were first created. Do you have time to try the latest version of the library and see if that fixes your problems?

@jtiala
Copy link
Contributor Author

jtiala commented Sep 8, 2020

Thanks! I'll try to find some time on the weekend to test this out.

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