Skip to content

Commit 93239dc

Browse files
authored
feat: remove the execute parameter on InMemoryLiveQueryStore (#928)
1 parent bb9c030 commit 93239dc

File tree

3 files changed

+60
-46
lines changed

3 files changed

+60
-46
lines changed

.changeset/satan-goats-sacrifice.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
"@n1ru4l/in-memory-live-query-store": minor
3+
---
4+
5+
Drop the `execute` constructor argument option.
6+
Please use `InMemoryLiveQueryStore.makeExecute` instead.
7+
8+
**Old**
9+
10+
```ts
11+
import { InMemoryLiveQueryStore } from "@n1ru4l/in-memory-live-query-store";
12+
import { execute as executeImplementation } from "graphql";
13+
const liveQueryStore = new InMemoryLiveQueryStore({ execute });
14+
const execute = liveQueryStore.execute;
15+
```
16+
17+
**New**
18+
19+
```ts
20+
import { InMemoryLiveQueryStore } from "@n1ru4l/in-memory-live-query-store";
21+
import { execute as executeImplementation } from "graphql";
22+
const liveQueryStore = new InMemoryLiveQueryStore();
23+
const execute = liveQueryStore.makeExecute(executeImplementation);
24+
```

packages/in-memory-live-query-store/src/InMemoryLiveQueryStore.spec.ts

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import {
55
GraphQLSchema,
66
GraphQLString,
77
parse,
8-
execute as executeImplementation,
8+
execute as defaultExecuteImplementation,
99
GraphQLList,
10+
ExecutionArgs,
1011
} from "graphql";
1112
import { isAsyncIterable } from "@graphql-tools/utils";
1213
import { InMemoryLiveQueryStore } from "./InMemoryLiveQueryStore";
@@ -28,6 +29,14 @@ function assertNoAsyncIterable(value: unknown) {
2829
}
2930
}
3031

32+
function execute(
33+
store: InMemoryLiveQueryStore,
34+
params: ExecutionArgs,
35+
executeImplementation = defaultExecuteImplementation
36+
) {
37+
return store.makeExecute(executeImplementation)(params);
38+
}
39+
3140
const runAllPendingStuff = () => new Promise((res) => setImmediate(res));
3241

3342
const getAllValues = async <T>(values: AsyncIterable<T>) => {
@@ -155,7 +164,7 @@ describe("conformance with default `graphql-js` exports", () => {
155164
foo
156165
}
157166
`);
158-
const result = store.execute({
167+
const result = execute(store, {
159168
document,
160169
schema,
161170
});
@@ -176,7 +185,7 @@ describe("conformance with default `graphql-js` exports", () => {
176185
}
177186
`);
178187

179-
const result = store.execute({
188+
const result = execute(store, {
180189
document,
181190
schema,
182191
});
@@ -197,7 +206,7 @@ describe("conformance with default `graphql-js` exports", () => {
197206
}
198207
`);
199208

200-
const result = store.execute({
209+
const result = execute(store, {
201210
document,
202211
schema,
203212
});
@@ -224,7 +233,7 @@ describe("conformance with default `graphql-js` exports", () => {
224233
}
225234
`);
226235

227-
const result = store.execute({
236+
const result = execute(store, {
228237
document,
229238
schema,
230239
});
@@ -249,7 +258,7 @@ it("returns a AsyncIterable that publishes a query result.", async () => {
249258
}
250259
`);
251260

252-
const executionResult = store.execute({
261+
const executionResult = execute(store, {
253262
schema,
254263
document,
255264
});
@@ -278,7 +287,7 @@ it("returns a AsyncIterable that publishes a query result after the schema coord
278287
}
279288
`);
280289

281-
const executionResult = store.execute({
290+
const executionResult = execute(store, {
282291
schema,
283292
document,
284293
});
@@ -325,7 +334,7 @@ it("returns a AsyncIterable that publishes a query result after the resource ide
325334
}
326335
`);
327336

328-
const executionResult = store.execute({
337+
const executionResult = execute(store, {
329338
schema,
330339
document,
331340
});
@@ -383,7 +392,7 @@ it("does not publish when a old resource identifier is invalidated", async () =>
383392
}
384393
`);
385394

386-
const executionResult = store.execute({
395+
const executionResult = execute(store, {
387396
schema,
388397
document,
389398
});
@@ -444,7 +453,7 @@ it("can be executed with polymorphic parameter type", () => {
444453
}
445454
`);
446455

447-
const executionResult = store.execute({ schema, document });
456+
const executionResult = execute(store, { schema, document });
448457
expect(executionResult).toEqual({
449458
data: {
450459
foo: "queried",
@@ -463,7 +472,7 @@ it("can handle missing NoLiveMixedWithDeferStreamRule", async () => {
463472
}
464473
`);
465474

466-
const executionResult = await store.execute({ schema, document });
475+
const executionResult = await execute(store, { schema, document });
467476
if (isAsyncIterable(executionResult)) {
468477
const asyncIterator = executionResult[Symbol.asyncIterator]();
469478
try {
@@ -508,7 +517,7 @@ it("can collect additional resource identifiers with 'extensions.liveQuery.colle
508517
}
509518
`);
510519
const store = new InMemoryLiveQueryStore();
511-
const executionResult = await store.execute({ schema, document });
520+
const executionResult = await execute(store, { schema, document });
512521

513522
assertAsyncIterable(executionResult);
514523

@@ -539,7 +548,7 @@ it("adds the resource identifiers as a extension field.", async () => {
539548
}
540549
`);
541550

542-
const executionResult = store.execute({
551+
const executionResult = execute(store, {
543552
schema,
544553
document,
545554
variableValues: {
@@ -624,7 +633,7 @@ it("can set the id field name arbitrarily", async () => {
624633
}
625634
`);
626635

627-
const executionResult = store.execute({
636+
const executionResult = execute(store, {
628637
schema,
629638
document,
630639
variableValues: {
@@ -656,7 +665,7 @@ it("can throttle and prevent multiple publishes", async () => {
656665

657666
const store = new InMemoryLiveQueryStore();
658667

659-
const executionResult = store.execute({
668+
const executionResult = execute(store, {
660669
schema,
661670
document,
662671
});
@@ -695,7 +704,7 @@ it("can throttle and publish new values after the throttle interval", async () =
695704

696705
const store = new InMemoryLiveQueryStore();
697706

698-
const executionResult = store.execute({
707+
const executionResult = execute(store, {
699708
schema,
700709
document,
701710
});
@@ -733,7 +742,7 @@ it("can prevent execution by returning a string from validateThrottle", async ()
733742
},
734743
});
735744

736-
let executionResult = store.execute({
745+
let executionResult = execute(store, {
737746
schema,
738747
document,
739748
variableValues: {
@@ -742,7 +751,7 @@ it("can prevent execution by returning a string from validateThrottle", async ()
742751
});
743752
assertAsyncIterable(executionResult);
744753

745-
executionResult = store.execute({
754+
executionResult = execute(store, {
746755
schema,
747756
document,
748757
variableValues: {
@@ -777,7 +786,7 @@ it("can override the throttle interval by returning a number from validateThrott
777786
},
778787
});
779788

780-
let executionResult = store.execute({
789+
let executionResult = execute(store, {
781790
schema,
782791
document,
783792
variableValues: {
@@ -816,17 +825,15 @@ it("makeExecute calls the execute it is passed to resolve live queries", async (
816825

817826
const executePassedAtInitializationTime = jest.fn();
818827
executePassedAtInitializationTime.mockImplementation((args) =>
819-
executeImplementation(args)
828+
defaultExecuteImplementation(args)
820829
);
821830

822831
const executePassedToMakeExecute = jest.fn();
823832
executePassedToMakeExecute.mockImplementation((args) =>
824-
executeImplementation(args)
833+
defaultExecuteImplementation(args)
825834
);
826835

827-
const store = new InMemoryLiveQueryStore({
828-
execute: executePassedAtInitializationTime,
829-
});
836+
const store = new InMemoryLiveQueryStore();
830837

831838
const makeExecuteFn = store.makeExecute(executePassedToMakeExecute);
832839

@@ -856,7 +863,7 @@ it("index via custom index field of type string", async () => {
856863
],
857864
});
858865

859-
const execute = store.makeExecute(executeImplementation);
866+
const execute = store.makeExecute(defaultExecuteImplementation);
860867

861868
const document = parse(/* GraphQL */ `
862869
query @live {
@@ -893,7 +900,7 @@ it("index via custom index field with string value", async () => {
893900
},
894901
],
895902
});
896-
const execute = store.makeExecute(executeImplementation);
903+
const execute = store.makeExecute(defaultExecuteImplementation);
897904

898905
const document = parse(/* GraphQL */ `
899906
query @live {
@@ -930,7 +937,7 @@ it("index via custom compound index", async () => {
930937
},
931938
],
932939
});
933-
const execute = store.makeExecute(executeImplementation);
940+
const execute = store.makeExecute(defaultExecuteImplementation);
934941

935942
const document = parse(/* GraphQL */ `
936943
query @live {

packages/in-memory-live-query-store/src/InMemoryLiveQueryStore.ts

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,6 @@ export type InMemoryLiveQueryStoreParameter = {
143143
* This may be useful if you are using a relay compliant schema and the Typename information is not required for building a unique topic.
144144
* */
145145
buildResourceIdentifier?: BuildResourceIdentifierFunction;
146-
/**
147-
* Function which is used for executing the operations.
148-
*
149-
* Uses the `execute` exported from graphql be default.
150-
*
151-
* @deprecated Please use the InMemoryStore.createExecute method instead.
152-
* */
153-
execute?: typeof defaultExecute;
154146
/**
155147
* Whether the extensions should include a list of all resource identifiers for the latest operation result.
156148
* Any of those can be used for invalidating and re-scheduling the operation execution.
@@ -188,7 +180,6 @@ export class InMemoryLiveQueryStore {
188180
private _resourceTracker = new ResourceTracker<() => void>();
189181
private _schemaCache = new WeakMap<GraphQLSchema, SchemaCacheRecord>();
190182
private _buildResourceIdentifier = defaultResourceIdentifierNormalizer;
191-
private _execute = defaultExecute;
192183
private _includeIdentifierExtension = false;
193184
private _idFieldName = "id";
194185
private _validateThrottleValue: Maybe<ValidateThrottleValueFunction>;
@@ -198,9 +189,6 @@ export class InMemoryLiveQueryStore {
198189
if (params?.buildResourceIdentifier) {
199190
this._buildResourceIdentifier = params.buildResourceIdentifier;
200191
}
201-
if (params?.execute) {
202-
this._execute = params.execute;
203-
}
204192
if (params?.idFieldName) {
205193
this._idFieldName = params.idFieldName;
206194
}
@@ -329,15 +317,13 @@ export class InMemoryLiveQueryStore {
329317
run();
330318
}
331319

332-
function dispose() {
320+
onStop.then(function dispose() {
333321
cancelThrottle?.();
334322
liveQueryStore._resourceTracker.release(
335323
scheduleRun,
336324
previousIdentifier
337325
);
338-
}
339-
340-
onStop.then(dispose);
326+
});
341327

342328
run = function run() {
343329
executionCounter = executionCounter + 1;
@@ -429,9 +415,6 @@ export class InMemoryLiveQueryStore {
429415
});
430416
};
431417

432-
/** @deprecated Please use InMemoryLiveQueryStore.makeExecute instead. */
433-
execute = this.makeExecute(this._execute);
434-
435418
/**
436419
* Invalidate queries (and schedule their re-execution) via a resource identifier.
437420
* @param identifiers A single or list of resource identifiers that should be invalidated.

0 commit comments

Comments
 (0)