react-native - 如何在与graphql的本机反应中基于ID进行查询?
问题描述
我想根据job_id: ID!
但似乎我做错的事情进行查询,我想了解是什么。
所以我在这里接受工作ID。
render() {
const { job } = this.props.navigation.state.params;
const job_id = job._id;
........
}
所以现在我想在job_id
这里用它来查询
const GET_APPLICATIONS = gql`
query getJobApplicationsForThisJob($job_id: ID!) {
getJobApplicationsForThisJob(job_id: $job_id) {
_id
}
}
`;
const DELETE_JOB = gql`
mutation deteleJob($_id: ID!) {
deleteJob(_id: $_id) {
message
}
}
`;
const mutationConfig = {
props: ({ mutate, ownProps }) => ({
deleteJob: (_id) => mutate({ variables: { _id } }),
...ownProps,
})
}
export default compose(
withApollo,
graphql(GET_APPLICATIONS, { name: "getApplications" }),
graphql(DELETE_JOB, mutationConfig)
)(JobDetails);
但我最终得到以下错误
Invariant Violation: The operation 'getJobApplicationsForThisJob' wrapping 'JobDetails' is expecting variable 'job_id' but it was not found in the props passed to 'Apollo(JobDetails)'
任何想法?
解决方案
问题解决了。
我已经像这样使用了 HOC
export default compose(
withApollo,
graphql(GET_APPLICATIONS, { name: "getApplications", options: (props) => ({ variables: { job_id: props.navigation.state.params.job._id } }) }),
graphql(DELETE_JOB, mutationConfig)
)(JobDetails);
推荐阅读
- excel - 如何将一个单元格的值更改为另一个
- javascript - package.json 中的代理属性问题(反应)
- c# - 我需要在拆分方法c#之后将字符串分配给数组列
- node.js - 节点版本 - 使用过时的版本
- jenkins - Groovy 注释中是否支持反斜杠?
- azure-devops - 在 Azure DevOps 中获取用户访问指标
- sql-server - 创建/更改引用不存在的表或视图的过程
- node.js - JS过滤或在数组中找到owner_name在反应中匹配的元素
- python - Python tkinter 在主函数之外更新画布标签
- javascript - 如何将项目列表添加到离线存储?