1 | import { parse, visit } from 'graphql';
|
2 | import { collectVariables } from './collectVariables';
|
3 | export 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 | }
|
15 | export 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 | }
|
27 | export const getQueryFacts = getOperationFacts;
|
28 |
|
\ | No newline at end of file |