-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathmixin.core.js
90 lines (82 loc) · 2.75 KB
/
mixin.core.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
const { existsSync } = require('fs');
const { Mixin } = require('hops-mixin');
const strip = require('strip-indent');
class GraphQLMixin extends Mixin {
constructor(config, ...args) {
super(config, ...args);
}
configureBuild(webpackConfig, loaderConfigs) {
const { allLoaderConfigs } = loaderConfigs;
if (
!allLoaderConfigs.find(({ loader }) => loader === 'graphql-tag/loader')
) {
allLoaderConfigs.splice(allLoaderConfigs.length - 1, 0, {
test: /\.(graphql|gql)$/,
loader: 'graphql-tag/loader',
});
}
if (existsSync(this.config.fragmentsFile)) {
webpackConfig.resolve.alias = {
...webpackConfig.resolve.alias,
'hops-react-apollo/fragmentTypes.json': this.config.fragmentsFile,
};
}
}
registerCommands(yargs) {
yargs.command('graphql', 'Execute GraphQL specific tasks', (yargs) =>
yargs
.usage('Usage: hops graphql <command>')
.command({
command: 'introspect',
describe: 'Fetches GraphQL schema information for introspection',
builder: {
header: {
alias: 'H',
type: 'array',
default: [],
describe: strip(`
Additional HTTP headers to be used when executing the schema
introspection on the remote server. Specify this multiple
times to add more headers.\nFormat: "Header: Value"
`),
},
},
handler: (argv) => {
require('./lib/fragments')({
graphqlUri: this.config.graphqlUri,
schemaFile: this.config.graphqlSchemaFile,
fragmentsFile: this.config.fragmentsFile,
headers: argv.header,
})
.then(() => {
if (typeof this.getLogger === 'function') {
this.getLogger().info('Fetched and saved GraphQL fragments');
}
})
.catch((err) => {
if (typeof this.getLogger === 'function') {
this.getLogger().error('Could not fetch GraphQL fragments:');
this.getLogger().error(err);
}
});
},
})
.help('help')
.alias('h', 'help')
.demandCommand()
);
}
handleArguments(argv) {
this.options = { ...this.options, ...argv };
}
diagnose({ detectDuplicatePackages, pushWarning }) {
detectDuplicatePackages('graphql');
if (!existsSync(this.config.fragmentsFile)) {
pushWarning(
`Could not find a graphql introspection query result at "${this.config.fragmentsFile}".`
);
pushWarning('Please execute "hops graphql introspect"');
}
}
}
module.exports = GraphQLMixin;