@graphql-codegen/typescript-urql 3.5.12 → 3.6.0-alpha-2fbcdb6d3.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,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/cjs/index.js ADDED
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UrqlVisitor = 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, "UrqlVisitor", { enumerable: true, get: function () { return visitor_js_1.UrqlVisitor; } });
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.UrqlVisitor(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 (config.withComponent === true) {
30
+ if ((0, path_1.extname)(outputFile) !== '.tsx') {
31
+ throw new Error(`Plugin "typescript-urql" requires extension to be ".tsx" when withComponent: true is set!`);
32
+ }
33
+ }
34
+ else if ((0, path_1.extname)(outputFile) !== '.ts' && (0, path_1.extname)(outputFile) !== '.tsx') {
35
+ throw new Error(`Plugin "typescript-urql" requires extension to be ".ts" or ".tsx"!`);
36
+ }
37
+ };
38
+ exports.validate = validate;
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -1,26 +1,21 @@
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 path = require('path');
12
-
13
- class UrqlVisitor extends visitorPluginCommon.ClientSideBaseVisitor {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UrqlVisitor = 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 graphql_1 = require("graphql");
8
+ class UrqlVisitor extends visitor_plugin_common_1.ClientSideBaseVisitor {
14
9
  constructor(schema, fragments, rawConfig) {
15
10
  super(schema, fragments, rawConfig, {
16
- withComponent: visitorPluginCommon.getConfigValue(rawConfig.withComponent, false),
17
- withHooks: visitorPluginCommon.getConfigValue(rawConfig.withHooks, true),
18
- urqlImportFrom: visitorPluginCommon.getConfigValue(rawConfig.urqlImportFrom, null),
11
+ withComponent: (0, visitor_plugin_common_1.getConfigValue)(rawConfig.withComponent, false),
12
+ withHooks: (0, visitor_plugin_common_1.getConfigValue)(rawConfig.withHooks, true),
13
+ urqlImportFrom: (0, visitor_plugin_common_1.getConfigValue)(rawConfig.urqlImportFrom, null),
19
14
  });
20
15
  this._externalImportPrefix = '';
21
16
  if (this.config.importOperationTypesFrom) {
22
17
  this._externalImportPrefix = `${this.config.importOperationTypesFrom}.`;
23
- if (this.config.documentMode !== visitorPluginCommon.DocumentMode.external || !this.config.importDocumentNodeExternallyFrom) {
18
+ if (this.config.documentMode !== visitor_plugin_common_1.DocumentMode.external || !this.config.importDocumentNodeExternallyFrom) {
24
19
  // eslint-disable-next-line no-console
25
20
  console.warn('"importOperationTypesFrom" should be used with "documentMode=external" and "importDocumentNodeExternallyFrom"');
26
21
  }
@@ -29,7 +24,7 @@ class UrqlVisitor extends visitorPluginCommon.ClientSideBaseVisitor {
29
24
  console.warn('importOperationTypesFrom only works correctly when left empty or set to "Operations"');
30
25
  }
31
26
  }
32
- autoBind(this);
27
+ (0, auto_bind_1.default)(this);
33
28
  }
34
29
  getImports() {
35
30
  const baseImports = super.getImports();
@@ -44,7 +39,7 @@ class UrqlVisitor extends visitorPluginCommon.ClientSideBaseVisitor {
44
39
  if (this.config.withComponent || this.config.withHooks) {
45
40
  imports.push(`import * as Urql from '${this.config.urqlImportFrom || 'urql'}';`);
46
41
  }
47
- imports.push(visitorPluginCommon.OMIT_TYPE);
42
+ imports.push(visitor_plugin_common_1.OMIT_TYPE);
48
43
  return [...baseImports, ...imports];
49
44
  }
50
45
  _buildComponent(node, documentVariableName, operationType, operationResultType, operationVariablesTypes) {
@@ -54,7 +49,7 @@ class UrqlVisitor extends visitorPluginCommon.ClientSideBaseVisitor {
54
49
  useTypesPrefix: false,
55
50
  });
56
51
  const isVariablesRequired = operationType === 'Query' &&
57
- node.variableDefinitions.some(variableDef => variableDef.type.kind === graphql.Kind.NON_NULL_TYPE);
52
+ node.variableDefinitions.some(variableDef => variableDef.type.kind === graphql_1.Kind.NON_NULL_TYPE);
58
53
  const generics = [operationResultType, operationVariablesTypes];
59
54
  if (operationType === 'Subscription') {
60
55
  generics.unshift(operationResultType);
@@ -83,7 +78,7 @@ export function use${operationName}<TData = ${operationResultType}>(options: Omi
83
78
  return Urql.use${operationType}<${operationResultType}, TData, ${operationVariablesTypes}>({ query: ${documentVariableName}, ...options }, handler);
84
79
  };`;
85
80
  }
86
- const isVariablesRequired = node.variableDefinitions.some(variableDef => variableDef.type.kind === graphql.Kind.NON_NULL_TYPE && variableDef.defaultValue == null);
81
+ const isVariablesRequired = node.variableDefinitions.some(variableDef => variableDef.type.kind === graphql_1.Kind.NON_NULL_TYPE && variableDef.defaultValue == null);
87
82
  return `
88
83
  export function use${operationName}(options${isVariablesRequired ? '' : '?'}: Omit<Urql.Use${operationType}Args<${operationVariablesTypes}>, 'query'>) {
89
84
  return Urql.use${operationType}<${operationResultType}>({ query: ${documentVariableName}, ...options });
@@ -102,36 +97,4 @@ export function use${operationName}(options${isVariablesRequired ? '' : '?'}: Om
102
97
  return [component, hooks].filter(a => a).join('\n');
103
98
  }
104
99
  }
105
-
106
- const plugin = (schema, documents, config) => {
107
- const allAst = graphql.concatAST(documents.map(v => v.document));
108
- const allFragments = [
109
- ...allAst.definitions.filter(d => d.kind === graphql.Kind.FRAGMENT_DEFINITION).map(fragmentDef => ({
110
- node: fragmentDef,
111
- name: fragmentDef.name.value,
112
- onType: fragmentDef.typeCondition.name.value,
113
- isExternal: false,
114
- })),
115
- ...(config.externalFragments || []),
116
- ];
117
- const visitor = new UrqlVisitor(schema, allFragments, config);
118
- const visitorResult = pluginHelpers.oldVisit(allAst, { leave: visitor });
119
- return {
120
- prepend: visitor.getImports(),
121
- content: [visitor.fragments, ...visitorResult.definitions.filter(t => typeof t === 'string')].join('\n'),
122
- };
123
- };
124
- const validate = async (schema, documents, config, outputFile) => {
125
- if (config.withComponent === true) {
126
- if (path.extname(outputFile) !== '.tsx') {
127
- throw new Error(`Plugin "typescript-urql" requires extension to be ".tsx" when withComponent: true is set!`);
128
- }
129
- }
130
- else if (path.extname(outputFile) !== '.ts' && path.extname(outputFile) !== '.tsx') {
131
- throw new Error(`Plugin "typescript-urql" requires extension to be ".ts" or ".tsx"!`);
132
- }
133
- };
134
-
135
100
  exports.UrqlVisitor = UrqlVisitor;
136
- exports.plugin = plugin;
137
- exports.validate = validate;
package/esm/config.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/esm/index.js ADDED
@@ -0,0 +1,33 @@
1
+ import { oldVisit } from '@graphql-codegen/plugin-helpers';
2
+ import { concatAST, Kind } from 'graphql';
3
+ import { UrqlVisitor } 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 UrqlVisitor(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 (config.withComponent === true) {
25
+ if (extname(outputFile) !== '.tsx') {
26
+ throw new Error(`Plugin "typescript-urql" requires extension to be ".tsx" when withComponent: true is set!`);
27
+ }
28
+ }
29
+ else if (extname(outputFile) !== '.ts' && extname(outputFile) !== '.tsx') {
30
+ throw new Error(`Plugin "typescript-urql" requires extension to be ".ts" or ".tsx"!`);
31
+ }
32
+ };
33
+ export { UrqlVisitor };
@@ -1,10 +1,7 @@
1
- import { oldVisit } from '@graphql-codegen/plugin-helpers';
2
- import { Kind, concatAST } from 'graphql';
3
- import { ClientSideBaseVisitor, getConfigValue, DocumentMode, OMIT_TYPE } from '@graphql-codegen/visitor-plugin-common';
1
+ import { ClientSideBaseVisitor, getConfigValue, OMIT_TYPE, DocumentMode, } from '@graphql-codegen/visitor-plugin-common';
4
2
  import autoBind from 'auto-bind';
5
- import { extname } from 'path';
6
-
7
- class UrqlVisitor extends ClientSideBaseVisitor {
3
+ import { Kind } from 'graphql';
4
+ export class UrqlVisitor extends ClientSideBaseVisitor {
8
5
  constructor(schema, fragments, rawConfig) {
9
6
  super(schema, fragments, rawConfig, {
10
7
  withComponent: getConfigValue(rawConfig.withComponent, false),
@@ -96,34 +93,3 @@ export function use${operationName}(options${isVariablesRequired ? '' : '?'}: Om
96
93
  return [component, hooks].filter(a => a).join('\n');
97
94
  }
98
95
  }
99
-
100
- const plugin = (schema, documents, config) => {
101
- const allAst = concatAST(documents.map(v => v.document));
102
- const allFragments = [
103
- ...allAst.definitions.filter(d => d.kind === Kind.FRAGMENT_DEFINITION).map(fragmentDef => ({
104
- node: fragmentDef,
105
- name: fragmentDef.name.value,
106
- onType: fragmentDef.typeCondition.name.value,
107
- isExternal: false,
108
- })),
109
- ...(config.externalFragments || []),
110
- ];
111
- const visitor = new UrqlVisitor(schema, allFragments, config);
112
- const visitorResult = oldVisit(allAst, { leave: visitor });
113
- return {
114
- prepend: visitor.getImports(),
115
- content: [visitor.fragments, ...visitorResult.definitions.filter(t => typeof t === 'string')].join('\n'),
116
- };
117
- };
118
- const validate = async (schema, documents, config, outputFile) => {
119
- if (config.withComponent === true) {
120
- if (extname(outputFile) !== '.tsx') {
121
- throw new Error(`Plugin "typescript-urql" requires extension to be ".tsx" when withComponent: true is set!`);
122
- }
123
- }
124
- else if (extname(outputFile) !== '.ts' && extname(outputFile) !== '.tsx') {
125
- throw new Error(`Plugin "typescript-urql" requires extension to be ".ts" or ".tsx"!`);
126
- }
127
- };
128
-
129
- export { UrqlVisitor, plugin, validate };
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@graphql-codegen/typescript-urql",
3
- "version": "3.5.12",
3
+ "version": "3.6.0-alpha-2fbcdb6d3.0",
4
4
  "description": "GraphQL Code Generator plugin for generating an introspection file for Urql's Schema Awareness",
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.4.0",
11
- "@graphql-codegen/visitor-plugin-common": "2.9.1",
10
+ "@graphql-codegen/plugin-helpers": "^2.5.0-alpha-2fbcdb6d3.0",
11
+ "@graphql-codegen/visitor-plugin-common": "2.11.0-alpha-2fbcdb6d3.0",
12
12
  "auto-bind": "~4.0.0",
13
13
  "tslib": "~2.4.0"
14
14
  },
@@ -18,21 +18,28 @@
18
18
  "directory": "packages/plugins/typescript/urql"
19
19
  },
20
20
  "license": "MIT",
21
- "main": "index.js",
22
- "module": "index.mjs",
23
- "typings": "index.d.ts",
21
+ "main": "cjs/index.js",
22
+ "module": "esm/index.js",
23
+ "typings": "typings/index.d.ts",
24
24
  "typescript": {
25
- "definition": "index.d.ts"
25
+ "definition": "typings/index.d.ts"
26
26
  },
27
+ "type": "module",
27
28
  "exports": {
28
- "./package.json": "./package.json",
29
29
  ".": {
30
- "require": "./index.js",
31
- "import": "./index.mjs"
30
+ "require": {
31
+ "types": "./typings/index.d.ts",
32
+ "default": "./cjs/index.js"
33
+ },
34
+ "import": {
35
+ "types": "./typings/index.d.ts",
36
+ "default": "./esm/index.js"
37
+ },
38
+ "default": {
39
+ "types": "./typings/index.d.ts",
40
+ "default": "./esm/index.js"
41
+ }
32
42
  },
33
- "./*": {
34
- "require": "./*.js",
35
- "import": "./*.mjs"
36
- }
43
+ "./package.json": "./package.json"
37
44
  }
38
- }
45
+ }
File without changes
@@ -1,6 +1,6 @@
1
1
  import { Types, PluginValidateFn, PluginFunction } from '@graphql-codegen/plugin-helpers';
2
- import { UrqlVisitor } from './visitor';
3
- import { UrqlRawPluginConfig } from './config';
2
+ import { UrqlVisitor } from './visitor.js';
3
+ import { UrqlRawPluginConfig } from './config.js';
4
4
  export declare const plugin: PluginFunction<UrqlRawPluginConfig, Types.ComplexPluginOutput>;
5
5
  export declare const validate: PluginValidateFn<any>;
6
6
  export { UrqlVisitor };
@@ -1,5 +1,5 @@
1
1
  import { ClientSideBaseVisitor, ClientSideBasePluginConfig, LoadedFragment } from '@graphql-codegen/visitor-plugin-common';
2
- import { UrqlRawPluginConfig } from './config';
2
+ import { UrqlRawPluginConfig } from './config.js';
3
3
  import { OperationDefinitionNode, GraphQLSchema } from 'graphql';
4
4
  export interface UrqlPluginConfig extends ClientSideBasePluginConfig {
5
5
  withComponent: boolean;