UNPKG

2.15 kBJavaScriptView Raw
1"use strict";
2var __assign = (this && this.__assign) || function () {
3 __assign = Object.assign || function(t) {
4 for (var s, i = 1, n = arguments.length; i < n; i++) {
5 s = arguments[i];
6 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7 t[p] = s[p];
8 }
9 return t;
10 };
11 return __assign.apply(this, arguments);
12};
13Object.defineProperty(exports, "__esModule", { value: true });
14var get_root_1 = require("../utils/get-root");
15var build_selection_set_1 = require("./build-selection-set");
16var transform_variables_1 = require("./transform-variables");
17var debugging_1 = require("../debugging");
18var printer_1 = require("graphql/language/printer");
19var get_directives_1 = require("../utils/get-directives");
20function transformOperation(schema, operationNode, overrideName) {
21 var name = overrideName ? overrideName : operationNode.name && operationNode.name.value ? operationNode.name.value : '';
22 debugging_1.debugLog("[transformOperation] transforming operation " + name + " of type " + operationNode.operation);
23 var root = get_root_1.getRoot(schema, operationNode);
24 if (!root) {
25 throw new Error("Unable to find the schema root matching: " + operationNode.operation);
26 }
27 var variables = transform_variables_1.transformVariables(schema, operationNode);
28 var directives = get_directives_1.getDirectives(schema, operationNode);
29 var selectionSet = build_selection_set_1.buildSelectionSet(schema, root, operationNode.selectionSet);
30 return __assign({ name: name,
31 selectionSet: selectionSet, operationType: operationNode.operation, variables: variables, hasVariables: variables.length > 0, isQuery: operationNode.operation === 'query', isMutation: operationNode.operation === 'mutation', isSubscription: operationNode.operation === 'subscription', document: printer_1.print(operationNode), directives: directives, usesDirectives: Object.keys(directives).length > 0 }, build_selection_set_1.separateSelectionSet(selectionSet));
32}
33exports.transformOperation = transformOperation;
34//# sourceMappingURL=transform-operation.js.map
\No newline at end of file