From 4a8f1c3a37e56d321890778b69f0e9ba8d72c433 Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Mon, 12 Jul 2021 12:56:19 -0400 Subject: [PATCH 1/3] Update to ts-invariant@0.9.0 for invariant.debug. --- config/processInvariants.ts | 2 +- package-lock.json | 13 +++---------- package.json | 2 +- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/config/processInvariants.ts b/config/processInvariants.ts index 0a26a01e9ee..6227acd5840 100644 --- a/config/processInvariants.ts +++ b/config/processInvariants.ts @@ -90,7 +90,7 @@ function transform(code: string, file: string) { if (node.callee.type === "MemberExpression" && isIdWithName(node.callee.object, "invariant") && - isIdWithName(node.callee.property, "log", "warn", "error")) { + isIdWithName(node.callee.property, "debug", "log", "warn", "error")) { if (isDEVLogicalAnd(path.parent.node)) { return; } diff --git a/package-lock.json b/package-lock.json index 4e01e0cc72e..304f39655a7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9075,18 +9075,11 @@ } }, "ts-invariant": { - "version": "0.8.2", - "resolved": "https://registry.npmjs.org/ts-invariant/-/ts-invariant-0.8.2.tgz", - "integrity": "sha512-VI1ZSMW8soizP5dU8DsMbj/TncHf7bIUqavuE7FTeYeQat454HHurJ8wbfCnVWcDOMkyiBUWOW2ytew3xUxlRw==", + "version": "0.9.0", + "resolved": "https://registry.npmjs.org/ts-invariant/-/ts-invariant-0.9.0.tgz", + "integrity": "sha512-+JqhKqywk+ue5JjAC6eTWe57mOIxYXypMUkBDStkAzvnlfkDJ1KGyeMuNRMwOt6GXzHSC1UT9JecowpZDmgXqA==", "requires": { "tslib": "^2.1.0" - }, - "dependencies": { - "tslib": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.0.tgz", - "integrity": "sha512-N82ooyxVNm6h1riLCoyS9e3fuJ3AMG2zIZs2Gd1ATcSFjSA23Q0fzjjZeh0jbJvWVDZ0cJT8yaNNaaXHzueNjg==" - } } }, "ts-jest": { diff --git a/package.json b/package.json index 2ce94e66e24..3a2498cb88b 100644 --- a/package.json +++ b/package.json @@ -81,7 +81,7 @@ "optimism": "^0.16.1", "prop-types": "^15.7.2", "symbol-observable": "^4.0.0", - "ts-invariant": "^0.8.2", + "ts-invariant": "^0.9.0", "tslib": "^2.1.0", "zen-observable-ts": "^1.1.0" }, From 2d89e227329bcbfb5118dba6e994a3a4dba2bfe8 Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Mon, 12 Jul 2021 12:57:34 -0400 Subject: [PATCH 2/3] Make 'Missing cache result fields...' warnings less noisy. https://github.com/apollographql/apollo-client/issues/8442#issuecomment-878418870 --- src/core/QueryManager.ts | 2 +- src/core/__tests__/QueryManager/index.ts | 11 +++-------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/core/QueryManager.ts b/src/core/QueryManager.ts index 22221e5055f..a30d1028555 100644 --- a/src/core/QueryManager.ts +++ b/src/core/QueryManager.ts @@ -1349,7 +1349,7 @@ export class QueryManager { isNonEmptyArray(diff.missing) && !equal(data, {}) && !returnPartialData) { - invariant.warn(`Missing cache result fields: ${ + invariant.debug(`Missing cache result fields: ${ diff.missing.map(m => m.path.join('.')).join(', ') }`, diff.missing); } diff --git a/src/core/__tests__/QueryManager/index.ts b/src/core/__tests__/QueryManager/index.ts index 8c30b7ced94..035e0b6acc7 100644 --- a/src/core/__tests__/QueryManager/index.ts +++ b/src/core/__tests__/QueryManager/index.ts @@ -1350,7 +1350,6 @@ describe('QueryManager', () => { }); itAsync('supports cache-only fetchPolicy fetching only cached data', (resolve, reject) => { - const spy = jest.spyOn(console, "warn").mockImplementation(); const primeQuery = gql` query primeQuery { luke: people_one(id: 1) { @@ -1395,13 +1394,9 @@ describe('QueryManager', () => { return handle.result().then(result => { expect(result.data['luke'].name).toBe('Luke Skywalker'); expect(result.data).not.toHaveProperty('vader'); - expect(spy).toHaveBeenCalledTimes(1); }); }) - .finally(() => { - spy.mockRestore(); - }) - .then(resolve, reject) + .then(resolve, reject); }); itAsync('runs a mutation', (resolve, reject) => { @@ -5785,8 +5780,8 @@ describe('QueryManager', () => { let verbosity: ReturnType; let spy: any; beforeEach(() => { - verbosity = setVerbosity("warn"); - spy = jest.spyOn(console, "warn").mockImplementation(); + verbosity = setVerbosity("debug"); + spy = jest.spyOn(console, "debug").mockImplementation(); }); afterEach(() => { From 431ce2af503b8403606f5fa1b9df3cdae3d05189 Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Mon, 12 Jul 2021 13:11:24 -0400 Subject: [PATCH 3/3] Mention PR #8489 in CHANGELOG.md. --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ac9171a2e77..a703649e049 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -109,6 +109,9 @@ - The `InMemoryCache` version of the `cache.gc` method now supports additional options for removing non-essential (recomputable) result caching data.
[@benjamn](https://github.com/benjamn) in [#8421](https://github.com/apollographql/apollo-client/pull/8421) +- Suppress noisy `Missing cache result fields...` warnings by default unless `setLogVerbosity("debug")` called.
+ [@benjamn](https://github.com/benjamn) in [#8489](https://github.com/apollographql/apollo-client/pull/8489) + ### Documentation TBD