【发布时间】:2018-02-27 10:57:42
【问题描述】:
我正在使用 react-native 和 apollo/graphql 开发一个应用程序。
在这种情况下,我想做的是在我的组件中进行计算(在这种情况下扫描条形码),然后将结果传递给我的 graphql 查询,以便它可以使用条形码访问我们的后端 api 并返回结果。
我已经在 apollo docs 和 google 中搜索了几个小时,但我不知所措。
这是我想要做的事情的要点:
class ScanBookScreen extends Component {
state = {
hasCameraPermission: null,
}
render() {
return (
<View style={{ flex: 1 }}>
<BarCodeScanner
onBarCodeRead={// pass this to the query down below} <-----
/>
</View>
);
}
}
const lookupTextbooksQuery = gql`
query lookupTextbooks($query: String) {
lookupTextbooks (query: $query, limit: 1) {
totalItems
textbooks {
id
title
description
}
}
}
`;
export default graphql(lookupTextbooksQuery, {
options: { variables: { query: // This is the part that needs to come from the component somehow} }, <----
})(ScanBookScreen);
【问题讨论】:
标签: reactjs react-native graphql react-apollo