Mirror: The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

(core) - Remove deprecated operationName property from Operations (#1357)

* Remove deprecated operationName property from Operation

* Add changeset

* Bump bindings by minor to adopt new major @urql/core

authored by

Phil Pluckthun and committed by
GitHub
9a1f1239 97689ff9

+15 -113
+10
.changeset/plenty-carrots-prove.md
··· 1 + --- 2 + '@urql/core': major 3 + '@urql/preact': minor 4 + '@urql/svelte': minor 5 + '@urql/vue': minor 6 + 'urql': minor 7 + --- 8 + 9 + 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. 10 + 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).
+5 -5
exchanges/graphcache/src/operations/write.ts
··· 94 94 ) => { 95 95 const operation = getMainOperation(request.query); 96 96 const result: WriteResult = { data, dependencies: getCurrentDependencies() }; 97 - const operationName = store.rootFields[operation.operation]; 97 + const kind = store.rootFields[operation.operation]; 98 98 99 99 const ctx = makeContext( 100 100 store, 101 101 normalizeVariables(operation, request.variables), 102 102 getFragments(request.query), 103 - operationName, 104 - operationName, 103 + kind, 104 + kind, 105 105 !!isOptimistic, 106 106 error 107 107 ); 108 108 109 109 if (process.env.NODE_ENV !== 'production') { 110 - pushDebugNode(operationName, operation); 110 + pushDebugNode(kind, operation); 111 111 } 112 112 113 - writeSelection(ctx, operationName, getSelectionSet(operation), data); 113 + writeSelection(ctx, kind, getSelectionSet(operation), data); 114 114 115 115 if (process.env.NODE_ENV !== 'production') { 116 116 popDebugNode();
-5
exchanges/multipart-fetch/src/__snapshots__/multipartFetchExchange.test.ts.snap
··· 15 15 }, 16 16 "key": 2, 17 17 "kind": "query", 18 - "operationName": "query", 19 18 "query": Object { 20 19 "__key": 3044551916, 21 20 "definitions": Array [ ··· 185 184 }, 186 185 "key": 2, 187 186 "kind": "query", 188 - "operationName": "query", 189 187 "query": Object { 190 188 "__key": 3044551916, 191 189 "definitions": Array [ ··· 357 355 }, 358 356 "key": 2, 359 357 "kind": "query", 360 - "operationName": "query", 361 358 "query": Object { 362 359 "__key": 3044551916, 363 360 "definitions": Array [ ··· 531 528 }, 532 529 "key": 3, 533 530 "kind": "mutation", 534 - "operationName": "mutation", 535 531 "query": Object { 536 532 "__key": 3781860981, 537 533 "definitions": Array [ ··· 681 677 }, 682 678 "key": 3, 683 679 "kind": "mutation", 684 - "operationName": "mutation", 685 680 "query": Object { 686 681 "__key": 1193185401, 687 682 "definitions": Array [
-3
exchanges/refocus/src/refocusExchange.test.ts
··· 88 88 key: 1, 89 89 query: queryOne, 90 90 kind: 'query', 91 - 92 - // TODO: Remove this when the deprecated "operationName" property is removed 93 - operationName: 'query', 94 91 }); 95 92 });
-3
packages/core/src/client.test.ts
··· 151 151 context: expect.anything(), 152 152 key: expect.any(Number), 153 153 kind: 'query', 154 - 155 - // TODO: Remove this when the deprecated `operationName` property is removed 156 - operationName: 'query', 157 154 }, 158 155 }); 159 156 });
-3
packages/core/src/exchanges/__snapshots__/fetch.test.ts.snap
··· 15 15 }, 16 16 "key": 2, 17 17 "kind": "query", 18 - "operationName": "query", 19 18 "query": Object { 20 19 "__key": 3044551916, 21 20 "definitions": Array [ ··· 185 184 }, 186 185 "key": 2, 187 186 "kind": "query", 188 - "operationName": "query", 189 187 "query": Object { 190 188 "__key": 3044551916, 191 189 "definitions": Array [ ··· 357 355 }, 358 356 "key": 2, 359 357 "kind": "query", 360 - "operationName": "query", 361 358 "query": Object { 362 359 "__key": 3044551916, 363 360 "definitions": Array [
-1
packages/core/src/exchanges/__snapshots__/subscription.test.ts.snap
··· 15 15 }, 16 16 "key": 4, 17 17 "kind": "subscription", 18 - "operationName": "subscription", 19 18 "query": Object { 20 19 "__key": 2616620656, 21 20 "definitions": Array [
-5
packages/core/src/internal/__snapshots__/fetchSource.test.ts.snap
··· 15 15 }, 16 16 "key": 2, 17 17 "kind": "query", 18 - "operationName": "query", 19 18 "query": Object { 20 19 "__key": 3044551916, 21 20 "definitions": Array [ ··· 175 174 }, 176 175 "key": 2, 177 176 "kind": "query", 178 - "operationName": "query", 179 177 "query": Object { 180 178 "__key": 3044551916, 181 179 "definitions": Array [ ··· 335 333 }, 336 334 "key": 2, 337 335 "kind": "query", 338 - "operationName": "query", 339 336 "query": Object { 340 337 "__key": 3044551916, 341 338 "definitions": Array [ ··· 499 496 }, 500 497 "key": 2, 501 498 "kind": "query", 502 - "operationName": "query", 503 499 "query": Object { 504 500 "__key": 3044551916, 505 501 "definitions": Array [ ··· 679 675 }, 680 676 "key": 2, 681 677 "kind": "query", 682 - "operationName": "query", 683 678 "query": Object { 684 679 "__key": 3044551916, 685 680 "definitions": Array [
-3
packages/core/src/types.ts
··· 57 57 extends GraphQLRequest<Data, Variables> { 58 58 readonly kind: OperationType; 59 59 context: OperationContext; 60 - 61 - /** @deprecated use Operation.kind instead */ 62 - readonly operationName: OperationType; 63 60 } 64 61 65 62 /** Resulting data from an [operation]{@link Operation}. */
-29
packages/core/src/utils/deprecation.test.ts
··· 1 - jest.unmock('./deprecation.ts'); 2 - 3 - import { _clearWarnings, deprecationWarning } from './deprecation'; 4 - 5 - describe('deprecationWarning()', () => { 6 - let warn: jest.SpyInstance; 7 - 8 - const key = 'deprecation.test'; 9 - const message = 'Test deprecation message.'; 10 - 11 - beforeAll(() => { 12 - warn = jest.spyOn(console, 'warn'); 13 - }); 14 - 15 - afterEach(_clearWarnings); 16 - 17 - afterAll(() => { 18 - warn.mockRestore(); 19 - }); 20 - 21 - it('only calls console.warn once per key', () => { 22 - deprecationWarning({ key, message }); 23 - deprecationWarning({ key, message }); 24 - deprecationWarning({ key, message }); 25 - 26 - expect(warn).toBeCalledTimes(1); 27 - expect(warn).toBeCalledWith(`[WARNING: Deprecated] ${message}`); 28 - }); 29 - });
-29
packages/core/src/utils/deprecation.ts
··· 1 - export interface Warning { 2 - key: string; 3 - message: string; 4 - } 5 - 6 - /** 7 - * Module-scoped state to track if deprecation warnings have already been issued 8 - * for a particular key. 9 - */ 10 - let issuedWarnings: Record<string, boolean> = {}; 11 - 12 - /** 13 - * If a deprecation warning has not already been issued, use `console.warn()` to 14 - * issue it with an eye-catching prefix string. 15 - */ 16 - export const deprecationWarning = ({ key, message }: Warning) => { 17 - if (!issuedWarnings[key]) { 18 - console.warn(`[WARNING: Deprecated] ${message}`); 19 - 20 - issuedWarnings[key] = true; 21 - } 22 - }; 23 - 24 - /** 25 - * Clears all issued warnings - intended for use in testing. 26 - */ 27 - export const _clearWarnings = () => { 28 - issuedWarnings = {}; 29 - };
-1
packages/core/src/utils/index.ts
··· 6 6 export * from './maskTypename'; 7 7 export * from './withPromise'; 8 8 export * from './operation'; 9 - export * from './deprecation'; 10 9 11 10 export const noop = () => { 12 11 /* noop */
-16
packages/core/src/utils/operation.ts
··· 4 4 OperationContext, 5 5 OperationType, 6 6 } from '../types'; 7 - import { Warning, deprecationWarning } from './deprecation'; 8 - 9 - // TODO: Remove when the deprecated `operationName` property is removed 10 - const DEPRECATED: Record<string, Warning> = { 11 - operationName: { 12 - key: 'Operation.operationName', 13 - message: 14 - 'The "Operation.operationName" property has been deprecated and will be removed in a future release of urql. Use "Operation.kind" instead.', 15 - }, 16 - }; 17 7 18 8 function makeOperation<Data = any, Variables = object>( 19 9 kind: OperationType, ··· 36 26 variables: request.variables, 37 27 kind, 38 28 context, 39 - 40 - get operationName(): OperationType { 41 - deprecationWarning(DEPRECATED.operationName); 42 - 43 - return this.kind; 44 - }, 45 29 }; 46 30 } 47 31
-10
scripts/jest/setup.js
··· 17 17 jest.spyOn(console, 'log'); 18 18 jest.spyOn(console, 'warn'); 19 19 jest.spyOn(console, 'error'); 20 - 21 - jest.mock('../../packages/core/src/utils/deprecation.ts', () => ({ 22 - deprecationWarning({ message }) { 23 - const error = new Error(`Deprecation Warnings are thrown in tests.\n${message}`); 24 - if (!/jest-snapshot|pretty-format|jest-jasmine2/i.test(error.stack)) { 25 - throw error; 26 - } 27 - }, 28 - _clearWarnings() {}, 29 - }));