debian-mirror-gitlab/app/assets/javascripts/actioncable_link.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

41 lines
1.1 KiB
JavaScript
Raw Normal View History

2022-04-04 11:22:00 +05:30
import { ApolloLink, Observable } from '@apollo/client/core';
2021-06-08 01:23:25 +05:30
import { print } from 'graphql';
import cable from '~/actioncable_consumer';
import { uuids } from '~/lib/utils/uuids';
export default class ActionCableLink extends ApolloLink {
// eslint-disable-next-line class-methods-use-this
request(operation) {
return new Observable((observer) => {
const subscription = cable.subscriptions.create(
{
channel: 'GraphqlChannel',
query: operation.query ? print(operation.query) : null,
variables: operation.variables,
operationName: operation.operationName,
nonce: uuids()[0],
},
{
received(data) {
if (data.errors) {
observer.error(data.errors);
} else if (data.result) {
observer.next(data.result);
}
if (!data.more) {
observer.complete();
}
},
},
);
return {
unsubscribe() {
subscription.unsubscribe();
},
};
});
}
}