输入对象类型XXX必须在棱镜2.0中定义一个或多个字段

问题描述 投票:0回答:1

我有以下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

没有错误,数据库看起来还不错(此屏幕快照还包含货币,但对这个问题没有影响。)>

enter image description here

但是当我执行使用ApolloServernexusPrismaPlugin时出现错误:

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相关的任何内容。如果我删除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
}

如何解决?

我有以下schema.prisma文件:模型帐户{id Int @default(autoincrement())@id名称字符串事务Transaction []}模型事务{id Int @default(autoincrement())@ ...

prisma prisma-graphql nexus-prisma
1个回答
0
投票

我已经设置了与上面相同的schema.prisma,并且已经通过以下方式使用Nexus创建了两种类型

© www.soinside.com 2019 - 2024. All rights reserved.