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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112const path = require('path')
module.exports = api => {
const CONFIG = 'org.akryum.vue-apollo.configs.apollo'
// Config file
api.describeConfig({
id: CONFIG,
name: 'Apollo Server',
description: 'Integrated GraphQL server',
link: 'https://github.com/Akryum/vue-cli-plugin-apollo#configuration',
files: {
vue: {
js: ['vue.config.js'],
},
graphql: {
yaml: ['.graphqlconfig.yml'],
},
},
onRead: ({ data, cwd }) => {
return {
prompts: [
{
name: 'enableMocks',
message: 'Mocking',
description: 'Enable auto-mocking for quick prototyping',
link: 'https://github.com/Akryum/vue-cli-plugin-apollo#mocks',
type: 'confirm',
file: 'vue',
default: false,
value: getConfigData(data).enableMocks,
},
{
name: 'serverFolder',
message: 'Server folder',
description: 'Folder containing the server source files',
type: 'input',
file: 'vue',
default: './apollo-server',
value: getConfigData(data).serverFolder,
},
{
name: 'cors',
message: 'CORS',
description: 'Allow access to other origins',
type: 'input',
file: 'vue',
default: '*',
value: stringOnly(getConfigData(data).cors),
},
{
name: 'timeout',
message: 'Response timeout',
description: 'Time before a Query request is timed out (in ms)',
type: 'input',
file: 'vue',
default: '120000',
transformer: value => value.toString(),
filter: value => parseInt(value),
value: getConfigData(data).timeout,
},
{
name: 'enableEngine',
group: 'Apollo Engine',
message: 'Apollo Engine',
description: 'Enable Apollo Engine, a cloud monitoring service',
link: 'https://github.com/Akryum/vue-cli-plugin-apollo#apollo-engine',
type: 'confirm',
file: 'vue',
default: false,
value: getConfigData(data).enableEngine,
},
{
name: 'integratedEngine',
group: 'Apollo Engine',
message: 'Integrated Engine layer',
description: 'Uncheck this if you want to use an external Engine container/layer',
link: 'https://www.apollographql.com/docs/apollo-server/v2/migration-engine.html#With-a-Running-Engine-Proxy',
type: 'confirm',
file: 'vue',
when: answers => answers.enableEngine,
default: true,
value: getConfigData(data).integratedEngine,
},
],
}
},
onWrite: async ({ api, prompts, cwd }) => {
const result = {}
for (const prompt of prompts.filter(p => p.raw.file === 'vue')) {
result[`pluginOptions.apollo.${prompt.id}`] = await api.getAnswer(prompt.id)
}
api.setData('vue', result)
// Update app manifest
const serverFolder = result['pluginOptions.apollo.serverFolder'] || prompts.find(p => p.id === 'serverFolder').raw.default
api.setData('graphql', {
'projects.app.schemaPath': path.join(serverFolder, 'schema.graphql'),
})
},
})
}
function getConfigData (data) {
return (data.vue && data.vue.pluginOptions && data.vue.pluginOptions.apollo) || {}
}
function stringOnly (value) {
return typeof value === 'string' ? value : undefined
}