Created
December 20, 2017 01:02
-
-
Save homerquan/a41aa59a75d05cca6fc9322e80666882 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const withDataAndSubscription = graphql(GETIMS_QUERY, { | |
options({toID}) { | |
console.log(GETIMS_QUERY); | |
const fromID = Meteor.userId(); | |
return { | |
fetchPolicy: 'cache-and-network', | |
variables: {fromID: `${fromID}`, toID: `${toID}`} | |
}; | |
} | |
, | |
props: props => { | |
return { | |
loading: props.data.loading, | |
instant_message: props.data.instant_message, | |
subscribeToMore: props.data.subscribeToMore, | |
subscribeToNewIMs: params => { | |
const fromID = Meteor.userId(); | |
const toID = params.toID; | |
return props.data.subscribeToMore({ | |
document: IM_SUBSCRIPTION_QUERY, | |
variables: {fromID: `${fromID}`, toID: `${toID}`}, | |
updateQuery: (previousResult, {subscriptionData}) => { | |
if (!subscriptionData.data) { | |
return previousResult; | |
} | |
const newMsg = subscriptionData.data.createIM; | |
return update(previousResult, { | |
instant_message: { | |
$push: [newMsg], | |
}, | |
}); | |
} | |
}); | |
} | |
}; | |
}, | |
}) | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment