Relay: Silent change in Subscriptions in version 6?

Created on 24 Sep 2019  路  6Comments  路  Source: facebook/relay

Did something silently changed in the new version 6, because my subscriptions suddenly stopped working.

I am getting this error. The source object in RelayModernQueryExecutor.js:89 only has a dispose() method.

index.js:1437 RelayObservable: Unhandled Error TypeError: source.subscribe is not a function
    at new Executor (RelayModernQueryExecutor.js:89)
    at Object.execute (RelayModernQueryExecutor.js:48)
    at RelayModernEnvironment.js:241
    at _subscribe (RelayObservable.js:579)
    at RelayObservable.subscribe (RelayObservable.js:280)
    at RelayObservable.js:195
    at _subscribe (RelayObservable.js:579)
    at RelayObservable.subscribe (RelayObservable.js:280)
    at RelayObservable.js:292
    at _subscribe (RelayObservable.js:579)
    at RelayObservable.subscribe (RelayObservable.js:280)
    at requestSubscription (requestSubscription.js:52)
    at UserSubscription.js:19

UserSubscription.js is 1:1 with the samples provided in the docs.

bug

Most helpful comment

example if someone was using the legacy observer in the 4th param & wants to get that functionality back:

const handleSubscribe = (operation, variables, cacheConfig) => {
    return Observable.create((sink) => {
      handleSubscribePromise(operation, variables, cacheConfig, {
        onNext: sink.next,
        onError: sink.error,
        onCompleted: sink.complete
      }).catch()
    })
  }

where handleSubscribePromise returns void. chances are it just fires off a message to the ws server & uses the observer to clean up unsubs.

All 6 comments

The source value passed to QueryExecutor comes from calling the user-provided networking layer, which is expected to return an Observable. I'm not aware of any particular changes in the core that would affect this.

@ivosabev can you share part of your network layer function?

Following your questions and explanations I managed to find the problem in the network layer that was setting up the subscriptions and was returning {dispose: () => {}} object instead of Observable. I guess the dispose() used to work up until now and we never figured that we should update our SubscribeFunction it to a proper Observable.

This is the working code if anyone has a similar issue:

function subscribeFn(operation, variables, cacheConfig) {
  const {text: query, name: operationName} = operation;
  const subscriptionId = Date.now();

  const observable = subscriptions.request({
    query,
    variables: {
      ...variables,
      subscriptionId,
    },
    operationName,
  });

  return RelayObservable.from(observable);
}

Thanks for the help @josephsavona and @sibelius !

we need to update docs

should we keep this one open util we update docs?

example if someone was using the legacy observer in the 4th param & wants to get that functionality back:

const handleSubscribe = (operation, variables, cacheConfig) => {
    return Observable.create((sink) => {
      handleSubscribePromise(operation, variables, cacheConfig, {
        onNext: sink.next,
        onError: sink.error,
        onCompleted: sink.complete
      }).catch()
    })
  }

where handleSubscribePromise returns void. chances are it just fires off a message to the ws server & uses the observer to clean up unsubs.

Was this page helpful?
0 / 5 - 0 ratings