How to use the react-relay.requestSubscription function in react-relay

To help you get started, we’ve selected a few react-relay examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bochen2014 / relay-todo-modern / client / subscriptions / todo.js View on Github external
* relay-muckaround/packages/relay-runtime/store/RelayModernEnvironment.js #sendSubscription
    *RelayModernEnvironment#sendSubscription({
      onCompleted,
      onNext,
      onError,
      operation,
      updater,
    }: {
      onCompleted?: ?(errors: ?Array) => void,
      onNext?: ?(payload: RelayResponsePayload) => void,
      onError?: ?(error: Error) => void,
      operation: OperationSelector,
      updater?: ?SelectorStoreUpdater,
    }): Disposable
   */
  requestSubscription(environment, {
    subscription,
    variables: arg,
    // after socket has been closed successfully
    onCompleted: () => {
      alert('done!'); /* need this if payload doesn't contain an id field*/
    },
    // connection_err ..etc
    onError: error => console.error(error),
    //end of pipe line; after store merged
    onNext: response => {},
    // begin of pipe line; before store merged
    updater: (
      store /*RelayRecordSourceSelectorProxy*/,
      data /*selector data, raw json*/
    ) => {
      //@see:   relay-muckaround/packages/relay-runtime/store/RelayPublishQueue.js
github guigrpa / mady / src / client / components / helpers.js View on Github external
const subscribe = ({
  environment,
  subscriptionOptions,
}: {|
  environment: Object,
  subscriptionOptions: Object,
|}) => {
  requestSubscription(environment, {
    ...subscriptionOptions,
    // onNext: data => {
    //   console.log('RX at END-USER-LEVEL:', data);
    // },
  });
};
github aws-samples / aws-appsync-relay / src / components / CreateTodo.js View on Github external
function subscribeToCreates(env, viewer) {
  return requestSubscription(env,
                             {
                               subscription: createSubscription,
                               variables: {user: viewer.id},
                               onCompleted: () => console.log('Create subscription closed.'),
                               onError: err => console.error('Error subscribing to todo updates:', err),
                               onNext: resp => console.log('Create event:', resp),
                               updater: makeUpdater(viewer, 'createdTodo')
                             });
}
github berty / berty / client / react-native / common / relay / subscriber.js View on Github external
export default ({ environment, subscription, updaters = [], variables }) => {
  let _updaters = updaters

  requestSubscription(environment, {
    subscription,
    variables,
    onNext: () => {},
    onCompleted: () => {},
    onError: error => console.error(error),
    updater: (store, data) =>
      _updaters.forEach(updater => updater(store, data)),
  })

  return {
    subscribe: ({ updater }) => {
      updater && _updaters.push(updater)
      return {
        unsubscribe: () => {
          _updaters = updater ? _updaters.filter(_ => _ !== updater) : _updaters
        },
github aws-samples / aws-appsync-relay / src / components / TodoList.js View on Github external
function subscribeToDeletes(env, viewer) {
  return requestSubscription(env,
                             {
                               subscription: deleteSubscription,
                               variables: {user: viewer.id},
                               onCompleted: () => console.log('Delete subscription closed.'),
                               onError: err => console.error('Error subscribing to todo deletes:', err),
                               onNext: resp => console.log('Delete event:', resp),
                               configs: [{
                                 type: 'RANGE_DELETE',
                                 parentID: viewer.id,
                                 connectionKeys: [{key: 'TodoList_listTodos'}],
                                 pathToConnection: ['viewer', 'edges'],
                                 deletedIDFieldName: 'deletedId',
                               }]
                             });
}
github renanmav / relay-twitter / src / modules / feed / subscription / NewTweetSubscription.ts View on Github external
const tweetsConnection = ConnectionHandler.getConnection(
        root,
        "Feed_tweets"
      );
      const tweetEdge = ConnectionHandler.createEdge(
        store,
        tweetsConnection!,
        tweet!,
        "TweetsEdge"
      );
      ConnectionHandler.insertEdgeBefore(tweetsConnection!, tweetEdge!);
    }
  };

  requestSubscription(Environment, subscriptionConfig);
};
github cirruslabs / cirrus-ci-web / src / components / chips / BuildStatusChip.tsx View on Github external
componentDidMount() {
    if (isBuildFinalStatus(this.props.build.status)) {
      return;
    }

    let variables = { buildID: this.props.build.id };

    this.subscription = requestSubscription(environment, {
      subscription: buildSubscription,
      variables: variables,
    });
  }
github OpenCTI-Platform / opencti / opencti-front / src / relay / environment.js View on Github external
export const requestSubscription = args => (WS_ACTIVATED ? RS(environment, args) : deactivateSubscription);
github cirruslabs / cirrus-ci-web / src / components / TaskDetails.tsx View on Github external
componentDidMount() {
    if (isTaskFinalStatus(this.props.task.status)) {
      return;
    }

    let variables = { taskID: this.props.task.id };

    this.subscription = requestSubscription(environment, {
      subscription: taskSubscription,
      variables: variables,
    });
  }
github OpenCTI-Platform / opencti / opencti-platform / opencti-front / src / relay / environment.js View on Github external
export const requestSubscription = (args) => (WS_ACTIVATED ? RS(environment, args) : deactivateSubscription);