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

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

Changed files
+25 -10
.changeset
exchanges
packages
core
src
+5
.changeset/quick-seahorses-cross.md
···
+
---
+
'@urql/core': patch
+
---
+
+
Fix incorrect operation name being picked from queries that contain multiple operations.
+6
.changeset/young-lamps-help.md
···
+
---
+
'@urql/core': major
+
'@urql/exchange-execute': minor
+
---
+
+
Remove `getOperationName` export from `@urql/core`
+2 -5
exchanges/execute/src/execute.test.ts
···
makeErrorResult,
makeOperation,
Client,
-
getOperationName,
OperationResult,
} from '@urql/core';
···
client: {},
} as any;
-
const expectedQueryOperationName = getOperationName(queryOperation.query);
-
const expectedSubscribeOperationName = getOperationName(
-
subscriptionOperation.query
-
);
+
const expectedQueryOperationName = 'getUser';
+
const expectedSubscribeOperationName = 'subscribeToUser';
const fetchMock = (global as any).fetch as Mock;
const mockHttpResponseData = { key: 'value' };
+10 -2
exchanges/execute/src/execute.ts
···
subscribe,
ExecutionArgs,
SubscriptionArgs,
+
Kind,
} from 'graphql';
import {
···
mergeResultPatch,
Operation,
OperationResult,
-
getOperationName,
} from '@urql/core';
export interface ExecuteExchangeArgs {
···
}
}
+
let operationName: string | undefined;
+
for (const node of operation.query.definitions) {
+
if (node.kind === Kind.OPERATION_DEFINITION) {
+
operationName = node.name ? node.name.value : undefined;
+
break;
+
}
+
}
+
return pipe(
makeExecuteSource(operation, {
schema,
···
rootValue,
contextValue,
variableValues,
-
operationName: getOperationName(operation.query),
+
operationName,
fieldResolver,
typeResolver,
subscribeFieldResolver,
-1
packages/core/src/index.ts
···
formatDocument,
maskTypename,
makeOperation,
-
getOperationName,
} from './utils';
+2 -2
packages/core/src/utils/request.ts
···
*/
export const getOperationName = (query: DocumentNode): string | undefined => {
for (const node of query.definitions) {
-
if (node.kind === Kind.OPERATION_DEFINITION && node.name) {
-
return node.name.value;
+
if (node.kind === Kind.OPERATION_DEFINITION) {
+
return node.name ? node.name.value : undefined;
}
}
};