@graphql-codegen/typescript-vue-apollo 3.2.15 → 3.3.0-alpha-bd464a586.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/config.js +2 -0
- package/cjs/index.js +36 -0
- package/cjs/package.json +1 -0
- package/{index.js → cjs/visitor.js} +17 -53
- package/esm/config.js +1 -0
- package/esm/index.js +31 -0
- package/{index.mjs → esm/visitor.js} +2 -35
- package/package.json +22 -15
- package/{config.d.ts → typings/config.d.ts} +0 -0
- package/{index.d.ts → typings/index.d.ts} +2 -2
- package/{visitor.d.ts → typings/visitor.d.ts} +1 -1
package/cjs/config.js
ADDED
package/cjs/index.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VueApolloVisitor = exports.validate = exports.plugin = void 0;
|
|
4
|
+
const plugin_helpers_1 = require("@graphql-codegen/plugin-helpers");
|
|
5
|
+
const graphql_1 = require("graphql");
|
|
6
|
+
const visitor_js_1 = require("./visitor.js");
|
|
7
|
+
Object.defineProperty(exports, "VueApolloVisitor", { enumerable: true, get: function () { return visitor_js_1.VueApolloVisitor; } });
|
|
8
|
+
const path_1 = require("path");
|
|
9
|
+
const plugin = (schema, documents, config) => {
|
|
10
|
+
const allAst = (0, graphql_1.concatAST)(documents.map(s => s.document));
|
|
11
|
+
const allFragments = [
|
|
12
|
+
...allAst.definitions.filter(d => d.kind === graphql_1.Kind.FRAGMENT_DEFINITION).map(fragmentDef => ({
|
|
13
|
+
node: fragmentDef,
|
|
14
|
+
name: fragmentDef.name.value,
|
|
15
|
+
onType: fragmentDef.typeCondition.name.value,
|
|
16
|
+
isExternal: false,
|
|
17
|
+
})),
|
|
18
|
+
...(config.externalFragments || []),
|
|
19
|
+
];
|
|
20
|
+
const visitor = new visitor_js_1.VueApolloVisitor(schema, allFragments, config, documents);
|
|
21
|
+
const visitorResult = (0, plugin_helpers_1.oldVisit)(allAst, { leave: visitor });
|
|
22
|
+
return {
|
|
23
|
+
prepend: visitor.getImports(),
|
|
24
|
+
content: [
|
|
25
|
+
visitor.fragments,
|
|
26
|
+
...visitorResult.definitions.filter((definition) => typeof definition === 'string'),
|
|
27
|
+
].join('\n'),
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
exports.plugin = plugin;
|
|
31
|
+
const validate = async (_schema, _documents, _config, outputFile) => {
|
|
32
|
+
if ((0, path_1.extname)(outputFile) !== '.ts' && (0, path_1.extname)(outputFile) !== '.tsx') {
|
|
33
|
+
throw new Error(`Plugin "vue-apollo" requires extension to be ".ts" or ".tsx"!`);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
exports.validate = validate;
|
package/cjs/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -1,31 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const graphql = require('graphql');
|
|
9
|
-
const visitorPluginCommon = require('@graphql-codegen/visitor-plugin-common');
|
|
10
|
-
const autoBind = _interopDefault(require('auto-bind'));
|
|
11
|
-
const changeCaseAll = require('change-case-all');
|
|
12
|
-
const path = require('path');
|
|
13
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VueApolloVisitor = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const visitor_plugin_common_1 = require("@graphql-codegen/visitor-plugin-common");
|
|
6
|
+
const auto_bind_1 = tslib_1.__importDefault(require("auto-bind"));
|
|
7
|
+
const change_case_all_1 = require("change-case-all");
|
|
14
8
|
function insertIf(condition, ...elements) {
|
|
15
9
|
return condition ? elements : [];
|
|
16
10
|
}
|
|
17
|
-
class VueApolloVisitor extends
|
|
11
|
+
class VueApolloVisitor extends visitor_plugin_common_1.ClientSideBaseVisitor {
|
|
18
12
|
constructor(schema, fragments, rawConfig, documents) {
|
|
19
13
|
super(schema, fragments, rawConfig, {
|
|
20
|
-
withCompositionFunctions:
|
|
21
|
-
vueApolloComposableImportFrom:
|
|
22
|
-
vueCompositionApiImportFrom:
|
|
23
|
-
addDocBlocks:
|
|
14
|
+
withCompositionFunctions: (0, visitor_plugin_common_1.getConfigValue)(rawConfig.withCompositionFunctions, true),
|
|
15
|
+
vueApolloComposableImportFrom: (0, visitor_plugin_common_1.getConfigValue)(rawConfig.vueApolloComposableImportFrom, '@vue/apollo-composable'),
|
|
16
|
+
vueCompositionApiImportFrom: (0, visitor_plugin_common_1.getConfigValue)(rawConfig.vueCompositionApiImportFrom, '@vue/composition-api'),
|
|
17
|
+
addDocBlocks: (0, visitor_plugin_common_1.getConfigValue)(rawConfig.addDocBlocks, true),
|
|
24
18
|
});
|
|
25
19
|
this.imports = new Set();
|
|
26
20
|
this.externalImportPrefix = this.config.importOperationTypesFrom ? `${this.config.importOperationTypesFrom}.` : '';
|
|
27
21
|
this._documents = documents;
|
|
28
|
-
|
|
22
|
+
(0, auto_bind_1.default)(this);
|
|
29
23
|
}
|
|
30
24
|
get vueApolloComposableImport() {
|
|
31
25
|
return `import * as VueApolloComposable from '${this.config.vueApolloComposableImportFrom}';`;
|
|
@@ -40,7 +34,7 @@ class VueApolloVisitor extends visitorPluginCommon.ClientSideBaseVisitor {
|
|
|
40
34
|
return 'export type ReactiveFunction<TParam> = () => TParam;';
|
|
41
35
|
}
|
|
42
36
|
getDocumentNodeVariable(node, documentVariableName) {
|
|
43
|
-
return this.config.documentMode ===
|
|
37
|
+
return this.config.documentMode === visitor_plugin_common_1.DocumentMode.external ? `Operations.${node.name.value}` : documentVariableName;
|
|
44
38
|
}
|
|
45
39
|
getImports() {
|
|
46
40
|
const baseImports = super.getImports();
|
|
@@ -94,12 +88,12 @@ class VueApolloVisitor extends visitorPluginCommon.ClientSideBaseVisitor {
|
|
|
94
88
|
}
|
|
95
89
|
getCompositionFunctionSuffix(name, operationType) {
|
|
96
90
|
if (!this.config.dedupeOperationSuffix) {
|
|
97
|
-
return this.config.omitOperationSuffix ? '' :
|
|
91
|
+
return this.config.omitOperationSuffix ? '' : (0, change_case_all_1.pascalCase)(operationType);
|
|
98
92
|
}
|
|
99
93
|
if (name.includes('Query') || name.includes('Mutation') || name.includes('Subscription')) {
|
|
100
94
|
return '';
|
|
101
95
|
}
|
|
102
|
-
return
|
|
96
|
+
return (0, change_case_all_1.pascalCase)(operationType);
|
|
103
97
|
}
|
|
104
98
|
buildOperation(node, documentVariableName, operationType, operationResultType, operationVariablesTypes) {
|
|
105
99
|
var _a, _b, _c;
|
|
@@ -144,7 +138,7 @@ class VueApolloVisitor extends visitorPluginCommon.ClientSideBaseVisitor {
|
|
|
144
138
|
];
|
|
145
139
|
if (operationType === 'Query') {
|
|
146
140
|
const lazyOperationName = this.convertName(node.name.value, {
|
|
147
|
-
suffix:
|
|
141
|
+
suffix: (0, change_case_all_1.titleCase)('LazyQuery'),
|
|
148
142
|
useTypesPrefix: false,
|
|
149
143
|
});
|
|
150
144
|
const lazyOperationType = 'LazyQuery';
|
|
@@ -195,34 +189,4 @@ class VueApolloVisitor extends visitorPluginCommon.ClientSideBaseVisitor {
|
|
|
195
189
|
return `export type ${operationName}CompositionFunctionResult = VueApolloComposable.Use${operationType}Return<${operationResultType}, ${operationVariablesTypes}>;`;
|
|
196
190
|
}
|
|
197
191
|
}
|
|
198
|
-
|
|
199
|
-
const plugin = (schema, documents, config) => {
|
|
200
|
-
const allAst = graphql.concatAST(documents.map(s => s.document));
|
|
201
|
-
const allFragments = [
|
|
202
|
-
...allAst.definitions.filter(d => d.kind === graphql.Kind.FRAGMENT_DEFINITION).map(fragmentDef => ({
|
|
203
|
-
node: fragmentDef,
|
|
204
|
-
name: fragmentDef.name.value,
|
|
205
|
-
onType: fragmentDef.typeCondition.name.value,
|
|
206
|
-
isExternal: false,
|
|
207
|
-
})),
|
|
208
|
-
...(config.externalFragments || []),
|
|
209
|
-
];
|
|
210
|
-
const visitor = new VueApolloVisitor(schema, allFragments, config, documents);
|
|
211
|
-
const visitorResult = pluginHelpers.oldVisit(allAst, { leave: visitor });
|
|
212
|
-
return {
|
|
213
|
-
prepend: visitor.getImports(),
|
|
214
|
-
content: [
|
|
215
|
-
visitor.fragments,
|
|
216
|
-
...visitorResult.definitions.filter((definition) => typeof definition === 'string'),
|
|
217
|
-
].join('\n'),
|
|
218
|
-
};
|
|
219
|
-
};
|
|
220
|
-
const validate = async (_schema, _documents, _config, outputFile) => {
|
|
221
|
-
if (path.extname(outputFile) !== '.ts' && path.extname(outputFile) !== '.tsx') {
|
|
222
|
-
throw new Error(`Plugin "vue-apollo" requires extension to be ".ts" or ".tsx"!`);
|
|
223
|
-
}
|
|
224
|
-
};
|
|
225
|
-
|
|
226
192
|
exports.VueApolloVisitor = VueApolloVisitor;
|
|
227
|
-
exports.plugin = plugin;
|
|
228
|
-
exports.validate = validate;
|
package/esm/config.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/esm/index.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { oldVisit } from '@graphql-codegen/plugin-helpers';
|
|
2
|
+
import { concatAST, Kind } from 'graphql';
|
|
3
|
+
import { VueApolloVisitor } from './visitor.js';
|
|
4
|
+
import { extname } from 'path';
|
|
5
|
+
export const plugin = (schema, documents, config) => {
|
|
6
|
+
const allAst = concatAST(documents.map(s => s.document));
|
|
7
|
+
const allFragments = [
|
|
8
|
+
...allAst.definitions.filter(d => d.kind === Kind.FRAGMENT_DEFINITION).map(fragmentDef => ({
|
|
9
|
+
node: fragmentDef,
|
|
10
|
+
name: fragmentDef.name.value,
|
|
11
|
+
onType: fragmentDef.typeCondition.name.value,
|
|
12
|
+
isExternal: false,
|
|
13
|
+
})),
|
|
14
|
+
...(config.externalFragments || []),
|
|
15
|
+
];
|
|
16
|
+
const visitor = new VueApolloVisitor(schema, allFragments, config, documents);
|
|
17
|
+
const visitorResult = oldVisit(allAst, { leave: visitor });
|
|
18
|
+
return {
|
|
19
|
+
prepend: visitor.getImports(),
|
|
20
|
+
content: [
|
|
21
|
+
visitor.fragments,
|
|
22
|
+
...visitorResult.definitions.filter((definition) => typeof definition === 'string'),
|
|
23
|
+
].join('\n'),
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
export const validate = async (_schema, _documents, _config, outputFile) => {
|
|
27
|
+
if (extname(outputFile) !== '.ts' && extname(outputFile) !== '.tsx') {
|
|
28
|
+
throw new Error(`Plugin "vue-apollo" requires extension to be ".ts" or ".tsx"!`);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
export { VueApolloVisitor };
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { concatAST, Kind } from 'graphql';
|
|
3
|
-
import { ClientSideBaseVisitor, getConfigValue, DocumentMode } from '@graphql-codegen/visitor-plugin-common';
|
|
1
|
+
import { ClientSideBaseVisitor, getConfigValue, DocumentMode, } from '@graphql-codegen/visitor-plugin-common';
|
|
4
2
|
import autoBind from 'auto-bind';
|
|
5
3
|
import { pascalCase, titleCase } from 'change-case-all';
|
|
6
|
-
import { extname } from 'path';
|
|
7
|
-
|
|
8
4
|
function insertIf(condition, ...elements) {
|
|
9
5
|
return condition ? elements : [];
|
|
10
6
|
}
|
|
11
|
-
class VueApolloVisitor extends ClientSideBaseVisitor {
|
|
7
|
+
export class VueApolloVisitor extends ClientSideBaseVisitor {
|
|
12
8
|
constructor(schema, fragments, rawConfig, documents) {
|
|
13
9
|
super(schema, fragments, rawConfig, {
|
|
14
10
|
withCompositionFunctions: getConfigValue(rawConfig.withCompositionFunctions, true),
|
|
@@ -189,32 +185,3 @@ class VueApolloVisitor extends ClientSideBaseVisitor {
|
|
|
189
185
|
return `export type ${operationName}CompositionFunctionResult = VueApolloComposable.Use${operationType}Return<${operationResultType}, ${operationVariablesTypes}>;`;
|
|
190
186
|
}
|
|
191
187
|
}
|
|
192
|
-
|
|
193
|
-
const plugin = (schema, documents, config) => {
|
|
194
|
-
const allAst = concatAST(documents.map(s => s.document));
|
|
195
|
-
const allFragments = [
|
|
196
|
-
...allAst.definitions.filter(d => d.kind === Kind.FRAGMENT_DEFINITION).map(fragmentDef => ({
|
|
197
|
-
node: fragmentDef,
|
|
198
|
-
name: fragmentDef.name.value,
|
|
199
|
-
onType: fragmentDef.typeCondition.name.value,
|
|
200
|
-
isExternal: false,
|
|
201
|
-
})),
|
|
202
|
-
...(config.externalFragments || []),
|
|
203
|
-
];
|
|
204
|
-
const visitor = new VueApolloVisitor(schema, allFragments, config, documents);
|
|
205
|
-
const visitorResult = oldVisit(allAst, { leave: visitor });
|
|
206
|
-
return {
|
|
207
|
-
prepend: visitor.getImports(),
|
|
208
|
-
content: [
|
|
209
|
-
visitor.fragments,
|
|
210
|
-
...visitorResult.definitions.filter((definition) => typeof definition === 'string'),
|
|
211
|
-
].join('\n'),
|
|
212
|
-
};
|
|
213
|
-
};
|
|
214
|
-
const validate = async (_schema, _documents, _config, outputFile) => {
|
|
215
|
-
if (extname(outputFile) !== '.ts' && extname(outputFile) !== '.tsx') {
|
|
216
|
-
throw new Error(`Plugin "vue-apollo" requires extension to be ".ts" or ".tsx"!`);
|
|
217
|
-
}
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
export { VueApolloVisitor, plugin, validate };
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/typescript-vue-apollo",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0-alpha-bd464a586.0",
|
|
4
4
|
"description": "GraphQL Code Generator plugin for generating ready-to-use Vue-Apollo composition functions based on GraphQL operations",
|
|
5
5
|
"peerDependencies": {
|
|
6
6
|
"graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0",
|
|
7
7
|
"graphql-tag": "^2.0.0"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@graphql-codegen/plugin-helpers": "^2.
|
|
11
|
-
"@graphql-codegen/visitor-plugin-common": "2.
|
|
10
|
+
"@graphql-codegen/plugin-helpers": "^2.5.0-alpha-bd464a586.0",
|
|
11
|
+
"@graphql-codegen/visitor-plugin-common": "2.11.0-alpha-bd464a586.0",
|
|
12
12
|
"auto-bind": "~4.0.0",
|
|
13
13
|
"change-case-all": "1.0.14",
|
|
14
14
|
"tslib": "~2.4.0"
|
|
@@ -19,21 +19,28 @@
|
|
|
19
19
|
"directory": "packages/plugins/typescript/vue-apollo"
|
|
20
20
|
},
|
|
21
21
|
"license": "MIT",
|
|
22
|
-
"main": "index.js",
|
|
23
|
-
"module": "index.
|
|
24
|
-
"typings": "index.d.ts",
|
|
22
|
+
"main": "cjs/index.js",
|
|
23
|
+
"module": "esm/index.js",
|
|
24
|
+
"typings": "typings/index.d.ts",
|
|
25
25
|
"typescript": {
|
|
26
|
-
"definition": "index.d.ts"
|
|
26
|
+
"definition": "typings/index.d.ts"
|
|
27
27
|
},
|
|
28
|
+
"type": "module",
|
|
28
29
|
"exports": {
|
|
29
|
-
"./package.json": "./package.json",
|
|
30
30
|
".": {
|
|
31
|
-
"require":
|
|
32
|
-
|
|
31
|
+
"require": {
|
|
32
|
+
"types": "./typings/index.d.ts",
|
|
33
|
+
"default": "./cjs/index.js"
|
|
34
|
+
},
|
|
35
|
+
"import": {
|
|
36
|
+
"types": "./typings/index.d.ts",
|
|
37
|
+
"default": "./esm/index.js"
|
|
38
|
+
},
|
|
39
|
+
"default": {
|
|
40
|
+
"types": "./typings/index.d.ts",
|
|
41
|
+
"default": "./esm/index.js"
|
|
42
|
+
}
|
|
33
43
|
},
|
|
34
|
-
"
|
|
35
|
-
"require": "./*.js",
|
|
36
|
-
"import": "./*.mjs"
|
|
37
|
-
}
|
|
44
|
+
"./package.json": "./package.json"
|
|
38
45
|
}
|
|
39
|
-
}
|
|
46
|
+
}
|
|
File without changes
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Types, PluginValidateFn, PluginFunction } from '@graphql-codegen/plugin-helpers';
|
|
2
|
-
import { VueApolloVisitor } from './visitor';
|
|
3
|
-
import { VueApolloRawPluginConfig } from './config';
|
|
2
|
+
import { VueApolloVisitor } from './visitor.js';
|
|
3
|
+
import { VueApolloRawPluginConfig } from './config.js';
|
|
4
4
|
export declare const plugin: PluginFunction<VueApolloRawPluginConfig, Types.ComplexPluginOutput>;
|
|
5
5
|
export declare const validate: PluginValidateFn<any>;
|
|
6
6
|
export { VueApolloVisitor };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ClientSideBaseVisitor, ClientSideBasePluginConfig, LoadedFragment } from '@graphql-codegen/visitor-plugin-common';
|
|
2
|
-
import { VueApolloRawPluginConfig } from './config';
|
|
2
|
+
import { VueApolloRawPluginConfig } from './config.js';
|
|
3
3
|
import { OperationDefinitionNode, GraphQLSchema } from 'graphql';
|
|
4
4
|
import { Types } from '@graphql-codegen/plugin-helpers';
|
|
5
5
|
export interface VueApolloPluginConfig extends ClientSideBasePluginConfig {
|