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

nested exists where does not work without id field #275

Open
leetmachine opened this issue Dec 5, 2018 · 6 comments
Open

nested exists where does not work without id field #275

leetmachine opened this issue Dec 5, 2018 · 6 comments

Comments

@leetmachine
Copy link

The exists does not work when using a nested where unless the id field is set on the type.

I have the schema:

User {
id: ID! 
email: String!
}

Company {
id: ID!
}

Employee {
user: User!
company: Company!
role: String!
}

When I tried to use exists on Employee I received a TypeError: "cannot read property 'length' of undefined' at Prisma.ts:79:31

example exists:
prisma.exists.Employee({ user: { email: '[email protected]'}});

I updated Employee in my Primsa datamodel to include id: ID! and then it was successful (even though I did not change my initial query to use/not use the id.

hopes this helps others!

@maticzav
Copy link
Collaborator

maticzav commented Dec 5, 2018

Hey @leetmachine 👋,

Thank you for reporting this! It would be super helpful if you could provide a small reproduction example - Github repository or CodeSandbox, whichever works best for you. 🙂

@leosuncin
Copy link

I have the same issue and created a repository with the code necessary to reproduce the issue https://github.com/leosuncin/prisma-binding_exists-bug

More specific the issues is raised here https://github.com/leosuncin/prisma-binding_exists-bug/blob/1dd9e9bfd0937c9c4297834a02f33e1ac0c9b4f5/resolvers/query.js#L2-L9

Moreover, I believe that all this issues #275 #252 #215 are related

@maticzav
Copy link
Collaborator

Hey @leosuncin 👋,

Thank you for the reproduction! Could you try adding id: ID! field to your datamodel?

type User {
  id: ID! # here
  email: String! @unique
  name: String!
  password: String! @private
  bio: String
  roles: [Roles!]!
}

I believe this should solve your problem because exists relies on the ID field. You can see that in the source link below.

https://github.com/prisma/prisma-binding/blob/62179c823a1a909c712fc0dbb143ec91d35677f3/src/info.ts#L29

@leosuncin
Copy link

I added functional tests to my repository, also I add id: ID! @unique to datamodel but in other branch and it works, although it should works in both case because Prisma creates by itself the id or that what I tough.

PS: If someone knows a better way to run tests with Prisma, I'm all ears.

@maticzav
Copy link
Collaborator

@leosuncin I agree, however, to my understanding your datamodel doesn't only shape the fields in your database but also portrays the exposed fields. Considering this, not having an id field effectively means hiding it in your data model.

@leosuncin
Copy link

@maticzav sometimes that's the desire behavior hide a big and not human friendly id with a slug or username for instance

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

3 participants