Skip to content

Commit

Permalink
fix(in-memory-live-query-store): use execute provided to makeExecute (#…
Browse files Browse the repository at this point in the history
…752)

* fix(in-memory-live-query-store): use execute provided to makeExecute

* refactor: omit  function alias assignment

* chore: add changeset

Co-authored-by: ben-pr-p <ben.paul.ryan.packer@gmail.com>
  • Loading branch information
n1ru4l and ben-pr-p authored Oct 23, 2021
1 parent 108970b commit cf552ec
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .changeset/odd-years-sniff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@n1ru4l/in-memory-live-query-store": patch
---

use the correct `execute` function for executing live queries.

When using the `InMemoryLiveQueryStore.makeExecute` API the returned function did not properly use the provided `execute` function. Instead the `execute` function provided to the `InMemoryLiveQueryStore` constructor was used. This issue caused unexpected behavior when using this library with envelop.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
GraphQLSchema,
GraphQLString,
parse,
execute,
} from "graphql";
import { InMemoryLiveQueryStore } from "./InMemoryLiveQueryStore";

Expand Down Expand Up @@ -792,3 +793,33 @@ it("can override the throttle interval by returning a number from validateThrott
executionResult.return!();
await done;
});

it("makeExecute calls the execute it is passed to resolve live queries", async () => {
const schema = createTestSchema();

const document = parse(/* GraphQL */ `
query foo @live {
foo
}
`);

const executePassedAtInitializationTime = jest.fn();
executePassedAtInitializationTime.mockImplementation((args) => execute(args));

const executePassedToMakeExecute = jest.fn();
executePassedToMakeExecute.mockImplementation((args) => execute(args));

const store = new InMemoryLiveQueryStore({
execute: executePassedAtInitializationTime,
});

const makeExecuteFn = store.makeExecute(executePassedToMakeExecute);

makeExecuteFn({
schema,
document,
});

expect(executePassedAtInitializationTime).not.toHaveBeenCalled();
expect(executePassedToMakeExecute).toHaveBeenCalled();
});
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ export class InMemoryLiveQueryStore {
}
};

const result = this._execute({
const result = execute({
schema,
document,
operationName,
Expand Down

0 comments on commit cf552ec

Please sign in to comment.