给出以下模式:
input TodoInput {
id: String
title: String
}
input SaveInput {
nodes: [TodoInput]
}
type SavePayload {
message: String!
}
type Mutation {
save(input: SaveInput): SavePayload
}
给出此解析器:
type TodoInput = {
id: string | null,
title: string
}
type SaveInput = {
nodes: TodoInput[];
}
type SavePayload = {
message: string;
}
export const resolver = {
save: (input: SaveInput): SavePayload => {
input.nodes.forEach(todo => api.saveTodo(todo as Todo));
return { message : 'success' };
}
}
我发送此请求时:
mutation {
save(input: {
nodes: [
{id: "1", title: "Todo 1"}
]
}) {
message
}
}
然后在服务器端,input.nodes
的值为undefined
。
有人知道我在做什么错吗?
有用的信息:
答案 0 :(得分:3)
您需要在解析器的key
中进行更改
export const resolver = {
save: (args: {input: SaveInput}): SavePayload => {
args.input.nodes.forEach(todo => api.saveTodo(todo as Todo));
return { message : 'success' };
}
}