@envelop/live-query
Version:
The easiest way of adding live queries to your GraphQL server!
37 lines (36 loc) • 1.88 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.useLiveQuery = exports.GraphQLLiveDirectiveSDL = exports.GraphQLLiveDirectiveAST = exports.GraphQLLiveDirective = void 0;
const graphql_1 = require("graphql");
const graphql_live_query_1 = require("@n1ru4l/graphql-live-query");
Object.defineProperty(exports, "GraphQLLiveDirective", { enumerable: true, get: function () { return graphql_live_query_1.GraphQLLiveDirective; } });
const utils_1 = require("@graphql-tools/utils");
exports.GraphQLLiveDirectiveAST = (0, utils_1.astFromDirective)(graphql_live_query_1.GraphQLLiveDirective);
exports.GraphQLLiveDirectiveSDL = (0, graphql_1.print)(exports.GraphQLLiveDirectiveAST);
const useLiveQuery = (opts) => {
return {
onExecute: ({ executeFn, setExecuteFn }) => {
const execute = opts.liveQueryStore.makeExecute(executeFn);
if (opts.applyLiveQueryPatchGenerator) {
const { applyLiveQueryPatchGenerator } = opts;
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore execute typings do not include AsyncIterable return right now
setExecuteFn((...args) => applyLiveQueryPatchGenerator(execute(...args)));
}
else {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore execute typings do not include AsyncIterable return right now
setExecuteFn(execute);
}
},
onValidate: ({ addValidationRule }) => {
addValidationRule(graphql_live_query_1.NoLiveMixedWithDeferStreamRule);
},
onContextBuilding: ({ extendContext }) => {
extendContext({
liveQueryStore: opts.liveQueryStore,
});
},
};
};
exports.useLiveQuery = useLiveQuery;