@graphql-codegen/typescript-document-nodes 2.2.13 → 2.2.15-alpha-2cc8b095b.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/index.js ADDED
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ 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
+ const plugin = (schema, documents, config) => {
8
+ const allAst = (0, graphql_1.concatAST)(documents.map(v => v.document));
9
+ const allFragments = [
10
+ ...allAst.definitions.filter(d => d.kind === graphql_1.Kind.FRAGMENT_DEFINITION).map(fragmentDef => ({
11
+ node: fragmentDef,
12
+ name: fragmentDef.name.value,
13
+ onType: fragmentDef.typeCondition.name.value,
14
+ isExternal: false,
15
+ })),
16
+ ...(config.externalFragments || []),
17
+ ];
18
+ const visitor = new visitor_js_1.TypeScriptDocumentNodesVisitor(schema, allFragments, config, documents);
19
+ const visitorResult = (0, plugin_helpers_1.oldVisit)(allAst, { leave: visitor });
20
+ return {
21
+ prepend: visitor.getImports(),
22
+ content: [visitor.fragments, ...visitorResult.definitions.filter(t => typeof t === 'string')].join('\n'),
23
+ };
24
+ };
25
+ exports.plugin = plugin;
26
+ const validate = async (schema, documents, config, outputFile) => {
27
+ if (!outputFile.endsWith('.ts')) {
28
+ throw new Error(`Plugin "typescript-document-nodes" requires extension to be ".ts"!`);
29
+ }
30
+ };
31
+ exports.validate = validate;
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
package/cjs/visitor.js ADDED
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TypeScriptDocumentNodesVisitor = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const auto_bind_1 = tslib_1.__importDefault(require("auto-bind"));
6
+ const visitor_plugin_common_1 = require("@graphql-codegen/visitor-plugin-common");
7
+ class TypeScriptDocumentNodesVisitor extends visitor_plugin_common_1.ClientSideBaseVisitor {
8
+ constructor(schema, fragments, rawConfig, documents) {
9
+ const additionalConfig = {
10
+ documentVariablePrefix: (0, visitor_plugin_common_1.getConfigValue)(rawConfig.namePrefix, ''),
11
+ documentVariableSuffix: (0, visitor_plugin_common_1.getConfigValue)(rawConfig.nameSuffix, ''),
12
+ fragmentVariablePrefix: (0, visitor_plugin_common_1.getConfigValue)(rawConfig.fragmentPrefix, ''),
13
+ fragmentVariableSuffix: (0, visitor_plugin_common_1.getConfigValue)(rawConfig.fragmentSuffix, ''),
14
+ };
15
+ super(schema, fragments, rawConfig, additionalConfig, documents);
16
+ (0, auto_bind_1.default)(this);
17
+ }
18
+ }
19
+ exports.TypeScriptDocumentNodesVisitor = TypeScriptDocumentNodesVisitor;
@@ -1,22 +1,7 @@
1
1
  import { oldVisit } from '@graphql-codegen/plugin-helpers';
2
2
  import { concatAST, Kind } from 'graphql';
3
- import autoBind from 'auto-bind';
4
- import { ClientSideBaseVisitor, getConfigValue } from '@graphql-codegen/visitor-plugin-common';
5
-
6
- class TypeScriptDocumentNodesVisitor extends ClientSideBaseVisitor {
7
- constructor(schema, fragments, rawConfig, documents) {
8
- const additionalConfig = {
9
- documentVariablePrefix: getConfigValue(rawConfig.namePrefix, ''),
10
- documentVariableSuffix: getConfigValue(rawConfig.nameSuffix, ''),
11
- fragmentVariablePrefix: getConfigValue(rawConfig.fragmentPrefix, ''),
12
- fragmentVariableSuffix: getConfigValue(rawConfig.fragmentSuffix, ''),
13
- };
14
- super(schema, fragments, rawConfig, additionalConfig, documents);
15
- autoBind(this);
16
- }
17
- }
18
-
19
- const plugin = (schema, documents, config) => {
3
+ import { TypeScriptDocumentNodesVisitor } from './visitor.js';
4
+ export const plugin = (schema, documents, config) => {
20
5
  const allAst = concatAST(documents.map(v => v.document));
21
6
  const allFragments = [
22
7
  ...allAst.definitions.filter(d => d.kind === Kind.FRAGMENT_DEFINITION).map(fragmentDef => ({
@@ -34,10 +19,8 @@ const plugin = (schema, documents, config) => {
34
19
  content: [visitor.fragments, ...visitorResult.definitions.filter(t => typeof t === 'string')].join('\n'),
35
20
  };
36
21
  };
37
- const validate = async (schema, documents, config, outputFile) => {
22
+ export const validate = async (schema, documents, config, outputFile) => {
38
23
  if (!outputFile.endsWith('.ts')) {
39
24
  throw new Error(`Plugin "typescript-document-nodes" requires extension to be ".ts"!`);
40
25
  }
41
26
  };
42
-
43
- export { plugin, validate };
package/esm/visitor.js ADDED
@@ -0,0 +1,14 @@
1
+ import autoBind from 'auto-bind';
2
+ import { getConfigValue, ClientSideBaseVisitor, } from '@graphql-codegen/visitor-plugin-common';
3
+ export class TypeScriptDocumentNodesVisitor extends ClientSideBaseVisitor {
4
+ constructor(schema, fragments, rawConfig, documents) {
5
+ const additionalConfig = {
6
+ documentVariablePrefix: getConfigValue(rawConfig.namePrefix, ''),
7
+ documentVariableSuffix: getConfigValue(rawConfig.nameSuffix, ''),
8
+ fragmentVariablePrefix: getConfigValue(rawConfig.fragmentPrefix, ''),
9
+ fragmentVariableSuffix: getConfigValue(rawConfig.fragmentSuffix, ''),
10
+ };
11
+ super(schema, fragments, rawConfig, additionalConfig, documents);
12
+ autoBind(this);
13
+ }
14
+ }
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@graphql-codegen/typescript-document-nodes",
3
- "version": "2.2.13",
3
+ "version": "2.2.15-alpha-2cc8b095b.0",
4
4
  "description": "GraphQL Code Generator plugin for generating TypeScript modules with embedded GraphQL document nodes",
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
  },
8
8
  "dependencies": {
9
9
  "@graphql-codegen/plugin-helpers": "^2.4.0",
10
- "@graphql-codegen/visitor-plugin-common": "2.9.1",
10
+ "@graphql-codegen/visitor-plugin-common": "2.11.0-alpha-2cc8b095b.0",
11
11
  "auto-bind": "~4.0.0",
12
12
  "tslib": "~2.4.0"
13
13
  },
@@ -17,21 +17,28 @@
17
17
  "directory": "packages/plugins/typescript/document-nodes"
18
18
  },
19
19
  "license": "MIT",
20
- "main": "index.js",
21
- "module": "index.mjs",
22
- "typings": "index.d.ts",
20
+ "main": "cjs/index.js",
21
+ "module": "esm/index.js",
22
+ "typings": "typings/index.d.ts",
23
23
  "typescript": {
24
- "definition": "index.d.ts"
24
+ "definition": "typings/index.d.ts"
25
25
  },
26
+ "type": "module",
26
27
  "exports": {
27
- "./package.json": "./package.json",
28
28
  ".": {
29
- "require": "./index.js",
30
- "import": "./index.mjs"
29
+ "require": {
30
+ "types": "./typings/index.d.ts",
31
+ "default": "./cjs/index.js"
32
+ },
33
+ "import": {
34
+ "types": "./typings/index.d.ts",
35
+ "default": "./esm/index.js"
36
+ },
37
+ "default": {
38
+ "types": "./typings/index.d.ts",
39
+ "default": "./esm/index.js"
40
+ }
31
41
  },
32
- "./*": {
33
- "require": "./*.js",
34
- "import": "./*.mjs"
35
- }
42
+ "./package.json": "./package.json"
36
43
  }
37
- }
44
+ }
File without changes
@@ -1,4 +1,4 @@
1
- import { TypeScriptDocumentNodesRawPluginConfig } from '.';
1
+ import { TypeScriptDocumentNodesRawPluginConfig } from './index.js';
2
2
  import { Types } from '@graphql-codegen/plugin-helpers';
3
3
  import { LoadedFragment, ClientSideBaseVisitor, NamingConvention, ClientSideBasePluginConfig } from '@graphql-codegen/visitor-plugin-common';
4
4
  import { GraphQLSchema } from 'graphql';
package/index.js DELETED
@@ -1,50 +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 autoBind = _interopDefault(require('auto-bind'));
10
- const visitorPluginCommon = require('@graphql-codegen/visitor-plugin-common');
11
-
12
- class TypeScriptDocumentNodesVisitor extends visitorPluginCommon.ClientSideBaseVisitor {
13
- constructor(schema, fragments, rawConfig, documents) {
14
- const additionalConfig = {
15
- documentVariablePrefix: visitorPluginCommon.getConfigValue(rawConfig.namePrefix, ''),
16
- documentVariableSuffix: visitorPluginCommon.getConfigValue(rawConfig.nameSuffix, ''),
17
- fragmentVariablePrefix: visitorPluginCommon.getConfigValue(rawConfig.fragmentPrefix, ''),
18
- fragmentVariableSuffix: visitorPluginCommon.getConfigValue(rawConfig.fragmentSuffix, ''),
19
- };
20
- super(schema, fragments, rawConfig, additionalConfig, documents);
21
- autoBind(this);
22
- }
23
- }
24
-
25
- const plugin = (schema, documents, config) => {
26
- const allAst = graphql.concatAST(documents.map(v => v.document));
27
- const allFragments = [
28
- ...allAst.definitions.filter(d => d.kind === graphql.Kind.FRAGMENT_DEFINITION).map(fragmentDef => ({
29
- node: fragmentDef,
30
- name: fragmentDef.name.value,
31
- onType: fragmentDef.typeCondition.name.value,
32
- isExternal: false,
33
- })),
34
- ...(config.externalFragments || []),
35
- ];
36
- const visitor = new TypeScriptDocumentNodesVisitor(schema, allFragments, config, documents);
37
- const visitorResult = pluginHelpers.oldVisit(allAst, { leave: visitor });
38
- return {
39
- prepend: visitor.getImports(),
40
- content: [visitor.fragments, ...visitorResult.definitions.filter(t => typeof t === 'string')].join('\n'),
41
- };
42
- };
43
- const validate = async (schema, documents, config, outputFile) => {
44
- if (!outputFile.endsWith('.ts')) {
45
- throw new Error(`Plugin "typescript-document-nodes" requires extension to be ".ts"!`);
46
- }
47
- };
48
-
49
- exports.plugin = plugin;
50
- exports.validate = validate;