-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
27 lines (23 loc) · 680 Bytes
/
index.ts
File metadata and controls
27 lines (23 loc) · 680 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { readFile } from 'node:fs/promises';
import { parse as parseVueSfc } from '@vue/compiler-sfc';
import { parse as parseGraphqlDocument, type DocumentNode } from 'graphql';
export default async function (
pointer: string,
): Promise<DocumentNode | undefined> {
if (!pointer.endsWith('.vue')) {
return;
}
const contents = await readFile(pointer, 'utf-8');
const { errors, descriptor } = parseVueSfc(contents);
if (errors.length > 0) {
return;
}
const queryBlock = descriptor.customBlocks.find(
({ type }) => type === 'query',
);
const source = queryBlock?.content;
if (!source) {
return;
}
return parseGraphqlDocument(source);
}