Reputation: 2753
I'm following the apollo subscriptions tutorial and my subscription is working, but I'm not getting to use the onSubscriptionData data callback.
Here's my code:
const MESSAGE_CREATED = gql`
subscription {
messageCreated {
id
content
}
}
`;
const MyComponent = () => (
<Subscription
subscription={MESSAGE_CREATED}
onSubscriptionData={() => {
console.log('subs');
}}
>
{({ data, loading }) => {
if (loading && !data) return <View />;
return (
<Text>New comment: {!loading && data.messageCreated.content}</Text>
);
}}
</Subscription>
);
I don't get the subs log on my console.
Upvotes: 1
Views: 738
Reputation: 446
This feature is only available on 'master' branch. I just tested it and 'onSubscriptionData' prop is working as desired. If you wanna test it, you should:
Update 'react-apollo' package version to 'master' as follow: "react-apollo": "apollographql/react-apollo"
Compile TS code executing: cd node_modules/react-apollo && yarn && yarn compile
Refactor all import paths from 'react-apollo' to 'react-apollo/lib' as follow: import { Subscription } from 'react-apollo/lib'
Upvotes: 2