Skip to content

Commit

Permalink
fix: use same none datasource name as resolver manager
Browse files Browse the repository at this point in the history
  • Loading branch information
SwaySway committed Sep 16, 2021
1 parent e9bc4af commit 98687a2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import {
addDirectivesToField,
getSearchableConfig,
getStackForField,
NONE_DS,
} from './utils';
import {
DirectiveNode,
Expand Down Expand Up @@ -481,14 +482,14 @@ Static group authorization should perform as expected.`,
// TODO: move pipeline resolvers created in the api host to the resolver manager
const fieldResolver = ctx.api.host.getResolver(typeName, fieldName) as any;
const fieldAuthExpression = generateAuthExpressionForField(this.configuredAuthProviders, roleDefinitions, []);
if (!ctx.api.host.hasDataSource('NONE')) {
ctx.api.host.addNoneDataSource('NONE');
if (!ctx.api.host.hasDataSource(NONE_DS)) {
ctx.api.host.addNoneDataSource(NONE_DS);
}
const authFunction = ctx.api.host.addAppSyncFunction(
`${toUpper(typeName)}${toUpper(fieldName)}AuthFN`,
MappingTemplate.s3MappingTemplateFromString(fieldAuthExpression, `${typeName}.${fieldName}.auth.req.vtl`),
MappingTemplate.inlineTemplateFromString('$util.toJson({})'),
'NONE',
NONE_DS,
stack,
);
(fieldResolver.pipelineConfig.functions as string[]).unshift(authFunction.functionId);
Expand All @@ -504,15 +505,15 @@ Static group authorization should perform as expected.`,
const fieldAuthExpression = generateAuthExpressionForField(this.configuredAuthProviders, roleDefinitions, def.fields ?? []);
const subsEnabled = hasModelDirective ? this.modelDirectiveConfig.get(typeName)!.subscriptions.level === 'on' : false;
const fieldResponse = generateFieldAuthResponse('Mutation', fieldName, subsEnabled);
if (!ctx.api.host.hasDataSource('NONE')) {
ctx.api.host.addNoneDataSource('NONE');
if (!ctx.api.host.hasDataSource(NONE_DS)) {
ctx.api.host.addNoneDataSource(NONE_DS);
}
ctx.api.host.addResolver(
typeName,
fieldName,
MappingTemplate.s3MappingTemplateFromString(fieldAuthExpression, `${typeName}.${fieldName}.req.vtl`, 'resolver'),
MappingTemplate.s3MappingTemplateFromString(fieldResponse, `${typeName}.${fieldName}.res.vtl`, 'resolver'),
'NONE',
NONE_DS,
undefined,
stack,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ export const IAM_UNAUTH_ROLE_PARAMETER = 'unauthRoleName';
// Admin Roles
export const ADMIN_ROLE = '_Full-access/CognitoIdentityCredentials';
export const MANAGE_ROLE = '_Manage-only/CognitoIdentityCredentials';
// resolver
export const NONE_DS = 'NONE_DS';

0 comments on commit 98687a2

Please sign in to comment.