@graphql-codegen/typescript-urql 3.1.3 → 3.2.1-alpha-16421e2d7.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/index.js CHANGED
@@ -17,6 +17,18 @@ class UrqlVisitor extends visitorPluginCommon.ClientSideBaseVisitor {
17
17
  withHooks: visitorPluginCommon.getConfigValue(rawConfig.withHooks, true),
18
18
  urqlImportFrom: visitorPluginCommon.getConfigValue(rawConfig.urqlImportFrom, null),
19
19
  });
20
+ this._externalImportPrefix = '';
21
+ if (this.config.importOperationTypesFrom) {
22
+ this._externalImportPrefix = `${this.config.importOperationTypesFrom}.`;
23
+ if (this.config.documentMode !== visitorPluginCommon.DocumentMode.external || !this.config.importDocumentNodeExternallyFrom) {
24
+ // eslint-disable-next-line no-console
25
+ console.warn('"importOperationTypesFrom" should be used with "documentMode=external" and "importDocumentNodeExternallyFrom"');
26
+ }
27
+ if (this.config.importOperationTypesFrom !== 'Operations') {
28
+ // eslint-disable-next-line no-console
29
+ console.warn('importOperationTypesFrom only works correctly when left empty or set to "Operations"');
30
+ }
31
+ }
20
32
  autoBind(this);
21
33
  }
22
34
  getImports() {
@@ -77,11 +89,15 @@ export function use${operationName}(options: Omit<Urql.Use${operationType}Args<$
77
89
  };`;
78
90
  }
79
91
  buildOperation(node, documentVariableName, operationType, operationResultType, operationVariablesTypes) {
92
+ const documentVariablePrefixed = this._externalImportPrefix + documentVariableName;
93
+ const operationTypePrefixed = this._externalImportPrefix + operationType;
94
+ const operationResultTypePrefixed = this._externalImportPrefix + operationResultType;
95
+ const operationVariablesTypesPrefixed = this._externalImportPrefix + operationVariablesTypes;
80
96
  const component = this.config.withComponent
81
- ? this._buildComponent(node, documentVariableName, operationType, operationResultType, operationVariablesTypes)
97
+ ? this._buildComponent(node, documentVariablePrefixed, operationTypePrefixed, operationResultTypePrefixed, operationVariablesTypesPrefixed)
82
98
  : null;
83
99
  const hooks = this.config.withHooks
84
- ? this._buildHooks(node, operationType, documentVariableName, operationResultType, operationVariablesTypes)
100
+ ? this._buildHooks(node, operationTypePrefixed, documentVariablePrefixed, operationResultTypePrefixed, operationVariablesTypesPrefixed)
85
101
  : null;
86
102
  return [component, hooks].filter(a => a).join('\n');
87
103
  }
package/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Kind, concatAST, visit } from 'graphql';
2
- import { ClientSideBaseVisitor, getConfigValue, OMIT_TYPE } from '@graphql-codegen/visitor-plugin-common';
2
+ import { ClientSideBaseVisitor, getConfigValue, DocumentMode, OMIT_TYPE } from '@graphql-codegen/visitor-plugin-common';
3
3
  import autoBind from 'auto-bind';
4
4
  import { pascalCase } from 'change-case-all';
5
5
  import { extname } from 'path';
@@ -11,6 +11,18 @@ class UrqlVisitor extends ClientSideBaseVisitor {
11
11
  withHooks: getConfigValue(rawConfig.withHooks, true),
12
12
  urqlImportFrom: getConfigValue(rawConfig.urqlImportFrom, null),
13
13
  });
14
+ this._externalImportPrefix = '';
15
+ if (this.config.importOperationTypesFrom) {
16
+ this._externalImportPrefix = `${this.config.importOperationTypesFrom}.`;
17
+ if (this.config.documentMode !== DocumentMode.external || !this.config.importDocumentNodeExternallyFrom) {
18
+ // eslint-disable-next-line no-console
19
+ console.warn('"importOperationTypesFrom" should be used with "documentMode=external" and "importDocumentNodeExternallyFrom"');
20
+ }
21
+ if (this.config.importOperationTypesFrom !== 'Operations') {
22
+ // eslint-disable-next-line no-console
23
+ console.warn('importOperationTypesFrom only works correctly when left empty or set to "Operations"');
24
+ }
25
+ }
14
26
  autoBind(this);
15
27
  }
16
28
  getImports() {
@@ -71,11 +83,15 @@ export function use${operationName}(options: Omit<Urql.Use${operationType}Args<$
71
83
  };`;
72
84
  }
73
85
  buildOperation(node, documentVariableName, operationType, operationResultType, operationVariablesTypes) {
86
+ const documentVariablePrefixed = this._externalImportPrefix + documentVariableName;
87
+ const operationTypePrefixed = this._externalImportPrefix + operationType;
88
+ const operationResultTypePrefixed = this._externalImportPrefix + operationResultType;
89
+ const operationVariablesTypesPrefixed = this._externalImportPrefix + operationVariablesTypes;
74
90
  const component = this.config.withComponent
75
- ? this._buildComponent(node, documentVariableName, operationType, operationResultType, operationVariablesTypes)
91
+ ? this._buildComponent(node, documentVariablePrefixed, operationTypePrefixed, operationResultTypePrefixed, operationVariablesTypesPrefixed)
76
92
  : null;
77
93
  const hooks = this.config.withHooks
78
- ? this._buildHooks(node, operationType, documentVariableName, operationResultType, operationVariablesTypes)
94
+ ? this._buildHooks(node, operationTypePrefixed, documentVariablePrefixed, operationResultTypePrefixed, operationVariablesTypesPrefixed)
79
95
  : null;
80
96
  return [component, hooks].filter(a => a).join('\n');
81
97
  }
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@graphql-codegen/typescript-urql",
3
- "version": "3.1.3",
3
+ "version": "3.2.1-alpha-16421e2d7.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",
7
7
  "graphql-tag": "^2.0.0"
8
8
  },
9
9
  "dependencies": {
10
- "@graphql-codegen/plugin-helpers": "^2.1.1",
11
- "@graphql-codegen/visitor-plugin-common": "2.2.0",
10
+ "@graphql-codegen/plugin-helpers": "2.2.0-alpha-16421e2d7.0",
11
+ "@graphql-codegen/visitor-plugin-common": "2.2.2-alpha-16421e2d7.0",
12
12
  "auto-bind": "~4.0.0",
13
13
  "change-case-all": "1.0.14",
14
14
  "tslib": "~2.3.0"
package/visitor.d.ts CHANGED
@@ -7,6 +7,7 @@ export interface UrqlPluginConfig extends ClientSideBasePluginConfig {
7
7
  urqlImportFrom: string;
8
8
  }
9
9
  export declare class UrqlVisitor extends ClientSideBaseVisitor<UrqlRawPluginConfig, UrqlPluginConfig> {
10
+ private _externalImportPrefix;
10
11
  constructor(schema: GraphQLSchema, fragments: LoadedFragment[], rawConfig: UrqlRawPluginConfig);
11
12
  getImports(): string[];
12
13
  private _buildComponent;