From 477243fc2c5c72cb2f50b984a7f9db1daebd9aed Mon Sep 17 00:00:00 2001 From: William Chargin Date: Sat, 29 Feb 2020 16:56:20 -0800 Subject: [PATCH] mirror: add typename support to query plan (#1663) Summary: The internal `QueryPlan` structure now lists IDs of objects whose typename is to be queried. This list is expected to be empty for now. Test Plan: Unit tests included. wchargin-branch: mirror-typename-queryplan --- src/graphql/mirror.js | 9 ++++++++- src/graphql/mirror.test.js | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/graphql/mirror.js b/src/graphql/mirror.js index 3a2f069..f5d9302 100644 --- a/src/graphql/mirror.js +++ b/src/graphql/mirror.js @@ -536,6 +536,9 @@ export class Mirror { _findOutdated(since: Date): QueryPlan { const db = this._db; return _inTransaction(db, () => { + // All objects must have recorded typenames due to the `NOT NULL` + // constraint on `typename` column of the `objects` table. + const typenames: $PropertyType = []; const objects: $PropertyType = db .prepare( dedent`\ @@ -575,7 +578,7 @@ export class Mirror { delete result.neverUpdated; return result; }); - return {objects, connections}; + return {typenames, objects, connections}; }); } @@ -605,6 +608,9 @@ export class Mirror { +connectionPageSize: number, |} ): Queries.Selection[] { + if (queryPlan.typenames.length > 0) { + throw new Error("Typename queries not yet supported"); + } // Group objects by type, so that we have to specify each type's // fieldset fewer times (only once per `nodesOfTypeLimit` nodes // instead of for every node). @@ -2051,6 +2057,7 @@ type NetworkLogId = number; * A set of objects and connections that should be updated. */ type QueryPlan = {| + +typenames: $ReadOnlyArray, +objects: $ReadOnlyArray<{| +typename: Schema.Typename, +id: Schema.ObjectId, diff --git a/src/graphql/mirror.test.js b/src/graphql/mirror.test.js index 38f7522..f359934 100644 --- a/src/graphql/mirror.test.js +++ b/src/graphql/mirror.test.js @@ -566,6 +566,7 @@ describe("graphql/mirror", () => { const actual = mirror._findOutdated(new Date(midUpdate.time)); const expected = { + typenames: [], objects: [ {typename: "Repository", id: "repo:ab/cd"}, // loaded before cutoff // issue:ab/cd#1 was loaded after the cutoff @@ -608,6 +609,7 @@ describe("graphql/mirror", () => { const db = new Database(":memory:"); const mirror = new Mirror(db, buildGithubSchema()); const plan = { + typenames: [], objects: [], connections: [ { @@ -636,10 +638,28 @@ describe("graphql/mirror", () => { '"Issue" vs. "Repository"' ); }); + it("errors if given any typename requests", () => { + const db = new Database(":memory:"); + const mirror = new Mirror(db, buildGithubSchema()); + const plan = { + typenames: ["hmmm"], + objects: [], + connections: [], + }; + expect(() => { + mirror._queryFromPlan(plan, { + nodesLimit: 10, + nodesOfTypeLimit: 5, + connectionLimit: 5, + connectionPageSize: 23, + }); + }).toThrow("Typename queries not yet supported"); + }); it("creates a good query", () => { const db = new Database(":memory:"); const mirror = new Mirror(db, buildGithubSchema()); const plan = { + typenames: [], objects: [ {typename: "Issue", id: "i#1"}, {typename: "Repository", id: "repo#2"}, @@ -1136,6 +1156,7 @@ describe("graphql/mirror", () => { spyFindOutdated.mock.results[1].value ); expect(spyFindOutdated.mock.results[2].value).toEqual({ + typenames: [], objects: [], connections: [], });