我正在尝试使用react.js中的graphQl的getQuery。但是我不知道该怎么做。我已经成功使用了列表查询。
state = { patients: [] }
async componentDidMount() {
try {
const apiData = await API.graphql(graphqlOperation(listxxxx))
const patie = apiData.data.listxxxx.items
this.setState({ patie })
console.log(patie)
} catch (err) {
console.log('qqqqqqqqqqqqqqqqq ', err)
}
}
一个人如何使用get查询?谢谢!
您需要一个ID来检索任何获取查询的项目。getPatient(ID:"您的ID此处"){}`
类似...
query Get_Patient_By_Id{
getPatient(id:"2dbcb870-e302-4ed5-a419-68751597129c"){
id
name
}
}
对于React,您将ID添加到变量列表参数:
const getPatient = await API.graphql(
graphqlOperation(
queries.getPatient,
{id: "2dbcb870-e302-4ed5-a419-68751597129c"}
)
);
console.log(getPatient.data.getPatient);
文档:https://aws-amplify.github.io/docs/js/api#simple-query