@graphql-codegen/typescript-apollo-angular 3.4.12-alpha-7a65ba05d.0 → 3.5.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,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/cjs/index.js ADDED
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ApolloAngularVisitor = exports.validate = exports.addToSchema = 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, "ApolloAngularVisitor", { enumerable: true, get: function () { return visitor_js_1.ApolloAngularVisitor; } });
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 operations = allAst.definitions.filter(d => d.kind === graphql_1.Kind.OPERATION_DEFINITION);
12
+ const allFragments = [
13
+ ...allAst.definitions.filter(d => d.kind === graphql_1.Kind.FRAGMENT_DEFINITION).map(fragmentDef => ({
14
+ node: fragmentDef,
15
+ name: fragmentDef.name.value,
16
+ onType: fragmentDef.typeCondition.name.value,
17
+ isExternal: false,
18
+ })),
19
+ ...(config.externalFragments || []),
20
+ ];
21
+ const visitor = new visitor_js_1.ApolloAngularVisitor(schema, allFragments, operations, config, documents);
22
+ const visitorResult = (0, plugin_helpers_1.oldVisit)(allAst, { leave: visitor });
23
+ return {
24
+ prepend: visitor.getImports(),
25
+ content: [
26
+ visitor.fragments,
27
+ ...visitorResult.definitions.filter(t => typeof t === 'string'),
28
+ config.sdkClass ? visitor.sdkClass : null,
29
+ ]
30
+ .filter(a => a)
31
+ .join('\n'),
32
+ };
33
+ };
34
+ exports.plugin = plugin;
35
+ exports.addToSchema = (0, graphql_1.parse)(`
36
+ directive @NgModule(module: String!) on OBJECT | FIELD
37
+ directive @namedClient(name: String!) on OBJECT | FIELD
38
+ `);
39
+ const validate = async (schema, documents, config, outputFile) => {
40
+ if ((0, path_1.extname)(outputFile) !== '.ts') {
41
+ throw new Error(`Plugin "apollo-angular" requires extension to be ".ts"!`);
42
+ }
43
+ };
44
+ exports.validate = validate;
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -1,22 +1,17 @@
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
-
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ApolloAngularVisitor = 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
+ const change_case_all_1 = require("change-case-all");
14
9
  const R_MOD = /module:\s*"([^"]+)"/; // matches: module: "..."
15
10
  const R_NAME = /name:\s*"([^"]+)"/; // matches: name: "..."
16
11
  function R_DEF(directive) {
17
12
  return new RegExp(`\\s+\\@${directive}\\([^)]+\\)`, 'gm');
18
13
  }
19
- class ApolloAngularVisitor extends visitorPluginCommon.ClientSideBaseVisitor {
14
+ class ApolloAngularVisitor extends visitor_plugin_common_1.ClientSideBaseVisitor {
20
15
  constructor(schema, fragments, _allOperations, rawConfig, documents) {
21
16
  super(schema, fragments, rawConfig, {
22
17
  sdkClass: rawConfig.sdkClass,
@@ -28,11 +23,11 @@ class ApolloAngularVisitor extends visitorPluginCommon.ClientSideBaseVisitor {
28
23
  querySuffix: rawConfig.querySuffix,
29
24
  mutationSuffix: rawConfig.mutationSuffix,
30
25
  subscriptionSuffix: rawConfig.subscriptionSuffix,
31
- additionalDI: visitorPluginCommon.getConfigValue(rawConfig.additionalDI, []),
32
- apolloAngularPackage: visitorPluginCommon.getConfigValue(rawConfig.apolloAngularPackage, 'apollo-angular'),
33
- apolloAngularVersion: visitorPluginCommon.getConfigValue(rawConfig.apolloAngularVersion, 2),
34
- gqlImport: visitorPluginCommon.getConfigValue(rawConfig.gqlImport, !rawConfig.apolloAngularVersion || rawConfig.apolloAngularVersion === 2 ? `apollo-angular#gql` : null),
35
- addExplicitOverride: visitorPluginCommon.getConfigValue(rawConfig.addExplicitOverride, false),
26
+ additionalDI: (0, visitor_plugin_common_1.getConfigValue)(rawConfig.additionalDI, []),
27
+ apolloAngularPackage: (0, visitor_plugin_common_1.getConfigValue)(rawConfig.apolloAngularPackage, 'apollo-angular'),
28
+ apolloAngularVersion: (0, visitor_plugin_common_1.getConfigValue)(rawConfig.apolloAngularVersion, 2),
29
+ gqlImport: (0, visitor_plugin_common_1.getConfigValue)(rawConfig.gqlImport, !rawConfig.apolloAngularVersion || rawConfig.apolloAngularVersion === 2 ? `apollo-angular#gql` : null),
30
+ addExplicitOverride: (0, visitor_plugin_common_1.getConfigValue)(rawConfig.addExplicitOverride, false),
36
31
  }, documents);
37
32
  this._allOperations = _allOperations;
38
33
  this._externalImportPrefix = '';
@@ -41,7 +36,7 @@ class ApolloAngularVisitor extends visitorPluginCommon.ClientSideBaseVisitor {
41
36
  this.dependencyInjectionArgs = '';
42
37
  if (this.config.importOperationTypesFrom) {
43
38
  this._externalImportPrefix = `${this.config.importOperationTypesFrom}.`;
44
- if (this.config.documentMode !== visitorPluginCommon.DocumentMode.external || !this.config.importDocumentNodeExternallyFrom) {
39
+ if (this.config.documentMode !== visitor_plugin_common_1.DocumentMode.external || !this.config.importDocumentNodeExternallyFrom) {
45
40
  // eslint-disable-next-line no-console
46
41
  console.warn('"importOperationTypesFrom" should be used with "documentMode=external" and "importDocumentNodeExternallyFrom"');
47
42
  }
@@ -56,7 +51,7 @@ class ApolloAngularVisitor extends visitorPluginCommon.ClientSideBaseVisitor {
56
51
  });
57
52
  this.dependencyInjections = dependencyInjections.join(', ');
58
53
  this.dependencyInjectionArgs = dependencyInjectionArgs.join(', ');
59
- autoBind(this);
54
+ (0, auto_bind_1.default)(this);
60
55
  }
61
56
  getImports() {
62
57
  const baseImports = super.getImports();
@@ -101,7 +96,7 @@ class ApolloAngularVisitor extends visitorPluginCommon.ClientSideBaseVisitor {
101
96
  return [...baseImports, ...imports];
102
97
  }
103
98
  _extractNgModule(operation) {
104
- const [, link] = graphql.print(operation).match(R_MOD);
99
+ const [, link] = (0, graphql_1.print)(operation).match(R_MOD);
105
100
  return this._parseNgModule(link);
106
101
  }
107
102
  _parseNgModule(link) {
@@ -117,7 +112,7 @@ class ApolloAngularVisitor extends visitorPluginCommon.ClientSideBaseVisitor {
117
112
  return operation.includes(`@${directive}`);
118
113
  }
119
114
  let found = false;
120
- graphql.visit(operation, {
115
+ (0, graphql_1.visit)(operation, {
121
116
  Directive(node) {
122
117
  if (node.name.value === directive) {
123
118
  found = true;
@@ -136,7 +131,7 @@ class ApolloAngularVisitor extends visitorPluginCommon.ClientSideBaseVisitor {
136
131
  return directives.reduce((doc, directive) => this._removeDirective(doc, directive), document);
137
132
  }
138
133
  _extractDirective(operation, directive) {
139
- const directives = graphql.print(operation).match(R_DEF(directive));
134
+ const directives = (0, graphql_1.print)(operation).match(R_DEF(directive));
140
135
  if (directives.length > 1) {
141
136
  throw new Error(`The ${directive} directive used multiple times in '${operation.name}' operation`);
142
137
  }
@@ -237,30 +232,30 @@ class ApolloAngularVisitor extends visitorPluginCommon.ClientSideBaseVisitor {
237
232
  const operationVariablesTypes = this._externalImportPrefix + o.operationVariablesTypes;
238
233
  const optionalVariables = !o.node.variableDefinitions ||
239
234
  o.node.variableDefinitions.length === 0 ||
240
- o.node.variableDefinitions.every(v => v.type.kind !== graphql.Kind.NON_NULL_TYPE || !!v.defaultValue);
235
+ o.node.variableDefinitions.every(v => v.type.kind !== graphql_1.Kind.NON_NULL_TYPE || !!v.defaultValue);
241
236
  const options = o.operationType === 'Mutation'
242
237
  ? `${o.operationType}OptionsAlone<${operationResultType}, ${operationVariablesTypes}>`
243
238
  : `${o.operationType}OptionsAlone<${operationVariablesTypes}>`;
244
239
  const method = `
245
- ${changeCaseAll.camelCase(o.node.name.value)}(variables${optionalVariables ? '?' : ''}: ${operationVariablesTypes}, options?: ${options}) {
246
- return this.${changeCaseAll.camelCase(o.serviceName)}.${actionType(o.operationType)}(variables, options)
240
+ ${(0, change_case_all_1.camelCase)(o.node.name.value)}(variables${optionalVariables ? '?' : ''}: ${operationVariablesTypes}, options?: ${options}) {
241
+ return this.${(0, change_case_all_1.camelCase)(o.serviceName)}.${actionType(o.operationType)}(variables, options)
247
242
  }`;
248
243
  let watchMethod;
249
244
  if (o.operationType === 'Query') {
250
245
  watchMethod = `
251
246
 
252
- ${changeCaseAll.camelCase(o.node.name.value)}Watch(variables${optionalVariables ? '?' : ''}: ${operationVariablesTypes}, options?: WatchQueryOptionsAlone<${operationVariablesTypes}>) {
253
- return this.${changeCaseAll.camelCase(o.serviceName)}.watch(variables, options)
247
+ ${(0, change_case_all_1.camelCase)(o.node.name.value)}Watch(variables${optionalVariables ? '?' : ''}: ${operationVariablesTypes}, options?: WatchQueryOptionsAlone<${operationVariablesTypes}>) {
248
+ return this.${(0, change_case_all_1.camelCase)(o.serviceName)}.watch(variables, options)
254
249
  }`;
255
250
  }
256
251
  return [method, watchMethod].join('');
257
252
  })
258
- .map(s => visitorPluginCommon.indentMultiline(s, 2));
253
+ .map(s => (0, visitor_plugin_common_1.indentMultiline)(s, 2));
259
254
  // Inject the generated services in the constructor
260
- const injectString = (service) => `private ${changeCaseAll.camelCase(service)}: ${service}`;
255
+ const injectString = (service) => `private ${(0, change_case_all_1.camelCase)(service)}: ${service}`;
261
256
  const injections = this._operationsToInclude
262
257
  .map(op => injectString(op.serviceName))
263
- .map(s => visitorPluginCommon.indentMultiline(s, 3))
258
+ .map(s => (0, visitor_plugin_common_1.indentMultiline)(s, 3))
264
259
  .join(',\n');
265
260
  const serviceName = this.config.serviceName || 'ApolloAngularSDK';
266
261
  const providedIn = this.config.serviceProvidedIn
@@ -287,7 +282,7 @@ ${changeCaseAll.camelCase(o.node.name.value)}Watch(variables${optionalVariables
287
282
  : '';
288
283
  const types = [omitType, watchType, queryType, mutationType, subscriptionType]
289
284
  .filter(s => s)
290
- .map(s => visitorPluginCommon.indent(s, 1))
285
+ .map(s => (0, visitor_plugin_common_1.indent)(s, 1))
291
286
  .join('\n\n');
292
287
  return `
293
288
  ${types}
@@ -301,43 +296,4 @@ ${injections}
301
296
  }`;
302
297
  }
303
298
  }
304
-
305
- const plugin = (schema, documents, config) => {
306
- const allAst = graphql.concatAST(documents.map(v => v.document));
307
- const operations = allAst.definitions.filter(d => d.kind === graphql.Kind.OPERATION_DEFINITION);
308
- const allFragments = [
309
- ...allAst.definitions.filter(d => d.kind === graphql.Kind.FRAGMENT_DEFINITION).map(fragmentDef => ({
310
- node: fragmentDef,
311
- name: fragmentDef.name.value,
312
- onType: fragmentDef.typeCondition.name.value,
313
- isExternal: false,
314
- })),
315
- ...(config.externalFragments || []),
316
- ];
317
- const visitor = new ApolloAngularVisitor(schema, allFragments, operations, config, documents);
318
- const visitorResult = pluginHelpers.oldVisit(allAst, { leave: visitor });
319
- return {
320
- prepend: visitor.getImports(),
321
- content: [
322
- visitor.fragments,
323
- ...visitorResult.definitions.filter(t => typeof t === 'string'),
324
- config.sdkClass ? visitor.sdkClass : null,
325
- ]
326
- .filter(a => a)
327
- .join('\n'),
328
- };
329
- };
330
- const addToSchema = graphql.parse(`
331
- directive @NgModule(module: String!) on OBJECT | FIELD
332
- directive @namedClient(name: String!) on OBJECT | FIELD
333
- `);
334
- const validate = async (schema, documents, config, outputFile) => {
335
- if (path.extname(outputFile) !== '.ts') {
336
- throw new Error(`Plugin "apollo-angular" requires extension to be ".ts"!`);
337
- }
338
- };
339
-
340
299
  exports.ApolloAngularVisitor = ApolloAngularVisitor;
341
- exports.addToSchema = addToSchema;
342
- exports.plugin = plugin;
343
- exports.validate = validate;
package/esm/config.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/esm/index.js ADDED
@@ -0,0 +1,39 @@
1
+ import { oldVisit } from '@graphql-codegen/plugin-helpers';
2
+ import { concatAST, Kind, parse } from 'graphql';
3
+ import { ApolloAngularVisitor } 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 operations = allAst.definitions.filter(d => d.kind === Kind.OPERATION_DEFINITION);
8
+ const allFragments = [
9
+ ...allAst.definitions.filter(d => d.kind === Kind.FRAGMENT_DEFINITION).map(fragmentDef => ({
10
+ node: fragmentDef,
11
+ name: fragmentDef.name.value,
12
+ onType: fragmentDef.typeCondition.name.value,
13
+ isExternal: false,
14
+ })),
15
+ ...(config.externalFragments || []),
16
+ ];
17
+ const visitor = new ApolloAngularVisitor(schema, allFragments, operations, config, documents);
18
+ const visitorResult = oldVisit(allAst, { leave: visitor });
19
+ return {
20
+ prepend: visitor.getImports(),
21
+ content: [
22
+ visitor.fragments,
23
+ ...visitorResult.definitions.filter(t => typeof t === 'string'),
24
+ config.sdkClass ? visitor.sdkClass : null,
25
+ ]
26
+ .filter(a => a)
27
+ .join('\n'),
28
+ };
29
+ };
30
+ export const addToSchema = parse(`
31
+ directive @NgModule(module: String!) on OBJECT | FIELD
32
+ directive @namedClient(name: String!) on OBJECT | FIELD
33
+ `);
34
+ export const validate = async (schema, documents, config, outputFile) => {
35
+ if (extname(outputFile) !== '.ts') {
36
+ throw new Error(`Plugin "apollo-angular" requires extension to be ".ts"!`);
37
+ }
38
+ };
39
+ export { ApolloAngularVisitor };
@@ -1,16 +1,13 @@
1
- import { oldVisit } from '@graphql-codegen/plugin-helpers';
2
- import { print, visit, Kind, concatAST, parse } from 'graphql';
3
- import { ClientSideBaseVisitor, getConfigValue, DocumentMode, indentMultiline, indent } from '@graphql-codegen/visitor-plugin-common';
1
+ import { ClientSideBaseVisitor, DocumentMode, indentMultiline, getConfigValue, indent, } from '@graphql-codegen/visitor-plugin-common';
4
2
  import autoBind from 'auto-bind';
3
+ import { print, visit, Kind } from 'graphql';
5
4
  import { camelCase } from 'change-case-all';
6
- import { extname } from 'path';
7
-
8
5
  const R_MOD = /module:\s*"([^"]+)"/; // matches: module: "..."
9
6
  const R_NAME = /name:\s*"([^"]+)"/; // matches: name: "..."
10
7
  function R_DEF(directive) {
11
8
  return new RegExp(`\\s+\\@${directive}\\([^)]+\\)`, 'gm');
12
9
  }
13
- class ApolloAngularVisitor extends ClientSideBaseVisitor {
10
+ export class ApolloAngularVisitor extends ClientSideBaseVisitor {
14
11
  constructor(schema, fragments, _allOperations, rawConfig, documents) {
15
12
  super(schema, fragments, rawConfig, {
16
13
  sdkClass: rawConfig.sdkClass,
@@ -295,40 +292,3 @@ ${injections}
295
292
  }`;
296
293
  }
297
294
  }
298
-
299
- const plugin = (schema, documents, config) => {
300
- const allAst = concatAST(documents.map(v => v.document));
301
- const operations = allAst.definitions.filter(d => d.kind === Kind.OPERATION_DEFINITION);
302
- const allFragments = [
303
- ...allAst.definitions.filter(d => d.kind === Kind.FRAGMENT_DEFINITION).map(fragmentDef => ({
304
- node: fragmentDef,
305
- name: fragmentDef.name.value,
306
- onType: fragmentDef.typeCondition.name.value,
307
- isExternal: false,
308
- })),
309
- ...(config.externalFragments || []),
310
- ];
311
- const visitor = new ApolloAngularVisitor(schema, allFragments, operations, config, documents);
312
- const visitorResult = oldVisit(allAst, { leave: visitor });
313
- return {
314
- prepend: visitor.getImports(),
315
- content: [
316
- visitor.fragments,
317
- ...visitorResult.definitions.filter(t => typeof t === 'string'),
318
- config.sdkClass ? visitor.sdkClass : null,
319
- ]
320
- .filter(a => a)
321
- .join('\n'),
322
- };
323
- };
324
- const addToSchema = parse(`
325
- directive @NgModule(module: String!) on OBJECT | FIELD
326
- directive @namedClient(name: String!) on OBJECT | FIELD
327
- `);
328
- const validate = async (schema, documents, config, outputFile) => {
329
- if (extname(outputFile) !== '.ts') {
330
- throw new Error(`Plugin "apollo-angular" requires extension to be ".ts"!`);
331
- }
332
- };
333
-
334
- export { ApolloAngularVisitor, addToSchema, plugin, validate };
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@graphql-codegen/typescript-apollo-angular",
3
- "version": "3.4.12-alpha-7a65ba05d.0",
3
+ "version": "3.5.0-alpha-29eb1293b.0",
4
4
  "description": "GraphQL Code Generator plugin for generating ready-to-use Angular 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"
7
7
  },
8
8
  "dependencies": {
9
- "@graphql-codegen/plugin-helpers": "^2.4.0",
10
- "@graphql-codegen/visitor-plugin-common": "2.9.1-alpha-7a65ba05d.0",
9
+ "@graphql-codegen/plugin-helpers": "^2.5.0-alpha-29eb1293b.0",
10
+ "@graphql-codegen/visitor-plugin-common": "2.11.0-alpha-29eb1293b.0",
11
11
  "auto-bind": "~4.0.0",
12
12
  "change-case-all": "1.0.14",
13
13
  "tslib": "~2.4.0"
@@ -18,21 +18,28 @@
18
18
  "directory": "packages/plugins/typescript/apollo-angular"
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 { PluginValidateFn, PluginFunction } from '@graphql-codegen/plugin-helpers';
2
- import { ApolloAngularVisitor } from './visitor';
3
- import { ApolloAngularRawPluginConfig } from './config';
2
+ import { ApolloAngularVisitor } from './visitor.js';
3
+ import { ApolloAngularRawPluginConfig } from './config.js';
4
4
  export declare const plugin: PluginFunction<ApolloAngularRawPluginConfig>;
5
5
  export declare const addToSchema: import("graphql").DocumentNode;
6
6
  export declare const validate: PluginValidateFn<any>;
@@ -1,6 +1,6 @@
1
1
  import { ClientSideBaseVisitor, ClientSideBasePluginConfig, LoadedFragment } from '@graphql-codegen/visitor-plugin-common';
2
2
  import { OperationDefinitionNode, GraphQLSchema } from 'graphql';
3
- import { ApolloAngularRawPluginConfig } from './config';
3
+ import { ApolloAngularRawPluginConfig } from './config.js';
4
4
  import { Types } from '@graphql-codegen/plugin-helpers';
5
5
  export interface ApolloAngularPluginConfig extends ClientSideBasePluginConfig {
6
6
  apolloAngularVersion: number;