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.

refactor(core): Remove getOperationName helper from @urql/core (#3062)

authored by

Phil Pluckthun and committed by
GitHub
557ee4eb c2c1328e

+25 -10
+5
.changeset/quick-seahorses-cross.md
··· 1 + --- 2 + '@urql/core': patch 3 + --- 4 + 5 + Fix incorrect operation name being picked from queries that contain multiple operations.
+6
.changeset/young-lamps-help.md
··· 1 + --- 2 + '@urql/core': major 3 + '@urql/exchange-execute': minor 4 + --- 5 + 6 + Remove `getOperationName` export from `@urql/core`
+2 -5
exchanges/execute/src/execute.test.ts
··· 33 33 makeErrorResult, 34 34 makeOperation, 35 35 Client, 36 - getOperationName, 37 36 OperationResult, 38 37 } from '@urql/core'; 39 38 ··· 45 44 client: {}, 46 45 } as any; 47 46 48 - const expectedQueryOperationName = getOperationName(queryOperation.query); 49 - const expectedSubscribeOperationName = getOperationName( 50 - subscriptionOperation.query 51 - ); 47 + const expectedQueryOperationName = 'getUser'; 48 + const expectedSubscribeOperationName = 'subscribeToUser'; 52 49 53 50 const fetchMock = (global as any).fetch as Mock; 54 51 const mockHttpResponseData = { key: 'value' };
+10 -2
exchanges/execute/src/execute.ts
··· 17 17 subscribe, 18 18 ExecutionArgs, 19 19 SubscriptionArgs, 20 + Kind, 20 21 } from 'graphql'; 21 22 22 23 import { ··· 27 28 mergeResultPatch, 28 29 Operation, 29 30 OperationResult, 30 - getOperationName, 31 31 } from '@urql/core'; 32 32 33 33 export interface ExecuteExchangeArgs { ··· 150 150 } 151 151 } 152 152 153 + let operationName: string | undefined; 154 + for (const node of operation.query.definitions) { 155 + if (node.kind === Kind.OPERATION_DEFINITION) { 156 + operationName = node.name ? node.name.value : undefined; 157 + break; 158 + } 159 + } 160 + 153 161 return pipe( 154 162 makeExecuteSource(operation, { 155 163 schema, ··· 157 165 rootValue, 158 166 contextValue, 159 167 variableValues, 160 - operationName: getOperationName(operation.query), 168 + operationName, 161 169 fieldResolver, 162 170 typeResolver, 163 171 subscribeFieldResolver,
-1
packages/core/src/index.ts
··· 14 14 formatDocument, 15 15 maskTypename, 16 16 makeOperation, 17 - getOperationName, 18 17 } from './utils';
+2 -2
packages/core/src/utils/request.ts
··· 169 169 */ 170 170 export const getOperationName = (query: DocumentNode): string | undefined => { 171 171 for (const node of query.definitions) { 172 - if (node.kind === Kind.OPERATION_DEFINITION && node.name) { 173 - return node.name.value; 172 + if (node.kind === Kind.OPERATION_DEFINITION) { 173 + return node.name ? node.name.value : undefined; 174 174 } 175 175 } 176 176 };