Hey, I have a table that has a unique field on 2 columns provider_item and user so I can query in my where based on those 2 columns and not the id as I don't have it. When I try to get a row from that table through those 2 columns I get an error in prisma
ValueTypeMismatchError { have: Int(1), want: Object((Weak)) }
Create the following schema:
// schema.prisma
model User {
id Int @id @default(autoincrement())
name String
email String @unique
username String @unique
passwordHash String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
deletedAt DateTime?
}
model ProviderItem {
id Int @id @default(autoincrement())
data String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model ProviderItemAttribute {
id Int @id @default(autoincrement())
provider_item ProviderItem @relation(references: [id])
user User @relation(references: [id])
data String
@@unique([provider_item, user])
}
Add the following nexus schema
import { objectType, extendType, intArg } from "nexus";
import { getLoggedInAuth } from "../utils/authUtils";
export const ProviderItemAttribute = objectType({
name: "ProviderItemAttribute",
definition(t) {
t.model.id();
t.model.user();
t.field("parsedData", {
type: "ProviderItemAttributeData",
resolve: root => {
return JSON.parse(root.data || "{}");
},
});
},
});
export const GetProviderItemAttribute = extendType({
type: "Query",
definition(t) {
t.field("getProviderItemAttribute", {
type: "ProviderItemAttribute",
args: {
provider_item_id: intArg({ nullable: false }),
},
nullable: true,
async resolve(root, { provider_item_id }, ctx) {
const { user } = getLoggedInAuth(ctx);
return await ctx.prisma.providerItemAttribute.findOne({
where: {
provider_item_user: {
provider_item: provider_item_id,
user: user.id,
},
},
});
},
});
},
});
Run the following query in your graphql playground
query GetProviderItemAttribute {
getProviderItemAttribute(provider_item_id: 1, user_id: 1) {
id
}
}
And this is the error you get.
2020-03-23T00:38:04.511Z engine stdout {
timestamp: 'Mar 23 00:38:04.511',
2020-03-23T00:38:04.526Z prisma-client Prisma Client call:
2020-03-23T00:38:04.527Z prisma-client prisma.providerItemAttribute.findOne({
provider_item_user: {
provider_item: 1,
user: 1
2020-03-23T00:38:04.527Z prisma-client Generated request:
2020-03-23T00:38:04.527Z prisma-client query {
findOneProviderItemAttribute(where: {
provider_item: 1
data
2020-03-23T00:38:04.529Z engine stdout {
timestamp: 'Mar 23 00:38:04.529',
2020-03-23T00:38:04.530Z engine {
error: Error: Error in query graph construction: QueryParserError(ObjectValidationError { object_name: "Query", inner: FieldValidationError { field_name: "findManyProviderItemAttribute", inner: ArgumentValidationError { argument: "where", inner: ObjectValidationError { object_name: "ProviderItemAttributeWhereInput", inner: FieldValidationError { field_name: "AND", inner: ObjectValidationError { object_name: "ProviderItemAttributeWhereInput", inner: FieldValidationError { field_name: "provider_item", inner: ValueTypeMismatchError { have: Int(1), want: Object((Weak)) } } } } } } } })
at /srv/graphql-server/node_modules/@prisma/client/runtime/index.js:1:16461
at processTicksAndRejections (internal/process/task_queues.js:97:5)
2020-03-23T00:38:04.530Z printStack callsite Error
at Object.s [as ProviderItemAttribute] (/srv/graphql-server/node_modules/@prisma/client/runtime/index.js:1:44641)
at Object.n.<computed> [as findOne] (/srv/graphql-server/node_modules/@prisma/client/runtime/index.js:1:46267)
at /srv/graphql-server/src/schema/ProviderItemAttribute.ts:31:55
at step (/srv/graphql-server/dist/schema/ProviderItemAttribute.js:33:23)
at Object.next (/srv/graphql-server/dist/schema/ProviderItemAttribute.js:14:53)
at /srv/graphql-server/dist/schema/ProviderItemAttribute.js:8:71
at new Promise (<anonymous>)
at __awaiter (/srv/graphql-server/dist/schema/ProviderItemAttribute.js:4:12)
at resolve (/srv/graphql-server/dist/schema/ProviderItemAttribute.js:65:24)
at field.resolve (/srv/graphql-server/node_modules/graphql-extensions/src/index.ts:155:61)
This is my DB in postgres:

It should return the providerItemAttribute based on those 2 columns.
Development machine using docker image.
[email protected], binary version: 377df4fe30aa992f13f1ba152cf83d5770bdbc85v10.13.0I'm able to go around this issue by using a raw query instead.
const data = await prisma.raw(
`SELECT * FROM "ProviderItemAttribute" WHERE "provider_item" = ${root.id} AND "user" = ${auth.user.id} limit 1;`,
);
return data[0];
or
const data = await prisma.providerItemAttribute.findMany({
where: {
provider_item: {
id: root.id,
},
user: {
id: auth.user.id,
},
},
first: 1,
});
return data[0];
This works so definitely seems like a bug with the client api.
@emroot
Can you please make sure that you have pasted the correct schema here?
I am getting validation errors when trying to reproduce this error:

@pantharshit00 updated. I nuked the @@unique for that model as it's not relevant.
closing this as it's been fixed with the beta release.