【发布时间】:2020-02-19 05:35:41
【问题描述】:
我正在使用compose 在一个组件中执行多个查询。我希望能够为查询使用变量。
1) 如何在查询中包含变量?
2) 如何执行查询?
以下是组件:
import React from 'react'
import {
View,
} from 'react-native'
import { graphql, withApollo } from 'react-apollo'
import { compose } from "recompose";
import { GET_ITEM, GET_REVIEWS } from '../graphql/query'
const PostingDetail = props => {
const itemId = props.navigation.getParam('itemId', null)
console.log("props", props.itemQuery)
return (
<View>
</View>
)
}
export default compose(
withApollo,
graphql(GET_ITEM, {
name: 'itemQuery',
options: ({ itemId }) => ({
variables: {
id: itemId
}
})
}),
graphql(GET_REVIEWS, { name: 'reviewsQuery'}),
)(PostingDetail)
我希望能够使用itemId 作为查询的变量,但是,上面的代码显示以下错误:
"message": 所需类型 \"ID!\" 的“变量 \"$id\" 不是 提供。”
【问题讨论】:
标签: reactjs react-native graphql react-apollo