@zendesk/laika
Version:
Test, mock, intercept and modify Apollo Client's operations — in both browser and unit tests!
23 lines • 1.61 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.matchesOperationDocument = exports.getOperationNameFromDocument = exports.hasQueryOperation = exports.hasMutationOperation = exports.hasSubscriptionOperation = void 0;
const graphql_1 = require("graphql");
const checkOperationType = (definitions, type) => definitions.some((element) => element.kind === 'OperationDefinition' && element.operation === type);
const hasSubscriptionOperation = (
/** @type {Operation} */ { query }) => checkOperationType(query.definitions, 'subscription');
exports.hasSubscriptionOperation = hasSubscriptionOperation;
const hasMutationOperation = (
/** @type {Operation} */ { query }) => checkOperationType(query.definitions, 'mutation');
exports.hasMutationOperation = hasMutationOperation;
const hasQueryOperation = (
/** @type {Operation} */ { query }) => checkOperationType(query.definitions, 'query');
exports.hasQueryOperation = hasQueryOperation;
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;
};
exports.getOperationNameFromDocument = getOperationNameFromDocument;
const matchesOperationDocument = (operationDocument, matcherDocument) => operationDocument === matcherDocument ||
(0, graphql_1.print)(operationDocument) === (0, graphql_1.print)(matcherDocument);
exports.matchesOperationDocument = matchesOperationDocument;
//# sourceMappingURL=hasOperation.js.map