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

prisma.exists throws an error #252

Closed
guatedude2 opened this issue Nov 14, 2018 · 2 comments
Closed

prisma.exists throws an error #252

guatedude2 opened this issue Nov 14, 2018 · 2 comments

Comments

@guatedude2
Copy link

Describe the bug
When calling prisma.exists on a type which is using "key" as the ID, prisma throws an Error.

To Reproduce
Steps to reproduce the behavior:

  1. Create a type in the datamodel.graphql
type I18String {
  key: ID!
  string: String!
  language: Language!
}
  1. Deploy and generate bindings
  2. Call prisma.exists.I18String({ key: "123" })
  3. See error
TypeError: Cannot read property 'length' of undefined
   at /Users/guatedude2/my-api/node_modules/prisma-binding/src/Prisma.ts:79:30

Expected behavior
Returns true or false

Versions (please complete the following information):

  • OS: OS X Mohave
  • prisma CLI: prisma/1.20.0 (darwin-x64) node-v10.4.0
  • Prisma Server: 1.20.0
  • prisma-binding, apollo-server, ts-node, typescript

Additional context

Doing my own investigation, seems like the issue is inside info.ts where buildExistsInfo, returns only a selection on id, which is hard-coded rather than what the model considers a primary key. In the case of I18String key is the ID but there is no unique primary key so it returns undefined and undefined.length throws the error.

I chose key as a non unique key because the key exists for each language (unique key + language) and I don't want prisma generating the id for me. So, I use key as the unique identifier where I set it to a human readable string e.g. "my-unique-key".

@schickling schickling transferred this issue from prisma/prisma1 Nov 17, 2018
@maticzav
Copy link
Collaborator

Hey @guatedude2 👋,

I believe this is hardcoded in light of the current Prisma ID! implementation. Check out the following piece of documentation https://www.prisma.io/docs/data-model-and-migrations/data-model-knul/#id.

An ID value is a generated unique 25-character string based on cuid. Fields with ID values are system fields and just used internally, therefore it is not possible to create new fields with the ID type.

I hope this helps 🙂

@maticzav
Copy link
Collaborator

Closing in favour of #275

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