@graphcommerce/graphql-codegen-near-operation-file 2.102.1 → 2.103.1
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/dist/fragment-resolver.js +52 -45
- package/dist/index.js +76 -65
- package/dist/injectable.js +48 -36
- package/dist/resolve-document-imports.js +59 -43
- package/dist/utils.js +11 -10
- package/package.json +13 -10
- package/src/fragment-resolver.ts +191 -0
- package/src/index.ts +266 -0
- package/src/injectable.graphqls +21 -0
- package/src/injectable.ts +126 -0
- package/src/resolve-document-imports.ts +173 -0
- package/src/test/InjectableFragment.graphql +3 -0
- package/src/test/InjectingFragment.graphql +3 -0
- package/src/test/QueryWithInjectable.graphql +5 -0
- package/src/utils.ts +61 -0
- package/dist/fragment-resolver.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/injectable.js.map +0 -1
- package/dist/resolve-document-imports.js.map +0 -1
- package/dist/utils.js.map +0 -1
|
@@ -1,25 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.buildFragmentRegistry = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
var visitor_plugin_common_1 = require("@graphql-codegen/visitor-plugin-common");
|
|
5
|
+
var graphql_1 = require("graphql");
|
|
6
|
+
var utils_1 = require("./utils");
|
|
7
7
|
/**
|
|
8
8
|
* Used by `buildFragmentResolver` to build a mapping of fragmentNames to paths, importNames, and
|
|
9
9
|
* other useful info
|
|
10
10
|
*/
|
|
11
|
-
function buildFragmentRegistry(
|
|
12
|
-
|
|
11
|
+
function buildFragmentRegistry(_a, _b, schemaObject) {
|
|
12
|
+
var generateFilePath = _a.generateFilePath;
|
|
13
|
+
var documents = _b.documents, config = _b.config;
|
|
14
|
+
var baseVisitor = new visitor_plugin_common_1.BaseVisitor(config, {
|
|
13
15
|
scalars: (0, visitor_plugin_common_1.buildScalarsFromConfig)(schemaObject, config),
|
|
14
16
|
dedupeOperationSuffix: (0, visitor_plugin_common_1.getConfigValue)(config.dedupeOperationSuffix, false),
|
|
15
17
|
omitOperationSuffix: (0, visitor_plugin_common_1.getConfigValue)(config.omitOperationSuffix, false),
|
|
16
18
|
fragmentVariablePrefix: (0, visitor_plugin_common_1.getConfigValue)(config.fragmentVariablePrefix, ''),
|
|
17
19
|
fragmentVariableSuffix: (0, visitor_plugin_common_1.getConfigValue)(config.fragmentVariableSuffix, 'FragmentDoc'),
|
|
18
20
|
});
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
var getFragmentImports = function (possbileTypes, name) {
|
|
22
|
+
var fragmentImports = [];
|
|
21
23
|
fragmentImports.push({ name: baseVisitor.getFragmentVariableName(name), kind: 'document' });
|
|
22
|
-
|
|
24
|
+
var fragmentSuffix = baseVisitor.getFragmentSuffix(name);
|
|
23
25
|
if (possbileTypes.length === 1) {
|
|
24
26
|
fragmentImports.push({
|
|
25
27
|
name: baseVisitor.convertName(name, {
|
|
@@ -30,11 +32,11 @@ function buildFragmentRegistry({ generateFilePath }, { documents, config }, sche
|
|
|
30
32
|
});
|
|
31
33
|
}
|
|
32
34
|
else if (possbileTypes.length !== 0) {
|
|
33
|
-
possbileTypes.forEach((typeName)
|
|
35
|
+
possbileTypes.forEach(function (typeName) {
|
|
34
36
|
fragmentImports.push({
|
|
35
37
|
name: baseVisitor.convertName(name, {
|
|
36
38
|
useTypesPrefix: true,
|
|
37
|
-
suffix:
|
|
39
|
+
suffix: "_" + typeName + "_" + fragmentSuffix,
|
|
38
40
|
}),
|
|
39
41
|
kind: 'type',
|
|
40
42
|
});
|
|
@@ -42,27 +44,28 @@ function buildFragmentRegistry({ generateFilePath }, { documents, config }, sche
|
|
|
42
44
|
}
|
|
43
45
|
return fragmentImports;
|
|
44
46
|
};
|
|
45
|
-
|
|
46
|
-
|
|
47
|
+
var duplicateFragmentNames = [];
|
|
48
|
+
var registry = documents.reduce(function (prev, documentRecord) {
|
|
47
49
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
48
|
-
|
|
50
|
+
var fragments = documentRecord.document.definitions.filter(function (d) { return d.kind === graphql_1.Kind.FRAGMENT_DEFINITION; });
|
|
49
51
|
if (fragments.length > 0) {
|
|
50
|
-
for (
|
|
51
|
-
|
|
52
|
+
for (var _i = 0, fragments_1 = fragments; _i < fragments_1.length; _i++) {
|
|
53
|
+
var fragment = fragments_1[_i];
|
|
54
|
+
var schemaType = schemaObject.getType(fragment.typeCondition.name.value);
|
|
52
55
|
if (!schemaType) {
|
|
53
|
-
throw new Error(
|
|
56
|
+
throw new Error("Fragment \"" + fragment.name.value + "\" is set on non-existing type \"" + fragment.typeCondition.name.value + "\"!");
|
|
54
57
|
}
|
|
55
|
-
|
|
58
|
+
var possibleTypes = (0, visitor_plugin_common_1.getPossibleTypes)(schemaObject, schemaType);
|
|
56
59
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
57
|
-
|
|
58
|
-
|
|
60
|
+
var filePath = generateFilePath(documentRecord.location);
|
|
61
|
+
var imports = getFragmentImports(possibleTypes.map(function (t) { return t.name; }), fragment.name.value);
|
|
59
62
|
if (prev[fragment.name.value] &&
|
|
60
63
|
(0, graphql_1.print)(fragment) !== (0, graphql_1.print)(prev[fragment.name.value].node)) {
|
|
61
64
|
duplicateFragmentNames.push(fragment.name.value);
|
|
62
65
|
}
|
|
63
66
|
prev[fragment.name.value] = {
|
|
64
|
-
filePath,
|
|
65
|
-
imports,
|
|
67
|
+
filePath: filePath,
|
|
68
|
+
imports: imports,
|
|
66
69
|
onType: fragment.typeCondition.name.value,
|
|
67
70
|
node: fragment,
|
|
68
71
|
};
|
|
@@ -71,24 +74,26 @@ function buildFragmentRegistry({ generateFilePath }, { documents, config }, sche
|
|
|
71
74
|
return prev;
|
|
72
75
|
}, {});
|
|
73
76
|
if (duplicateFragmentNames.length) {
|
|
74
|
-
throw new Error(
|
|
77
|
+
throw new Error("Multiple fragments with the name(s) \"" + duplicateFragmentNames.join(', ') + "\" were found.");
|
|
75
78
|
}
|
|
76
79
|
return registry;
|
|
77
80
|
}
|
|
78
81
|
exports.buildFragmentRegistry = buildFragmentRegistry;
|
|
79
82
|
/** Builds a fragment "resolver" that collects `externalFragments` definitions and `fragmentImportStatements` */
|
|
80
83
|
function buildFragmentResolver(collectorOptions, presetOptions, schemaObject) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
+
var fragmentRegistry = buildFragmentRegistry(collectorOptions, presetOptions, schemaObject);
|
|
85
|
+
var baseOutputDir = presetOptions.baseOutputDir;
|
|
86
|
+
var baseDir = collectorOptions.baseDir, typesImport = collectorOptions.typesImport;
|
|
84
87
|
function resolveFragments(generatedFilePath, documentFileContent) {
|
|
85
|
-
|
|
86
|
-
|
|
88
|
+
var _a;
|
|
89
|
+
var fragmentsInUse = (0, utils_1.extractExternalFragmentsInUse)(documentFileContent, fragmentRegistry);
|
|
90
|
+
var externalFragments = [];
|
|
87
91
|
// fragment files to import names
|
|
88
|
-
|
|
89
|
-
for (
|
|
90
|
-
|
|
91
|
-
|
|
92
|
+
var fragmentFileImports = {};
|
|
93
|
+
for (var _i = 0, _b = Object.keys(fragmentsInUse); _i < _b.length; _i++) {
|
|
94
|
+
var fragmentName = _b[_i];
|
|
95
|
+
var level = fragmentsInUse[fragmentName];
|
|
96
|
+
var fragmentDetails = fragmentRegistry[fragmentName];
|
|
92
97
|
if (fragmentDetails) {
|
|
93
98
|
// add top level references to the import object
|
|
94
99
|
// we don't checkf or global namespace because the calling config can do so
|
|
@@ -97,11 +102,11 @@ function buildFragmentResolver(collectorOptions, presetOptions, schemaObject) {
|
|
|
97
102
|
fragmentFileImports[fragmentDetails.filePath] = fragmentDetails.imports;
|
|
98
103
|
}
|
|
99
104
|
else {
|
|
100
|
-
fragmentFileImports[fragmentDetails.filePath].push(
|
|
105
|
+
(_a = fragmentFileImports[fragmentDetails.filePath]).push.apply(_a, fragmentDetails.imports);
|
|
101
106
|
}
|
|
102
107
|
}
|
|
103
108
|
externalFragments.push({
|
|
104
|
-
level,
|
|
109
|
+
level: level,
|
|
105
110
|
isExternal: true,
|
|
106
111
|
name: fragmentName,
|
|
107
112
|
onType: fragmentDetails.onType,
|
|
@@ -110,20 +115,22 @@ function buildFragmentResolver(collectorOptions, presetOptions, schemaObject) {
|
|
|
110
115
|
}
|
|
111
116
|
}
|
|
112
117
|
return {
|
|
113
|
-
externalFragments,
|
|
114
|
-
fragmentImports: Object.entries(fragmentFileImports).map((
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
118
|
+
externalFragments: externalFragments,
|
|
119
|
+
fragmentImports: Object.entries(fragmentFileImports).map(function (_a) {
|
|
120
|
+
var fragmentsFilePath = _a[0], identifiers = _a[1];
|
|
121
|
+
return ({
|
|
122
|
+
baseDir: baseDir,
|
|
123
|
+
baseOutputDir: baseOutputDir,
|
|
124
|
+
outputPath: generatedFilePath,
|
|
125
|
+
importSource: {
|
|
126
|
+
path: fragmentsFilePath,
|
|
127
|
+
identifiers: identifiers,
|
|
128
|
+
},
|
|
129
|
+
typesImport: typesImport,
|
|
130
|
+
});
|
|
131
|
+
}),
|
|
124
132
|
};
|
|
125
133
|
}
|
|
126
134
|
return resolveFragments;
|
|
127
135
|
}
|
|
128
136
|
exports.default = buildFragmentResolver;
|
|
129
|
-
//# sourceMappingURL=fragment-resolver.js.map
|
package/dist/index.js
CHANGED
|
@@ -1,21 +1,52 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
14
|
+
var t = {};
|
|
15
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
16
|
+
t[p] = s[p];
|
|
17
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
18
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
19
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
20
|
+
t[p[i]] = s[p[i]];
|
|
21
|
+
}
|
|
22
|
+
return t;
|
|
23
|
+
};
|
|
24
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
25
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
26
|
+
if (ar || !(i in from)) {
|
|
27
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
28
|
+
ar[i] = from[i];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
32
|
+
};
|
|
2
33
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
34
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
35
|
};
|
|
5
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
37
|
exports.preset = exports.resolveDocumentImports = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
38
|
+
var path_1 = require("path");
|
|
39
|
+
var add_1 = __importDefault(require("@graphql-codegen/add"));
|
|
40
|
+
var graphql_1 = require("graphql");
|
|
41
|
+
var injectable_1 = require("./injectable");
|
|
42
|
+
var resolve_document_imports_1 = require("./resolve-document-imports");
|
|
12
43
|
Object.defineProperty(exports, "resolveDocumentImports", { enumerable: true, get: function () { return resolve_document_imports_1.resolveDocumentImports; } });
|
|
13
|
-
|
|
44
|
+
var utils_1 = require("./utils");
|
|
14
45
|
function isFragment(documentFile) {
|
|
15
|
-
|
|
46
|
+
var name = false;
|
|
16
47
|
(0, graphql_1.visit)(documentFile.document, {
|
|
17
48
|
enter: {
|
|
18
|
-
FragmentDefinition: ()
|
|
49
|
+
FragmentDefinition: function () {
|
|
19
50
|
name = true;
|
|
20
51
|
},
|
|
21
52
|
},
|
|
@@ -26,82 +57,62 @@ function isDocument(documentFiles) {
|
|
|
26
57
|
return !documentFiles.every(isFragment);
|
|
27
58
|
}
|
|
28
59
|
exports.preset = {
|
|
29
|
-
buildGeneratesSection: (options)
|
|
60
|
+
buildGeneratesSection: function (options) {
|
|
61
|
+
var _a, _b, _c, _d, _e, _f;
|
|
30
62
|
if (options.presetConfig.injectables) {
|
|
31
63
|
options.documents = (0, injectable_1.injectInjectables)(options.documents);
|
|
32
64
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
65
|
+
var schemaObject = (_a = options.schemaAst) !== null && _a !== void 0 ? _a : (0, graphql_1.buildASTSchema)(options.schema, options.config);
|
|
66
|
+
var baseDir = (_b = options.presetConfig.cwd) !== null && _b !== void 0 ? _b : process.cwd();
|
|
67
|
+
var extension = (_c = options.presetConfig.extension) !== null && _c !== void 0 ? _c : '.generated.ts';
|
|
68
|
+
var folder = (_d = options.presetConfig.folder) !== null && _d !== void 0 ? _d : '';
|
|
69
|
+
var importTypesNamespace = (_e = options.presetConfig.importTypesNamespace) !== null && _e !== void 0 ? _e : 'Types';
|
|
70
|
+
var importAllFragmentsFrom = options.presetConfig.importAllFragmentsFrom;
|
|
71
|
+
var baseTypesPath = options.presetConfig.baseTypesPath;
|
|
40
72
|
if (!baseTypesPath) {
|
|
41
|
-
throw new Error(
|
|
73
|
+
throw new Error("Preset \"near-operation-file\" requires you to specify \"baseTypesPath\" configuration and point it to your base types file (generated by \"typescript\" plugin)!");
|
|
42
74
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
baseDir,
|
|
50
|
-
generateFilePath(location) {
|
|
51
|
-
const newFilePath = (0, utils_1.defineFilepathSubfolder)(location, folder);
|
|
75
|
+
var shouldAbsolute = !baseTypesPath.startsWith('~');
|
|
76
|
+
var pluginMap = __assign(__assign({}, options.pluginMap), { add: add_1.default });
|
|
77
|
+
var sources = (0, resolve_document_imports_1.resolveDocumentImports)(options, schemaObject, {
|
|
78
|
+
baseDir: baseDir,
|
|
79
|
+
generateFilePath: function (location) {
|
|
80
|
+
var newFilePath = (0, utils_1.defineFilepathSubfolder)(location, folder);
|
|
52
81
|
return (0, utils_1.appendExtensionToFilePath)(newFilePath, extension);
|
|
53
82
|
},
|
|
54
83
|
schemaTypesSource: {
|
|
55
84
|
path: shouldAbsolute ? (0, path_1.join)(options.baseOutputDir, baseTypesPath) : baseTypesPath,
|
|
56
85
|
namespace: importTypesNamespace,
|
|
57
86
|
},
|
|
58
|
-
typesImport: options.config.useTypeImports
|
|
87
|
+
typesImport: (_f = options.config.useTypeImports) !== null && _f !== void 0 ? _f : false,
|
|
59
88
|
});
|
|
60
|
-
return sources.map((
|
|
61
|
-
|
|
89
|
+
return sources.map(function (_a) {
|
|
90
|
+
var importStatements = _a.importStatements, externalFragments = _a.externalFragments, fragmentImports = _a.fragmentImports, documents = _a.documents, source = __rest(_a, ["importStatements", "externalFragments", "fragmentImports", "documents"]);
|
|
91
|
+
var fragmentImportsArr = fragmentImports;
|
|
62
92
|
if (importAllFragmentsFrom) {
|
|
63
|
-
fragmentImportsArr = fragmentImports.map((t)
|
|
64
|
-
|
|
65
|
-
? {
|
|
66
|
-
|
|
67
|
-
return {
|
|
68
|
-
...t,
|
|
69
|
-
importSource: newImportSource || t.importSource,
|
|
70
|
-
};
|
|
93
|
+
fragmentImportsArr = fragmentImports.map(function (t) {
|
|
94
|
+
var newImportSource = typeof importAllFragmentsFrom === 'string'
|
|
95
|
+
? __assign(__assign({}, t.importSource), { path: importAllFragmentsFrom }) : importAllFragmentsFrom(t.importSource, source.filename);
|
|
96
|
+
return __assign(__assign({}, t), { importSource: newImportSource || t.importSource });
|
|
71
97
|
});
|
|
72
98
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
99
|
+
var isDoc = isDocument(documents);
|
|
100
|
+
var isRelayOptimizer = !!Object.keys(pluginMap).find(function (plugin) {
|
|
101
|
+
return plugin.includes('relay-optimizer-plugin');
|
|
102
|
+
});
|
|
103
|
+
var plugins = __spreadArray(__spreadArray([], (options.config.globalNamespace
|
|
104
|
+
? []
|
|
105
|
+
: importStatements.map(function (importStatement) { return ({ add: { content: importStatement } }); })), true), options.plugins.filter(function (pluginOptions) {
|
|
106
|
+
return !isRelayOptimizer ||
|
|
81
107
|
isDoc ||
|
|
82
|
-
!Object.keys(pluginOptions).includes('typed-document-node')
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
...options.config,
|
|
108
|
+
!Object.keys(pluginOptions).includes('typed-document-node');
|
|
109
|
+
}), true);
|
|
110
|
+
var config = __assign(__assign({}, options.config), {
|
|
86
111
|
// This is set here in order to make sure the fragment spreads sub types
|
|
87
112
|
// are exported from operations file
|
|
88
|
-
exportFragmentSpreadSubTypes: true,
|
|
89
|
-
|
|
90
|
-
externalFragments,
|
|
91
|
-
fragmentImports: fragmentImportsArr,
|
|
92
|
-
};
|
|
93
|
-
return {
|
|
94
|
-
...source,
|
|
95
|
-
documents,
|
|
96
|
-
plugins,
|
|
97
|
-
pluginMap,
|
|
98
|
-
config,
|
|
99
|
-
schema: options.schema,
|
|
100
|
-
schemaAst: schemaObject,
|
|
101
|
-
skipDocumentsValidation: true,
|
|
102
|
-
};
|
|
113
|
+
exportFragmentSpreadSubTypes: true, namespacedImportName: importTypesNamespace, externalFragments: externalFragments, fragmentImports: fragmentImportsArr });
|
|
114
|
+
return __assign(__assign({}, source), { documents: documents, plugins: plugins, pluginMap: pluginMap, config: config, schema: options.schema, schemaAst: schemaObject, skipDocumentsValidation: true });
|
|
103
115
|
});
|
|
104
116
|
},
|
|
105
117
|
};
|
|
106
118
|
exports.default = exports.preset;
|
|
107
|
-
//# sourceMappingURL=index.js.map
|
package/dist/injectable.js
CHANGED
|
@@ -1,20 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
3
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
4
|
+
if (ar || !(i in from)) {
|
|
5
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
6
|
+
ar[i] = from[i];
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.injectInjectables = void 0;
|
|
4
|
-
|
|
13
|
+
var graphql_1 = require("graphql");
|
|
5
14
|
function isFragment(document) {
|
|
6
|
-
|
|
15
|
+
var is = false;
|
|
7
16
|
(0, graphql_1.visit)(document, {
|
|
8
|
-
FragmentDefinition: ()
|
|
17
|
+
FragmentDefinition: function () {
|
|
9
18
|
is = true;
|
|
10
19
|
},
|
|
11
20
|
});
|
|
12
21
|
return is;
|
|
13
22
|
}
|
|
14
23
|
function hasInjectableDirective(document) {
|
|
15
|
-
|
|
24
|
+
var is = false;
|
|
16
25
|
(0, graphql_1.visit)(document, {
|
|
17
|
-
Directive: (node)
|
|
26
|
+
Directive: function (node) {
|
|
18
27
|
if (!is && node.name.value === 'injectable')
|
|
19
28
|
is = true;
|
|
20
29
|
},
|
|
@@ -22,9 +31,9 @@ function hasInjectableDirective(document) {
|
|
|
22
31
|
return is && isFragment;
|
|
23
32
|
}
|
|
24
33
|
function hasInjectDirective(document) {
|
|
25
|
-
|
|
34
|
+
var is = false;
|
|
26
35
|
(0, graphql_1.visit)(document, {
|
|
27
|
-
Directive: (node)
|
|
36
|
+
Directive: function (node) {
|
|
28
37
|
if (!is && node.name.value === 'inject')
|
|
29
38
|
is = true;
|
|
30
39
|
},
|
|
@@ -32,33 +41,34 @@ function hasInjectDirective(document) {
|
|
|
32
41
|
return is && isFragment;
|
|
33
42
|
}
|
|
34
43
|
function throwInjectError(conf, message) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
fragment
|
|
44
|
+
var _a, _b, _c;
|
|
45
|
+
var val = (_a = conf.into) === null || _a === void 0 ? void 0 : _a.map(function (v) { return "\"" + v + "\""; });
|
|
46
|
+
throw Error(message + "\n fragment " + ((_b = conf.fragment) === null || _b === void 0 ? void 0 : _b.name.value) + " on " + ((_c = conf.fragment) === null || _c === void 0 ? void 0 : _c.typeCondition.name.value) + " @inject(into: [" + val + "]) { ... }");
|
|
38
47
|
}
|
|
39
48
|
function assertValidInject(injectVal) {
|
|
40
|
-
|
|
41
|
-
if (!fragment || into
|
|
49
|
+
var into = injectVal.into, fragment = injectVal.fragment;
|
|
50
|
+
if (!fragment || (into === null || into === void 0 ? void 0 : into.length) === 0)
|
|
42
51
|
throwInjectError(injectVal, 'Invalid inject');
|
|
43
52
|
}
|
|
44
53
|
function getInjectConf(document) {
|
|
45
54
|
if (!hasInjectDirective(document))
|
|
46
55
|
throw Error('');
|
|
47
|
-
|
|
56
|
+
var conf = { into: [] };
|
|
48
57
|
(0, graphql_1.visit)(document, {
|
|
49
|
-
Directive: (node)
|
|
58
|
+
Directive: function (node) {
|
|
50
59
|
if (node.name.value !== 'inject')
|
|
51
60
|
return false;
|
|
52
61
|
(0, graphql_1.visit)(node, {
|
|
53
|
-
Argument: (arg)
|
|
62
|
+
Argument: function (arg) {
|
|
54
63
|
if (arg.name.value !== 'into')
|
|
55
64
|
return false;
|
|
56
65
|
(0, graphql_1.visit)(arg, {
|
|
57
|
-
ListValue: (list)
|
|
58
|
-
list.values.forEach((value)
|
|
66
|
+
ListValue: function (list) {
|
|
67
|
+
list.values.forEach(function (value) {
|
|
59
68
|
(0, graphql_1.visit)(value, {
|
|
60
|
-
StringValue: (string)
|
|
61
|
-
|
|
69
|
+
StringValue: function (string) {
|
|
70
|
+
var _a;
|
|
71
|
+
(_a = conf.into) === null || _a === void 0 ? void 0 : _a.push(string.value);
|
|
62
72
|
},
|
|
63
73
|
});
|
|
64
74
|
});
|
|
@@ -69,7 +79,7 @@ function getInjectConf(document) {
|
|
|
69
79
|
});
|
|
70
80
|
return null;
|
|
71
81
|
},
|
|
72
|
-
FragmentDefinition: (node)
|
|
82
|
+
FragmentDefinition: function (node) {
|
|
73
83
|
conf.fragment = node;
|
|
74
84
|
},
|
|
75
85
|
});
|
|
@@ -77,36 +87,38 @@ function getInjectConf(document) {
|
|
|
77
87
|
return conf;
|
|
78
88
|
}
|
|
79
89
|
function injectInjectable(injectables, injector) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
into.forEach((target)
|
|
83
|
-
|
|
84
|
-
injectables.forEach((injectable)
|
|
90
|
+
var injectVal = getInjectConf(injector);
|
|
91
|
+
var into = injectVal.into, fragment = injectVal.fragment;
|
|
92
|
+
into.forEach(function (target) {
|
|
93
|
+
var found = false;
|
|
94
|
+
injectables.forEach(function (injectable) {
|
|
85
95
|
(0, graphql_1.visit)(injectable, {
|
|
86
|
-
FragmentDefinition: (frag)
|
|
96
|
+
FragmentDefinition: function (frag) {
|
|
87
97
|
if (frag.name.value === target) {
|
|
88
98
|
found = true;
|
|
89
|
-
|
|
99
|
+
var spread = {
|
|
90
100
|
kind: 'FragmentSpread',
|
|
91
101
|
name: { kind: 'Name', value: fragment.name.value },
|
|
92
102
|
};
|
|
93
|
-
frag.selectionSet.selections = [
|
|
103
|
+
frag.selectionSet.selections = __spreadArray(__spreadArray([], frag.selectionSet.selections, true), [spread], false);
|
|
94
104
|
}
|
|
95
105
|
},
|
|
96
106
|
});
|
|
97
107
|
});
|
|
98
108
|
if (!found)
|
|
99
|
-
throwInjectError(injectVal,
|
|
109
|
+
throwInjectError(injectVal, "fragment " + target + " @injectable { ... } can not be found or isn't injectable");
|
|
100
110
|
});
|
|
101
111
|
}
|
|
102
112
|
function injectInjectables(documentFiles) {
|
|
103
|
-
|
|
104
|
-
.map((
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
113
|
+
var documents = documentFiles
|
|
114
|
+
.map(function (_a) {
|
|
115
|
+
var document = _a.document;
|
|
116
|
+
return document;
|
|
117
|
+
})
|
|
118
|
+
.filter(function (doc) { return doc; });
|
|
119
|
+
var injectables = documents.filter(function (d) { return isFragment(d) && hasInjectableDirective(d); });
|
|
120
|
+
var injectors = documents.filter(function (d) { return isFragment(d) && hasInjectDirective(d); });
|
|
121
|
+
injectors.forEach(function (d) { return injectInjectable(injectables, d); });
|
|
109
122
|
return documentFiles;
|
|
110
123
|
}
|
|
111
124
|
exports.injectInjectables = injectInjectables;
|
|
112
|
-
//# sourceMappingURL=injectable.js.map
|