我被迷惑了。我最初创建了用户查询,它给了我我认为是语法错误的错误。但后来我为完美运行的车辆创建了一个相同的查询。我怀疑它与ID有关!类型,但我已经用完了线索。任何帮助,将不胜感激!
这是我的 typedef 和解析器。
//类型定义//
type User {
id: ID!
fname: String
lname: String
email: String
password: String
vehicles: [Vehicle]
}
type Vehicle {
id: ID!
vin: String
model: String
make: String
drivers: [User]
}
type Query {
users: [User]
user(id: ID!): User
vehicles: [Vehicle]
vehicle(vin: String): Vehicle
}
//解析器//
user: async (parent, args, context) => {
const { id } = args
return context.prisma.user.findUnique({
where: {
id,
},
})
},
vehicle: async (parent, args, context) => {
const { vin } = args
return context.prisma.vehicle.findUnique({
where: {
vin,
}
})
}
//查询//
**这个是坏的,有错误:在 prisma.findOneUser 上得到无效值 '1'。提供的字符串,预期的 Int **我已经尝试过id: "1"
并且user(where: {id: 1})
query {
user(id:1){
id
fname
}
}
**这个按预期工作
query {
vehicle(vin:"123123123"){
vin
make
}
}
//完全错误*//
{
"errors": [
{
"message": "\nInvalid `prisma.user.findUnique()` invocation:\n\n{\n where: {\n id: '1'\n ~~~\n }\n}\n\nArgument id: Got invalid value '1' on prisma.findOneUser. Provided String, expected Int.\n\n",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"user"
],
"extensions": {
"code": "INTERNAL_SERVER_ERROR",
"exception": {
"clientVersion": "2.13.1",
"stacktrace": [
"Error: ",
"Invalid `prisma.user.findUnique()` invocation:",
"",
"{",
" where: {",
" id: '1'",
" ~~~",
" }",
"}",
"",
"Argument id: Got invalid value '1' on prisma.findOneUser. Provided String, expected Int.",
"",
"",
" at Document.validate (/home/atran/workspace/m4m/m4m_server/node_modules/@prisma/client/runtime/index.js:76090:19)",
" at NewPrismaClient._executeRequest (/home/atran/workspace/m4m/m4m_server/node_modules/@prisma/client/runtime/index.js:77796:17)",
" at resource.runInAsyncScope (/home/atran/workspace/m4m/m4m_server/node_modules/@prisma/client/runtime/index.js:77733:52)",
" at AsyncResource.runInAsyncScope (async_hooks.js:188:21)",
" at NewPrismaClient._request (/home/atran/workspace/m4m/m4m_server/node_modules/@prisma/client/runtime/index.js:77733:25)",
" at Object.then (/home/atran/workspace/m4m/m4m_server/node_modules/@prisma/client/runtime/index.js:77850:39)",
" at process._tickCallback (internal/process/next_tick.js:68:7)"
]
}
}
}
],
"data": {
"user": null
}
}