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

RelationFilter ambiguity #9889

Closed
terion-name opened this issue Oct 21, 2021 · 3 comments
Closed

RelationFilter ambiguity #9889

terion-name opened this issue Oct 21, 2021 · 3 comments
Labels
kind/bug A reported bug.

Comments

@terion-name
Copy link

terion-name commented Oct 21, 2021

Bug description

Given query:

const surveys = (await ctx.prisma.response.findMany({
        where: {user: {id: {equals: ctx.user.id}}},
        distinct: "surveyId"
    }))

Errors like this:

Invalid `prisma.response.findMany()` invocation:
[
  {
    message: '\n' +
      'Invalid `prisma.response.findMany()` invocation:\n' +
      '\n' +
      '{\n' +
      '  where: {\n' +
      '    user: {\n' +
      '      id: {\n' +
      '      ~~\n' +
      '        equals: 1\n' +
      '      }\n' +
      '    }\n' +
      '  },\n' +
      "  distinct: 'surveyId'\n" +
      '}\n' +
      '\n' +
      'Unknown arg `id` in where.user.id for type UsersUserRelationFilter. Did you mean `is`? Available args:\n' +
      'type UsersUserRelationFilter {\n' +
      '  is?: UsersUserWhereInput | Null\n' +
      '  isNot?: UsersUserWhereInput | Null\n' +
      '}\n' +
      '\n',
    locations: [ [Object] ],
    path: [ 'me' ],
    extensions: { code: 'INTERNAL_SERVER_ERROR', exception: [Object] }
  }
]

Ok, changing query as it says, using UsersUserRelationFilter:

const surveys = (await ctx.prisma.response.findMany({
        where: {user: {is: {id: {equals: ctx.user.id}}}},
        distinct: "surveyId"
    }))

Now it errors like this and says that first variant should be correct:

Invalid `prisma.response.findMany()` invocation:
[
  {
    message: '\n' +
      'Invalid `prisma.response.findMany()` invocation:\n' +
      '\n' +
      '{\n' +
      '  where: {\n' +
      '    user: {\n' +
      '      is: {\n' +
      '      ~~\n' +
      '        id: {\n' +
      '          equals: 1\n' +
      '        }\n' +
      '      }\n' +
      '    }\n' +
      '  },\n' +
      "  distinct: 'surveyId'\n" +
      '}\n' +
      '\n' +
      'Unknown arg `is` in where.user.is for type UsersUserWhereInput. Did you mean `id`? Available args:\n' +
      'type UsersUserWhereInput {\n' +
      '  AND?: UsersUserWhereInput | List<UsersUserWhereInput>\n' +
      '  OR?: List<UsersUserWhereInput>\n' +
      '  NOT?: UsersUserWhereInput | List<UsersUserWhereInput>\n' +
      '  id?: StringFilter | String\n' +
      '  entityId?: StringFilter | String\n' +
      '  createdAt?: DateTimeFilter | DateTime\n' +
      '  updatedAt?: DateTimeFilter | DateTime\n' +
      '  comments?: CommentListRelationFilter\n' +
      '  likes?: LikeListRelationFilter\n' +
      '  responses?: ResponseListRelationFilter\n' +
      '}\n' +
      '\n',
    locations: [ [Object] ],
    path: [ 'me' ],
    extensions: { code: 'INTERNAL_SERVER_ERROR', exception: [Object] }
  }
]

Sooo.. how?

Yes, in this concrete case I can use simply userId, but in any case relation filter should work

How to reproduce

Use models provided below and run queries provided above

Expected behavior

Either variant works

Prisma information

model Response {
  id String @id @default(cuid())
  createdAt DateTime   @default(now())
  updatedAt DateTime    @updatedAt
  user UsersUser?      @relation(name: "ResponseToUsersUser", fields: [userId], references: [id])
  survey Survey?      @relation(name: "SurveyResponse", fields: [surveyId], references: [id])
  text String?
  questionId String?
  surveyId String?
  variantId String?
  userId String?
}

model UsersUser {
  id String  @unique
  entityId String @id @default(cuid())
  createdAt DateTime   @default(now())
  updatedAt DateTime    @updatedAt
  responses Response[]     @relation(name: "ResponseToUsersUser")
}

# not relevant
model Survey {
  id String @id @default(cuid())    
}

Environment & setup

  • OS: Mac OS
  • Database: MySQL
  • Node.js version: v14.13.1

Prisma Version

3.3.0
@terion-name terion-name added the kind/bug A reported bug. label Oct 21, 2021
@terion-name
Copy link
Author

Ok, figured out that:

  1. Correct variant is where: {user: {id: {equals: ctx.user.id}}}
  2. These strange errors where spawned because of type mismatch: user id should be a string, but I've passed an int. So the problem is in error handling department

@janpio
Copy link
Member

janpio commented Nov 4, 2021

Hey @terion-name, great you figure it out. Can you maybe just open a new issue about the bad error message? Then our developers do not have to understand the first issue description here but can directly see what the problem is. Thanks. (Afterwards you can just close this issue.)

@terion-name
Copy link
Author

@janpio got it: #10117

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug A reported bug.
Projects
None yet
Development

No branches or pull requests

2 participants