Alessander Franca
Alessander Franca

Reputation: 2753

apollo client onSubscriptionData is not working

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

Answers (1)

Carlos Rufo
Carlos Rufo

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:

  1. Update 'react-apollo' package version to 'master' as follow: "react-apollo": "apollographql/react-apollo"

  2. Compile TS code executing: cd node_modules/react-apollo && yarn && yarn compile

  3. Refactor all import paths from 'react-apollo' to 'react-apollo/lib' as follow: import { Subscription } from 'react-apollo/lib'

Upvotes: 2

Related Questions