@graphql-codegen/typescript-apollo-angular 3.4.3-alpha-cb3f44ae4.0 → 3.4.5
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 +25 -13
- package/index.mjs +26 -14
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -229,6 +229,9 @@ class ApolloAngularVisitor extends visitorPluginCommon.ClientSideBaseVisitor {
|
|
|
229
229
|
return 'fetch';
|
|
230
230
|
}
|
|
231
231
|
};
|
|
232
|
+
const hasMutations = this._operationsToInclude.find(o => o.operationType === 'Mutation');
|
|
233
|
+
const hasSubscriptions = this._operationsToInclude.find(o => o.operationType === 'Subscription');
|
|
234
|
+
const hasQueries = this._operationsToInclude.find(o => o.operationType === 'Query');
|
|
232
235
|
const allPossibleActions = this._operationsToInclude
|
|
233
236
|
.map(o => {
|
|
234
237
|
const operationResultType = this._externalImportPrefix + o.operationResultType;
|
|
@@ -266,20 +269,29 @@ ${changeCaseAll.camelCase(o.node.name.value)}Watch(variables${optionalVariables
|
|
|
266
269
|
: this.config.serviceProvidedInRoot === false
|
|
267
270
|
? ''
|
|
268
271
|
: `{ providedIn: 'root' }`;
|
|
272
|
+
// Generate these types only if they're going to be used,
|
|
273
|
+
// to avoid "unused variable" compile errors in generated code
|
|
274
|
+
const omitType = hasQueries || hasMutations || hasSubscriptions
|
|
275
|
+
? `type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;`
|
|
276
|
+
: '';
|
|
277
|
+
const watchType = hasQueries
|
|
278
|
+
? `interface WatchQueryOptionsAlone<V> extends Omit<ApolloCore.WatchQueryOptions<V>, 'query' | 'variables'> {}`
|
|
279
|
+
: '';
|
|
280
|
+
const queryType = hasQueries
|
|
281
|
+
? `interface QueryOptionsAlone<V> extends Omit<ApolloCore.QueryOptions<V>, 'query' | 'variables'> {}`
|
|
282
|
+
: '';
|
|
283
|
+
const mutationType = hasMutations
|
|
284
|
+
? `interface MutationOptionsAlone<T, V> extends Omit<ApolloCore.MutationOptions<T, V>, 'mutation' | 'variables'> {}`
|
|
285
|
+
: '';
|
|
286
|
+
const subscriptionType = hasSubscriptions
|
|
287
|
+
? `interface SubscriptionOptionsAlone<V> extends Omit<ApolloCore.SubscriptionOptions<V>, 'query' | 'variables'> {}`
|
|
288
|
+
: '';
|
|
289
|
+
const types = [omitType, watchType, queryType, mutationType, subscriptionType]
|
|
290
|
+
.filter(s => s)
|
|
291
|
+
.map(s => visitorPluginCommon.indent(s, 1))
|
|
292
|
+
.join('\n\n');
|
|
269
293
|
return `
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
interface WatchQueryOptionsAlone<V>
|
|
273
|
-
extends Omit<ApolloCore.WatchQueryOptions<V>, 'query' | 'variables'> {}
|
|
274
|
-
|
|
275
|
-
interface QueryOptionsAlone<V>
|
|
276
|
-
extends Omit<ApolloCore.QueryOptions<V>, 'query' | 'variables'> {}
|
|
277
|
-
|
|
278
|
-
interface MutationOptionsAlone<T, V>
|
|
279
|
-
extends Omit<ApolloCore.MutationOptions<T, V>, 'mutation' | 'variables'> {}
|
|
280
|
-
|
|
281
|
-
interface SubscriptionOptionsAlone<V>
|
|
282
|
-
extends Omit<ApolloCore.SubscriptionOptions<V>, 'query' | 'variables'> {}
|
|
294
|
+
${types}
|
|
283
295
|
|
|
284
296
|
@Injectable(${providedIn})
|
|
285
297
|
export class ${serviceName} {
|
package/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { oldVisit } from '@graphql-codegen/plugin-helpers';
|
|
2
2
|
import { print, visit, Kind, concatAST, parse } from 'graphql';
|
|
3
|
-
import { ClientSideBaseVisitor, getConfigValue, DocumentMode, indentMultiline } from '@graphql-codegen/visitor-plugin-common';
|
|
3
|
+
import { ClientSideBaseVisitor, getConfigValue, DocumentMode, indentMultiline, indent } from '@graphql-codegen/visitor-plugin-common';
|
|
4
4
|
import autoBind from 'auto-bind';
|
|
5
5
|
import { camelCase } from 'change-case-all';
|
|
6
6
|
import { extname } from 'path';
|
|
@@ -223,6 +223,9 @@ class ApolloAngularVisitor extends ClientSideBaseVisitor {
|
|
|
223
223
|
return 'fetch';
|
|
224
224
|
}
|
|
225
225
|
};
|
|
226
|
+
const hasMutations = this._operationsToInclude.find(o => o.operationType === 'Mutation');
|
|
227
|
+
const hasSubscriptions = this._operationsToInclude.find(o => o.operationType === 'Subscription');
|
|
228
|
+
const hasQueries = this._operationsToInclude.find(o => o.operationType === 'Query');
|
|
226
229
|
const allPossibleActions = this._operationsToInclude
|
|
227
230
|
.map(o => {
|
|
228
231
|
const operationResultType = this._externalImportPrefix + o.operationResultType;
|
|
@@ -260,20 +263,29 @@ ${camelCase(o.node.name.value)}Watch(variables${optionalVariables ? '?' : ''}: $
|
|
|
260
263
|
: this.config.serviceProvidedInRoot === false
|
|
261
264
|
? ''
|
|
262
265
|
: `{ providedIn: 'root' }`;
|
|
266
|
+
// Generate these types only if they're going to be used,
|
|
267
|
+
// to avoid "unused variable" compile errors in generated code
|
|
268
|
+
const omitType = hasQueries || hasMutations || hasSubscriptions
|
|
269
|
+
? `type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;`
|
|
270
|
+
: '';
|
|
271
|
+
const watchType = hasQueries
|
|
272
|
+
? `interface WatchQueryOptionsAlone<V> extends Omit<ApolloCore.WatchQueryOptions<V>, 'query' | 'variables'> {}`
|
|
273
|
+
: '';
|
|
274
|
+
const queryType = hasQueries
|
|
275
|
+
? `interface QueryOptionsAlone<V> extends Omit<ApolloCore.QueryOptions<V>, 'query' | 'variables'> {}`
|
|
276
|
+
: '';
|
|
277
|
+
const mutationType = hasMutations
|
|
278
|
+
? `interface MutationOptionsAlone<T, V> extends Omit<ApolloCore.MutationOptions<T, V>, 'mutation' | 'variables'> {}`
|
|
279
|
+
: '';
|
|
280
|
+
const subscriptionType = hasSubscriptions
|
|
281
|
+
? `interface SubscriptionOptionsAlone<V> extends Omit<ApolloCore.SubscriptionOptions<V>, 'query' | 'variables'> {}`
|
|
282
|
+
: '';
|
|
283
|
+
const types = [omitType, watchType, queryType, mutationType, subscriptionType]
|
|
284
|
+
.filter(s => s)
|
|
285
|
+
.map(s => indent(s, 1))
|
|
286
|
+
.join('\n\n');
|
|
263
287
|
return `
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
interface WatchQueryOptionsAlone<V>
|
|
267
|
-
extends Omit<ApolloCore.WatchQueryOptions<V>, 'query' | 'variables'> {}
|
|
268
|
-
|
|
269
|
-
interface QueryOptionsAlone<V>
|
|
270
|
-
extends Omit<ApolloCore.QueryOptions<V>, 'query' | 'variables'> {}
|
|
271
|
-
|
|
272
|
-
interface MutationOptionsAlone<T, V>
|
|
273
|
-
extends Omit<ApolloCore.MutationOptions<T, V>, 'mutation' | 'variables'> {}
|
|
274
|
-
|
|
275
|
-
interface SubscriptionOptionsAlone<V>
|
|
276
|
-
extends Omit<ApolloCore.SubscriptionOptions<V>, 'query' | 'variables'> {}
|
|
288
|
+
${types}
|
|
277
289
|
|
|
278
290
|
@Injectable(${providedIn})
|
|
279
291
|
export class ${serviceName} {
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/typescript-apollo-angular",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.5",
|
|
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
9
|
"@graphql-codegen/plugin-helpers": "^2.4.0",
|
|
10
|
-
"@graphql-codegen/visitor-plugin-common": "2.7.
|
|
10
|
+
"@graphql-codegen/visitor-plugin-common": "2.7.3",
|
|
11
11
|
"auto-bind": "~4.0.0",
|
|
12
12
|
"change-case-all": "1.0.14",
|
|
13
13
|
"tslib": "~2.3.0"
|