1 | const { Mixin } = require('hops-mixin');
|
2 | const strip = require('strip-indent');
|
3 |
|
4 | class GraphQLMixin extends Mixin {
|
5 | registerCommands(yargs) {
|
6 | return yargs.command('graphql', 'Execute GraphQL specific tasks', yargs =>
|
7 | yargs
|
8 | .usage('Usage: hops graphql <command>')
|
9 | .command({
|
10 | command: 'introspect',
|
11 | describe: 'Fetches GraphQL schema information for introspection',
|
12 | builder: {
|
13 | header: {
|
14 | alias: 'H',
|
15 | type: 'array',
|
16 | default: [],
|
17 | describe: strip(`
|
18 | Additional HTTP headers to be used when executing the schema
|
19 | introspection on the remote server. Specify this multiple
|
20 | times to add more headers.\nFormat: "Header: Value"
|
21 | `),
|
22 | },
|
23 | },
|
24 | handler: argv => {
|
25 | require('./lib/fragments')({
|
26 | graphqlUri: this.config.graphqlUri,
|
27 | schemaFile: this.config.graphqlSchemaFile,
|
28 | fragmentsFile: this.config.fragmentsFile,
|
29 | headers: argv.header,
|
30 | })
|
31 | .then(() => {
|
32 | console.log('Fetched and saved GraphQL fragments');
|
33 | })
|
34 | .catch(err => {
|
35 | console.error('Could not fetch GraphQL fragments:');
|
36 | console.trace(err);
|
37 | });
|
38 | },
|
39 | })
|
40 | .help('help')
|
41 | .alias('h', 'help')
|
42 | .demandCommand()
|
43 | );
|
44 | }
|
45 |
|
46 | configureBuild(config, loaderConfigs) {
|
47 | const { allLoaderConfigs } = loaderConfigs;
|
48 | const tagLoader = {
|
49 | test: /\.(graphql|gql)$/,
|
50 | loader: 'graphql-tag/loader',
|
51 | };
|
52 | allLoaderConfigs.splice(allLoaderConfigs.length - 1, 0, tagLoader);
|
53 | return config;
|
54 | }
|
55 | }
|
56 |
|
57 | module.exports = GraphQLMixin;
|