@aws-amplify/graphql-auth-transformer 0.7.10 → 0.7.11-alpha.11
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/lib/graphql-auth-transformer.d.ts +8 -8
- package/lib/graphql-auth-transformer.d.ts.map +1 -1
- package/lib/graphql-auth-transformer.js +119 -127
- package/lib/graphql-auth-transformer.js.map +1 -1
- package/lib/resolvers/field.d.ts.map +1 -1
- package/lib/resolvers/field.js +2 -2
- package/lib/resolvers/field.js.map +1 -1
- package/lib/resolvers/index.d.ts +1 -1
- package/lib/resolvers/index.d.ts.map +1 -1
- package/lib/resolvers/index.js +2 -1
- package/lib/resolvers/index.js.map +1 -1
- package/lib/resolvers/mutation.create.d.ts.map +1 -1
- package/lib/resolvers/mutation.create.js +6 -8
- package/lib/resolvers/mutation.create.js.map +1 -1
- package/lib/resolvers/mutation.delete.d.ts.map +1 -1
- package/lib/resolvers/mutation.delete.js +7 -11
- package/lib/resolvers/mutation.delete.js.map +1 -1
- package/lib/resolvers/mutation.update.d.ts.map +1 -1
- package/lib/resolvers/mutation.update.js +11 -13
- package/lib/resolvers/mutation.update.js.map +1 -1
- package/lib/resolvers/query.d.ts.map +1 -1
- package/lib/resolvers/query.js +15 -15
- package/lib/resolvers/query.js.map +1 -1
- package/lib/resolvers/search.d.ts.map +1 -1
- package/lib/resolvers/search.js +6 -6
- package/lib/resolvers/search.js.map +1 -1
- package/lib/resolvers/subscriptions.d.ts.map +1 -1
- package/lib/resolvers/subscriptions.js +5 -3
- package/lib/resolvers/subscriptions.js.map +1 -1
- package/lib/utils/index.d.ts +1 -1
- package/lib/utils/index.d.ts.map +1 -1
- package/lib/utils/index.js +20 -22
- package/lib/utils/index.js.map +1 -1
- package/package.json +10 -10
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { TransformerAuthBase } from '@aws-amplify/graphql-transformer-core';
|
|
2
2
|
import { TransformerTransformSchemaStepContextProvider, TransformerContextProvider, TransformerSchemaVisitStepContextProvider, TransformerAuthProvider, TransformerBeforeStepContextProvider } from '@aws-amplify/graphql-transformer-interfaces';
|
|
3
|
-
import { AuthTransformerConfig, RoleDefinition } from './utils';
|
|
4
3
|
import { DirectiveNode, FieldDefinitionNode, ObjectTypeDefinitionNode, InterfaceTypeDefinitionNode } from 'graphql';
|
|
5
4
|
import { AccessControlMatrix } from './accesscontrol';
|
|
5
|
+
import { AuthTransformerConfig, RoleDefinition } from './utils';
|
|
6
6
|
export declare class AuthTransformer extends TransformerAuthBase implements TransformerAuthProvider {
|
|
7
7
|
private config;
|
|
8
8
|
private configuredAuthProviders;
|
|
@@ -11,8 +11,8 @@ export declare class AuthTransformer extends TransformerAuthBase implements Tran
|
|
|
11
11
|
private authNonModelConfig;
|
|
12
12
|
private modelDirectiveConfig;
|
|
13
13
|
private seenNonModelTypes;
|
|
14
|
-
private
|
|
15
|
-
private
|
|
14
|
+
private generateIAMPolicyForUnauthRole;
|
|
15
|
+
private generateIAMPolicyForAuthRole;
|
|
16
16
|
private authPolicyResources;
|
|
17
17
|
private unauthPolicyResources;
|
|
18
18
|
constructor(config?: AuthTransformerConfig);
|
|
@@ -35,8 +35,8 @@ export declare class AuthTransformer extends TransformerAuthBase implements Tran
|
|
|
35
35
|
private convertRulesToRoles;
|
|
36
36
|
private doesTypeHaveRulesForOperation;
|
|
37
37
|
private getAuthProviders;
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
static getRelatedModelObject(ctx: TransformerContextProvider, typeName: string): ObjectTypeDefinitionNode | undefined;
|
|
39
|
+
static addFieldsToObject(ctx: TransformerTransformSchemaStepContextProvider, modelName: string, ownerFields: string[]): void;
|
|
40
40
|
private propagateAuthDirectivesToNestedTypes;
|
|
41
41
|
private getServiceDirectives;
|
|
42
42
|
private shouldAddDefaultServiceDirective;
|
|
@@ -48,9 +48,9 @@ export declare class AuthTransformer extends TransformerAuthBase implements Tran
|
|
|
48
48
|
private addFieldToResourceReferences;
|
|
49
49
|
addAutoGeneratedFields: (ctx: TransformerContextProvider, def: ObjectTypeDefinitionNode, allowedFields: string[], fields: readonly string[]) => string[];
|
|
50
50
|
addAutoGeneratedRelationalFields: (ctx: TransformerContextProvider, def: ObjectTypeDefinitionNode, allowedFields: Set<string>, fields: readonly string[]) => void;
|
|
51
|
-
addAutoGeneratedIndexFields: (
|
|
52
|
-
addAutoGeneratedHasManyFields: (
|
|
53
|
-
|
|
51
|
+
addAutoGeneratedIndexFields: (definition: ObjectTypeDefinitionNode, allowedFields: Set<string>) => void;
|
|
52
|
+
addAutoGeneratedHasManyFields: (typeDefinitions: ObjectTypeDefinitionNode[], def: ObjectTypeDefinitionNode, allowedFields: Set<string>) => void;
|
|
53
|
+
static addAutoGeneratedHasOneFields(typeDefinitions: ObjectTypeDefinitionNode[], fields: readonly string[], def: ObjectTypeDefinitionNode, allowedFields: Set<string>): void;
|
|
54
54
|
addAutoGeneratedDataStoreFields: (ctx: TransformerContextProvider, allowedFields: Set<string>) => void;
|
|
55
55
|
}
|
|
56
56
|
//# sourceMappingURL=graphql-auth-transformer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql-auth-transformer.d.ts","sourceRoot":"","sources":["../src/graphql-auth-transformer.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,mBAAmB,EAQpB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAIL,6CAA6C,EAC7C,0BAA0B,EAE1B,yCAAyC,EACzC,uBAAuB,EACvB,oCAAoC,EACrC,MAAM,6CAA6C,CAAC;AACrD,OAAO,
|
|
1
|
+
{"version":3,"file":"graphql-auth-transformer.d.ts","sourceRoot":"","sources":["../src/graphql-auth-transformer.ts"],"names":[],"mappings":"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"}
|
|
@@ -22,17 +22,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
22
22
|
exports.AuthTransformer = void 0;
|
|
23
23
|
const graphql_transformer_core_1 = require("@aws-amplify/graphql-transformer-core");
|
|
24
24
|
const graphql_transformer_interfaces_1 = require("@aws-amplify/graphql-transformer-interfaces");
|
|
25
|
-
const utils_1 = require("./utils");
|
|
26
25
|
const graphql_1 = require("graphql");
|
|
27
26
|
const graphql_model_transformer_1 = require("@aws-amplify/graphql-model-transformer");
|
|
28
|
-
const accesscontrol_1 = require("./accesscontrol");
|
|
29
27
|
const graphql_transformer_common_1 = require("graphql-transformer-common");
|
|
30
28
|
const iam = __importStar(require("@aws-cdk/aws-iam"));
|
|
31
29
|
const cdk = __importStar(require("@aws-cdk/core"));
|
|
32
|
-
const resolvers_1 = require("./resolvers");
|
|
33
|
-
const graphql_transformer_common_2 = require("graphql-transformer-common");
|
|
34
|
-
const field_1 = require("./resolvers/field");
|
|
35
30
|
const graphql_relational_transformer_1 = require("@aws-amplify/graphql-relational-transformer");
|
|
31
|
+
const resolvers_1 = require("./resolvers");
|
|
32
|
+
const accesscontrol_1 = require("./accesscontrol");
|
|
33
|
+
const utils_1 = require("./utils");
|
|
36
34
|
class AuthTransformer extends graphql_transformer_core_1.TransformerAuthBase {
|
|
37
35
|
constructor(config = {}) {
|
|
38
36
|
super('amplify-auth-transformer', utils_1.authDirectiveDefinition);
|
|
@@ -73,13 +71,13 @@ class AuthTransformer extends graphql_transformer_core_1.TransformerAuthBase {
|
|
|
73
71
|
if (parent.kind === graphql_1.Kind.INTERFACE_TYPE_DEFINITION) {
|
|
74
72
|
throw new graphql_transformer_core_1.InvalidDirectiveError(`The @auth directive cannot be placed on an interface's field. See ${parent.name.value}${field.name.value}`);
|
|
75
73
|
}
|
|
76
|
-
const isParentTypeBuiltinType = parent.name.value === context.output.getQueryTypeName()
|
|
77
|
-
parent.name.value === context.output.getMutationTypeName()
|
|
78
|
-
parent.name.value === context.output.getSubscriptionTypeName();
|
|
74
|
+
const isParentTypeBuiltinType = parent.name.value === context.output.getQueryTypeName()
|
|
75
|
+
|| parent.name.value === context.output.getMutationTypeName()
|
|
76
|
+
|| parent.name.value === context.output.getSubscriptionTypeName();
|
|
79
77
|
if (isParentTypeBuiltinType) {
|
|
80
|
-
console.warn(
|
|
81
|
-
object to perform authorization logic and the source will be an empty object for fields on root types.
|
|
82
|
-
Static group authorization should perform as expected
|
|
78
|
+
console.warn('Be careful when using @auth directives on a field in a root type. @auth directives on field definitions use the source '
|
|
79
|
+
+ 'object to perform authorization logic and the source will be an empty object for fields on root types. '
|
|
80
|
+
+ 'Static group authorization should perform as expected.');
|
|
83
81
|
}
|
|
84
82
|
const modelDirective = (_a = parent.directives) === null || _a === void 0 ? void 0 : _a.find(dir => dir.name.value === 'model');
|
|
85
83
|
const typeName = parent.name.value;
|
|
@@ -121,17 +119,15 @@ Static group authorization should perform as expected.`);
|
|
|
121
119
|
};
|
|
122
120
|
this.transformSchema = (context) => {
|
|
123
121
|
const searchableAggregateServiceDirectives = new Set();
|
|
124
|
-
const getOwnerFields = (acm) => {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
};
|
|
131
|
-
for (let [modelName, acm] of this.authModelConfig) {
|
|
122
|
+
const getOwnerFields = (acm) => acm.getRoles().reduce((prev, role) => {
|
|
123
|
+
if (this.roleMap.get(role).strategy === 'owner')
|
|
124
|
+
prev.push(this.roleMap.get(role).entity);
|
|
125
|
+
return prev;
|
|
126
|
+
}, []);
|
|
127
|
+
this.authModelConfig.forEach((acm, modelName) => {
|
|
132
128
|
const def = context.output.getObject(modelName);
|
|
133
129
|
const modelHasSearchable = def.directives.some(dir => dir.name.value === 'searchable');
|
|
134
|
-
|
|
130
|
+
AuthTransformer.addFieldsToObject(context, modelName, getOwnerFields(acm));
|
|
135
131
|
const providers = this.getAuthProviders(acm.getRoles());
|
|
136
132
|
const directives = this.getServiceDirectives(providers, providers.length === 0 ? this.shouldAddDefaultServiceDirective() : false);
|
|
137
133
|
if (modelHasSearchable) {
|
|
@@ -142,32 +138,32 @@ Static group authorization should perform as expected.`);
|
|
|
142
138
|
}
|
|
143
139
|
this.protectSchemaOperations(context, def, acm);
|
|
144
140
|
this.propagateAuthDirectivesToNestedTypes(context, context.output.getObject(modelName), providers);
|
|
145
|
-
}
|
|
146
|
-
|
|
141
|
+
});
|
|
142
|
+
this.authNonModelConfig.forEach((acm, typeFieldName) => {
|
|
147
143
|
const [typeName, fieldName] = typeFieldName.split(':');
|
|
148
144
|
const providers = this.getAuthProviders(acm.getRoles());
|
|
149
145
|
const directives = this.getServiceDirectives(providers, false);
|
|
150
146
|
if (directives.length > 0) {
|
|
151
147
|
(0, utils_1.addDirectivesToField)(context, typeName, fieldName, directives);
|
|
152
148
|
}
|
|
153
|
-
}
|
|
149
|
+
});
|
|
154
150
|
if (searchableAggregateServiceDirectives.size > 0) {
|
|
155
151
|
const serviceDirectives = this.getServiceDirectives(Array.from(searchableAggregateServiceDirectives), false);
|
|
156
|
-
|
|
152
|
+
utils_1.SEARCHABLE_AGGREGATE_TYPES.forEach(aggType => {
|
|
157
153
|
(0, utils_1.extendTypeWithDirectives)(context, aggType, serviceDirectives);
|
|
158
|
-
}
|
|
154
|
+
});
|
|
159
155
|
}
|
|
160
156
|
};
|
|
161
157
|
this.generateResolvers = (context) => {
|
|
162
|
-
var _a, _b, _c;
|
|
163
158
|
this.generateIAMPolicies(context);
|
|
164
|
-
|
|
159
|
+
this.authModelConfig.forEach((acm, modelName) => {
|
|
160
|
+
var _a, _b, _c;
|
|
165
161
|
const indexKeyName = `${modelName}:indicies`;
|
|
166
162
|
const def = context.output.getObject(modelName);
|
|
167
163
|
const modelNameConfig = this.modelDirectiveConfig.get(modelName);
|
|
168
164
|
const searchableDirective = def.directives.find(dir => dir.name.value === 'searchable');
|
|
169
165
|
const queryFields = (0, utils_1.getQueryFieldNames)(this.modelDirectiveConfig.get(modelName));
|
|
170
|
-
|
|
166
|
+
queryFields.forEach(query => {
|
|
171
167
|
switch (query.type) {
|
|
172
168
|
case graphql_transformer_interfaces_1.QueryFieldType.GET:
|
|
173
169
|
this.protectGetResolver(context, def, query.typeName, query.fieldName, acm);
|
|
@@ -179,14 +175,14 @@ Static group authorization should perform as expected.`);
|
|
|
179
175
|
this.protectSyncResolver(context, def, query.typeName, query.fieldName, acm);
|
|
180
176
|
break;
|
|
181
177
|
default:
|
|
182
|
-
throw new graphql_transformer_core_1.TransformerContractError('
|
|
178
|
+
throw new graphql_transformer_core_1.TransformerContractError('Unknown query field type');
|
|
183
179
|
}
|
|
184
|
-
}
|
|
180
|
+
});
|
|
185
181
|
if (context.metadata.has(indexKeyName)) {
|
|
186
|
-
|
|
182
|
+
context.metadata.get(indexKeyName).forEach(index => {
|
|
187
183
|
const [indexName, indexQueryName] = index.split(':');
|
|
188
184
|
this.protectListResolver(context, def, def.name.value, indexQueryName, acm, indexName);
|
|
189
|
-
}
|
|
185
|
+
});
|
|
190
186
|
}
|
|
191
187
|
if (searchableDirective) {
|
|
192
188
|
const config = (0, utils_1.getSearchableConfig)(searchableDirective, modelName);
|
|
@@ -195,7 +191,7 @@ Static group authorization should perform as expected.`);
|
|
|
195
191
|
const readRoles = acm.getRolesPerOperation('read');
|
|
196
192
|
const modelFields = (_b = (_a = def.fields) === null || _a === void 0 ? void 0 : _a.filter(f => acm.hasResource(f.name.value))) !== null && _b !== void 0 ? _b : [];
|
|
197
193
|
const errorFields = new Array();
|
|
198
|
-
|
|
194
|
+
modelFields.forEach(field => {
|
|
199
195
|
const fieldReadRoles = (0, utils_1.getReadRolesForField)(acm, readRoles, field.name.value);
|
|
200
196
|
const allowedRoles = fieldReadRoles.filter(r => acm.isAllowed(r, field.name.value, 'read'));
|
|
201
197
|
const needsFieldResolver = allowedRoles.length < fieldReadRoles.length;
|
|
@@ -208,13 +204,13 @@ Static group authorization should perform as expected.`);
|
|
|
208
204
|
else if (needsFieldResolver) {
|
|
209
205
|
this.protectFieldResolver(context, def, modelName, field.name.value, allowedRoles);
|
|
210
206
|
}
|
|
211
|
-
}
|
|
207
|
+
});
|
|
212
208
|
if (errorFields.length > 0 && ((_c = modelNameConfig.subscriptions) === null || _c === void 0 ? void 0 : _c.level) === graphql_model_transformer_1.SubscriptionLevel.on) {
|
|
213
|
-
throw new graphql_transformer_core_1.InvalidDirectiveError(`Because "${def.name.value}" has a field-level authorization rule and subscriptions are enabled,`
|
|
214
|
-
` you need to either apply field-level authorization rules to all required fields where all rules have read access ${JSON.stringify(errorFields)}, make those fields nullable, or disable subscriptions for "${def.name.value}" (setting level to off or public).`);
|
|
209
|
+
throw new graphql_transformer_core_1.InvalidDirectiveError(`Because "${def.name.value}" has a field-level authorization rule and subscriptions are enabled,`
|
|
210
|
+
+ ` you need to either apply field-level authorization rules to all required fields where all rules have read access ${JSON.stringify(errorFields)}, make those fields nullable, or disable subscriptions for "${def.name.value}" (setting level to off or public).`);
|
|
215
211
|
}
|
|
216
212
|
const mutationFields = (0, utils_1.getMutationFieldNames)(this.modelDirectiveConfig.get(modelName));
|
|
217
|
-
|
|
213
|
+
mutationFields.forEach(mutation => {
|
|
218
214
|
switch (mutation.type) {
|
|
219
215
|
case graphql_transformer_interfaces_1.MutationFieldType.CREATE:
|
|
220
216
|
this.protectCreateResolver(context, def, mutation.typeName, mutation.fieldName, acm);
|
|
@@ -228,21 +224,21 @@ Static group authorization should perform as expected.`);
|
|
|
228
224
|
default:
|
|
229
225
|
throw new graphql_transformer_core_1.TransformerContractError('Unknown Mutation field type');
|
|
230
226
|
}
|
|
231
|
-
}
|
|
227
|
+
});
|
|
232
228
|
const subscriptionFieldNames = (0, utils_1.getSubscriptionFieldNames)(this.modelDirectiveConfig.get(modelName));
|
|
233
229
|
const subscriptionRoles = acm
|
|
234
230
|
.getRolesPerOperation('read')
|
|
235
231
|
.map(role => this.roleMap.get(role))
|
|
236
232
|
.filter(roleDef => { var _a; return (roleDef.strategy === 'owner' && !(0, utils_1.fieldIsList)((_a = def.fields) !== null && _a !== void 0 ? _a : [], roleDef.entity)) || roleDef.static; });
|
|
237
|
-
|
|
233
|
+
subscriptionFieldNames.forEach(subscription => {
|
|
238
234
|
this.protectSubscriptionResolver(context, subscription.typeName, subscription.fieldName, subscriptionRoles);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
this.authNonModelConfig.forEach((acm, typeFieldName) => {
|
|
242
238
|
const [typeName, fieldName] = typeFieldName.split(':');
|
|
243
239
|
const def = context.output.getObject(typeName);
|
|
244
240
|
this.protectFieldResolver(context, def, typeName, fieldName, acm.getRoles());
|
|
245
|
-
}
|
|
241
|
+
});
|
|
246
242
|
};
|
|
247
243
|
this.protectSchemaOperations = (ctx, def, acm) => {
|
|
248
244
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
@@ -267,9 +263,9 @@ Static group authorization should perform as expected.`);
|
|
|
267
263
|
addServiceDirective(ctx.output.getMutationTypeName(), 'update', (_e = modelConfig === null || modelConfig === void 0 ? void 0 : modelConfig.mutations) === null || _e === void 0 ? void 0 : _e.update);
|
|
268
264
|
addServiceDirective(ctx.output.getMutationTypeName(), 'delete', (_f = modelConfig === null || modelConfig === void 0 ? void 0 : modelConfig.mutations) === null || _f === void 0 ? void 0 : _f.delete);
|
|
269
265
|
if (ctx.metadata.has(indexKeyName)) {
|
|
270
|
-
|
|
266
|
+
ctx.metadata.get(indexKeyName).forEach(index => {
|
|
271
267
|
addServiceDirective(ctx.output.getQueryTypeName(), 'read', index.split(':')[1]);
|
|
272
|
-
}
|
|
268
|
+
});
|
|
273
269
|
}
|
|
274
270
|
if (searchableDirective) {
|
|
275
271
|
const config = (0, utils_1.getSearchableConfig)(searchableDirective, def.name.value);
|
|
@@ -282,22 +278,22 @@ Static group authorization should perform as expected.`);
|
|
|
282
278
|
.map(role => this.roleMap.get(role))
|
|
283
279
|
.filter(roleDef => { var _a; return roleDef.strategy === 'owner' && !(0, utils_1.fieldIsList)((_a = def.fields) !== null && _a !== void 0 ? _a : [], roleDef.entity); });
|
|
284
280
|
if (subscriptions.onCreate && ((_g = modelConfig === null || modelConfig === void 0 ? void 0 : modelConfig.mutations) === null || _g === void 0 ? void 0 : _g.create)) {
|
|
285
|
-
|
|
281
|
+
subscriptions.onCreate.forEach(onCreateSub => {
|
|
286
282
|
addServiceDirective(ctx.output.getSubscriptionTypeName(), 'read', onCreateSub);
|
|
287
283
|
(0, utils_1.addSubscriptionArguments)(ctx, onCreateSub, subscriptionArguments);
|
|
288
|
-
}
|
|
284
|
+
});
|
|
289
285
|
}
|
|
290
286
|
if (subscriptions.onUpdate && ((_h = modelConfig === null || modelConfig === void 0 ? void 0 : modelConfig.mutations) === null || _h === void 0 ? void 0 : _h.update)) {
|
|
291
|
-
|
|
287
|
+
subscriptions.onUpdate.forEach(onUpdateSub => {
|
|
292
288
|
addServiceDirective(ctx.output.getSubscriptionTypeName(), 'read', onUpdateSub);
|
|
293
289
|
(0, utils_1.addSubscriptionArguments)(ctx, onUpdateSub, subscriptionArguments);
|
|
294
|
-
}
|
|
290
|
+
});
|
|
295
291
|
}
|
|
296
292
|
if (subscriptions.onDelete && ((_j = modelConfig === null || modelConfig === void 0 ? void 0 : modelConfig.mutations) === null || _j === void 0 ? void 0 : _j.delete)) {
|
|
297
|
-
|
|
293
|
+
subscriptions.onDelete.forEach(onDeleteSub => {
|
|
298
294
|
addServiceDirective(ctx.output.getSubscriptionTypeName(), 'read', onDeleteSub);
|
|
299
295
|
(0, utils_1.addSubscriptionArguments)(ctx, onDeleteSub, subscriptionArguments);
|
|
300
|
-
}
|
|
296
|
+
});
|
|
301
297
|
}
|
|
302
298
|
}
|
|
303
299
|
};
|
|
@@ -337,7 +333,7 @@ Static group authorization should perform as expected.`);
|
|
|
337
333
|
var _a, _b, _c;
|
|
338
334
|
let fieldAuthExpression;
|
|
339
335
|
let relatedAuthExpression;
|
|
340
|
-
const relatedModelObject =
|
|
336
|
+
const relatedModelObject = AuthTransformer.getRelatedModelObject(ctx, (0, graphql_transformer_common_1.getBaseType)(field.type));
|
|
341
337
|
if (this.authModelConfig.has(relatedModelObject.name.value)) {
|
|
342
338
|
const acm = this.authModelConfig.get(relatedModelObject.name.value);
|
|
343
339
|
const roleDefinitions = acm.getRolesPerOperation('read').map(r => this.roleMap.get(r));
|
|
@@ -345,12 +341,12 @@ Static group authorization should perform as expected.`);
|
|
|
345
341
|
relatedAuthExpression = (0, resolvers_1.generateAuthExpressionForRelationQuery)(this.configuredAuthProviders, roleDefinitions, (_a = relatedModelObject.fields) !== null && _a !== void 0 ? _a : [], relationalPrimaryMap);
|
|
346
342
|
}
|
|
347
343
|
else {
|
|
348
|
-
relatedAuthExpression = (0,
|
|
344
|
+
relatedAuthExpression = (0, resolvers_1.generateSandboxExpressionForField)(ctx.sandboxModeEnabled);
|
|
349
345
|
}
|
|
350
346
|
if (fieldRoles) {
|
|
351
347
|
const roleDefinitions = fieldRoles.map(r => this.roleMap.get(r));
|
|
352
348
|
const hasSubsEnabled = ((_b = this.modelDirectiveConfig.get(typeName).subscriptions) === null || _b === void 0 ? void 0 : _b.level) === 'on';
|
|
353
|
-
relatedAuthExpression = (0, resolvers_1.setDeniedFieldFlag)('Mutation', hasSubsEnabled)
|
|
349
|
+
relatedAuthExpression = `${(0, resolvers_1.setDeniedFieldFlag)('Mutation', hasSubsEnabled)}\n${relatedAuthExpression}`;
|
|
354
350
|
fieldAuthExpression = (0, resolvers_1.generateAuthExpressionForField)(this.configuredAuthProviders, roleDefinitions, (_c = def.fields) !== null && _c !== void 0 ? _c : []);
|
|
355
351
|
}
|
|
356
352
|
const resolver = ctx.resolvers.getResolver(typeName, field.name.value);
|
|
@@ -405,7 +401,7 @@ Static group authorization should perform as expected.`);
|
|
|
405
401
|
if (!ctx.api.host.hasDataSource(utils_1.NONE_DS)) {
|
|
406
402
|
ctx.api.host.addNoneDataSource(utils_1.NONE_DS);
|
|
407
403
|
}
|
|
408
|
-
const authFunction = ctx.api.host.addAppSyncFunction(`${(0,
|
|
404
|
+
const authFunction = ctx.api.host.addAppSyncFunction(`${(0, graphql_transformer_common_1.toUpper)(typeName)}${(0, graphql_transformer_common_1.toUpper)(fieldName)}AuthFN`, graphql_transformer_core_1.MappingTemplate.s3MappingTemplateFromString(fieldAuthExpression, `${typeName}.${fieldName}.auth.req.vtl`), graphql_transformer_core_1.MappingTemplate.inlineTemplateFromString('$util.toJson({})'), utils_1.NONE_DS, stack);
|
|
409
405
|
fieldResolver.pipelineConfig.functions.unshift(authFunction.functionId);
|
|
410
406
|
}
|
|
411
407
|
else {
|
|
@@ -445,19 +441,19 @@ Static group authorization should perform as expected.`);
|
|
|
445
441
|
roleDefinition.nullAllowedFields = nullAllowedFields;
|
|
446
442
|
return roleDefinition;
|
|
447
443
|
});
|
|
448
|
-
const
|
|
444
|
+
const dataSource = ctx.api.host.getDataSource(`${def.name.value}Table`);
|
|
449
445
|
const requestExpression = (0, resolvers_1.generateAuthRequestExpression)();
|
|
450
446
|
const authExpression = (0, resolvers_1.generateAuthExpressionForUpdate)(this.configuredAuthProviders, totalRoles, (_a = def.fields) !== null && _a !== void 0 ? _a : []);
|
|
451
|
-
resolver.addToSlot('auth', graphql_transformer_core_1.MappingTemplate.s3MappingTemplateFromString(requestExpression, `${typeName}.${fieldName}.{slotName}.{slotIndex}.req.vtl`), graphql_transformer_core_1.MappingTemplate.s3MappingTemplateFromString(authExpression, `${typeName}.${fieldName}.{slotName}.{slotIndex}.res.vtl`),
|
|
447
|
+
resolver.addToSlot('auth', graphql_transformer_core_1.MappingTemplate.s3MappingTemplateFromString(requestExpression, `${typeName}.${fieldName}.{slotName}.{slotIndex}.req.vtl`), graphql_transformer_core_1.MappingTemplate.s3MappingTemplateFromString(authExpression, `${typeName}.${fieldName}.{slotName}.{slotIndex}.res.vtl`), dataSource);
|
|
452
448
|
};
|
|
453
449
|
this.protectDeleteResolver = (ctx, def, typeName, fieldName, acm) => {
|
|
454
450
|
var _a;
|
|
455
451
|
const resolver = ctx.resolvers.getResolver(typeName, fieldName);
|
|
456
452
|
const deleteRoles = acm.getRolesPerOperation('delete', true).map(role => this.roleMap.get(role));
|
|
457
|
-
const
|
|
453
|
+
const dataSource = ctx.api.host.getDataSource(`${def.name.value}Table`);
|
|
458
454
|
const requestExpression = (0, resolvers_1.generateAuthRequestExpression)();
|
|
459
455
|
const authExpression = (0, resolvers_1.generateAuthExpressionForDelete)(this.configuredAuthProviders, deleteRoles, (_a = def.fields) !== null && _a !== void 0 ? _a : []);
|
|
460
|
-
resolver.addToSlot('auth', graphql_transformer_core_1.MappingTemplate.s3MappingTemplateFromString(requestExpression, `${typeName}.${fieldName}.{slotName}.{slotIndex}.req.vtl`), graphql_transformer_core_1.MappingTemplate.s3MappingTemplateFromString(authExpression, `${typeName}.${fieldName}.{slotName}.{slotIndex}.res.vtl`),
|
|
456
|
+
resolver.addToSlot('auth', graphql_transformer_core_1.MappingTemplate.s3MappingTemplateFromString(requestExpression, `${typeName}.${fieldName}.{slotName}.{slotIndex}.req.vtl`), graphql_transformer_core_1.MappingTemplate.s3MappingTemplateFromString(authExpression, `${typeName}.${fieldName}.{slotName}.{slotIndex}.res.vtl`), dataSource);
|
|
461
457
|
};
|
|
462
458
|
this.protectSubscriptionResolver = (ctx, typeName, fieldName, subscriptionRoles) => {
|
|
463
459
|
const resolver = ctx.resolvers.getResolver(typeName, fieldName);
|
|
@@ -472,14 +468,14 @@ Static group authorization should perform as expected.`);
|
|
|
472
468
|
return Array.from(allowedFieldsSet);
|
|
473
469
|
};
|
|
474
470
|
this.addAutoGeneratedRelationalFields = (ctx, def, allowedFields, fields) => {
|
|
475
|
-
const
|
|
476
|
-
this.addAutoGeneratedHasManyFields(
|
|
477
|
-
|
|
471
|
+
const typeDefinitions = ctx.inputDocument.definitions.filter(it => it.kind === 'ObjectTypeDefinition');
|
|
472
|
+
this.addAutoGeneratedHasManyFields(typeDefinitions, def, allowedFields);
|
|
473
|
+
AuthTransformer.addAutoGeneratedHasOneFields(typeDefinitions, fields, def, allowedFields);
|
|
478
474
|
};
|
|
479
|
-
this.addAutoGeneratedIndexFields = (
|
|
475
|
+
this.addAutoGeneratedIndexFields = (definition, allowedFields) => {
|
|
480
476
|
var _a;
|
|
481
|
-
const sortKeyFieldValues = (_a =
|
|
482
|
-
|
|
477
|
+
const sortKeyFieldValues = (_a = definition.fields) === null || _a === void 0 ? void 0 : _a.map(it => it.directives).flat().filter(it => it.name.value === 'primaryKey' || it.name.value === 'index').map(it => it.arguments).flat().filter(it => it.name.value === 'sortKeyFields' && it.value.kind === 'ListValue' && it.value.values.length > 1).map(it => it.value).flat();
|
|
478
|
+
sortKeyFieldValues.forEach(sortKeyFieldValue => {
|
|
483
479
|
const accessOnAllKeys = !sortKeyFieldValue.values.some(it => it.kind !== 'StringValue' || !allowedFields.has(it.value));
|
|
484
480
|
if (accessOnAllKeys) {
|
|
485
481
|
const keyName = sortKeyFieldValue.values
|
|
@@ -487,18 +483,16 @@ Static group authorization should perform as expected.`);
|
|
|
487
483
|
.join(graphql_transformer_common_1.ModelResourceIDs.ModelCompositeKeySeparator());
|
|
488
484
|
allowedFields.add(keyName);
|
|
489
485
|
}
|
|
490
|
-
}
|
|
486
|
+
});
|
|
491
487
|
};
|
|
492
|
-
this.addAutoGeneratedHasManyFields = (
|
|
493
|
-
const hasManyRelatedFields =
|
|
494
|
-
.map(it => it.fields.map(field => {
|
|
495
|
-
return { ...field, relatedType: it.name.value };
|
|
496
|
-
}))
|
|
488
|
+
this.addAutoGeneratedHasManyFields = (typeDefinitions, def, allowedFields) => {
|
|
489
|
+
const hasManyRelatedFields = typeDefinitions
|
|
490
|
+
.map(it => it.fields.map(field => ({ ...field, relatedType: it.name.value })))
|
|
497
491
|
.flat()
|
|
498
492
|
.filter(it => { var _a; return (0, graphql_transformer_common_1.getBaseType)(it.type) === def.name.value && ((_a = it.directives) === null || _a === void 0 ? void 0 : _a.some(d => d.name.value === 'hasMany')); });
|
|
499
|
-
|
|
493
|
+
hasManyRelatedFields.forEach(relatedField => {
|
|
500
494
|
allowedFields.add((0, graphql_relational_transformer_1.getConnectionAttributeName)(relatedField.relatedType, relatedField.name.value));
|
|
501
|
-
}
|
|
495
|
+
});
|
|
502
496
|
};
|
|
503
497
|
this.addAutoGeneratedDataStoreFields = (ctx, allowedFields) => {
|
|
504
498
|
const dataStoreFields = ctx.isProjectUsingDataStore() ? ['_version', '_deleted', '_lastChangedAt'] : [];
|
|
@@ -509,13 +503,13 @@ Static group authorization should perform as expected.`);
|
|
|
509
503
|
this.seenNonModelTypes = new Map();
|
|
510
504
|
this.authModelConfig = new Map();
|
|
511
505
|
this.roleMap = new Map();
|
|
512
|
-
this.
|
|
513
|
-
this.
|
|
506
|
+
this.generateIAMPolicyForUnauthRole = false;
|
|
507
|
+
this.generateIAMPolicyForAuthRole = false;
|
|
514
508
|
this.authNonModelConfig = new Map();
|
|
515
509
|
}
|
|
516
510
|
convertRulesToRoles(acm, authRules, allowRoleOverwrite, field, overrideOperations) {
|
|
517
|
-
|
|
518
|
-
|
|
511
|
+
authRules.forEach(rule => {
|
|
512
|
+
const operations = overrideOperations || rule.operations || utils_1.MODEL_OPERATIONS;
|
|
519
513
|
if (rule.groups && !rule.groupsField) {
|
|
520
514
|
rule.groups.forEach(group => {
|
|
521
515
|
const groupClaim = rule.groupClaim || utils_1.DEFAULT_GROUP_CLAIM;
|
|
@@ -529,7 +523,9 @@ Static group authorization should perform as expected.`);
|
|
|
529
523
|
entity: group,
|
|
530
524
|
});
|
|
531
525
|
}
|
|
532
|
-
acm.setRole({
|
|
526
|
+
acm.setRole({
|
|
527
|
+
role: roleName, resource: field, operations, allowRoleOverwrite,
|
|
528
|
+
});
|
|
533
529
|
});
|
|
534
530
|
}
|
|
535
531
|
else {
|
|
@@ -597,28 +593,26 @@ Static group authorization should perform as expected.`);
|
|
|
597
593
|
if (!(roleName in this.roleMap)) {
|
|
598
594
|
this.roleMap.set(roleName, roleDefinition);
|
|
599
595
|
}
|
|
600
|
-
acm.setRole({
|
|
596
|
+
acm.setRole({
|
|
597
|
+
role: roleName, resource: field, operations, allowRoleOverwrite,
|
|
598
|
+
});
|
|
601
599
|
}
|
|
602
|
-
}
|
|
600
|
+
});
|
|
603
601
|
}
|
|
604
602
|
doesTypeHaveRulesForOperation(acm, operation) {
|
|
605
|
-
const rolesHasDefaultProvider = (roles) =>
|
|
606
|
-
return roles.some(r => this.roleMap.get(r).provider === this.configuredAuthProviders.default);
|
|
607
|
-
};
|
|
603
|
+
const rolesHasDefaultProvider = (roles) => roles.some(r => this.roleMap.get(r).provider === this.configuredAuthProviders.default);
|
|
608
604
|
const roles = acm.getRolesPerOperation(operation, operation === 'delete');
|
|
609
605
|
return rolesHasDefaultProvider(roles) || (roles.length === 0 && this.shouldAddDefaultServiceDirective());
|
|
610
606
|
}
|
|
611
607
|
getAuthProviders(roles) {
|
|
612
608
|
const providers = new Set();
|
|
613
|
-
|
|
614
|
-
providers.add(this.roleMap.get(role).provider);
|
|
615
|
-
}
|
|
609
|
+
roles.forEach(role => providers.add(this.roleMap.get(role).provider));
|
|
616
610
|
if (this.configuredAuthProviders.hasAdminRolesEnabled) {
|
|
617
611
|
providers.add('iam');
|
|
618
612
|
}
|
|
619
613
|
return Array.from(providers);
|
|
620
614
|
}
|
|
621
|
-
getRelatedModelObject(ctx, typeName) {
|
|
615
|
+
static getRelatedModelObject(ctx, typeName) {
|
|
622
616
|
const modelObjectName = graphql_transformer_common_1.ModelResourceIDs.IsModelConnectionType(typeName)
|
|
623
617
|
? graphql_transformer_common_1.ModelResourceIDs.GetModelFromConnectionType(typeName)
|
|
624
618
|
: typeName;
|
|
@@ -629,13 +623,13 @@ Static group authorization should perform as expected.`);
|
|
|
629
623
|
return ctx.output.getObject(modelObjectName);
|
|
630
624
|
}
|
|
631
625
|
}
|
|
632
|
-
addFieldsToObject(ctx, modelName, ownerFields) {
|
|
626
|
+
static addFieldsToObject(ctx, modelName, ownerFields) {
|
|
633
627
|
const modelObject = ctx.output.getObject(modelName);
|
|
634
628
|
const existingFields = (0, utils_1.collectFieldNames)(modelObject);
|
|
635
629
|
const ownerFieldsToAdd = ownerFields.filter(field => !existingFields.includes(field));
|
|
636
|
-
|
|
630
|
+
ownerFieldsToAdd.forEach(ownerField => {
|
|
637
631
|
modelObject.fields.push((0, graphql_transformer_common_1.makeField)(ownerField, [], (0, graphql_transformer_common_1.makeNamedType)('String')));
|
|
638
|
-
}
|
|
632
|
+
});
|
|
639
633
|
ctx.output.putType(modelObject);
|
|
640
634
|
}
|
|
641
635
|
propagateAuthDirectivesToNestedTypes(ctx, def, providers) {
|
|
@@ -652,7 +646,7 @@ Static group authorization should perform as expected.`);
|
|
|
652
646
|
const nonModelFieldTypes = def
|
|
653
647
|
.fields.map(f => ctx.output.getType((0, graphql_transformer_common_1.getBaseType)(f.type)))
|
|
654
648
|
.filter(nonModelTypePredicate);
|
|
655
|
-
|
|
649
|
+
nonModelFieldTypes.forEach(nonModelFieldType => {
|
|
656
650
|
const nonModelName = nonModelFieldType.name.value;
|
|
657
651
|
const hasSeenType = this.seenNonModelTypes.has(nonModelFieldType.name.value);
|
|
658
652
|
let directives = this.getServiceDirectives(providers, hasSeenType);
|
|
@@ -673,25 +667,25 @@ Static group authorization should perform as expected.`);
|
|
|
673
667
|
(0, utils_1.extendTypeWithDirectives)(ctx, nonModelFieldType.name.value, directives);
|
|
674
668
|
this.propagateAuthDirectivesToNestedTypes(ctx, nonModelFieldType, providers);
|
|
675
669
|
}
|
|
676
|
-
}
|
|
670
|
+
});
|
|
677
671
|
}
|
|
678
672
|
getServiceDirectives(providers, addDefaultIfNeeded = true) {
|
|
679
673
|
if (providers.length === 0) {
|
|
680
674
|
return [];
|
|
681
675
|
}
|
|
682
|
-
const directives =
|
|
676
|
+
const directives = [];
|
|
683
677
|
const addDirectiveIfNeeded = (provider, directiveName) => {
|
|
684
|
-
if ((this.configuredAuthProviders.default !== provider && providers.some(p => p === provider))
|
|
685
|
-
(this.configuredAuthProviders.default === provider && providers.some(p => p !== provider && addDefaultIfNeeded === true))) {
|
|
678
|
+
if ((this.configuredAuthProviders.default !== provider && providers.some(p => p === provider))
|
|
679
|
+
|| (this.configuredAuthProviders.default === provider && providers.some(p => p !== provider && addDefaultIfNeeded === true))) {
|
|
686
680
|
directives.push((0, graphql_transformer_common_1.makeDirective)(directiveName, []));
|
|
687
681
|
}
|
|
688
682
|
};
|
|
689
|
-
|
|
683
|
+
utils_1.AUTH_PROVIDER_DIRECTIVE_MAP.forEach((directiveName, authProvider) => {
|
|
690
684
|
addDirectiveIfNeeded(authProvider, directiveName);
|
|
691
|
-
}
|
|
692
|
-
if (providers.some(p => p === this.configuredAuthProviders.default)
|
|
693
|
-
providers.some(p => p !== this.configuredAuthProviders.default)
|
|
694
|
-
!directives.some(d => d.name.value === utils_1.AUTH_PROVIDER_DIRECTIVE_MAP.get(this.configuredAuthProviders.default))) {
|
|
685
|
+
});
|
|
686
|
+
if (providers.some(p => p === this.configuredAuthProviders.default)
|
|
687
|
+
&& providers.some(p => p !== this.configuredAuthProviders.default)
|
|
688
|
+
&& !directives.some(d => d.name.value === utils_1.AUTH_PROVIDER_DIRECTIVE_MAP.get(this.configuredAuthProviders.default))) {
|
|
695
689
|
directives.push((0, graphql_transformer_common_1.makeDirective)(utils_1.AUTH_PROVIDER_DIRECTIVE_MAP.get(this.configuredAuthProviders.default), []));
|
|
696
690
|
}
|
|
697
691
|
return directives;
|
|
@@ -700,7 +694,7 @@ Static group authorization should perform as expected.`);
|
|
|
700
694
|
return (this.configuredAuthProviders.hasAdminRolesEnabled && this.config.authConfig.defaultAuthentication.authenticationType !== 'AWS_IAM');
|
|
701
695
|
}
|
|
702
696
|
generateIAMPolicies(ctx) {
|
|
703
|
-
if (this.
|
|
697
|
+
if (this.generateIAMPolicyForAuthRole) {
|
|
704
698
|
if (this.authPolicyResources.size === 0) {
|
|
705
699
|
if (!this.configuredAuthProviders.hasAdminRolesEnabled) {
|
|
706
700
|
throw new graphql_transformer_core_1.TransformerContractError('AuthRole policies should be generated, but no resources were added.');
|
|
@@ -709,9 +703,9 @@ Static group authorization should perform as expected.`);
|
|
|
709
703
|
else {
|
|
710
704
|
const authRoleParameter = ctx.stackManager.getParameter(graphql_transformer_core_1.IAM_AUTH_ROLE_PARAMETER).valueAsString;
|
|
711
705
|
const authPolicyDocuments = (0, utils_1.createPolicyDocumentForManagedPolicy)(this.authPolicyResources);
|
|
712
|
-
const rootStack = ctx.stackManager
|
|
706
|
+
const { rootStack } = ctx.stackManager;
|
|
713
707
|
const iamAuthRoleArn = iam.Role.fromRoleArn(rootStack, 'auth-role-name', `arn:aws:iam::${cdk.Stack.of(rootStack).account}:role/${authRoleParameter}`);
|
|
714
|
-
for (let i = 0; i < authPolicyDocuments.length; i
|
|
708
|
+
for (let i = 0; i < authPolicyDocuments.length; i += 1) {
|
|
715
709
|
const paddedIndex = `${i + 1}`.padStart(2, '0');
|
|
716
710
|
const resourceName = `${graphql_transformer_common_1.ResourceConstants.RESOURCES.AuthRolePolicy}${paddedIndex}`;
|
|
717
711
|
new iam.ManagedPolicy(rootStack, resourceName, {
|
|
@@ -721,15 +715,15 @@ Static group authorization should perform as expected.`);
|
|
|
721
715
|
}
|
|
722
716
|
}
|
|
723
717
|
}
|
|
724
|
-
if (this.
|
|
718
|
+
if (this.generateIAMPolicyForUnauthRole) {
|
|
725
719
|
if (this.unauthPolicyResources.size === 0) {
|
|
726
720
|
throw new graphql_transformer_core_1.TransformerContractError('UnauthRole policies should be generated, but no resources were added');
|
|
727
721
|
}
|
|
728
722
|
const unauthRoleParameter = ctx.stackManager.getParameter(graphql_transformer_core_1.IAM_UNAUTH_ROLE_PARAMETER).valueAsString;
|
|
729
723
|
const unauthPolicyDocuments = (0, utils_1.createPolicyDocumentForManagedPolicy)(this.unauthPolicyResources);
|
|
730
|
-
const rootStack = ctx.stackManager
|
|
724
|
+
const { rootStack } = ctx.stackManager;
|
|
731
725
|
const iamUnauthRoleArn = iam.Role.fromRoleArn(rootStack, 'unauth-role-name', `arn:aws:iam::${cdk.Stack.of(rootStack).account}:role/${unauthRoleParameter}`);
|
|
732
|
-
for (let i = 0; i < unauthPolicyDocuments.length; i
|
|
726
|
+
for (let i = 0; i < unauthPolicyDocuments.length; i += 1) {
|
|
733
727
|
const paddedIndex = `${i + 1}`.padStart(2, '0');
|
|
734
728
|
const resourceName = `${graphql_transformer_common_1.ResourceConstants.RESOURCES.UnauthRolePolicy}${paddedIndex}`;
|
|
735
729
|
new iam.ManagedPolicy(ctx.stackManager.rootStack, resourceName, {
|
|
@@ -740,26 +734,24 @@ Static group authorization should perform as expected.`);
|
|
|
740
734
|
}
|
|
741
735
|
}
|
|
742
736
|
setAuthPolicyFlag(rules) {
|
|
743
|
-
if (rules.length === 0 || this.
|
|
737
|
+
if (rules.length === 0 || this.generateIAMPolicyForAuthRole === true) {
|
|
744
738
|
return;
|
|
745
739
|
}
|
|
746
|
-
|
|
740
|
+
rules.forEach(rule => {
|
|
747
741
|
if ((rule.allow === 'private' || rule.allow === 'public') && rule.provider === 'iam') {
|
|
748
|
-
this.
|
|
749
|
-
return;
|
|
742
|
+
this.generateIAMPolicyForAuthRole = true;
|
|
750
743
|
}
|
|
751
|
-
}
|
|
744
|
+
});
|
|
752
745
|
}
|
|
753
746
|
setUnauthPolicyFlag(rules) {
|
|
754
|
-
if (rules.length === 0 || this.
|
|
747
|
+
if (rules.length === 0 || this.generateIAMPolicyForUnauthRole === true) {
|
|
755
748
|
return;
|
|
756
749
|
}
|
|
757
|
-
|
|
750
|
+
rules.forEach(rule => {
|
|
758
751
|
if (rule.allow === 'public' && rule.provider === 'iam') {
|
|
759
|
-
this.
|
|
760
|
-
return;
|
|
752
|
+
this.generateIAMPolicyForUnauthRole = true;
|
|
761
753
|
}
|
|
762
|
-
}
|
|
754
|
+
});
|
|
763
755
|
}
|
|
764
756
|
addOperationToResourceReferences(operationName, fieldName, roles) {
|
|
765
757
|
const iamPublicRolesExist = roles.some(r => this.roleMap.get(r).provider === 'iam' && this.roleMap.get(r).strategy === 'public');
|
|
@@ -794,27 +786,27 @@ Static group authorization should perform as expected.`);
|
|
|
794
786
|
this.authPolicyResources.add(`${typeName}/${fieldName}`);
|
|
795
787
|
}
|
|
796
788
|
}
|
|
797
|
-
addAutoGeneratedHasOneFields(
|
|
798
|
-
|
|
799
|
-
|
|
789
|
+
static addAutoGeneratedHasOneFields(typeDefinitions, fields, def, allowedFields) {
|
|
790
|
+
fields.forEach(field => {
|
|
791
|
+
var _a;
|
|
800
792
|
const modelField = def.fields.find(it => it.name.value === field);
|
|
801
793
|
const directives = (_a = modelField.directives) === null || _a === void 0 ? void 0 : _a.filter(dir => { var _a; return !((_a = dir.arguments) === null || _a === void 0 ? void 0 : _a.some(it => it.name.value === 'fields')) && (dir.name.value === 'hasOne' || dir.name.value === 'belongsTo'); });
|
|
802
|
-
|
|
803
|
-
if (
|
|
794
|
+
directives.forEach(directive => {
|
|
795
|
+
if (directive.name.value === 'hasOne') {
|
|
804
796
|
allowedFields.add((0, graphql_relational_transformer_1.getConnectionAttributeName)(def.name.value, field));
|
|
805
797
|
}
|
|
806
|
-
else if (
|
|
807
|
-
const relatedType =
|
|
798
|
+
else if (directive.name.value === 'belongsTo') {
|
|
799
|
+
const relatedType = typeDefinitions.find(it => {
|
|
808
800
|
var _a;
|
|
809
|
-
return it.name.value === (0, graphql_transformer_common_1.getBaseType)(modelField.type)
|
|
810
|
-
((_a = it.fields) === null || _a === void 0 ? void 0 : _a.some(f => { var _a; return (0, graphql_transformer_common_1.getBaseType)(f.type) === def.name.value && ((_a = f.directives) === null || _a === void 0 ? void 0 : _a.some(d => d.name.value === 'hasOne')); }));
|
|
801
|
+
return it.name.value === (0, graphql_transformer_common_1.getBaseType)(modelField.type)
|
|
802
|
+
&& ((_a = it.fields) === null || _a === void 0 ? void 0 : _a.some(f => { var _a; return (0, graphql_transformer_common_1.getBaseType)(f.type) === def.name.value && ((_a = f.directives) === null || _a === void 0 ? void 0 : _a.some(d => d.name.value === 'hasOne')); }));
|
|
811
803
|
});
|
|
812
804
|
if (relatedType) {
|
|
813
805
|
allowedFields.add((0, graphql_relational_transformer_1.getConnectionAttributeName)(def.name.value, field));
|
|
814
806
|
}
|
|
815
807
|
}
|
|
816
|
-
}
|
|
817
|
-
}
|
|
808
|
+
});
|
|
809
|
+
});
|
|
818
810
|
}
|
|
819
811
|
}
|
|
820
812
|
exports.AuthTransformer = AuthTransformer;
|