@graphql-codegen/cli 2.7.0 → 2.7.1-alpha-9d615db71.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/bin.js +13 -0
- package/cjs/cli.js +60 -0
- package/cjs/codegen.js +319 -0
- package/cjs/config.js +303 -0
- package/cjs/generate-and-save.js +110 -0
- package/cjs/graphql-config.js +69 -0
- package/cjs/hooks.js +87 -0
- package/cjs/index.js +13 -0
- package/cjs/init/helpers.js +64 -0
- package/cjs/init/index.js +60 -0
- package/cjs/init/plugins.js +163 -0
- package/cjs/init/questions.js +147 -0
- package/cjs/init/targets.js +44 -0
- package/cjs/init/types.js +14 -0
- package/cjs/load.js +93 -0
- package/cjs/package.json +1 -0
- package/cjs/plugins.js +45 -0
- package/cjs/presets.js +50 -0
- package/cjs/utils/cli-error.js +25 -0
- package/cjs/utils/debugging.js +27 -0
- package/cjs/utils/file-system.js +26 -0
- package/cjs/utils/get-latest-version.js +15 -0
- package/cjs/utils/logger.js +25 -0
- package/cjs/utils/watcher.js +140 -0
- package/esm/bin.js +11 -0
- package/esm/cli.js +32 -0
- package/esm/codegen.js +314 -0
- package/esm/config.js +290 -0
- package/esm/generate-and-save.js +105 -0
- package/esm/graphql-config.js +64 -0
- package/esm/hooks.js +83 -0
- package/esm/index.js +7 -0
- package/esm/init/helpers.js +55 -0
- package/esm/init/index.js +55 -0
- package/esm/init/plugins.js +160 -0
- package/esm/init/questions.js +140 -0
- package/esm/init/targets.js +40 -0
- package/esm/init/types.js +11 -0
- package/esm/load.js +88 -0
- package/esm/plugins.js +41 -0
- package/esm/presets.js +46 -0
- package/esm/utils/cli-error.js +20 -0
- package/esm/utils/debugging.js +21 -0
- package/esm/utils/file-system.js +19 -0
- package/esm/utils/get-latest-version.js +11 -0
- package/esm/utils/logger.js +18 -0
- package/esm/utils/watcher.js +135 -0
- package/package.json +34 -30
- package/typings/bin.d.ts +2 -0
- package/{cli.d.ts → typings/cli.d.ts} +0 -0
- package/{codegen.d.ts → typings/codegen.d.ts} +1 -1
- package/{config.d.ts → typings/config.d.ts} +0 -0
- package/{generate-and-save.d.ts → typings/generate-and-save.d.ts} +1 -1
- package/{graphql-config.d.ts → typings/graphql-config.d.ts} +0 -0
- package/{hooks.d.ts → typings/hooks.d.ts} +0 -0
- package/typings/index.d.ts +7 -0
- package/{init → typings/init}/helpers.d.ts +1 -1
- package/{init → typings/init}/index.d.ts +0 -0
- package/{init → typings/init}/plugins.d.ts +1 -1
- package/{init → typings/init}/questions.d.ts +1 -1
- package/{init → typings/init}/targets.d.ts +1 -1
- package/{init → typings/init}/types.d.ts +0 -0
- package/{load.d.ts → typings/load.d.ts} +0 -0
- package/{plugins.d.ts → typings/plugins.d.ts} +0 -0
- package/{presets.d.ts → typings/presets.d.ts} +0 -0
- package/{utils → typings/utils}/cli-error.d.ts +0 -0
- package/{utils → typings/utils}/debugging.d.ts +0 -0
- package/{utils → typings/utils}/file-system.d.ts +0 -0
- package/typings/utils/get-latest-version.d.ts +6 -0
- package/{utils → typings/utils}/logger.d.ts +0 -0
- package/{utils → typings/utils}/watcher.d.ts +1 -1
- package/bin.d.ts +0 -1
- package/bin.js +0 -1891
- package/index.d.ts +0 -7
- package/index.js +0 -1902
- package/index.mjs +0 -1858
- package/utils/indentString.d.ts +0 -26
- package/utils/listr-renderer.d.ts +0 -18
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.init = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const inquirer_1 = tslib_1.__importDefault(require("inquirer"));
|
|
6
|
+
const questions_js_1 = require("./questions.js");
|
|
7
|
+
const targets_js_1 = require("./targets.js");
|
|
8
|
+
const types_js_1 = require("./types.js");
|
|
9
|
+
const helpers_js_1 = require("./helpers.js");
|
|
10
|
+
function log(...msgs) {
|
|
11
|
+
// eslint-disable-next-line no-console
|
|
12
|
+
console.log(...msgs);
|
|
13
|
+
}
|
|
14
|
+
async function init() {
|
|
15
|
+
log(`
|
|
16
|
+
Welcome to ${(0, helpers_js_1.bold)('GraphQL Code Generator')}!
|
|
17
|
+
Answer few questions and we will setup everything for you.
|
|
18
|
+
`);
|
|
19
|
+
const possibleTargets = await (0, targets_js_1.guessTargets)();
|
|
20
|
+
const answers = await inquirer_1.default.prompt((0, questions_js_1.getQuestions)(possibleTargets));
|
|
21
|
+
// define config
|
|
22
|
+
const config = {
|
|
23
|
+
overwrite: true,
|
|
24
|
+
schema: answers.schema,
|
|
25
|
+
documents: answers.targets.includes(types_js_1.Tags.browser) ? answers.documents : null,
|
|
26
|
+
generates: {
|
|
27
|
+
[answers.output]: {
|
|
28
|
+
plugins: answers.plugins.map(p => p.value),
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
// introspection
|
|
33
|
+
if (answers.introspection) {
|
|
34
|
+
addIntrospection(config);
|
|
35
|
+
}
|
|
36
|
+
// config file
|
|
37
|
+
const { relativePath } = await (0, helpers_js_1.writeConfig)(answers, config);
|
|
38
|
+
log(`Fetching latest versions of selected plugins...`);
|
|
39
|
+
// write package.json
|
|
40
|
+
await (0, helpers_js_1.writePackage)(answers, relativePath);
|
|
41
|
+
// Emit status to the terminal
|
|
42
|
+
log(`
|
|
43
|
+
Config file generated at ${(0, helpers_js_1.bold)(relativePath)}
|
|
44
|
+
|
|
45
|
+
${(0, helpers_js_1.bold)('$ npm install')}
|
|
46
|
+
|
|
47
|
+
To install the plugins.
|
|
48
|
+
|
|
49
|
+
${(0, helpers_js_1.bold)(`$ npm run ${answers.script}`)}
|
|
50
|
+
|
|
51
|
+
To run GraphQL Code Generator.
|
|
52
|
+
`);
|
|
53
|
+
}
|
|
54
|
+
exports.init = init;
|
|
55
|
+
// adds an introspection to `generates`
|
|
56
|
+
function addIntrospection(config) {
|
|
57
|
+
config.generates['./graphql.schema.json'] = {
|
|
58
|
+
plugins: ['introspection'],
|
|
59
|
+
};
|
|
60
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.plugins = void 0;
|
|
4
|
+
const helpers_js_1 = require("./helpers.js");
|
|
5
|
+
const types_js_1 = require("./types.js");
|
|
6
|
+
exports.plugins = [
|
|
7
|
+
{
|
|
8
|
+
name: `TypeScript ${(0, helpers_js_1.italic)('(required by other typescript plugins)')}`,
|
|
9
|
+
package: '@graphql-codegen/typescript',
|
|
10
|
+
value: 'typescript',
|
|
11
|
+
pathInRepo: 'typescript/typescript',
|
|
12
|
+
available: hasTag(types_js_1.Tags.typescript),
|
|
13
|
+
shouldBeSelected: tags => oneOf(tags, types_js_1.Tags.angular, types_js_1.Tags.stencil) || allOf(tags, types_js_1.Tags.typescript, types_js_1.Tags.react) || noneOf(tags, types_js_1.Tags.flow),
|
|
14
|
+
defaultExtension: '.ts',
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
name: `TypeScript Operations ${(0, helpers_js_1.italic)('(operations and fragments)')}`,
|
|
18
|
+
package: '@graphql-codegen/typescript-operations',
|
|
19
|
+
value: 'typescript-operations',
|
|
20
|
+
pathInRepo: 'typescript/operations',
|
|
21
|
+
available: tags => allOf(tags, types_js_1.Tags.browser, types_js_1.Tags.typescript),
|
|
22
|
+
shouldBeSelected: tags => oneOf(tags, types_js_1.Tags.angular, types_js_1.Tags.stencil) || allOf(tags, types_js_1.Tags.typescript, types_js_1.Tags.react),
|
|
23
|
+
defaultExtension: '.ts',
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
name: `TypeScript Resolvers ${(0, helpers_js_1.italic)('(strongly typed resolve functions)')}`,
|
|
27
|
+
package: '@graphql-codegen/typescript-resolvers',
|
|
28
|
+
value: 'typescript-resolvers',
|
|
29
|
+
pathInRepo: 'typescript/resolvers',
|
|
30
|
+
available: tags => allOf(tags, types_js_1.Tags.node, types_js_1.Tags.typescript),
|
|
31
|
+
shouldBeSelected: tags => noneOf(tags, types_js_1.Tags.flow),
|
|
32
|
+
defaultExtension: '.ts',
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: `Flow ${(0, helpers_js_1.italic)('(required by other flow plugins)')}`,
|
|
36
|
+
package: '@graphql-codegen/flow',
|
|
37
|
+
value: 'flow',
|
|
38
|
+
pathInRepo: 'flow/flow',
|
|
39
|
+
available: hasTag(types_js_1.Tags.flow),
|
|
40
|
+
shouldBeSelected: tags => noneOf(tags, types_js_1.Tags.typescript),
|
|
41
|
+
defaultExtension: '.js',
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: `Flow Operations ${(0, helpers_js_1.italic)('(operations and fragments)')}`,
|
|
45
|
+
package: '@graphql-codegen/flow-operations',
|
|
46
|
+
value: 'flow-operations',
|
|
47
|
+
pathInRepo: 'flow/operations',
|
|
48
|
+
available: tags => allOf(tags, types_js_1.Tags.browser, types_js_1.Tags.flow),
|
|
49
|
+
shouldBeSelected: tags => noneOf(tags, types_js_1.Tags.typescript),
|
|
50
|
+
defaultExtension: '.js',
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: `Flow Resolvers ${(0, helpers_js_1.italic)('(strongly typed resolve functions)')}`,
|
|
54
|
+
package: '@graphql-codegen/flow-resolvers',
|
|
55
|
+
value: 'flow-resolvers',
|
|
56
|
+
pathInRepo: 'flow/resolvers',
|
|
57
|
+
available: tags => allOf(tags, types_js_1.Tags.node, types_js_1.Tags.flow),
|
|
58
|
+
shouldBeSelected: tags => noneOf(tags, types_js_1.Tags.typescript),
|
|
59
|
+
defaultExtension: '.js',
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
name: `TypeScript Apollo Angular ${(0, helpers_js_1.italic)('(typed GQL services)')}`,
|
|
63
|
+
package: '@graphql-codegen/typescript-apollo-angular',
|
|
64
|
+
value: 'typescript-apollo-angular',
|
|
65
|
+
pathInRepo: 'typescript/apollo-angular',
|
|
66
|
+
available: hasTag(types_js_1.Tags.angular),
|
|
67
|
+
shouldBeSelected: () => true,
|
|
68
|
+
defaultExtension: '.js',
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
name: `TypeScript Vue Apollo Composition API ${(0, helpers_js_1.italic)('(typed functions)')}`,
|
|
72
|
+
package: '@graphql-codegen/typescript-vue-apollo',
|
|
73
|
+
value: 'typescript-vue-apollo',
|
|
74
|
+
pathInRepo: 'typescript/vue-apollo',
|
|
75
|
+
available: tags => allOf(tags, types_js_1.Tags.vue, types_js_1.Tags.typescript),
|
|
76
|
+
shouldBeSelected: () => true,
|
|
77
|
+
defaultExtension: '.ts',
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
name: `TypeScript Vue Apollo Smart Operations ${(0, helpers_js_1.italic)('(typed functions)')}`,
|
|
81
|
+
package: '@graphql-codegen/typescript-vue-apollo-smart-ops',
|
|
82
|
+
value: 'typescript-vue-apollo-smart-ops',
|
|
83
|
+
pathInRepo: 'typescript/vue-apollo-smart-ops',
|
|
84
|
+
available: tags => allOf(tags, types_js_1.Tags.vue, types_js_1.Tags.typescript),
|
|
85
|
+
shouldBeSelected: () => true,
|
|
86
|
+
defaultExtension: '.ts',
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
name: `TypeScript React Apollo ${(0, helpers_js_1.italic)('(typed components and HOCs)')}`,
|
|
90
|
+
package: '@graphql-codegen/typescript-react-apollo',
|
|
91
|
+
value: 'typescript-react-apollo',
|
|
92
|
+
pathInRepo: 'typescript/react-apollo',
|
|
93
|
+
available: tags => allOf(tags, types_js_1.Tags.react, types_js_1.Tags.typescript),
|
|
94
|
+
shouldBeSelected: () => true,
|
|
95
|
+
defaultExtension: '.tsx',
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
name: `TypeScript Stencil Apollo ${(0, helpers_js_1.italic)('(typed components)')}`,
|
|
99
|
+
package: '@graphql-codegen/typescript-stencil-apollo',
|
|
100
|
+
value: 'typescript-stencil-apollo',
|
|
101
|
+
pathInRepo: 'typescript/stencil-apollo',
|
|
102
|
+
available: hasTag(types_js_1.Tags.stencil),
|
|
103
|
+
shouldBeSelected: () => true,
|
|
104
|
+
defaultExtension: '.tsx',
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
name: `TypeScript MongoDB ${(0, helpers_js_1.italic)('(typed MongoDB objects)')}`,
|
|
108
|
+
package: '@graphql-codegen/typescript-mongodb',
|
|
109
|
+
value: 'typescript-mongodb',
|
|
110
|
+
pathInRepo: 'typescript/mongodb',
|
|
111
|
+
available: tags => allOf(tags, types_js_1.Tags.node, types_js_1.Tags.typescript),
|
|
112
|
+
shouldBeSelected: () => false,
|
|
113
|
+
defaultExtension: '.ts',
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
name: `TypeScript GraphQL files modules ${(0, helpers_js_1.italic)('(declarations for .graphql files)')}`,
|
|
117
|
+
package: '@graphql-codegen/typescript-graphql-files-modules',
|
|
118
|
+
value: 'typescript-graphql-files-modules',
|
|
119
|
+
pathInRepo: 'typescript/graphql-files-modules',
|
|
120
|
+
available: tags => allOf(tags, types_js_1.Tags.browser, types_js_1.Tags.typescript),
|
|
121
|
+
shouldBeSelected: () => false,
|
|
122
|
+
defaultExtension: '.ts',
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
name: `TypeScript GraphQL document nodes ${(0, helpers_js_1.italic)('(embedded GraphQL document)')}`,
|
|
126
|
+
package: '@graphql-codegen/typescript-document-nodes',
|
|
127
|
+
value: 'typescript-document-nodes',
|
|
128
|
+
pathInRepo: 'typescript/document-nodes',
|
|
129
|
+
available: tags => allOf(tags, types_js_1.Tags.typescript),
|
|
130
|
+
shouldBeSelected: () => false,
|
|
131
|
+
defaultExtension: '.ts',
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
name: `Introspection Fragment Matcher ${(0, helpers_js_1.italic)('(for Apollo Client)')}`,
|
|
135
|
+
package: '@graphql-codegen/fragment-matcher',
|
|
136
|
+
value: 'fragment-matcher',
|
|
137
|
+
pathInRepo: 'other/fragment-matcher',
|
|
138
|
+
available: hasTag(types_js_1.Tags.browser),
|
|
139
|
+
shouldBeSelected: () => false,
|
|
140
|
+
defaultExtension: '.ts',
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
name: `Urql Introspection ${(0, helpers_js_1.italic)('(for Urql Client)')}`,
|
|
144
|
+
package: '@graphql-codegen/urql-introspection',
|
|
145
|
+
value: 'urql-introspection',
|
|
146
|
+
pathInRepo: 'other/urql-introspection',
|
|
147
|
+
available: hasTag(types_js_1.Tags.browser),
|
|
148
|
+
shouldBeSelected: () => false,
|
|
149
|
+
defaultExtension: '.ts',
|
|
150
|
+
},
|
|
151
|
+
];
|
|
152
|
+
function hasTag(tag) {
|
|
153
|
+
return (tags) => tags.includes(tag);
|
|
154
|
+
}
|
|
155
|
+
function oneOf(list, ...items) {
|
|
156
|
+
return list.some(i => items.includes(i));
|
|
157
|
+
}
|
|
158
|
+
function noneOf(list, ...items) {
|
|
159
|
+
return !list.some(i => items.includes(i));
|
|
160
|
+
}
|
|
161
|
+
function allOf(list, ...items) {
|
|
162
|
+
return items.every(i => list.includes(i));
|
|
163
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getOutputDefaultValue = exports.getPluginChoices = exports.getApplicationTypeChoices = exports.getQuestions = void 0;
|
|
4
|
+
const helpers_js_1 = require("./helpers.js");
|
|
5
|
+
const types_js_1 = require("./types.js");
|
|
6
|
+
const plugins_js_1 = require("./plugins.js");
|
|
7
|
+
function getQuestions(possibleTargets) {
|
|
8
|
+
return [
|
|
9
|
+
{
|
|
10
|
+
type: 'checkbox',
|
|
11
|
+
name: 'targets',
|
|
12
|
+
message: `What type of application are you building?`,
|
|
13
|
+
choices: getApplicationTypeChoices(possibleTargets),
|
|
14
|
+
validate: ((targets) => targets.length > 0),
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
type: 'input',
|
|
18
|
+
name: 'schema',
|
|
19
|
+
message: 'Where is your schema?:',
|
|
20
|
+
suffix: (0, helpers_js_1.grey)(' (path or url)'),
|
|
21
|
+
default: 'http://localhost:4000',
|
|
22
|
+
validate: (str) => str.length > 0,
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
type: 'input',
|
|
26
|
+
name: 'documents',
|
|
27
|
+
message: 'Where are your operations and fragments?:',
|
|
28
|
+
when: answers => {
|
|
29
|
+
// flatten targets
|
|
30
|
+
// I can't find an API in Inquirer that would do that
|
|
31
|
+
answers.targets = normalizeTargets(answers.targets);
|
|
32
|
+
return answers.targets.includes(types_js_1.Tags.browser);
|
|
33
|
+
},
|
|
34
|
+
default: 'src/**/*.graphql',
|
|
35
|
+
validate: (str) => str.length > 0,
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
type: 'checkbox',
|
|
39
|
+
name: 'plugins',
|
|
40
|
+
message: 'Pick plugins:',
|
|
41
|
+
choices: getPluginChoices,
|
|
42
|
+
validate: ((plugins) => plugins.length > 0),
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
type: 'input',
|
|
46
|
+
name: 'output',
|
|
47
|
+
message: 'Where to write the output:',
|
|
48
|
+
default: getOutputDefaultValue,
|
|
49
|
+
validate: (str) => str.length > 0,
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
type: 'confirm',
|
|
53
|
+
name: 'introspection',
|
|
54
|
+
message: 'Do you want to generate an introspection file?',
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
type: 'input',
|
|
58
|
+
name: 'config',
|
|
59
|
+
message: 'How to name the config file?',
|
|
60
|
+
default: 'codegen.yml',
|
|
61
|
+
validate: (str) => {
|
|
62
|
+
const isNotEmpty = str.length > 0;
|
|
63
|
+
const hasCorrectExtension = ['json', 'yml', 'yaml'].some(ext => str.toLocaleLowerCase().endsWith(`.${ext}`));
|
|
64
|
+
return isNotEmpty && hasCorrectExtension;
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
type: 'input',
|
|
69
|
+
name: 'script',
|
|
70
|
+
message: 'What script in package.json should run the codegen?',
|
|
71
|
+
validate: (str) => str.length > 0,
|
|
72
|
+
},
|
|
73
|
+
];
|
|
74
|
+
}
|
|
75
|
+
exports.getQuestions = getQuestions;
|
|
76
|
+
function getApplicationTypeChoices(possibleTargets) {
|
|
77
|
+
function withFlowOrTypescript(tags) {
|
|
78
|
+
if (possibleTargets.TypeScript) {
|
|
79
|
+
tags.push(types_js_1.Tags.typescript);
|
|
80
|
+
}
|
|
81
|
+
else if (possibleTargets.Flow) {
|
|
82
|
+
tags.push(types_js_1.Tags.flow);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
tags.push(types_js_1.Tags.flow, types_js_1.Tags.typescript);
|
|
86
|
+
}
|
|
87
|
+
return tags;
|
|
88
|
+
}
|
|
89
|
+
return [
|
|
90
|
+
{
|
|
91
|
+
name: 'Backend - API or server',
|
|
92
|
+
key: 'backend',
|
|
93
|
+
value: withFlowOrTypescript([types_js_1.Tags.node]),
|
|
94
|
+
checked: possibleTargets.Node,
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
name: 'Application built with Angular',
|
|
98
|
+
key: 'angular',
|
|
99
|
+
value: [types_js_1.Tags.angular, types_js_1.Tags.browser, types_js_1.Tags.typescript],
|
|
100
|
+
checked: possibleTargets.Angular,
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
name: 'Application built with React',
|
|
104
|
+
key: 'react',
|
|
105
|
+
value: withFlowOrTypescript([types_js_1.Tags.react, types_js_1.Tags.browser]),
|
|
106
|
+
checked: possibleTargets.React,
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
name: 'Application built with Stencil',
|
|
110
|
+
key: 'stencil',
|
|
111
|
+
value: [types_js_1.Tags.stencil, types_js_1.Tags.browser, types_js_1.Tags.typescript],
|
|
112
|
+
checked: possibleTargets.Stencil,
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
name: 'Application built with other framework or vanilla JS',
|
|
116
|
+
key: 'client',
|
|
117
|
+
value: [types_js_1.Tags.browser, types_js_1.Tags.typescript, types_js_1.Tags.flow],
|
|
118
|
+
checked: possibleTargets.Browser && !possibleTargets.Angular && !possibleTargets.React && !possibleTargets.Stencil,
|
|
119
|
+
},
|
|
120
|
+
];
|
|
121
|
+
}
|
|
122
|
+
exports.getApplicationTypeChoices = getApplicationTypeChoices;
|
|
123
|
+
function getPluginChoices(answers) {
|
|
124
|
+
return plugins_js_1.plugins
|
|
125
|
+
.filter(p => p.available(answers.targets))
|
|
126
|
+
.map(p => {
|
|
127
|
+
return {
|
|
128
|
+
name: p.name,
|
|
129
|
+
value: p,
|
|
130
|
+
checked: p.shouldBeSelected(answers.targets),
|
|
131
|
+
};
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
exports.getPluginChoices = getPluginChoices;
|
|
135
|
+
function normalizeTargets(targets) {
|
|
136
|
+
return [].concat(...targets);
|
|
137
|
+
}
|
|
138
|
+
function getOutputDefaultValue(answers) {
|
|
139
|
+
if (answers.plugins.some(plugin => plugin.defaultExtension === '.tsx')) {
|
|
140
|
+
return 'src/generated/graphql.tsx';
|
|
141
|
+
}
|
|
142
|
+
if (answers.plugins.some(plugin => plugin.defaultExtension === '.ts')) {
|
|
143
|
+
return 'src/generated/graphql.ts';
|
|
144
|
+
}
|
|
145
|
+
return 'src/generated/graphql.js';
|
|
146
|
+
}
|
|
147
|
+
exports.getOutputDefaultValue = getOutputDefaultValue;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.guessTargets = void 0;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
const types_js_1 = require("./types.js");
|
|
7
|
+
async function guessTargets() {
|
|
8
|
+
const pkg = JSON.parse((0, fs_1.readFileSync)((0, path_1.resolve)(process.cwd(), 'package.json'), {
|
|
9
|
+
encoding: 'utf-8',
|
|
10
|
+
}));
|
|
11
|
+
const dependencies = Object.keys({
|
|
12
|
+
...pkg.dependencies,
|
|
13
|
+
...pkg.devDependencies,
|
|
14
|
+
});
|
|
15
|
+
return {
|
|
16
|
+
[types_js_1.Tags.angular]: isAngular(dependencies),
|
|
17
|
+
[types_js_1.Tags.react]: isReact(dependencies),
|
|
18
|
+
[types_js_1.Tags.stencil]: isStencil(dependencies),
|
|
19
|
+
[types_js_1.Tags.vue]: isVue(dependencies),
|
|
20
|
+
[types_js_1.Tags.browser]: false,
|
|
21
|
+
[types_js_1.Tags.node]: false,
|
|
22
|
+
[types_js_1.Tags.typescript]: isTypescript(dependencies),
|
|
23
|
+
[types_js_1.Tags.flow]: isFlow(dependencies),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
exports.guessTargets = guessTargets;
|
|
27
|
+
function isAngular(dependencies) {
|
|
28
|
+
return dependencies.includes('@angular/core');
|
|
29
|
+
}
|
|
30
|
+
function isReact(dependencies) {
|
|
31
|
+
return dependencies.includes('react');
|
|
32
|
+
}
|
|
33
|
+
function isStencil(dependencies) {
|
|
34
|
+
return dependencies.includes('@stencil/core');
|
|
35
|
+
}
|
|
36
|
+
function isVue(dependencies) {
|
|
37
|
+
return dependencies.includes('vue') || dependencies.includes('nuxt');
|
|
38
|
+
}
|
|
39
|
+
function isTypescript(dependencies) {
|
|
40
|
+
return dependencies.includes('typescript');
|
|
41
|
+
}
|
|
42
|
+
function isFlow(dependencies) {
|
|
43
|
+
return dependencies.includes('flow');
|
|
44
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Tags = void 0;
|
|
4
|
+
var Tags;
|
|
5
|
+
(function (Tags) {
|
|
6
|
+
Tags["browser"] = "Browser";
|
|
7
|
+
Tags["node"] = "Node";
|
|
8
|
+
Tags["typescript"] = "TypeScript";
|
|
9
|
+
Tags["flow"] = "Flow";
|
|
10
|
+
Tags["angular"] = "Angular";
|
|
11
|
+
Tags["stencil"] = "Stencil";
|
|
12
|
+
Tags["react"] = "React";
|
|
13
|
+
Tags["vue"] = "Vue";
|
|
14
|
+
})(Tags = exports.Tags || (exports.Tags = {}));
|
package/cjs/load.js
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadDocuments = exports.loadSchema = exports.defaultDocumentsLoadOptions = exports.defaultSchemaLoadOptions = void 0;
|
|
4
|
+
const load_1 = require("@graphql-tools/load");
|
|
5
|
+
const plugin_helpers_1 = require("@graphql-codegen/plugin-helpers");
|
|
6
|
+
const code_file_loader_1 = require("@graphql-tools/code-file-loader");
|
|
7
|
+
const git_loader_1 = require("@graphql-tools/git-loader");
|
|
8
|
+
const github_loader_1 = require("@graphql-tools/github-loader");
|
|
9
|
+
const graphql_file_loader_1 = require("@graphql-tools/graphql-file-loader");
|
|
10
|
+
const json_file_loader_1 = require("@graphql-tools/json-file-loader");
|
|
11
|
+
const url_loader_1 = require("@graphql-tools/url-loader");
|
|
12
|
+
const apollo_engine_loader_1 = require("@graphql-tools/apollo-engine-loader");
|
|
13
|
+
const prisma_loader_1 = require("@graphql-tools/prisma-loader");
|
|
14
|
+
const path_1 = require("path");
|
|
15
|
+
exports.defaultSchemaLoadOptions = {
|
|
16
|
+
assumeValidSDL: true,
|
|
17
|
+
sort: true,
|
|
18
|
+
convertExtensions: true,
|
|
19
|
+
includeSources: true,
|
|
20
|
+
};
|
|
21
|
+
exports.defaultDocumentsLoadOptions = {
|
|
22
|
+
sort: true,
|
|
23
|
+
skipGraphQLImport: true,
|
|
24
|
+
};
|
|
25
|
+
async function loadSchema(schemaPointers, config) {
|
|
26
|
+
try {
|
|
27
|
+
const loaders = [
|
|
28
|
+
new code_file_loader_1.CodeFileLoader(),
|
|
29
|
+
new git_loader_1.GitLoader(),
|
|
30
|
+
new github_loader_1.GithubLoader(),
|
|
31
|
+
new graphql_file_loader_1.GraphQLFileLoader(),
|
|
32
|
+
new json_file_loader_1.JsonFileLoader(),
|
|
33
|
+
new url_loader_1.UrlLoader(),
|
|
34
|
+
new apollo_engine_loader_1.ApolloEngineLoader(),
|
|
35
|
+
new prisma_loader_1.PrismaLoader(),
|
|
36
|
+
];
|
|
37
|
+
const schema = await (0, load_1.loadSchema)(schemaPointers, {
|
|
38
|
+
...exports.defaultSchemaLoadOptions,
|
|
39
|
+
loaders,
|
|
40
|
+
...config,
|
|
41
|
+
...config.config,
|
|
42
|
+
});
|
|
43
|
+
return schema;
|
|
44
|
+
}
|
|
45
|
+
catch (e) {
|
|
46
|
+
throw new plugin_helpers_1.DetailedError('Failed to load schema', `
|
|
47
|
+
Failed to load schema from ${Object.keys(schemaPointers).join(',')}:
|
|
48
|
+
|
|
49
|
+
${e.message || e}
|
|
50
|
+
${e.stack || ''}
|
|
51
|
+
|
|
52
|
+
GraphQL Code Generator supports:
|
|
53
|
+
- ES Modules and CommonJS exports (export as default or named export "schema")
|
|
54
|
+
- Introspection JSON File
|
|
55
|
+
- URL of GraphQL endpoint
|
|
56
|
+
- Multiple files with type definitions (glob expression)
|
|
57
|
+
- String in config file
|
|
58
|
+
|
|
59
|
+
Try to use one of above options and run codegen again.
|
|
60
|
+
|
|
61
|
+
`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.loadSchema = loadSchema;
|
|
65
|
+
async function loadDocuments(documentPointers, config) {
|
|
66
|
+
const loaders = [
|
|
67
|
+
new code_file_loader_1.CodeFileLoader({
|
|
68
|
+
pluckConfig: {
|
|
69
|
+
skipIndent: true,
|
|
70
|
+
},
|
|
71
|
+
}),
|
|
72
|
+
new git_loader_1.GitLoader(),
|
|
73
|
+
new github_loader_1.GithubLoader(),
|
|
74
|
+
new graphql_file_loader_1.GraphQLFileLoader(),
|
|
75
|
+
];
|
|
76
|
+
const ignore = [];
|
|
77
|
+
for (const generatePath of Object.keys(config.generates)) {
|
|
78
|
+
if ((0, path_1.extname)(generatePath) === '') {
|
|
79
|
+
// we omit paths that don't resolve to a specific file
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
ignore.push((0, path_1.join)(process.cwd(), generatePath));
|
|
83
|
+
}
|
|
84
|
+
const loadedFromToolkit = await (0, load_1.loadDocuments)(documentPointers, {
|
|
85
|
+
...exports.defaultDocumentsLoadOptions,
|
|
86
|
+
ignore,
|
|
87
|
+
loaders,
|
|
88
|
+
...config,
|
|
89
|
+
...config.config,
|
|
90
|
+
});
|
|
91
|
+
return loadedFromToolkit;
|
|
92
|
+
}
|
|
93
|
+
exports.loadDocuments = loadDocuments;
|
package/cjs/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
package/cjs/plugins.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPluginByName = void 0;
|
|
4
|
+
const plugin_helpers_1 = require("@graphql-codegen/plugin-helpers");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
async function getPluginByName(name, pluginLoader) {
|
|
7
|
+
const possibleNames = [
|
|
8
|
+
`@graphql-codegen/${name}`,
|
|
9
|
+
`@graphql-codegen/${name}-template`,
|
|
10
|
+
`@graphql-codegen/${name}-plugin`,
|
|
11
|
+
`graphql-codegen-${name}`,
|
|
12
|
+
`graphql-codegen-${name}-template`,
|
|
13
|
+
`graphql-codegen-${name}-plugin`,
|
|
14
|
+
`codegen-${name}`,
|
|
15
|
+
`codegen-${name}-template`,
|
|
16
|
+
name,
|
|
17
|
+
];
|
|
18
|
+
const possibleModules = possibleNames.concat((0, path_1.resolve)(process.cwd(), name));
|
|
19
|
+
for (const moduleName of possibleModules) {
|
|
20
|
+
try {
|
|
21
|
+
return await pluginLoader(moduleName);
|
|
22
|
+
}
|
|
23
|
+
catch (err) {
|
|
24
|
+
if (err.code !== 'MODULE_NOT_FOUND') {
|
|
25
|
+
throw new plugin_helpers_1.DetailedError(`Unable to load template plugin matching ${name}`, `
|
|
26
|
+
Unable to load template plugin matching '${name}'.
|
|
27
|
+
Reason:
|
|
28
|
+
${err.message}
|
|
29
|
+
`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const possibleNamesMsg = possibleNames
|
|
34
|
+
.map(name => `
|
|
35
|
+
- ${name}
|
|
36
|
+
`.trimRight())
|
|
37
|
+
.join('');
|
|
38
|
+
throw new plugin_helpers_1.DetailedError(`Unable to find template plugin matching ${name}`, `
|
|
39
|
+
Unable to find template plugin matching '${name}'
|
|
40
|
+
Install one of the following packages:
|
|
41
|
+
|
|
42
|
+
${possibleNamesMsg}
|
|
43
|
+
`);
|
|
44
|
+
}
|
|
45
|
+
exports.getPluginByName = getPluginByName;
|
package/cjs/presets.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPresetByName = void 0;
|
|
4
|
+
const plugin_helpers_1 = require("@graphql-codegen/plugin-helpers");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
async function getPresetByName(name, loader) {
|
|
7
|
+
const possibleNames = [
|
|
8
|
+
`@graphql-codegen/${name}`,
|
|
9
|
+
`@graphql-codegen/${name}-preset`,
|
|
10
|
+
name,
|
|
11
|
+
(0, path_1.resolve)(process.cwd(), name),
|
|
12
|
+
];
|
|
13
|
+
for (const moduleName of possibleNames) {
|
|
14
|
+
try {
|
|
15
|
+
const loaded = await loader(moduleName);
|
|
16
|
+
if (loaded && loaded.preset) {
|
|
17
|
+
return loaded.preset;
|
|
18
|
+
}
|
|
19
|
+
if (loaded && loaded.default) {
|
|
20
|
+
return loaded.default;
|
|
21
|
+
}
|
|
22
|
+
return loaded;
|
|
23
|
+
}
|
|
24
|
+
catch (err) {
|
|
25
|
+
if (
|
|
26
|
+
/** CJS Error code */
|
|
27
|
+
err.code !== 'MODULE_NOT_FOUND' &&
|
|
28
|
+
/** ESM Error code */
|
|
29
|
+
err.code !== 'ERR_MODULE_NOT_FOUND') {
|
|
30
|
+
throw new plugin_helpers_1.DetailedError(`Unable to load preset matching ${name}`, `
|
|
31
|
+
Unable to load preset matching '${name}'.
|
|
32
|
+
Reason:
|
|
33
|
+
${err.message}
|
|
34
|
+
`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const possibleNamesMsg = possibleNames
|
|
39
|
+
.map(name => `
|
|
40
|
+
- ${name}
|
|
41
|
+
`.trimRight())
|
|
42
|
+
.join('');
|
|
43
|
+
throw new plugin_helpers_1.DetailedError(`Unable to find preset matching ${name}`, `
|
|
44
|
+
Unable to find preset matching '${name}'
|
|
45
|
+
Install one of the following packages:
|
|
46
|
+
|
|
47
|
+
${possibleNamesMsg}
|
|
48
|
+
`);
|
|
49
|
+
}
|
|
50
|
+
exports.getPresetByName = getPresetByName;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cliError = exports.isListrError = void 0;
|
|
4
|
+
function isListrError(err) {
|
|
5
|
+
return err.name === 'ListrError' && Array.isArray(err.errors) && err.errors.length > 0;
|
|
6
|
+
}
|
|
7
|
+
exports.isListrError = isListrError;
|
|
8
|
+
function cliError(err, exitOnError = true) {
|
|
9
|
+
let msg;
|
|
10
|
+
if (err instanceof Error) {
|
|
11
|
+
msg = err.message || err.toString();
|
|
12
|
+
}
|
|
13
|
+
else if (typeof err === 'string') {
|
|
14
|
+
msg = err;
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
msg = JSON.stringify(err);
|
|
18
|
+
}
|
|
19
|
+
// eslint-disable-next-line no-console
|
|
20
|
+
console.error(msg);
|
|
21
|
+
if (exitOnError) {
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.cliError = cliError;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resetLogs = exports.printLogs = exports.debugLog = void 0;
|
|
4
|
+
const logger_js_1 = require("./logger.js");
|
|
5
|
+
let queue = [];
|
|
6
|
+
function debugLog(message, ...meta) {
|
|
7
|
+
if (!process.env.GQL_CODEGEN_NODEBUG && process.env.DEBUG !== undefined) {
|
|
8
|
+
queue.push({
|
|
9
|
+
message,
|
|
10
|
+
meta,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.debugLog = debugLog;
|
|
15
|
+
function printLogs() {
|
|
16
|
+
if (!process.env.GQL_CODEGEN_NODEBUG && process.env.DEBUG !== undefined) {
|
|
17
|
+
queue.forEach(log => {
|
|
18
|
+
(0, logger_js_1.getLogger)().info(log.message, ...log.meta);
|
|
19
|
+
});
|
|
20
|
+
resetLogs();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.printLogs = printLogs;
|
|
24
|
+
function resetLogs() {
|
|
25
|
+
queue = [];
|
|
26
|
+
}
|
|
27
|
+
exports.resetLogs = resetLogs;
|