Skip to content
This repository has been archived by the owner on Jan 14, 2021. It is now read-only.

Possibly wrong type generation for after argument in findMany method (Postgres) #241

Closed
sdnts opened this issue Oct 1, 2019 · 2 comments
Assignees
Labels
kind/discussion Discussion is required.
Milestone

Comments

@sdnts
Copy link
Contributor

sdnts commented Oct 1, 2019

Steps to reproduce:

  1. Create a new Blank P2 project with Postgres. Change the schema to have one model with an integer ID. I used this:
generator photon {
  provider = "photonjs"
}

datasource db {
  provider = "postgresql"
  url      = "postgresql://siddhant@localhost/experiments?schema=public"
}

model User {
  id   Int     @id
  name String?
}
  1. Add a couple of users to this DB:
import { Photon } from "@generated/photon";
const photon = new Photon();

async function main() {
  await photon.connect()

  await photon.users.create({
    data: {
      name: 'U1'
    },
  })
  await photon.users.create({
    data: {
      name: 'U2'
    },
  })

  await photon.disconnect()
}

main()
  1. My aim is to get the second user only, so I run this script:
const secondUser = await photon.users.findMany({
  after: 1
});

This does not compile, because the type of the after argument is supposed to be string (which should be number IMO), and so if I change the 1 to a "1" like so:

const secondUser = await photon.users.findMany({
  after: "1"
});

I get a connector error that says:

Reason: Error in connector: Error querying the database: error serializing parameter 0: cannot convert to or from a Postgres value of type `int4`

which is expected I think.

SQLite breaks with after: 1, but works just fine with after: "1"

I'd assume this would also break with other types of IDs that aren't strings (floats etc.)

@divyenduz
Copy link

divyenduz commented Oct 1, 2019

If the ID of the model is Int then after should be an Int too, but that ID can also be of some other type (like UUID).

There was a discussion around this a while ago somewhere, trying to dig that up.

This is the (most likely) legacy reason for it to be a string: https://facebook.github.io/relay/graphql/connections.htm#sec-Cursor

Relay spec says that a cursor should be serializable to a string. Ideally, it should match the type of the underlying model, we we need to map it out further.

@sdnts sdnts added the process/candidate Candidate for next Milestone. label Oct 14, 2019
@mavilein mavilein self-assigned this Oct 14, 2019
@mavilein mavilein added this to the Preview 15 milestone Oct 14, 2019
@mavilein
Copy link

fixed with: prisma/prisma-engines@332b3ba

The fix will be available on alpha in a few minutes.

@janpio janpio removed the process/candidate Candidate for next Milestone. label Oct 23, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/discussion Discussion is required.
Projects
None yet
Development

No branches or pull requests

4 participants