forked from Swydo/meteor-graphql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compiler.js
37 lines (33 loc) · 981 Bytes
/
compiler.js
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
28
29
30
31
32
33
34
35
36
37
/* eslint-disable prefer-arrow-callback, func-names, class-methods-use-this */
import loader from 'graphql-tag/loader';
export default class GraphQLCompiler {
processFilesForTarget(files) {
// Fake webpack context
// @see https://github.com/apollographql/graphql-tag/blob/57a258713acecde5ebef0c5771a975d6446703c7/loader.js#L43
const context = {
cacheable() {},
};
files
.forEach((file) => {
const path = `${file.getPathInPackage()}.js`;
const content = file.getContentsAsString().trim();
try {
const data = loader.call(context, content);
file.addJavaScript({
data,
path,
});
} catch (e) {
if (e.locations) {
file.error({
message: e.message,
line: e.locations[0].line,
column: e.locations[0].column,
});
} else {
throw e;
}
}
});
}
}