From 54ecce157debb44b08e3da81805c8cbcc2b41120 Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Tue, 2 Feb 2021 12:54:23 +0000 Subject: [PATCH 1/3] Remove deprecated operationName property from Operation --- exchanges/graphcache/src/operations/write.ts | 10 +++---- .../multipartFetchExchange.test.ts.snap | 5 ---- exchanges/refocus/src/refocusExchange.test.ts | 3 -- packages/core/src/client.test.ts | 3 -- .../__snapshots__/fetch.test.ts.snap | 3 -- .../__snapshots__/subscription.test.ts.snap | 1 - .../__snapshots__/fetchSource.test.ts.snap | 5 ---- packages/core/src/types.ts | 3 -- packages/core/src/utils/deprecation.test.ts | 29 ------------------- packages/core/src/utils/deprecation.ts | 29 ------------------- packages/core/src/utils/index.ts | 1 - packages/core/src/utils/operation.ts | 16 ---------- scripts/jest/setup.js | 10 ------- 13 files changed, 5 insertions(+), 113 deletions(-) delete mode 100644 packages/core/src/utils/deprecation.test.ts delete mode 100644 packages/core/src/utils/deprecation.ts diff --git a/exchanges/graphcache/src/operations/write.ts b/exchanges/graphcache/src/operations/write.ts index fbc4410501..2e2244e388 100644 --- a/exchanges/graphcache/src/operations/write.ts +++ b/exchanges/graphcache/src/operations/write.ts @@ -94,23 +94,23 @@ export const startWrite = ( ) => { const operation = getMainOperation(request.query); const result: WriteResult = { data, dependencies: getCurrentDependencies() }; - const operationName = store.rootFields[operation.operation]; + const kind = store.rootFields[operation.operation]; const ctx = makeContext( store, normalizeVariables(operation, request.variables), getFragments(request.query), - operationName, - operationName, + kind, + kind, !!isOptimistic, error ); if (process.env.NODE_ENV !== 'production') { - pushDebugNode(operationName, operation); + pushDebugNode(kind, operation); } - writeSelection(ctx, operationName, getSelectionSet(operation), data); + writeSelection(ctx, kind, getSelectionSet(operation), data); if (process.env.NODE_ENV !== 'production') { popDebugNode(); diff --git a/exchanges/multipart-fetch/src/__snapshots__/multipartFetchExchange.test.ts.snap b/exchanges/multipart-fetch/src/__snapshots__/multipartFetchExchange.test.ts.snap index d8a6ac5706..34b8d66608 100644 --- a/exchanges/multipart-fetch/src/__snapshots__/multipartFetchExchange.test.ts.snap +++ b/exchanges/multipart-fetch/src/__snapshots__/multipartFetchExchange.test.ts.snap @@ -15,7 +15,6 @@ Object { }, "key": 2, "kind": "query", - "operationName": "query", "query": Object { "__key": 3044551916, "definitions": Array [ @@ -185,7 +184,6 @@ Object { }, "key": 2, "kind": "query", - "operationName": "query", "query": Object { "__key": 3044551916, "definitions": Array [ @@ -357,7 +355,6 @@ Object { }, "key": 2, "kind": "query", - "operationName": "query", "query": Object { "__key": 3044551916, "definitions": Array [ @@ -531,7 +528,6 @@ Object { }, "key": 3, "kind": "mutation", - "operationName": "mutation", "query": Object { "__key": 3781860981, "definitions": Array [ @@ -681,7 +677,6 @@ Object { }, "key": 3, "kind": "mutation", - "operationName": "mutation", "query": Object { "__key": 1193185401, "definitions": Array [ diff --git a/exchanges/refocus/src/refocusExchange.test.ts b/exchanges/refocus/src/refocusExchange.test.ts index e90777d137..d8bbdf6474 100644 --- a/exchanges/refocus/src/refocusExchange.test.ts +++ b/exchanges/refocus/src/refocusExchange.test.ts @@ -88,8 +88,5 @@ it(`attaches a listener and redispatches queries on call`, () => { key: 1, query: queryOne, kind: 'query', - - // TODO: Remove this when the deprecated "operationName" property is removed - operationName: 'query', }); }); diff --git a/packages/core/src/client.test.ts b/packages/core/src/client.test.ts index 809db44da4..5336ebd329 100755 --- a/packages/core/src/client.test.ts +++ b/packages/core/src/client.test.ts @@ -151,9 +151,6 @@ describe('synchronous methods', () => { context: expect.anything(), key: expect.any(Number), kind: 'query', - - // TODO: Remove this when the deprecated `operationName` property is removed - operationName: 'query', }, }); }); diff --git a/packages/core/src/exchanges/__snapshots__/fetch.test.ts.snap b/packages/core/src/exchanges/__snapshots__/fetch.test.ts.snap index f0691c4eed..6d1d342c08 100644 --- a/packages/core/src/exchanges/__snapshots__/fetch.test.ts.snap +++ b/packages/core/src/exchanges/__snapshots__/fetch.test.ts.snap @@ -15,7 +15,6 @@ Object { }, "key": 2, "kind": "query", - "operationName": "query", "query": Object { "__key": 3044551916, "definitions": Array [ @@ -185,7 +184,6 @@ Object { }, "key": 2, "kind": "query", - "operationName": "query", "query": Object { "__key": 3044551916, "definitions": Array [ @@ -357,7 +355,6 @@ Object { }, "key": 2, "kind": "query", - "operationName": "query", "query": Object { "__key": 3044551916, "definitions": Array [ diff --git a/packages/core/src/exchanges/__snapshots__/subscription.test.ts.snap b/packages/core/src/exchanges/__snapshots__/subscription.test.ts.snap index 53c422fa55..864ba6fcd3 100644 --- a/packages/core/src/exchanges/__snapshots__/subscription.test.ts.snap +++ b/packages/core/src/exchanges/__snapshots__/subscription.test.ts.snap @@ -15,7 +15,6 @@ Object { }, "key": 4, "kind": "subscription", - "operationName": "subscription", "query": Object { "__key": 2616620656, "definitions": Array [ diff --git a/packages/core/src/internal/__snapshots__/fetchSource.test.ts.snap b/packages/core/src/internal/__snapshots__/fetchSource.test.ts.snap index 994af45bf0..2dbf72aea2 100644 --- a/packages/core/src/internal/__snapshots__/fetchSource.test.ts.snap +++ b/packages/core/src/internal/__snapshots__/fetchSource.test.ts.snap @@ -15,7 +15,6 @@ Object { }, "key": 2, "kind": "query", - "operationName": "query", "query": Object { "__key": 3044551916, "definitions": Array [ @@ -175,7 +174,6 @@ Object { }, "key": 2, "kind": "query", - "operationName": "query", "query": Object { "__key": 3044551916, "definitions": Array [ @@ -335,7 +333,6 @@ Object { }, "key": 2, "kind": "query", - "operationName": "query", "query": Object { "__key": 3044551916, "definitions": Array [ @@ -499,7 +496,6 @@ Object { }, "key": 2, "kind": "query", - "operationName": "query", "query": Object { "__key": 3044551916, "definitions": Array [ @@ -679,7 +675,6 @@ Object { }, "key": 2, "kind": "query", - "operationName": "query", "query": Object { "__key": 3044551916, "definitions": Array [ diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index 2aea604ad6..a61dea9c32 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -57,9 +57,6 @@ export interface Operation extends GraphQLRequest { readonly kind: OperationType; context: OperationContext; - - /** @deprecated use Operation.kind instead */ - readonly operationName: OperationType; } /** Resulting data from an [operation]{@link Operation}. */ diff --git a/packages/core/src/utils/deprecation.test.ts b/packages/core/src/utils/deprecation.test.ts deleted file mode 100644 index 89c0da4e71..0000000000 --- a/packages/core/src/utils/deprecation.test.ts +++ /dev/null @@ -1,29 +0,0 @@ -jest.unmock('./deprecation.ts'); - -import { _clearWarnings, deprecationWarning } from './deprecation'; - -describe('deprecationWarning()', () => { - let warn: jest.SpyInstance; - - const key = 'deprecation.test'; - const message = 'Test deprecation message.'; - - beforeAll(() => { - warn = jest.spyOn(console, 'warn'); - }); - - afterEach(_clearWarnings); - - afterAll(() => { - warn.mockRestore(); - }); - - it('only calls console.warn once per key', () => { - deprecationWarning({ key, message }); - deprecationWarning({ key, message }); - deprecationWarning({ key, message }); - - expect(warn).toBeCalledTimes(1); - expect(warn).toBeCalledWith(`[WARNING: Deprecated] ${message}`); - }); -}); diff --git a/packages/core/src/utils/deprecation.ts b/packages/core/src/utils/deprecation.ts deleted file mode 100644 index f1abf4e88e..0000000000 --- a/packages/core/src/utils/deprecation.ts +++ /dev/null @@ -1,29 +0,0 @@ -export interface Warning { - key: string; - message: string; -} - -/** - * Module-scoped state to track if deprecation warnings have already been issued - * for a particular key. - */ -let issuedWarnings: Record = {}; - -/** - * If a deprecation warning has not already been issued, use `console.warn()` to - * issue it with an eye-catching prefix string. - */ -export const deprecationWarning = ({ key, message }: Warning) => { - if (!issuedWarnings[key]) { - console.warn(`[WARNING: Deprecated] ${message}`); - - issuedWarnings[key] = true; - } -}; - -/** - * Clears all issued warnings - intended for use in testing. - */ -export const _clearWarnings = () => { - issuedWarnings = {}; -}; diff --git a/packages/core/src/utils/index.ts b/packages/core/src/utils/index.ts index ee2437c463..bba813b8fe 100644 --- a/packages/core/src/utils/index.ts +++ b/packages/core/src/utils/index.ts @@ -6,7 +6,6 @@ export * from './stringifyVariables'; export * from './maskTypename'; export * from './withPromise'; export * from './operation'; -export * from './deprecation'; export const noop = () => { /* noop */ diff --git a/packages/core/src/utils/operation.ts b/packages/core/src/utils/operation.ts index 70a7bdfef9..78eb157c84 100644 --- a/packages/core/src/utils/operation.ts +++ b/packages/core/src/utils/operation.ts @@ -4,16 +4,6 @@ import { OperationContext, OperationType, } from '../types'; -import { Warning, deprecationWarning } from './deprecation'; - -// TODO: Remove when the deprecated `operationName` property is removed -const DEPRECATED: Record = { - operationName: { - key: 'Operation.operationName', - message: - 'The "Operation.operationName" property has been deprecated and will be removed in a future release of urql. Use "Operation.kind" instead.', - }, -}; function makeOperation( kind: OperationType, @@ -36,12 +26,6 @@ function makeOperation(kind, request, context) { variables: request.variables, kind, context, - - get operationName(): OperationType { - deprecationWarning(DEPRECATED.operationName); - - return this.kind; - }, }; } diff --git a/scripts/jest/setup.js b/scripts/jest/setup.js index ab9c0181d4..78436ea7e0 100644 --- a/scripts/jest/setup.js +++ b/scripts/jest/setup.js @@ -17,13 +17,3 @@ global.console = { jest.spyOn(console, 'log'); jest.spyOn(console, 'warn'); jest.spyOn(console, 'error'); - -jest.mock('../../packages/core/src/utils/deprecation.ts', () => ({ - deprecationWarning({ message }) { - const error = new Error(`Deprecation Warnings are thrown in tests.\n${message}`); - if (!/jest-snapshot|pretty-format|jest-jasmine2/i.test(error.stack)) { - throw error; - } - }, - _clearWarnings() {}, -})); From 7854f8e741a6ec61a37c109d82042794f8c3e05c Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Tue, 2 Feb 2021 12:55:58 +0000 Subject: [PATCH 2/3] Add changeset --- .changeset/plenty-carrots-prove.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/plenty-carrots-prove.md diff --git a/.changeset/plenty-carrots-prove.md b/.changeset/plenty-carrots-prove.md new file mode 100644 index 0000000000..c344809b7c --- /dev/null +++ b/.changeset/plenty-carrots-prove.md @@ -0,0 +1,6 @@ +--- +'@urql/core': major +--- + +Remove deprecated `operationName` property from `Operation`s. The new `Operation.kind` property is now preferred. If you're creating new operations you may also use the `makeOperation` utility instead. +When upgrading `@urql/core` please ensure that your package manager didn't install any duplicates of it. You may deduplicate it manually using `npx yarn-deduplicate` (for Yarn) or `npm dedupe` (for npm). From adba18368ee75051b039c98da713aa6fe3d9d171 Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Tue, 9 Feb 2021 11:05:42 +0000 Subject: [PATCH 3/3] Bump bindings by minor to adopt new major @urql/core --- .changeset/plenty-carrots-prove.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.changeset/plenty-carrots-prove.md b/.changeset/plenty-carrots-prove.md index c344809b7c..9cb1a292d4 100644 --- a/.changeset/plenty-carrots-prove.md +++ b/.changeset/plenty-carrots-prove.md @@ -1,5 +1,9 @@ --- '@urql/core': major +'@urql/preact': minor +'@urql/svelte': minor +'@urql/vue': minor +'urql': minor --- Remove deprecated `operationName` property from `Operation`s. The new `Operation.kind` property is now preferred. If you're creating new operations you may also use the `makeOperation` utility instead.