【发布时间】:2021-10-09 15:49:35
【问题描述】:
我最近遇到了一个 GraphQL 问题,我不知道该去哪里,因为我相信我在查询时正确地遵循了 GraphQL 文档。
我有以下型号。
model Contract {
id Int @id @default(autoincrement())
userId Int?
vin String
make String
model String
year Int
ownersName String @default("")
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
ownersEmail String @default("")
User User? @relation(fields: [userId], references: [id])
Dealership Dealership @relation(fields: [dealershipId], references: [id])
notes Note[]
dealershipId Int
}
这里是相关的类型
type Contract {
id: Int!
vin: String!
make: String!
model: String!
year: Int!
ownersName: String!
User: User
userId: Int
createdAt: DateTime
updatedAt: DateTime
ownersEmail: String
}
type Query {
contractsByUser: [Contract]
}
这是我从单元格中导出的查询
export const QUERY = gql`
query ContractByUser {
contractsByUser {
id
vin
make
model
year
ownersName
createdAt
}
}
我收到以下错误。
api | ERROR [2021-08-04 13:28:03.477 +0000] (apollo-graphql-server): GraphQL didEncounterErrors
api | errors: [
api | {
api | "message": "Cannot query field \"contractsByUser\" on type \"Query\".",
api | "locations": [
api | {
api | "line": 2,
api | "column": 3
api | }
api | ]
api | }
api | ]
api | INFO [2021-08-04 13:28:03.479 +0000] (apollo-graphql-server): GraphQL willSendResponse
api |
api | Error: Cannot query field "contractsByUser" on type "Query".
api |
api |
api | POST /graphql 400 21.533 ms - 1329
api |
api | GraphQLError: Cannot query field "contractsByUser" on type "Query".
这绝对是一个验证错误,但我不确定我错过了什么或做错了什么。我正在使用最新版本的 Redwood 并更新了重大更改。任何帮助都会很好。也许它没有正确生成类型或者....任何帮助将不胜感激。
【问题讨论】:
-
playground docs - 这个查询在那里 - 它在操场上工作吗?如果不是 - 错误的 BE/代码/配置