@stepzen/transpiler 0.0.35 → 0.0.38
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/lib/actions/merge.d.ts +2 -0
- package/lib/actions/merge.js +93 -68
- package/lib/actions/merge.js.map +1 -1
- package/lib/utils/merge-helpers.d.ts +1 -0
- package/lib/utils/merge-helpers.js +11 -1
- package/lib/utils/merge-helpers.js.map +1 -1
- package/package.json +1 -1
- package/src/actions/merge.ts +123 -85
- package/src/utils/merge-helpers.ts +11 -0
package/lib/actions/merge.d.ts
CHANGED
|
@@ -5,5 +5,7 @@ declare const _default: (original: string, imported: {
|
|
|
5
5
|
answers: any;
|
|
6
6
|
output: string | null;
|
|
7
7
|
silent: boolean;
|
|
8
|
+
/** when `false` merge only covers config files and updates @sdl directrive */
|
|
9
|
+
mergeTypes?: boolean;
|
|
8
10
|
}) => Promise<string>;
|
|
9
11
|
export default _default;
|
package/lib/actions/merge.js
CHANGED
|
@@ -14,7 +14,8 @@ const BLANK_INDEX_TEMPLATE = `
|
|
|
14
14
|
schema @sdl(files: []) {
|
|
15
15
|
query: Query
|
|
16
16
|
}
|
|
17
|
-
|
|
17
|
+
`.trim();
|
|
18
|
+
const BLANK_QUERY_TYPE = `
|
|
18
19
|
type Query {
|
|
19
20
|
__query: String
|
|
20
21
|
}
|
|
@@ -23,6 +24,7 @@ exports.default = async (original, imported, options = {
|
|
|
23
24
|
answers: {},
|
|
24
25
|
output: null,
|
|
25
26
|
silent: false,
|
|
27
|
+
mergeTypes: true,
|
|
26
28
|
}) => {
|
|
27
29
|
// Make sure there is an output directory
|
|
28
30
|
if (!options.answers)
|
|
@@ -31,6 +33,8 @@ exports.default = async (original, imported, options = {
|
|
|
31
33
|
options.output = path.join(os.tmpdir(), `stepzen-tmp-${Date.now()}`);
|
|
32
34
|
if (!options.silent)
|
|
33
35
|
options.silent = false;
|
|
36
|
+
if (options.mergeTypes === undefined)
|
|
37
|
+
options.mergeTypes = true;
|
|
34
38
|
// To stop things like
|
|
35
39
|
// C:\Users\Darren\AppData\Local\Temp\stepzen-tmp-config-1638293497187\C:\Users\Darren\AppData\Local\Temp\stepzen-tmp-1638293496286
|
|
36
40
|
options.output = merge_helpers_1.dedupeTempFolder(options.output);
|
|
@@ -45,77 +49,98 @@ exports.default = async (original, imported, options = {
|
|
|
45
49
|
// Ensure an index.graphql exists
|
|
46
50
|
const outputIndex = path.join(options.output, 'index.graphql');
|
|
47
51
|
if (!fs.existsSync(outputIndex)) {
|
|
48
|
-
fs.writeFileSync(outputIndex,
|
|
52
|
+
fs.writeFileSync(outputIndex, options.mergeTypes
|
|
53
|
+
? // (2022-03-09, vluakshov) Not sure what'd break without the
|
|
54
|
+
// blank Query type, but that's why I do not want to remove it
|
|
55
|
+
// from the default code path.
|
|
56
|
+
BLANK_INDEX_TEMPLATE + BLANK_QUERY_TYPE
|
|
57
|
+
: // In the non-default code path that does NOT merge types
|
|
58
|
+
// the blank Query type causes explicit problems
|
|
59
|
+
// (https://github.com/steprz/stepzen-cli/issues/482).
|
|
60
|
+
BLANK_INDEX_TEMPLATE);
|
|
49
61
|
}
|
|
50
|
-
const
|
|
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
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
62
|
+
const targetSubfolder = merge_helpers_1.findNextAvailableSubfolder(original, imported.name);
|
|
63
|
+
if (options.mergeTypes) {
|
|
64
|
+
const merged = merge_1.mergeTypeDefs([
|
|
65
|
+
await merge_helpers_1.getSchema(options.output),
|
|
66
|
+
await merge_helpers_1.getSchema(imported.source),
|
|
67
|
+
]);
|
|
68
|
+
let queries = [];
|
|
69
|
+
let mutations = [];
|
|
70
|
+
let types = [];
|
|
71
|
+
graphql_1.visit(merged, {
|
|
72
|
+
ObjectTypeDefinition(node) {
|
|
73
|
+
if (node.name.value === 'Query')
|
|
74
|
+
queries = queries.concat(node.fields);
|
|
75
|
+
else if (node.name.value === 'Mutation')
|
|
76
|
+
mutations = mutations.concat(node.fields);
|
|
77
|
+
else
|
|
78
|
+
types = types.concat(node);
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
const details = {
|
|
82
|
+
original: glob.sync('**/*.graphql', { cwd: options.output }).map(file => {
|
|
83
|
+
const content = fs.readFileSync(`${options.output}/${file}`, 'utf8');
|
|
84
|
+
return { ast: graphql_1.parse(content), file };
|
|
85
|
+
}),
|
|
86
|
+
imported: glob.sync('**/*.graphql', { cwd: imported.source }).map(file => {
|
|
87
|
+
const content = fs.readFileSync(`${imported.source}/${file}`, 'utf8');
|
|
88
|
+
return { ast: graphql_1.parse(content), file };
|
|
89
|
+
}),
|
|
90
|
+
};
|
|
91
|
+
// Merge Queries and Mutations
|
|
92
|
+
for (const type of [...queries, ...mutations]) {
|
|
93
|
+
const isInOriginal = merge_helpers_1.findQueryMutationInSchema(type.name.value, details.original);
|
|
94
|
+
const isInImported = merge_helpers_1.findQueryMutationInSchema(type.name.value, details.imported);
|
|
95
|
+
if (isInOriginal && isInImported) {
|
|
96
|
+
details.original = merge_helpers_1.mergeQueryMutationIntoSchema(type, details.original);
|
|
97
|
+
details.imported = merge_helpers_1.removeQueryMutationFromSchema(type.name.value, details.imported);
|
|
98
|
+
}
|
|
84
99
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
100
|
+
// Merge Types
|
|
101
|
+
for (const type of types) {
|
|
102
|
+
const isInOriginal = merge_helpers_1.findTypeInSchema(type.name.value, details.original);
|
|
103
|
+
const isInImported = merge_helpers_1.findTypeInSchema(type.name.value, details.imported);
|
|
104
|
+
if (isInOriginal && isInImported) {
|
|
105
|
+
details.original = merge_helpers_1.mergeTypeIntoSchema(type, details.original);
|
|
106
|
+
details.imported = merge_helpers_1.removeTypeFromSchema(type.name.value, details.imported);
|
|
107
|
+
}
|
|
93
108
|
}
|
|
109
|
+
// Clean up the files. Remove empty Query / Mutation types, filter out now-empty files
|
|
110
|
+
const cleaned = {
|
|
111
|
+
original: details.original
|
|
112
|
+
.map(item => (Object.assign(Object.assign({}, item), { ast: strip_empty_queries_and_mutations_1.default(item.ast) })))
|
|
113
|
+
.filter(item => item.ast.definitions.length > 0),
|
|
114
|
+
imported: details.imported
|
|
115
|
+
.map(item => (Object.assign(Object.assign({}, item), { ast: strip_empty_queries_and_mutations_1.default(item.ast) })))
|
|
116
|
+
.filter(item => item.ast.definitions.length > 0),
|
|
117
|
+
};
|
|
118
|
+
// Write the files to the output directory
|
|
119
|
+
cleaned.original.forEach((a) => {
|
|
120
|
+
// eslint-disable-next-line
|
|
121
|
+
const file = path.join(options.output, a.file);
|
|
122
|
+
const deduped = merge_helpers_1.dedupeTempFolder(file);
|
|
123
|
+
fs.ensureFileSync(deduped);
|
|
124
|
+
fs.writeFileSync(deduped, print_1.default(a.ast));
|
|
125
|
+
});
|
|
126
|
+
cleaned.imported.forEach(a => {
|
|
127
|
+
// eslint-disable-next-line
|
|
128
|
+
const file = path.join(options.output, targetSubfolder, a.file);
|
|
129
|
+
const deduped = merge_helpers_1.dedupeTempFolder(file);
|
|
130
|
+
fs.ensureFileSync(deduped);
|
|
131
|
+
fs.writeFileSync(deduped, print_1.default(a.ast));
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
// Write the files to the output directory
|
|
136
|
+
fs.copySync(original, options.output);
|
|
137
|
+
glob.sync('**/*.graphql', { cwd: imported.source }).forEach(relativePath => {
|
|
138
|
+
const importedFullPath = path.join(imported.source, relativePath);
|
|
139
|
+
const targetFullPath = path.join(options.output, targetSubfolder, relativePath);
|
|
140
|
+
fs.ensureDirSync(path.dirname(targetFullPath));
|
|
141
|
+
fs.copyFileSync(importedFullPath, targetFullPath);
|
|
142
|
+
});
|
|
94
143
|
}
|
|
95
|
-
// Clean up the files. Remove empty Query / Mutation types, filter out now-empty files
|
|
96
|
-
const cleaned = {
|
|
97
|
-
original: details.original
|
|
98
|
-
.map(item => (Object.assign(Object.assign({}, item), { ast: strip_empty_queries_and_mutations_1.default(item.ast) })))
|
|
99
|
-
.filter(item => item.ast.definitions.length > 0),
|
|
100
|
-
imported: details.imported
|
|
101
|
-
.map(item => (Object.assign(Object.assign({}, item), { ast: strip_empty_queries_and_mutations_1.default(item.ast) })))
|
|
102
|
-
.filter(item => item.ast.definitions.length > 0),
|
|
103
|
-
};
|
|
104
|
-
// Write the files to the output directory
|
|
105
|
-
cleaned.original.forEach((a) => {
|
|
106
|
-
// eslint-disable-next-line
|
|
107
|
-
const file = path.join(options.output, a.file);
|
|
108
|
-
const deduped = merge_helpers_1.dedupeTempFolder(file);
|
|
109
|
-
fs.ensureFileSync(deduped);
|
|
110
|
-
fs.writeFileSync(deduped, print_1.default(a.ast));
|
|
111
|
-
});
|
|
112
|
-
cleaned.imported.forEach(a => {
|
|
113
|
-
// eslint-disable-next-line
|
|
114
|
-
const file = path.join(options.output, imported.name, a.file);
|
|
115
|
-
const deduped = merge_helpers_1.dedupeTempFolder(file);
|
|
116
|
-
fs.ensureFileSync(deduped);
|
|
117
|
-
fs.writeFileSync(deduped, print_1.default(a.ast));
|
|
118
|
-
});
|
|
119
144
|
// Make sure all files are referenced in @sdl
|
|
120
145
|
set_files_in_sdl_1.default(options.output);
|
|
121
146
|
// Generate configuration
|
package/lib/actions/merge.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"merge.js","sourceRoot":"","sources":["../../src/actions/merge.ts"],"names":[],"mappings":";;AAAA,+BAA8B;AAC9B,6BAA4B;AAC5B,gDAAkD;AAClD,qCAAoC;AACpC,yBAAwB;AACxB,6BAA4B;AAE5B,
|
|
1
|
+
{"version":3,"file":"merge.js","sourceRoot":"","sources":["../../src/actions/merge.ts"],"names":[],"mappings":";;AAAA,+BAA8B;AAC9B,6BAA4B;AAC5B,gDAAkD;AAClD,qCAAoC;AACpC,yBAAwB;AACxB,6BAA4B;AAE5B,0DAW+B;AAC/B,mCAA2B;AAC3B,gEAAqD;AACrD,kGAAsF;AAEtF,MAAM,oBAAoB,GAAG;;;;CAI5B,CAAC,IAAI,EAAE,CAAA;AAER,MAAM,gBAAgB,GAAG;;;;CAIxB,CAAC,IAAI,EAAE,CAAA;AAER,kBAAe,KAAK,EAClB,QAAgB,EAChB,QAGC,EACD,UAMI;IACF,OAAO,EAAE,EAAE;IACX,MAAM,EAAE,IAAI;IACZ,MAAM,EAAE,KAAK;IACb,UAAU,EAAE,IAAI;CACjB,EACD,EAAE;IACF,yCAAyC;IACzC,IAAI,CAAC,OAAO,CAAC,OAAO;QAAE,OAAO,CAAC,OAAO,GAAG,EAAE,CAAA;IAC1C,IAAI,CAAC,OAAO,CAAC,MAAM;QACjB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,eAAe,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,CAAA;IACtE,IAAI,CAAC,OAAO,CAAC,MAAM;QAAE,OAAO,CAAC,MAAM,GAAG,KAAK,CAAA;IAC3C,IAAI,OAAO,CAAC,UAAU,KAAK,SAAS;QAAE,OAAO,CAAC,UAAU,GAAG,IAAI,CAAA;IAE/D,sBAAsB;IACtB,mIAAmI;IACnI,OAAO,CAAC,MAAM,GAAG,gCAAgB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;IAEjD,0DAA0D;IAC1D,IAAI,CAAC,EAAE,CA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I,CAAC,cAAc,EAAE,EAAC,GAAG,EAAE,QAAQ,CAAC,MAAM,EAAC,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE;YACvE,MAAM,gBAAgB,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC,CAAA;YACjE,MAAM,cAAc,GAAG,IAAI,CAAC,IAAI,CAC9B,OAAO,CAAC,MAAO,EACf,eAAe,EACf,YAAY,CACb,CAAA;YACD,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,CAAA;YAC9C,EAAE,CAAC,YAAY,CAAC,gBAAgB,EAAE,cAAc,CAAC,CAAA;QACnD,CAAC,CAAC,CAAA;KACH;IAED,6CAA6C;IAC7C,0BAAa,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;IAE7B,yBAAyB;IACzB,MAAM,MAAM,GAAG,MAAM,gCAAgB,CACnC,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,EACjC,OAAO,CAAC,MAAM,EACd,OAAO,CAAC,OAAO,CAChB,CAAA;IACD,IAAI,MAAM,EAAE;QACV,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;QAC3D,EAAE,CAAC,aAAa,CAAC,UAAU,EAAE,MAAgB,CAAC,CAAA;KAC/C;IAED,0BAA0B;IAC1B,OAAO,OAAO,CAAC,MAAM,CAAA;AACvB,CAAC,CAAA"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { GraphQLSchema } from 'graphql';
|
|
2
2
|
export declare const dedupeTempFolder: (dirpath: string) => string;
|
|
3
|
+
export declare const findNextAvailableSubfolder: (folder: string, name: string) => string;
|
|
3
4
|
export declare const findQueryMutationInSchema: (name: string, files: any) => Boolean;
|
|
4
5
|
export declare const findTypeInSchema: (name: string, files: any) => Boolean;
|
|
5
6
|
export declare const getConfiguration: (directories: string[], silent?: boolean, answers?: any) => Promise<string | boolean>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.removeTypeFromSchema = exports.removeQueryMutationFromSchema = exports.mergeTypeIntoSchema = exports.mergeQueryMutationIntoSchema = exports.getSchema = exports.getExtensions = exports.getConfiguration = exports.findTypeInSchema = exports.findQueryMutationInSchema = exports.dedupeTempFolder = void 0;
|
|
3
|
+
exports.removeTypeFromSchema = exports.removeQueryMutationFromSchema = exports.mergeTypeIntoSchema = exports.mergeQueryMutationIntoSchema = exports.getSchema = exports.getExtensions = exports.getConfiguration = exports.findTypeInSchema = exports.findQueryMutationInSchema = exports.findNextAvailableSubfolder = exports.dedupeTempFolder = void 0;
|
|
4
4
|
const graphql_1 = require("graphql");
|
|
5
5
|
const utilities_1 = require("graphql/utilities");
|
|
6
6
|
const node_fetch_1 = require("node-fetch");
|
|
@@ -21,6 +21,16 @@ const dedupeTempFolder = (dirpath) => {
|
|
|
21
21
|
return dirpath;
|
|
22
22
|
};
|
|
23
23
|
exports.dedupeTempFolder = dedupeTempFolder;
|
|
24
|
+
const findNextAvailableSubfolder = (folder, name) => {
|
|
25
|
+
let subfolder = name;
|
|
26
|
+
let counter = 1;
|
|
27
|
+
while (fs.existsSync(path.join(folder, subfolder))) {
|
|
28
|
+
const suffix = `${counter++}`.padStart(2, '0');
|
|
29
|
+
subfolder = `${name}-${suffix}`;
|
|
30
|
+
}
|
|
31
|
+
return subfolder;
|
|
32
|
+
};
|
|
33
|
+
exports.findNextAvailableSubfolder = findNextAvailableSubfolder;
|
|
24
34
|
const findQueryMutationInSchema = (name, files) => {
|
|
25
35
|
for (const file of files) {
|
|
26
36
|
let found = false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"merge-helpers.js","sourceRoot":"","sources":["../../src/utils/merge-helpers.ts"],"names":[],"mappings":";;;AAAA,qCAAm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C,IAAI,CAAC,GAAG,EAAE;gBACnB,eAAe,CAAC,IAAI;oBAClB,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,KAAK,IAAI,EAAE;wBAC5B,OAAO,IAAI,CAAA;qBACZ;gBACH,CAAC;aACF,CAAC,IACH;IACH,CAAC,CAAC,CAAA;IACF,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAdY,QAAA,6BAA6B,iCAczC;AAEM,MAAM,oBAAoB,GAAG,CAAC,IAAY,EAAE,KAAU,EAAE,EAAE;IAC/D,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAS,EAAE,EAAE;QAC9B,uCACK,IAAI,KACP,GAAG,EAAE,eAAK,CAAC,IAAI,CAAC,GAAG,EAAE;gBACnB,oBAAoB,CAAC,IAAI;oBACvB,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,KAAK,IAAI,EAAE;wBAC5B,OAAO,IAAI,CAAA;qBACZ;gBACH,CAAC;aACF,CAAC,IACH;IACH,CAAC,CAAC,CAAA;IACF,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAdY,QAAA,oBAAoB,wBAchC"}
|
package/package.json
CHANGED
package/src/actions/merge.ts
CHANGED
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
mergeTypeIntoSchema,
|
|
16
16
|
removeTypeFromSchema,
|
|
17
17
|
getConfiguration,
|
|
18
|
+
findNextAvailableSubfolder,
|
|
18
19
|
} from '../utils/merge-helpers'
|
|
19
20
|
import print from './print'
|
|
20
21
|
import setFilesInSDL from '../utils/set-files-in-sdl'
|
|
@@ -24,7 +25,9 @@ const BLANK_INDEX_TEMPLATE = `
|
|
|
24
25
|
schema @sdl(files: []) {
|
|
25
26
|
query: Query
|
|
26
27
|
}
|
|
28
|
+
`.trim()
|
|
27
29
|
|
|
30
|
+
const BLANK_QUERY_TYPE = `
|
|
28
31
|
type Query {
|
|
29
32
|
__query: String
|
|
30
33
|
}
|
|
@@ -40,10 +43,13 @@ export default async (
|
|
|
40
43
|
answers: any
|
|
41
44
|
output: string | null
|
|
42
45
|
silent: boolean
|
|
46
|
+
/** when `false` merge only covers config files and updates @sdl directrive */
|
|
47
|
+
mergeTypes?: boolean
|
|
43
48
|
} = {
|
|
44
49
|
answers: {},
|
|
45
50
|
output: null,
|
|
46
51
|
silent: false,
|
|
52
|
+
mergeTypes: true,
|
|
47
53
|
},
|
|
48
54
|
) => {
|
|
49
55
|
// Make sure there is an output directory
|
|
@@ -51,6 +57,7 @@ export default async (
|
|
|
51
57
|
if (!options.output)
|
|
52
58
|
options.output = path.join(os.tmpdir(), `stepzen-tmp-${Date.now()}`)
|
|
53
59
|
if (!options.silent) options.silent = false
|
|
60
|
+
if (options.mergeTypes === undefined) options.mergeTypes = true
|
|
54
61
|
|
|
55
62
|
// To stop things like
|
|
56
63
|
// C:\Users\Darren\AppData\Local\Temp\stepzen-tmp-config-1638293497187\C:\Users\Darren\AppData\Local\Temp\stepzen-tmp-1638293496286
|
|
@@ -69,104 +76,135 @@ export default async (
|
|
|
69
76
|
// Ensure an index.graphql exists
|
|
70
77
|
const outputIndex = path.join(options.output, 'index.graphql')
|
|
71
78
|
if (!fs.existsSync(outputIndex)) {
|
|
72
|
-
fs.writeFileSync(
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
visit(merged, {
|
|
85
|
-
ObjectTypeDefinition(node) {
|
|
86
|
-
if (node.name.value === 'Query') queries = queries.concat(node.fields)
|
|
87
|
-
else if (node.name.value === 'Mutation')
|
|
88
|
-
mutations = mutations.concat(node.fields)
|
|
89
|
-
else types = types.concat(node)
|
|
90
|
-
},
|
|
91
|
-
})
|
|
92
|
-
|
|
93
|
-
const details = {
|
|
94
|
-
original: glob.sync('**/*.graphql', {cwd: options.output}).map(file => {
|
|
95
|
-
const content = fs.readFileSync(`${options.output}/${file}`, 'utf8')
|
|
96
|
-
return {ast: parse(content), file}
|
|
97
|
-
}),
|
|
98
|
-
imported: glob.sync('**/*.graphql', {cwd: imported.source}).map(file => {
|
|
99
|
-
const content = fs.readFileSync(`${imported.source}/${file}`, 'utf8')
|
|
100
|
-
return {ast: parse(content), file}
|
|
101
|
-
}),
|
|
79
|
+
fs.writeFileSync(
|
|
80
|
+
outputIndex,
|
|
81
|
+
options.mergeTypes
|
|
82
|
+
? // (2022-03-09, vluakshov) Not sure what'd break without the
|
|
83
|
+
// blank Query type, but that's why I do not want to remove it
|
|
84
|
+
// from the default code path.
|
|
85
|
+
BLANK_INDEX_TEMPLATE + BLANK_QUERY_TYPE
|
|
86
|
+
: // In the non-default code path that does NOT merge types
|
|
87
|
+
// the blank Query type causes explicit problems
|
|
88
|
+
// (https://github.com/steprz/stepzen-cli/issues/482).
|
|
89
|
+
BLANK_INDEX_TEMPLATE,
|
|
90
|
+
)
|
|
102
91
|
}
|
|
103
92
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
93
|
+
const targetSubfolder = findNextAvailableSubfolder(original, imported.name)
|
|
94
|
+
|
|
95
|
+
if (options.mergeTypes) {
|
|
96
|
+
const merged = mergeTypeDefs([
|
|
97
|
+
await getSchema(options.output),
|
|
98
|
+
await getSchema(imported.source),
|
|
99
|
+
])
|
|
100
|
+
|
|
101
|
+
let queries: any[] = []
|
|
102
|
+
let mutations: any[] = []
|
|
103
|
+
let types: any[] = []
|
|
104
|
+
|
|
105
|
+
visit(merged, {
|
|
106
|
+
ObjectTypeDefinition(node) {
|
|
107
|
+
if (node.name.value === 'Query') queries = queries.concat(node.fields)
|
|
108
|
+
else if (node.name.value === 'Mutation')
|
|
109
|
+
mutations = mutations.concat(node.fields)
|
|
110
|
+
else types = types.concat(node)
|
|
111
|
+
},
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
const details = {
|
|
115
|
+
original: glob.sync('**/*.graphql', {cwd: options.output}).map(file => {
|
|
116
|
+
const content = fs.readFileSync(`${options.output}/${file}`, 'utf8')
|
|
117
|
+
return {ast: parse(content), file}
|
|
118
|
+
}),
|
|
119
|
+
imported: glob.sync('**/*.graphql', {cwd: imported.source}).map(file => {
|
|
120
|
+
const content = fs.readFileSync(`${imported.source}/${file}`, 'utf8')
|
|
121
|
+
return {ast: parse(content), file}
|
|
122
|
+
}),
|
|
123
|
+
}
|
|
114
124
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
125
|
+
// Merge Queries and Mutations
|
|
126
|
+
for (const type of [...queries, ...mutations]) {
|
|
127
|
+
const isInOriginal = findQueryMutationInSchema(
|
|
128
|
+
type.name.value,
|
|
129
|
+
details.original,
|
|
130
|
+
)
|
|
131
|
+
const isInImported = findQueryMutationInSchema(
|
|
118
132
|
type.name.value,
|
|
119
133
|
details.imported,
|
|
120
134
|
)
|
|
135
|
+
|
|
136
|
+
if (isInOriginal && isInImported) {
|
|
137
|
+
details.original = mergeQueryMutationIntoSchema(type, details.original)
|
|
138
|
+
details.imported = removeQueryMutationFromSchema(
|
|
139
|
+
type.name.value,
|
|
140
|
+
details.imported,
|
|
141
|
+
)
|
|
142
|
+
}
|
|
121
143
|
}
|
|
122
|
-
}
|
|
123
144
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
145
|
+
// Merge Types
|
|
146
|
+
for (const type of types) {
|
|
147
|
+
const isInOriginal = findTypeInSchema(type.name.value, details.original)
|
|
148
|
+
const isInImported = findTypeInSchema(type.name.value, details.imported)
|
|
149
|
+
|
|
150
|
+
if (isInOriginal && isInImported) {
|
|
151
|
+
details.original = mergeTypeIntoSchema(type, details.original)
|
|
152
|
+
details.imported = removeTypeFromSchema(
|
|
153
|
+
type.name.value,
|
|
154
|
+
details.imported,
|
|
155
|
+
)
|
|
156
|
+
}
|
|
157
|
+
}
|
|
128
158
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
159
|
+
// Clean up the files. Remove empty Query / Mutation types, filter out now-empty files
|
|
160
|
+
const cleaned = {
|
|
161
|
+
original: details.original
|
|
162
|
+
.map(item => ({
|
|
163
|
+
...item,
|
|
164
|
+
ast: stripEmptyQueriesAndMutations(item.ast),
|
|
165
|
+
}))
|
|
166
|
+
.filter(item => item.ast.definitions.length > 0),
|
|
167
|
+
imported: details.imported
|
|
168
|
+
.map(item => ({
|
|
169
|
+
...item,
|
|
170
|
+
ast: stripEmptyQueriesAndMutations(item.ast),
|
|
171
|
+
}))
|
|
172
|
+
.filter(item => item.ast.definitions.length > 0),
|
|
132
173
|
}
|
|
133
|
-
}
|
|
134
174
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
.
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
.
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
175
|
+
// Write the files to the output directory
|
|
176
|
+
cleaned.original.forEach((a: any) => {
|
|
177
|
+
// eslint-disable-next-line
|
|
178
|
+
const file = path.join(options.output as any, a.file)
|
|
179
|
+
const deduped = dedupeTempFolder(file)
|
|
180
|
+
|
|
181
|
+
fs.ensureFileSync(deduped)
|
|
182
|
+
fs.writeFileSync(deduped, print(a.ast))
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
cleaned.imported.forEach(a => {
|
|
186
|
+
// eslint-disable-next-line
|
|
187
|
+
const file = path.join(options.output as any, targetSubfolder, a.file)
|
|
188
|
+
const deduped = dedupeTempFolder(file)
|
|
189
|
+
|
|
190
|
+
fs.ensureFileSync(deduped)
|
|
191
|
+
fs.writeFileSync(deduped, print(a.ast))
|
|
192
|
+
})
|
|
193
|
+
} else {
|
|
194
|
+
// Write the files to the output directory
|
|
195
|
+
fs.copySync(original, options.output)
|
|
196
|
+
glob.sync('**/*.graphql', {cwd: imported.source}).forEach(relativePath => {
|
|
197
|
+
const importedFullPath = path.join(imported.source, relativePath)
|
|
198
|
+
const targetFullPath = path.join(
|
|
199
|
+
options.output!,
|
|
200
|
+
targetSubfolder,
|
|
201
|
+
relativePath,
|
|
202
|
+
)
|
|
203
|
+
fs.ensureDirSync(path.dirname(targetFullPath))
|
|
204
|
+
fs.copyFileSync(importedFullPath, targetFullPath)
|
|
205
|
+
})
|
|
149
206
|
}
|
|
150
207
|
|
|
151
|
-
// Write the files to the output directory
|
|
152
|
-
cleaned.original.forEach((a: any) => {
|
|
153
|
-
// eslint-disable-next-line
|
|
154
|
-
const file = path.join(options.output as any, a.file)
|
|
155
|
-
const deduped = dedupeTempFolder(file)
|
|
156
|
-
|
|
157
|
-
fs.ensureFileSync(deduped)
|
|
158
|
-
fs.writeFileSync(deduped, print(a.ast))
|
|
159
|
-
})
|
|
160
|
-
|
|
161
|
-
cleaned.imported.forEach(a => {
|
|
162
|
-
// eslint-disable-next-line
|
|
163
|
-
const file = path.join(options.output as any, imported.name, a.file)
|
|
164
|
-
const deduped = dedupeTempFolder(file)
|
|
165
|
-
|
|
166
|
-
fs.ensureFileSync(deduped)
|
|
167
|
-
fs.writeFileSync(deduped, print(a.ast))
|
|
168
|
-
})
|
|
169
|
-
|
|
170
208
|
// Make sure all files are referenced in @sdl
|
|
171
209
|
setFilesInSDL(options.output)
|
|
172
210
|
|
|
@@ -23,6 +23,17 @@ export const dedupeTempFolder = (dirpath: string) => {
|
|
|
23
23
|
return dirpath
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
export const findNextAvailableSubfolder = (folder: string, name: string) => {
|
|
27
|
+
let subfolder = name
|
|
28
|
+
let counter = 1
|
|
29
|
+
while (fs.existsSync(path.join(folder, subfolder))) {
|
|
30
|
+
const suffix = `${counter++}`.padStart(2, '0')
|
|
31
|
+
subfolder = `${name}-${suffix}`
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return subfolder
|
|
35
|
+
}
|
|
36
|
+
|
|
26
37
|
export const findQueryMutationInSchema = (
|
|
27
38
|
name: string,
|
|
28
39
|
files: any,
|