【发布时间】:2019-07-31 17:48:27
【问题描述】:
我正在尝试创建一个 graphql 突变来使用其他对象数组更新对象字段。这是我的架构:
type Guide {
_id: ID!
first_name: String!
last_name: String
email: String!
phone: String!
creator: User!
}
input GuideInput {
_id: ID!
first_name: String!
last_name: String
email: String!
phone: String!
}
type Trip {
_id: ID!
name: String!
description: String
location: String
start_date: String
start_time: String
duration: Int
creator: User!
guides: [Guide!]
guests: [Guest!]
}
input TripInput {
name: String
description: String
location: String
start_date: String
start_time: String
duration: Int
guides: [GuideInput]
}
type RootQuery {
trips: [Trip!]
guides: [Guide!]
}
type RootMutation {
updateTrip(tripId: ID!, tripInput: TripInput): Trip
deleteTrip(tripId: ID!): Trip
createGuide(guideInput: GuideInput): Guide
deleteGuide(guideId: ID!): Guide
}
schema {
query: RootQuery
mutation: RootMutation
}
我的查询如下所示:
const requestBody = {
query: `
mutation {
updateTrip(
tripId: "${tripId}",
tripInput: {
guides: ${guides}
}
) {
guides {
first_name
last_name
}
}
}
`
}
执行此请求时遇到的错误是:
Expected type GuideInput, found object.
Expected type GuideInput, found Object.
我将一组对象传递到与 GuideInput 对象形状相同的突变中,所以我很难过。提前谢谢!
【问题讨论】: