javascript - 如何在 React 中使用来自 aws 的 GraphQL Get 查询
问题描述
我正在尝试在 react.js 中使用 getquery for graphql。但我不知道该怎么做。我已经成功使用了列表查询。
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);
推荐阅读
- apache-flink - 使用 debezium-json 格式的 Flink 1.11
- http - salesforce:请求 URI 中的绝对路径
- javascript - HTML中的javascript和datalist问题
- python - 如何改变 Anaconda 的用户群
- activemq-artemis - 大量预定消息似乎卡在 ActiveMQ Artemis 代理上
- python - 根据列值添加值
- java - 有没有办法导出带有图像的 JFrame?
- python - Python:eval('import re')不起作用
- node.js - 如何使用 gitlab-ci 正确缓存 node_modules
- java - 单击某个按钮时如何添加带有文本的按钮?