Here's what the bug is, and how you can reproduce the same!
As per Order by Related Fields issue, users yet cannot sort postsConnection by orderBy: upvotes_DESC when this is the schema ๐
type Post {
id: ID!
...
upvotes: [Upvote]!
...
}
So, I created upvotesNumber field which accepts an Int. Every time I mutate an upvote from backend, I increment or decrement the field.
But to sort postsConnection by upvotesNumber, the orderBy introduces a severe bug.
query {
postsConnection (
orderBy: upvotesNumber_DESC,
first: 1
) {
edges {
node {
id
title
createdAt
upvotesNumber
}
}
pageInfo {
endCursor
}
}
}
Suppose I have 3 posts. 1st post has 2 upvotes, i.e upvotesNumber: 2, 2nd post has 1 upvote, and the third post has 0 upvotes.
In this case, I get the correct postsConnection order and all three posts are fetched using the after argument.
But, if two or more than two posts have the same upvotesNumber value, then those posts won't render in postsConnection!
Consider, 1st post has 1 upvote, 2nd post also has 1 upvote, third has none...
then the same query will return return 1st and 3rd post but will skip the 2nd even if I use the correct after value that endCursor gives.
Same happens when 2nd and 3rd posts have 0 upvotes and 1st post has 1. Then, the query will return 1st and 2nd post, but would skip the three.
Expected behavior
I expect it to render all posts correctly just as it renders when I order it by createdAt_DESC.
createdAt_DESC works very well. I want to sort the posts by upvotesNumber even if they are the same!
Versions (please complete the following information):
v1.26.0prisma CLI: prisma/1.26.4 (darwin-x64) node-v11.4.0OSX Mojaveprisma-client, prisma-binding, etc.Additional context
This makes me unable to use Prisma. I'm a novice. This might be the way how Prisma works or I might be doing it wrong. Please help ๐
Resources I read before posting this bug report
Order by Multiple Fields
Order by Related Fields
Load More on Upvote bug
I was unable to reproduce this with 1.31. The cursor is not skipping values.
Can you please tell me which connector are you using?
I am using the postgres connector.
Thanks for reply, I am using mysql connector.
My docker compose file ๐
version: '3'
services:
prisma:
image: prismagraphql/prisma:1.26
restart: always
ports:
- "4466:4466"
environment:
PRISMA_CONFIG: |
port: 4466
# uncomment the next line and provide the env var PRISMA_MANAGEMENT_API_SECRET=my-secret to activate cluster security
# managementApiSecret: my-secret
databases:
default:
connector: mysql
host: mysql
user: root
password: prisma
rawAccess: true
port: 3306
migrations: true
mysql:
image: mysql:5.7
restart: always
environment:
MYSQL_ROOT_PASSWORD: prisma
volumes:
- mysql:/var/lib/mysql
volumes:
mysql:
@KumarAbhirup
I was using the latest version 1.31, maybe try that.
okay, sorry to be silly, but any guide on how do I update the docker container?
Since you will also need to upgrade to the new datamodel if you upgrade to 1.31, refer to this video: https://www.youtube.com/watch?v=48m1Gnmu19Q
Thanks bro ๐ will soon give an update on whether the bug persists. :-)
Neat ๐ upgrading to 1.31 fixes the issue โ