Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release Commit #759

Merged
merged 6 commits into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export class AuthTransformer extends TransformerAuthBase implements TransformerA
if (context.metadata.has('joinTypeList')) {
isJoinType = context.metadata.get<Array<string>>('joinTypeList')!.includes(typeName);
}
this.rules = getAuthDirectiveRules(new DirectiveWrapper(directive), context.featureFlags);
this.rules = getAuthDirectiveRules(new DirectiveWrapper(directive));

// validate rules
validateRules(this.rules, this.configuredAuthProviders, def.name.value);
Expand All @@ -187,7 +187,7 @@ export class AuthTransformer extends TransformerAuthBase implements TransformerA
this.addTypeToResourceReferences(def.name.value, this.rules);
// turn rules into roles and add into acm and roleMap
this.convertRulesToRoles(acm, this.rules, isJoinType, undefined, undefined, context);
this.modelDirectiveConfig.set(typeName, getModelConfig(modelDirective, typeName, context.featureFlags, context.isProjectUsingDataStore()));
this.modelDirectiveConfig.set(typeName, getModelConfig(modelDirective, typeName, context.isProjectUsingDataStore()));
this.authModelConfig.set(typeName, acm);
};

Expand Down Expand Up @@ -225,8 +225,8 @@ export class AuthTransformer extends TransformerAuthBase implements TransformerA
const modelDirective = parent.directives?.find(dir => dir.name.value === 'model');
const typeName = parent.name.value;
const fieldName = field.name.value;
const rules: AuthRule[] = getAuthDirectiveRules(new DirectiveWrapper(directive), context.featureFlags, true);
validateFieldRules(new DirectiveWrapper(directive), isParentTypeBuiltinType, modelDirective !== undefined, field.name.value, context.featureFlags);
const rules: AuthRule[] = getAuthDirectiveRules(new DirectiveWrapper(directive), true);
validateFieldRules(new DirectiveWrapper(directive), isParentTypeBuiltinType, modelDirective !== undefined, field.name.value);
validateRules(rules, this.configuredAuthProviders, field.name.value);

// regardless if a model directive is used we generate the policy for iam auth
Expand All @@ -239,7 +239,7 @@ export class AuthTransformer extends TransformerAuthBase implements TransformerA
let acm: AccessControlMatrix;
// check if the parent is already in the model config if not add it
if (!this.modelDirectiveConfig.has(typeName)) {
this.modelDirectiveConfig.set(typeName, getModelConfig(modelDirective, typeName, context.featureFlags, context.isProjectUsingDataStore()));
this.modelDirectiveConfig.set(typeName, getModelConfig(modelDirective, typeName, context.isProjectUsingDataStore()));
acm = new AccessControlMatrix({
name: parent.name.value,
operations: MODEL_OPERATIONS,
Expand Down Expand Up @@ -345,7 +345,7 @@ export class AuthTransformer extends TransformerAuthBase implements TransformerA
// check if searchable if included in the typeName
if (searchableDirective) {
// protect search query
const config = getSearchableConfig(searchableDirective, modelName, context.featureFlags);
const config = getSearchableConfig(searchableDirective, modelName);
this.protectSearchResolver(context, def, context.output.getQueryTypeName()!, config.queries.search, acm);
}
// get fields specified in the schema
Expand Down Expand Up @@ -515,7 +515,7 @@ export class AuthTransformer extends TransformerAuthBase implements TransformerA
}
// @searchable
if (searchableDirective) {
const config = getSearchableConfig(searchableDirective, def.name.value, ctx.featureFlags);
const config = getSearchableConfig(searchableDirective, def.name.value);
addServiceDirective(ctx.output.getQueryTypeName(), 'search', config.queries.search);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DirectiveWrapper, InvalidDirectiveError } from '@aws-amplify/graphql-transformer-core';
import { AppSyncAuthMode, FeatureFlagProvider, TransformerContextProvider } from '@aws-amplify/graphql-transformer-interfaces';
import { AppSyncAuthMode, TransformerContextProvider } from '@aws-amplify/graphql-transformer-interfaces';
import { Stack } from '@aws-cdk/core';
import { ObjectTypeDefinitionNode } from 'graphql';
import { MODEL_OPERATIONS, READ_MODEL_OPERATIONS } from './constants';
Expand Down Expand Up @@ -35,7 +35,7 @@ export const splitRoles = (roles: Array<RoleDefinition>): RolesByProvider => ({
/**
* returns @auth directive rules
*/
export const getAuthDirectiveRules = (authDir: DirectiveWrapper, featureFlags: FeatureFlagProvider, isField = false): AuthRule[] => {
export const getAuthDirectiveRules = (authDir: DirectiveWrapper, isField = false): AuthRule[] => {
const splitReadOperation = (rule: AuthRule): void => {
const operations: (ModelOperation | 'read')[] = rule.operations ?? [];
const indexOfRead = operations.indexOf('read', 0);
Expand All @@ -51,7 +51,7 @@ export const getAuthDirectiveRules = (authDir: DirectiveWrapper, featureFlags: F
}
};

const { rules } = authDir.getArguments<{ rules: Array<AuthRule> }>({ rules: [] }, featureFlags);
const { rules } = authDir.getArguments<{ rules: Array<AuthRule> }>({ rules: [] });
rules.forEach(rule => {
const operations: (ModelOperation | 'read')[] = rule.operations ?? MODEL_OPERATIONS;

Expand Down
17 changes: 8 additions & 9 deletions packages/amplify-graphql-auth-transformer/src/utils/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
MutationFieldType,
TransformerTransformSchemaStepContextProvider,
TransformerContextProvider,
FeatureFlagProvider,
} from '@aws-amplify/graphql-transformer-interfaces';
import {
ObjectTypeDefinitionNode, FieldDefinitionNode, DirectiveNode, NamedTypeNode,
Expand Down Expand Up @@ -43,7 +42,7 @@ export const fieldIsList = (fields: ReadonlyArray<FieldDefinitionNode>, fieldNam
/**
* getModelConfig
*/
export const getModelConfig = (directive: DirectiveNode, typeName: string, featureFlags: FeatureFlagProvider, isDataStoreEnabled = false): ModelDirectiveConfiguration => {
export const getModelConfig = (directive: DirectiveNode, typeName: string, isDataStoreEnabled = false): ModelDirectiveConfiguration => {
const directiveWrapped: DirectiveWrapper = new DirectiveWrapper(directive);
const options = directiveWrapped.getArguments<ModelDirectiveConfiguration>({
queries: {
Expand All @@ -66,20 +65,20 @@ export const getModelConfig = (directive: DirectiveNode, typeName: string, featu
createdAt: 'createdAt',
updatedAt: 'updatedAt',
},
}, featureFlags);
});
return options;
};

/**
* getSearchableConfig
*/
export const getSearchableConfig = (directive: DirectiveNode, typeName: string, featureFlags: FeatureFlagProvider): SearchableConfig | null => {
export const getSearchableConfig = (directive: DirectiveNode, typeName: string): SearchableConfig | null => {
const directiveWrapped: DirectiveWrapper = new DirectiveWrapper(directive);
const options = directiveWrapped.getArguments<SearchableConfig>({
queries: {
search: graphqlName(`search${plurality(toUpper(typeName), true)}`),
},
}, featureFlags);
});
return options;
};
/*
Expand Down Expand Up @@ -112,7 +111,7 @@ export const getRelationalPrimaryMap = (
const args = directiveWrapped.getArguments({
indexName: undefined,
fields: undefined,
}, ctx.featureFlags);
});
// we only generate a primary map if a index name or field is specified
// if both are undefined then @hasMany will create a new gsi with a new readonly field
// we don't need a primary map since this readonly field is not a auth field
Expand All @@ -136,10 +135,10 @@ export const getRelationalPrimaryMap = (
fields: [
getConnectionAttributeName(ctx.featureFlags, def.name.value, field.name.value, relatedModel.name.value),
...getSortKeyFieldNames(relatedModel).map(
(it) => getSortKeyConnectionAttributeName(def.name.value, field.name.value, it),
),
it => getSortKeyConnectionAttributeName(def.name.value, field.name.value, it),
)
],
}, ctx.featureFlags);
});
const relatedPrimaryFields = getKeyFields(ctx, relatedModel);
// the fields provided by the directive (implicit/explicit) need to match the total amount of fields used for the primary key in the related table
// otherwise the get request is incomplete
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { DirectiveWrapper, InvalidDirectiveError } from '@aws-amplify/graphql-transformer-core';
import { AuthRule, ConfiguredAuthProviders } from './definitions';
import {FeatureFlagProvider} from "@aws-amplify/graphql-transformer-interfaces";

export const validateRuleAuthStrategy = (rule: AuthRule, configuredAuthProviders: ConfiguredAuthProviders) => {
//
Expand Down Expand Up @@ -104,9 +103,8 @@ export const validateFieldRules = (
isParentTypeBuiltinType: boolean,
parentHasModelDirective: boolean,
fieldName: string,
featureFlags: FeatureFlagProvider,
) => {
const rules = authDir.getArguments<{ rules: Array<AuthRule> }>({ rules: [] }, featureFlags).rules;
const rules = authDir.getArguments<{ rules: Array<AuthRule> }>({ rules: [] }).rules;

if (rules.length === 0) {
throw new InvalidDirectiveError(`@auth on ${fieldName} does not have any auth rules.`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,17 +204,10 @@ type Mutation {
deleteTest(input: DeleteTestInput!, condition: ModelTestConditionInput): Test
}

input ModelSubscriptionTestFilterInput {
id: ModelSubscriptionIDInput
stringValue: ModelSubscriptionStringInput
and: [ModelSubscriptionTestFilterInput]
or: [ModelSubscriptionTestFilterInput]
}

type Subscription {
onCreateTest(filter: ModelSubscriptionTestFilterInput): Test @aws_subscribe(mutations: [\\"createTest\\"])
onUpdateTest(filter: ModelSubscriptionTestFilterInput): Test @aws_subscribe(mutations: [\\"updateTest\\"])
onDeleteTest(filter: ModelSubscriptionTestFilterInput): Test @aws_subscribe(mutations: [\\"deleteTest\\"])
onCreateTest: Test @aws_subscribe(mutations: [\\"createTest\\"])
onUpdateTest: Test @aws_subscribe(mutations: [\\"updateTest\\"])
onDeleteTest: Test @aws_subscribe(mutations: [\\"deleteTest\\"])
}

"
Expand Down Expand Up @@ -504,31 +497,10 @@ type Mutation {
deletePost(input: DeletePostInput!, condition: ModelPostConditionInput): Post
}

input ModelSubscriptionPostFilterInput {
id: ModelSubscriptionIDInput
stringValue: ModelSubscriptionStringInput
intVal: ModelSubscriptionIntInput
floatValue: ModelSubscriptionFloatInput
booleanValue: ModelSubscriptionBooleanInput
awsJsonValue: ModelSubscriptionStringInput
awsDateValue: ModelSubscriptionStringInput
awsTimestampValue: ModelSubscriptionIntInput
awsEmailValue: ModelSubscriptionStringInput
awsURLValue: ModelSubscriptionStringInput
awsPhoneValue: ModelSubscriptionStringInput
awsIPAddressValue1: ModelSubscriptionStringInput
awsIPAddressValue2: ModelSubscriptionStringInput
enumValue: ModelSubscriptionStringInput
awsTimeValue: ModelSubscriptionStringInput
awsDateTime: ModelSubscriptionStringInput
and: [ModelSubscriptionPostFilterInput]
or: [ModelSubscriptionPostFilterInput]
}

type Subscription {
onCreatePost(filter: ModelSubscriptionPostFilterInput): Post @aws_subscribe(mutations: [\\"createPost\\"])
onUpdatePost(filter: ModelSubscriptionPostFilterInput): Post @aws_subscribe(mutations: [\\"updatePost\\"])
onDeletePost(filter: ModelSubscriptionPostFilterInput): Post @aws_subscribe(mutations: [\\"deletePost\\"])
onCreatePost: Post @aws_subscribe(mutations: [\\"createPost\\"])
onUpdatePost: Post @aws_subscribe(mutations: [\\"updatePost\\"])
onDeletePost: Post @aws_subscribe(mutations: [\\"deletePost\\"])
}

"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export class DefaultValueTransformer extends TransformerPluginBase {
object: parent as ObjectTypeDefinitionNode,
field: definition,
directive,
} as DefaultValueDirectiveConfiguration, ctx.featureFlags);
} as DefaultValueDirectiveConfiguration);
validate(ctx, config);

if (!this.directiveMap.has(parent.name.value)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class FunctionTransformer extends TransformerPluginBase {
const args = directiveWrapped.getArguments({
resolverTypeName: parent.name.value,
resolverFieldName: definition.name.value,
} as FunctionDirectiveConfiguration, acc.featureFlags);
} as FunctionDirectiveConfiguration);
let resolver = this.resolverGroups.get(definition);

if (resolver === undefined) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export class HttpTransformer extends TransformerPluginBase {
resolverTypeName: parent.name.value,
resolverFieldName: definition.name.value,
supportsBody: false,
} as HttpDirectiveConfiguration, context.featureFlags);
} as HttpDirectiveConfiguration);

if (!VALID_PROTOCOLS_REGEX.test(args.url)) {
throw new TransformerContractError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class IndexTransformer extends TransformerPluginBase {
object: parent as ObjectTypeDefinitionNode,
field: definition,
directive,
} as IndexDirectiveConfiguration, context.featureFlags);
} as IndexDirectiveConfiguration);

/**
* Impute Optional Fields
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class PrimaryKeyTransformer extends TransformerPluginBase {
object: parent as ObjectTypeDefinitionNode,
field: definition,
directive,
} as PrimaryKeyDirectiveConfiguration, context.featureFlags);
} as PrimaryKeyDirectiveConfiguration);

if (!args.sortKeyFields) {
args.sortKeyFields = [];
Expand Down
Loading