我在 FaunaDB 中导入了我的 GraphQL 模式并想创建一个新问题
type Choices {
key: String!
value: String!
question: Question
}
type Question {
title: String!
snippet: String
choices: [Choices!]! @relation
answer: String!
explanation: String!
}
type Query {
allQuestions: [Question!]!
}
为此,我正在使用 axios 并有这样的 GraphQL 突变:
const CREATE_QUESTION = `
mutation($title: String!, $explanation: String!, $snippet: String, $answer: String!, $choices: [ChoicesInput]!) {
createQuestion(data: {
title: $title
explanation: $explanation,
snippet: $snippet,
answer: $answer,
choices: {
create: $choices
}
}) {
_id
explanation
answer
title
snippet
choices {
data {
key
value
}
}
}
}
`
除了选择之外,一切正常,我想发送一个对象数组但收到错误:
Variable '$choices' expected value of type '[ChoicesInput]!' but got: "[ { key: 'A', value: '`0 1 2` and `0 1 2`' }, { key: 'B', value: '`0 1 2` and `3 3 3`' }, { key: 'C', value: '`3 3 3` and `0 1 2`' } ]". Reason: '[0]' Expected 'ChoicesInput', found not an object. (line 2, column 86): mutation($title: String!, $explanation: String!, $snippet: String, $answer: String!, $choices: [ChoicesInput]!) { ^
为了能够发送我的对象数组,我应该做些什么不同的事情?