我正在尝试对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来检索任何带有get查询的项目。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);
docs:https : //aws-amplify.github.io/docs/js/api#simple-query
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句