【发布时间】:2022-01-21 03:30:23
【问题描述】:
我在我的 React Native 应用程序上使用 AWS Amplify 的 GraphQL API。我的应用中有一组对象,如下所示:
const [data, setData] = useState([
{
id: someid,
thing: thing,
otherThing: otherThing
},
{
id: someid,
thing: thing,
otherThing: otherThing
}
]);
这需要在我的schema.graphql 中看起来像什么?我目前的定义是这样的:
type someThing @model {
UserID: String!
thingName: String
thingID: String! @primaryKey(sortKeyFields: ["UserID"])
data: [AWSJSON]
}
在调用 createSomeThing 突变后,我目前在我的应用程序中收到此错误,其中我将 data: data 作为输入传递:
Variable 'data' has an invalid value. Unable to parse {id=8f3aa794-1881-4eaa-ba4e-0ac979b5b0a6, thing=pasta, otherThing=one} as valid JSON.
这里有什么问题?我是否在schema.graphql 中错误地定义了这个?或者我需要在传递到我的突变之前转换数据吗?
【问题讨论】:
-
检查提交的
data是否是有效的JSON。 -
我实际上必须将对象数组作为字符串传递
标签: react-native graphql aws-amplify