UNPKG

1.11 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.getQueryFacts = exports.getOperationASTFacts = void 0;
4const graphql_1 = require("graphql");
5const collectVariables_1 = require("./collectVariables");
6function getOperationASTFacts(documentAST, schema) {
7 const variableToType = schema
8 ? collectVariables_1.collectVariables(schema, documentAST)
9 : undefined;
10 const operations = [];
11 graphql_1.visit(documentAST, {
12 OperationDefinition(node) {
13 operations.push(node);
14 },
15 });
16 return { variableToType, operations };
17}
18exports.getOperationASTFacts = getOperationASTFacts;
19function getOperationFacts(schema, documentString) {
20 if (!documentString) {
21 return;
22 }
23 try {
24 const documentAST = graphql_1.parse(documentString);
25 return Object.assign(Object.assign({}, getOperationASTFacts(documentAST, schema)), { documentAST });
26 }
27 catch (_a) {
28 return;
29 }
30}
31exports.default = getOperationFacts;
32exports.getQueryFacts = getOperationFacts;
33//# sourceMappingURL=getOperationFacts.js.map
\No newline at end of file