From 93239dc6524119fa831cf42a94d114446d3b42cf Mon Sep 17 00:00:00 2001 From: Laurin Quast Date: Mon, 20 Jun 2022 15:23:27 +0200 Subject: [PATCH] feat: remove the execute parameter on InMemoryLiveQueryStore (#928) --- .changeset/satan-goats-sacrifice.md | 24 ++++++++ .../src/InMemoryLiveQueryStore.spec.ts | 61 +++++++++++-------- .../src/InMemoryLiveQueryStore.ts | 21 +------ 3 files changed, 60 insertions(+), 46 deletions(-) create mode 100644 .changeset/satan-goats-sacrifice.md diff --git a/.changeset/satan-goats-sacrifice.md b/.changeset/satan-goats-sacrifice.md new file mode 100644 index 00000000..b1bc0504 --- /dev/null +++ b/.changeset/satan-goats-sacrifice.md @@ -0,0 +1,24 @@ +--- +"@n1ru4l/in-memory-live-query-store": minor +--- + +Drop the `execute` constructor argument option. +Please use `InMemoryLiveQueryStore.makeExecute` instead. + +**Old** + +```ts +import { InMemoryLiveQueryStore } from "@n1ru4l/in-memory-live-query-store"; +import { execute as executeImplementation } from "graphql"; +const liveQueryStore = new InMemoryLiveQueryStore({ execute }); +const execute = liveQueryStore.execute; +``` + +**New** + +```ts +import { InMemoryLiveQueryStore } from "@n1ru4l/in-memory-live-query-store"; +import { execute as executeImplementation } from "graphql"; +const liveQueryStore = new InMemoryLiveQueryStore(); +const execute = liveQueryStore.makeExecute(executeImplementation); +``` diff --git a/packages/in-memory-live-query-store/src/InMemoryLiveQueryStore.spec.ts b/packages/in-memory-live-query-store/src/InMemoryLiveQueryStore.spec.ts index b0125cac..bc871f71 100644 --- a/packages/in-memory-live-query-store/src/InMemoryLiveQueryStore.spec.ts +++ b/packages/in-memory-live-query-store/src/InMemoryLiveQueryStore.spec.ts @@ -5,8 +5,9 @@ import { GraphQLSchema, GraphQLString, parse, - execute as executeImplementation, + execute as defaultExecuteImplementation, GraphQLList, + ExecutionArgs, } from "graphql"; import { isAsyncIterable } from "@graphql-tools/utils"; import { InMemoryLiveQueryStore } from "./InMemoryLiveQueryStore"; @@ -28,6 +29,14 @@ function assertNoAsyncIterable(value: unknown) { } } +function execute( + store: InMemoryLiveQueryStore, + params: ExecutionArgs, + executeImplementation = defaultExecuteImplementation +) { + return store.makeExecute(executeImplementation)(params); +} + const runAllPendingStuff = () => new Promise((res) => setImmediate(res)); const getAllValues = async (values: AsyncIterable) => { @@ -155,7 +164,7 @@ describe("conformance with default `graphql-js` exports", () => { foo } `); - const result = store.execute({ + const result = execute(store, { document, schema, }); @@ -176,7 +185,7 @@ describe("conformance with default `graphql-js` exports", () => { } `); - const result = store.execute({ + const result = execute(store, { document, schema, }); @@ -197,7 +206,7 @@ describe("conformance with default `graphql-js` exports", () => { } `); - const result = store.execute({ + const result = execute(store, { document, schema, }); @@ -224,7 +233,7 @@ describe("conformance with default `graphql-js` exports", () => { } `); - const result = store.execute({ + const result = execute(store, { document, schema, }); @@ -249,7 +258,7 @@ it("returns a AsyncIterable that publishes a query result.", async () => { } `); - const executionResult = store.execute({ + const executionResult = execute(store, { schema, document, }); @@ -278,7 +287,7 @@ it("returns a AsyncIterable that publishes a query result after the schema coord } `); - const executionResult = store.execute({ + const executionResult = execute(store, { schema, document, }); @@ -325,7 +334,7 @@ it("returns a AsyncIterable that publishes a query result after the resource ide } `); - const executionResult = store.execute({ + const executionResult = execute(store, { schema, document, }); @@ -383,7 +392,7 @@ it("does not publish when a old resource identifier is invalidated", async () => } `); - const executionResult = store.execute({ + const executionResult = execute(store, { schema, document, }); @@ -444,7 +453,7 @@ it("can be executed with polymorphic parameter type", () => { } `); - const executionResult = store.execute({ schema, document }); + const executionResult = execute(store, { schema, document }); expect(executionResult).toEqual({ data: { foo: "queried", @@ -463,7 +472,7 @@ it("can handle missing NoLiveMixedWithDeferStreamRule", async () => { } `); - const executionResult = await store.execute({ schema, document }); + const executionResult = await execute(store, { schema, document }); if (isAsyncIterable(executionResult)) { const asyncIterator = executionResult[Symbol.asyncIterator](); try { @@ -508,7 +517,7 @@ it("can collect additional resource identifiers with 'extensions.liveQuery.colle } `); const store = new InMemoryLiveQueryStore(); - const executionResult = await store.execute({ schema, document }); + const executionResult = await execute(store, { schema, document }); assertAsyncIterable(executionResult); @@ -539,7 +548,7 @@ it("adds the resource identifiers as a extension field.", async () => { } `); - const executionResult = store.execute({ + const executionResult = execute(store, { schema, document, variableValues: { @@ -624,7 +633,7 @@ it("can set the id field name arbitrarily", async () => { } `); - const executionResult = store.execute({ + const executionResult = execute(store, { schema, document, variableValues: { @@ -656,7 +665,7 @@ it("can throttle and prevent multiple publishes", async () => { const store = new InMemoryLiveQueryStore(); - const executionResult = store.execute({ + const executionResult = execute(store, { schema, document, }); @@ -695,7 +704,7 @@ it("can throttle and publish new values after the throttle interval", async () = const store = new InMemoryLiveQueryStore(); - const executionResult = store.execute({ + const executionResult = execute(store, { schema, document, }); @@ -733,7 +742,7 @@ it("can prevent execution by returning a string from validateThrottle", async () }, }); - let executionResult = store.execute({ + let executionResult = execute(store, { schema, document, variableValues: { @@ -742,7 +751,7 @@ it("can prevent execution by returning a string from validateThrottle", async () }); assertAsyncIterable(executionResult); - executionResult = store.execute({ + executionResult = execute(store, { schema, document, variableValues: { @@ -777,7 +786,7 @@ it("can override the throttle interval by returning a number from validateThrott }, }); - let executionResult = store.execute({ + let executionResult = execute(store, { schema, document, variableValues: { @@ -816,17 +825,15 @@ it("makeExecute calls the execute it is passed to resolve live queries", async ( const executePassedAtInitializationTime = jest.fn(); executePassedAtInitializationTime.mockImplementation((args) => - executeImplementation(args) + defaultExecuteImplementation(args) ); const executePassedToMakeExecute = jest.fn(); executePassedToMakeExecute.mockImplementation((args) => - executeImplementation(args) + defaultExecuteImplementation(args) ); - const store = new InMemoryLiveQueryStore({ - execute: executePassedAtInitializationTime, - }); + const store = new InMemoryLiveQueryStore(); const makeExecuteFn = store.makeExecute(executePassedToMakeExecute); @@ -856,7 +863,7 @@ it("index via custom index field of type string", async () => { ], }); - const execute = store.makeExecute(executeImplementation); + const execute = store.makeExecute(defaultExecuteImplementation); const document = parse(/* GraphQL */ ` query @live { @@ -893,7 +900,7 @@ it("index via custom index field with string value", async () => { }, ], }); - const execute = store.makeExecute(executeImplementation); + const execute = store.makeExecute(defaultExecuteImplementation); const document = parse(/* GraphQL */ ` query @live { @@ -930,7 +937,7 @@ it("index via custom compound index", async () => { }, ], }); - const execute = store.makeExecute(executeImplementation); + const execute = store.makeExecute(defaultExecuteImplementation); const document = parse(/* GraphQL */ ` query @live { diff --git a/packages/in-memory-live-query-store/src/InMemoryLiveQueryStore.ts b/packages/in-memory-live-query-store/src/InMemoryLiveQueryStore.ts index 63b6a872..12f3d858 100644 --- a/packages/in-memory-live-query-store/src/InMemoryLiveQueryStore.ts +++ b/packages/in-memory-live-query-store/src/InMemoryLiveQueryStore.ts @@ -143,14 +143,6 @@ export type InMemoryLiveQueryStoreParameter = { * This may be useful if you are using a relay compliant schema and the Typename information is not required for building a unique topic. * */ buildResourceIdentifier?: BuildResourceIdentifierFunction; - /** - * Function which is used for executing the operations. - * - * Uses the `execute` exported from graphql be default. - * - * @deprecated Please use the InMemoryStore.createExecute method instead. - * */ - execute?: typeof defaultExecute; /** * Whether the extensions should include a list of all resource identifiers for the latest operation result. * Any of those can be used for invalidating and re-scheduling the operation execution. @@ -188,7 +180,6 @@ export class InMemoryLiveQueryStore { private _resourceTracker = new ResourceTracker<() => void>(); private _schemaCache = new WeakMap(); private _buildResourceIdentifier = defaultResourceIdentifierNormalizer; - private _execute = defaultExecute; private _includeIdentifierExtension = false; private _idFieldName = "id"; private _validateThrottleValue: Maybe; @@ -198,9 +189,6 @@ export class InMemoryLiveQueryStore { if (params?.buildResourceIdentifier) { this._buildResourceIdentifier = params.buildResourceIdentifier; } - if (params?.execute) { - this._execute = params.execute; - } if (params?.idFieldName) { this._idFieldName = params.idFieldName; } @@ -329,15 +317,13 @@ export class InMemoryLiveQueryStore { run(); } - function dispose() { + onStop.then(function dispose() { cancelThrottle?.(); liveQueryStore._resourceTracker.release( scheduleRun, previousIdentifier ); - } - - onStop.then(dispose); + }); run = function run() { executionCounter = executionCounter + 1; @@ -429,9 +415,6 @@ export class InMemoryLiveQueryStore { }); }; - /** @deprecated Please use InMemoryLiveQueryStore.makeExecute instead. */ - execute = this.makeExecute(this._execute); - /** * Invalidate queries (and schedule their re-execution) via a resource identifier. * @param identifiers A single or list of resource identifiers that should be invalidated.