UNPKG

872 BJavaScriptView Raw
1import { parse, visit } from 'graphql';
2import { collectVariables } from './collectVariables';
3export function getOperationASTFacts(documentAST, schema) {
4 const variableToType = schema
5 ? collectVariables(schema, documentAST)
6 : undefined;
7 const operations = [];
8 visit(documentAST, {
9 OperationDefinition(node) {
10 operations.push(node);
11 },
12 });
13 return { variableToType, operations };
14}
15export default function getOperationFacts(schema, documentString) {
16 if (!documentString) {
17 return;
18 }
19 try {
20 const documentAST = parse(documentString);
21 return Object.assign(Object.assign({}, getOperationASTFacts(documentAST, schema)), { documentAST });
22 }
23 catch (_a) {
24 return;
25 }
26}
27export const getQueryFacts = getOperationFacts;
28//# sourceMappingURL=getOperationFacts.js.map
\No newline at end of file