![](/img/trans.png)
[英]How can I use a field as a filter from one graphql query to get a fluid image thats in a separate query?
[英]How to use the GraphQL Get query from aws in React
我正在嘗試在 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:"YOUR ID HERE"){}`
就像是...
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.