@zendesk/laika
Version:
Test, mock, intercept and modify Apollo Client's operations — in both browser and unit tests!
15 lines • 1.07 kB
JavaScript
import { print } from 'graphql';
const checkOperationType = (definitions, type) => definitions.some((element) => element.kind === 'OperationDefinition' && element.operation === type);
export const hasSubscriptionOperation = (
/** @type {Operation} */ { query }) => checkOperationType(query.definitions, 'subscription');
export const hasMutationOperation = (
/** @type {Operation} */ { query }) => checkOperationType(query.definitions, 'mutation');
export const hasQueryOperation = (
/** @type {Operation} */ { query }) => checkOperationType(query.definitions, 'query');
export const getOperationNameFromDocument = (document) => {
var _a, _b;
return (_b = (_a = document.definitions.find((definition) => definition.kind === 'OperationDefinition')) === null || _a === void 0 ? void 0 : _a.name) === null || _b === void 0 ? void 0 : _b.value;
};
export const matchesOperationDocument = (operationDocument, matcherDocument) => operationDocument === matcherDocument ||
print(operationDocument) === print(matcherDocument);
//# sourceMappingURL=hasOperation.js.map