我有以下schema.prisma
文件:
model Account {
id Int @default(autoincrement()) @id
name String
transactions Transaction[]
}
model Transaction {
id Int @default(autoincrement()) @id
accountId Int
account Account @relation(fields: [accountId], references: [id])
}
我可以执行
npx prisma migrate save --experimental
npx prisma migrate up --experimental --verbose
npx prisma generate
没有错误,数据库看起来还可以(此屏幕截图还包含货币,但对这个问题没有影响)。
但是当我执行时ApolloServer
使用nexusPrismaPlugin
我有错误:
Using ts-node version 8.9.0, typescript version 3.8.3
Error: Input Object type TransactionCreateWithoutAccountInput must define one or more fields.
at assertValidSchema (/home/daniel/pro/cash/core/node_modules/graphql/type/validate.js:71:11)
at assertValidExecutionArguments (/home/daniel/pro/cash/core/node_modules/graphql/execution/execute.js:136:35)
at executeImpl (/home/daniel/pro/cash/core/node_modules/graphql/execution/execute.js:86:3)
at Object.execute (/home/daniel/pro/cash/core/node_modules/graphql/execution/execute.js:64:63)
at Object.generateSchemaHash (/home/daniel/pro/cash/core/node_modules/apollo-server-core/src/utils/schemaHash.ts:11:18)
at ApolloServer.generateSchemaDerivedData (/home/daniel/pro/cash/core/node_modules/apollo-server-core/src/ApolloServer.ts:541:24)
at new ApolloServerBase (/home/daniel/pro/cash/core/node_modules/apollo-server-core/src/ApolloServer.ts:400:32)
at new ApolloServer (/home/daniel/pro/cash/core/node_modules/apollo-server-express/src/ApolloServer.ts:88:5)
at new ApolloServer (/home/daniel/pro/cash/core/node_modules/apollo-server/src/index.ts:36:5)
at Object.<anonymous> (/home/daniel/pro/cash/core/src/server.ts:5:1)
[ERROR] 01:01:32 Error: Input Object type TransactionCreateWithoutAccountInput must define one or more fields.
我的代码不包含任何与事务相关的内容。如果我删除Transaction
一切都很好。
在生成的代码中,我可以在文件中看到:
node_modules/@prisma/client/index.d.ts
export type TransactionCreateWithoutAccountInput = {
}
...
export type TransactionCreateManyWithoutAccountInput = {
create?: Enumerable<TransactionCreateWithoutAccountInput> | null
connect?: Enumerable<TransactionWhereUniqueInput> | null
}
...
export type TransactionUpdateManyWithoutAccountInput = {
create?: Enumerable<TransactionCreateWithoutAccountInput> | null
connect?: Enumerable<TransactionWhereUniqueInput> | null
set?: Enumerable<TransactionWhereUniqueInput> | null
disconnect?: Enumerable<TransactionWhereUniqueInput> | null
delete?: Enumerable<TransactionWhereUniqueInput> | null
update?: Enumerable<TransactionUpdateWithWhereUniqueWithoutAccountInput> | null
updateMany?: Enumerable<TransactionUpdateManyWithWhereNestedInput> | null
deleteMany?: Enumerable<TransactionScalarWhereInput> | null
}
如何解决?