如何接收数组作为 GraphQL 服务输入参数的成员?

How to receive an array as member of an input parameter of a GraphQL service?

鉴于此架构:

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

有人知道我做错了什么吗?

有用信息:

您需要在解析器 key 中进行更改,

export const resolver = {
  save: (args: {input: SaveInput}): SavePayload => {
    args.input.nodes.forEach(todo => api.saveTodo(todo as Todo));
    return { message : 'success' };
  }
}