@graphql-codegen/typescript-stencil-apollo 2.2.14 → 2.3.0-alpha-29eb1293b.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 ADDED
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StencilComponentType = void 0;
4
+ var StencilComponentType;
5
+ (function (StencilComponentType) {
6
+ StencilComponentType["functional"] = "functional";
7
+ StencilComponentType["class"] = "class";
8
+ })(StencilComponentType = exports.StencilComponentType || (exports.StencilComponentType = {}));
package/cjs/index.js ADDED
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StencilApolloVisitor = 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, "StencilApolloVisitor", { enumerable: true, get: function () { return visitor_js_1.StencilApolloVisitor; } });
8
+ const path_1 = require("path");
9
+ const plugin = (schema, documents, config) => {
10
+ const allAst = (0, graphql_1.concatAST)(documents.map(v => v.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.StencilApolloVisitor(schema, allFragments, config);
21
+ const visitorResult = (0, plugin_helpers_1.oldVisit)(allAst, { leave: visitor });
22
+ return {
23
+ prepend: visitor.getImports(),
24
+ content: ['', visitor.fragments, ...visitorResult.definitions.filter(t => typeof t === 'string')].join('\n'),
25
+ };
26
+ };
27
+ exports.plugin = plugin;
28
+ const validate = async (schema, documents, config, outputFile) => {
29
+ if ((0, path_1.extname)(outputFile) !== '.tsx') {
30
+ throw new Error(`Plugin "stencil-apollo" requires extension to be ".tsx"!`);
31
+ }
32
+ };
33
+ exports.validate = validate;
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
package/cjs/visitor.js ADDED
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StencilApolloVisitor = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const visitor_plugin_common_1 = require("@graphql-codegen/visitor-plugin-common");
6
+ const config_js_1 = require("./config.js");
7
+ const auto_bind_1 = tslib_1.__importDefault(require("auto-bind"));
8
+ const change_case_all_1 = require("change-case-all");
9
+ class StencilApolloVisitor extends visitor_plugin_common_1.ClientSideBaseVisitor {
10
+ constructor(schema, fragments, rawConfig) {
11
+ super(schema, fragments, rawConfig, {
12
+ componentType: (0, visitor_plugin_common_1.getConfigValue)(rawConfig.componentType, config_js_1.StencilComponentType.functional),
13
+ noExport: rawConfig.componentType === config_js_1.StencilComponentType.class,
14
+ });
15
+ (0, auto_bind_1.default)(this);
16
+ }
17
+ getImports() {
18
+ const baseImports = super.getImports();
19
+ const imports = [];
20
+ const hasOperations = this._collectedOperations.length > 0;
21
+ if (!hasOperations) {
22
+ return baseImports;
23
+ }
24
+ if (this.config.componentType === config_js_1.StencilComponentType.class) {
25
+ imports.push(`import 'stencil-apollo';`);
26
+ imports.push(`import { Component, Prop, h } from '@stencil/core';`);
27
+ }
28
+ else {
29
+ imports.push(`import * as StencilApollo from 'stencil-apollo';`);
30
+ imports.push(`import { h } from '@stencil/core';`);
31
+ }
32
+ return [...baseImports, ...imports];
33
+ }
34
+ _buildOperationFunctionalComponent(node, documentVariableName, operationType, operationResultType, operationVariablesTypes) {
35
+ const operationName = this.convertName(node.name.value);
36
+ const propsTypeName = this.convertName(operationName + 'Props');
37
+ const rendererSignature = (0, change_case_all_1.pascalCase)(`${operationType}Renderer`) + `<${operationResultType}, ${operationVariablesTypes}>`;
38
+ const apolloStencilComponentTag = (0, change_case_all_1.paramCase)(`Apollo${operationType}`);
39
+ const componentName = this.convertName(`${operationName}Component`);
40
+ const propsVar = `
41
+ export type ${propsTypeName} = {
42
+ variables ?: ${operationVariablesTypes};
43
+ inlist ?: StencilApollo.${rendererSignature};
44
+ };
45
+ `;
46
+ const component = `
47
+ export const ${componentName} = (props: ${propsTypeName}, children: [StencilApollo.${rendererSignature}]) => (
48
+ <${apolloStencilComponentTag} ${operationType.toLowerCase()}={ ${documentVariableName} } { ...props } renderer={ children[0] } />
49
+ );
50
+ `;
51
+ return [propsVar, component].filter(a => a).join('\n');
52
+ }
53
+ _buildClassComponent(node, documentVariableName, operationType, operationResultType, operationVariablesTypes) {
54
+ const componentName = this.convertName(node.name.value + 'Component');
55
+ const apolloStencilComponentTag = (0, change_case_all_1.paramCase)(`Apollo${operationType}`);
56
+ const rendererSignature = (0, change_case_all_1.pascalCase)(`${operationType}Renderer`);
57
+ return `
58
+ @Component({
59
+ tag: '${(0, change_case_all_1.paramCase)(`Apollo${(0, change_case_all_1.pascalCase)(node.name.value)}`)}'
60
+ })
61
+ export class ${componentName} {
62
+ @Prop() renderer: import('stencil-apollo').${rendererSignature}<${operationResultType}, ${operationVariablesTypes}>;
63
+ @Prop() variables: ${operationVariablesTypes};
64
+ render() {
65
+ return <${apolloStencilComponentTag} ${operationType.toLowerCase()}={ ${documentVariableName} } variables={ this.variables } renderer={ this.renderer } />;
66
+ }
67
+ }
68
+ `;
69
+ }
70
+ buildOperation(node, documentVariableName, operationType, operationResultType, operationVariablesTypes) {
71
+ switch (this.config.componentType) {
72
+ case config_js_1.StencilComponentType.class:
73
+ return this._buildClassComponent(node, documentVariableName, operationType, operationResultType, operationVariablesTypes);
74
+ case config_js_1.StencilComponentType.functional:
75
+ return this._buildOperationFunctionalComponent(node, documentVariableName, operationType, operationResultType, operationVariablesTypes);
76
+ default:
77
+ return '';
78
+ }
79
+ }
80
+ }
81
+ exports.StencilApolloVisitor = StencilApolloVisitor;
package/esm/config.js ADDED
@@ -0,0 +1,5 @@
1
+ export var StencilComponentType;
2
+ (function (StencilComponentType) {
3
+ StencilComponentType["functional"] = "functional";
4
+ StencilComponentType["class"] = "class";
5
+ })(StencilComponentType || (StencilComponentType = {}));
package/esm/index.js ADDED
@@ -0,0 +1,28 @@
1
+ import { oldVisit } from '@graphql-codegen/plugin-helpers';
2
+ import { concatAST, Kind } from 'graphql';
3
+ import { StencilApolloVisitor } from './visitor.js';
4
+ import { extname } from 'path';
5
+ export const plugin = (schema, documents, config) => {
6
+ const allAst = concatAST(documents.map(v => v.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 StencilApolloVisitor(schema, allFragments, config);
17
+ const visitorResult = oldVisit(allAst, { leave: visitor });
18
+ return {
19
+ prepend: visitor.getImports(),
20
+ content: ['', visitor.fragments, ...visitorResult.definitions.filter(t => typeof t === 'string')].join('\n'),
21
+ };
22
+ };
23
+ export const validate = async (schema, documents, config, outputFile) => {
24
+ if (extname(outputFile) !== '.tsx') {
25
+ throw new Error(`Plugin "stencil-apollo" requires extension to be ".tsx"!`);
26
+ }
27
+ };
28
+ export { StencilApolloVisitor };
@@ -1,17 +1,8 @@
1
- import { oldVisit } from '@graphql-codegen/plugin-helpers';
2
- import { concatAST, Kind } from 'graphql';
3
- import { ClientSideBaseVisitor, getConfigValue } from '@graphql-codegen/visitor-plugin-common';
1
+ import { ClientSideBaseVisitor, getConfigValue, } from '@graphql-codegen/visitor-plugin-common';
2
+ import { StencilComponentType } from './config.js';
4
3
  import autoBind from 'auto-bind';
5
- import { pascalCase, paramCase } from 'change-case-all';
6
- import { extname } from 'path';
7
-
8
- var StencilComponentType;
9
- (function (StencilComponentType) {
10
- StencilComponentType["functional"] = "functional";
11
- StencilComponentType["class"] = "class";
12
- })(StencilComponentType || (StencilComponentType = {}));
13
-
14
- class StencilApolloVisitor extends ClientSideBaseVisitor {
4
+ import { paramCase, pascalCase } from 'change-case-all';
5
+ export class StencilApolloVisitor extends ClientSideBaseVisitor {
15
6
  constructor(schema, fragments, rawConfig) {
16
7
  super(schema, fragments, rawConfig, {
17
8
  componentType: getConfigValue(rawConfig.componentType, StencilComponentType.functional),
@@ -83,29 +74,3 @@ export class ${componentName} {
83
74
  }
84
75
  }
85
76
  }
86
-
87
- const plugin = (schema, documents, config) => {
88
- const allAst = concatAST(documents.map(v => v.document));
89
- const allFragments = [
90
- ...allAst.definitions.filter(d => d.kind === Kind.FRAGMENT_DEFINITION).map(fragmentDef => ({
91
- node: fragmentDef,
92
- name: fragmentDef.name.value,
93
- onType: fragmentDef.typeCondition.name.value,
94
- isExternal: false,
95
- })),
96
- ...(config.externalFragments || []),
97
- ];
98
- const visitor = new StencilApolloVisitor(schema, allFragments, config);
99
- const visitorResult = oldVisit(allAst, { leave: visitor });
100
- return {
101
- prepend: visitor.getImports(),
102
- content: ['', visitor.fragments, ...visitorResult.definitions.filter(t => typeof t === 'string')].join('\n'),
103
- };
104
- };
105
- const validate = async (schema, documents, config, outputFile) => {
106
- if (extname(outputFile) !== '.tsx') {
107
- throw new Error(`Plugin "stencil-apollo" requires extension to be ".tsx"!`);
108
- }
109
- };
110
-
111
- export { StencilApolloVisitor, plugin, validate };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-codegen/typescript-stencil-apollo",
3
- "version": "2.2.14",
3
+ "version": "2.3.0-alpha-29eb1293b.0",
4
4
  "description": "GraphQL Code Generator plugin for generating Stencil Components 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",
@@ -8,8 +8,8 @@
8
8
  "stencil-apollo": "^0.1.3"
9
9
  },
10
10
  "dependencies": {
11
- "@graphql-codegen/plugin-helpers": "^2.4.0",
12
- "@graphql-codegen/visitor-plugin-common": "2.10.0",
11
+ "@graphql-codegen/plugin-helpers": "^2.5.0-alpha-29eb1293b.0",
12
+ "@graphql-codegen/visitor-plugin-common": "2.11.0-alpha-29eb1293b.0",
13
13
  "auto-bind": "~4.0.0",
14
14
  "change-case-all": "1.0.14",
15
15
  "tslib": "~2.4.0"
@@ -20,21 +20,28 @@
20
20
  "directory": "packages/plugins/typescript/stencil-apollo"
21
21
  },
22
22
  "license": "MIT",
23
- "main": "index.js",
24
- "module": "index.mjs",
25
- "typings": "index.d.ts",
23
+ "main": "cjs/index.js",
24
+ "module": "esm/index.js",
25
+ "typings": "typings/index.d.ts",
26
26
  "typescript": {
27
- "definition": "index.d.ts"
27
+ "definition": "typings/index.d.ts"
28
28
  },
29
+ "type": "module",
29
30
  "exports": {
30
- "./package.json": "./package.json",
31
31
  ".": {
32
- "require": "./index.js",
33
- "import": "./index.mjs"
32
+ "require": {
33
+ "types": "./typings/index.d.ts",
34
+ "default": "./cjs/index.js"
35
+ },
36
+ "import": {
37
+ "types": "./typings/index.d.ts",
38
+ "default": "./esm/index.js"
39
+ },
40
+ "default": {
41
+ "types": "./typings/index.d.ts",
42
+ "default": "./esm/index.js"
43
+ }
34
44
  },
35
- "./*": {
36
- "require": "./*.js",
37
- "import": "./*.mjs"
38
- }
45
+ "./package.json": "./package.json"
39
46
  }
40
- }
47
+ }
File without changes
@@ -1,6 +1,6 @@
1
1
  import { PluginValidateFn, PluginFunction } from '@graphql-codegen/plugin-helpers';
2
- import { StencilApolloVisitor } from './visitor';
3
- import { StencilApolloRawPluginConfig } from './config';
2
+ import { StencilApolloVisitor } from './visitor.js';
3
+ import { StencilApolloRawPluginConfig } from './config.js';
4
4
  export declare const plugin: PluginFunction<StencilApolloRawPluginConfig>;
5
5
  export declare const validate: PluginValidateFn<any>;
6
6
  export { StencilApolloVisitor };
@@ -1,5 +1,5 @@
1
1
  import { ClientSideBaseVisitor, ClientSideBasePluginConfig, LoadedFragment } from '@graphql-codegen/visitor-plugin-common';
2
- import { StencilComponentType, StencilApolloRawPluginConfig } from './config';
2
+ import { StencilComponentType, StencilApolloRawPluginConfig } from './config.js';
3
3
  import { OperationDefinitionNode, GraphQLSchema } from 'graphql';
4
4
  export interface StencilApolloPluginConfig extends ClientSideBasePluginConfig {
5
5
  componentType: StencilComponentType;
package/index.js DELETED
@@ -1,119 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
-
7
- const pluginHelpers = require('@graphql-codegen/plugin-helpers');
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
-
14
- var StencilComponentType;
15
- (function (StencilComponentType) {
16
- StencilComponentType["functional"] = "functional";
17
- StencilComponentType["class"] = "class";
18
- })(StencilComponentType || (StencilComponentType = {}));
19
-
20
- class StencilApolloVisitor extends visitorPluginCommon.ClientSideBaseVisitor {
21
- constructor(schema, fragments, rawConfig) {
22
- super(schema, fragments, rawConfig, {
23
- componentType: visitorPluginCommon.getConfigValue(rawConfig.componentType, StencilComponentType.functional),
24
- noExport: rawConfig.componentType === StencilComponentType.class,
25
- });
26
- autoBind(this);
27
- }
28
- getImports() {
29
- const baseImports = super.getImports();
30
- const imports = [];
31
- const hasOperations = this._collectedOperations.length > 0;
32
- if (!hasOperations) {
33
- return baseImports;
34
- }
35
- if (this.config.componentType === StencilComponentType.class) {
36
- imports.push(`import 'stencil-apollo';`);
37
- imports.push(`import { Component, Prop, h } from '@stencil/core';`);
38
- }
39
- else {
40
- imports.push(`import * as StencilApollo from 'stencil-apollo';`);
41
- imports.push(`import { h } from '@stencil/core';`);
42
- }
43
- return [...baseImports, ...imports];
44
- }
45
- _buildOperationFunctionalComponent(node, documentVariableName, operationType, operationResultType, operationVariablesTypes) {
46
- const operationName = this.convertName(node.name.value);
47
- const propsTypeName = this.convertName(operationName + 'Props');
48
- const rendererSignature = changeCaseAll.pascalCase(`${operationType}Renderer`) + `<${operationResultType}, ${operationVariablesTypes}>`;
49
- const apolloStencilComponentTag = changeCaseAll.paramCase(`Apollo${operationType}`);
50
- const componentName = this.convertName(`${operationName}Component`);
51
- const propsVar = `
52
- export type ${propsTypeName} = {
53
- variables ?: ${operationVariablesTypes};
54
- inlist ?: StencilApollo.${rendererSignature};
55
- };
56
- `;
57
- const component = `
58
- export const ${componentName} = (props: ${propsTypeName}, children: [StencilApollo.${rendererSignature}]) => (
59
- <${apolloStencilComponentTag} ${operationType.toLowerCase()}={ ${documentVariableName} } { ...props } renderer={ children[0] } />
60
- );
61
- `;
62
- return [propsVar, component].filter(a => a).join('\n');
63
- }
64
- _buildClassComponent(node, documentVariableName, operationType, operationResultType, operationVariablesTypes) {
65
- const componentName = this.convertName(node.name.value + 'Component');
66
- const apolloStencilComponentTag = changeCaseAll.paramCase(`Apollo${operationType}`);
67
- const rendererSignature = changeCaseAll.pascalCase(`${operationType}Renderer`);
68
- return `
69
- @Component({
70
- tag: '${changeCaseAll.paramCase(`Apollo${changeCaseAll.pascalCase(node.name.value)}`)}'
71
- })
72
- export class ${componentName} {
73
- @Prop() renderer: import('stencil-apollo').${rendererSignature}<${operationResultType}, ${operationVariablesTypes}>;
74
- @Prop() variables: ${operationVariablesTypes};
75
- render() {
76
- return <${apolloStencilComponentTag} ${operationType.toLowerCase()}={ ${documentVariableName} } variables={ this.variables } renderer={ this.renderer } />;
77
- }
78
- }
79
- `;
80
- }
81
- buildOperation(node, documentVariableName, operationType, operationResultType, operationVariablesTypes) {
82
- switch (this.config.componentType) {
83
- case StencilComponentType.class:
84
- return this._buildClassComponent(node, documentVariableName, operationType, operationResultType, operationVariablesTypes);
85
- case StencilComponentType.functional:
86
- return this._buildOperationFunctionalComponent(node, documentVariableName, operationType, operationResultType, operationVariablesTypes);
87
- default:
88
- return '';
89
- }
90
- }
91
- }
92
-
93
- const plugin = (schema, documents, config) => {
94
- const allAst = graphql.concatAST(documents.map(v => v.document));
95
- const allFragments = [
96
- ...allAst.definitions.filter(d => d.kind === graphql.Kind.FRAGMENT_DEFINITION).map(fragmentDef => ({
97
- node: fragmentDef,
98
- name: fragmentDef.name.value,
99
- onType: fragmentDef.typeCondition.name.value,
100
- isExternal: false,
101
- })),
102
- ...(config.externalFragments || []),
103
- ];
104
- const visitor = new StencilApolloVisitor(schema, allFragments, config);
105
- const visitorResult = pluginHelpers.oldVisit(allAst, { leave: visitor });
106
- return {
107
- prepend: visitor.getImports(),
108
- content: ['', visitor.fragments, ...visitorResult.definitions.filter(t => typeof t === 'string')].join('\n'),
109
- };
110
- };
111
- const validate = async (schema, documents, config, outputFile) => {
112
- if (path.extname(outputFile) !== '.tsx') {
113
- throw new Error(`Plugin "stencil-apollo" requires extension to be ".tsx"!`);
114
- }
115
- };
116
-
117
- exports.StencilApolloVisitor = StencilApolloVisitor;
118
- exports.plugin = plugin;
119
- exports.validate = validate;