您好,我在使用GraphQL订阅时遇到了一些奇怪的事情。因此,由于必须上传的文档类型,我在3个不同的屏幕中具有以下订阅。
function bbloomer_checkout_radio_choice_set_session() {
if ( isset($_POST['radio']) ){
$radio = sanitize_key( $_POST['radio'] );
$cart = WC()->cart;
$cart_content = $cart->cart_contents;
foreach ( $cart_content as $cart_item_key => $cart_item ) {
if( 'no_option' === $radio ){
$cart->set_quantity($cart_item_key, 1);
}elseif( 'option_1' === $radio ){
$cart->set_quantity($cart_item_key, 10);
}elseif( 'option_2' === $radio ){
$cart->set_quantity($cart_item_key, 20);
}
}
}
echo json_encode( $_POST['radio'] ) ;
die();
}
这就是我的解析器中的内容
componentWillReceiveProps(nextProps) {
if (!nextProps.getKYCDocuments.loading) {
let { subscribeToMore } = this.props.getKYCDocuments;
subscribeToMore({
document: KYC_ADDED,
variables: {
user: this.props.getMe.me._id
},
updateQuery: (prev, { subscriptionData }) => {
if (!subscriptionData.data) {
return prev;
}
const kycAdded = subscriptionData.data.kycAdded;
if (
!prev.getKYCDocumentsForThisUser.find(d => d._id === kycAdded._id)
) {
return {
...prev,
getKYCDocumentsForThisUser: [
{ ...kycAdded },
...prev.getKYCDocumentsForThisUser
]
};
}
return prev;
},
onError: err => console.log(err)
});
}
}
现在,当我进入pubsub.publish(KYC_ADDED, { [KYC_ADDED]: KYCToUpdate });
kycAdded: {
subscribe: withFilter(
() => pubsub.asyncIterator(KYC_ADDED),
(payload, args) => {
return payload.kycAdded.user === args.user;
}
)
},
屏幕时,我正在进行更改以创建第一个文档。订阅运作良好。我返回,然后转到Kyc Document One
屏幕。我在做同样的事情,但是没有订阅响应返回。检查了数据库,我的突变对象在那里。现在,我正在刷新应用程序,并选择Kyc Document Two
屏幕进行更改,并在其中显示订阅响应。回到Kyc Document Two
屏幕进行突变,没有订阅响应