Skip to content

Commit

Permalink
lint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sundersc committed Jul 20, 2023
1 parent 3a780c6 commit 9215316
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 43 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ module.exports = {
// Ignore CHANGELOG.md files
'/packages/*/CHANGELOG.md',

'/packages/amplify-graphql-model-transformer/rds-lambda',
'/packages/amplify-graphql-model-transformer/rds-patching-lambda',
'/packages/amplify-graphql-model-transformer/publish-notification-lambda',
'client-test-apps',
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export abstract class DataSourceAdapter {
primaryKey && model.setPrimaryKey(primaryKey.getFields());
indexes.forEach((index) => model.addIndex(index.name, index.getFields()));
return model;
}
}

public useVpc(vpcSchemaInspectorLambda: string, region: string): void {
this.useVPC = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,10 @@ export class MySQLDataSourceAdapter extends DataSourceAdapter {

public async getTablesList(): Promise<string[]> {
const SHOW_TABLES_QUERY = 'SHOW TABLES';
const result = this.useVPC && this.vpcSchemaInspectorLambda
? await invokeSchemaInspectorLambda(this.vpcSchemaInspectorLambda, this.config, SHOW_TABLES_QUERY, this.vpcLambdaRegion)
: (await this.dbBuilder.raw(SHOW_TABLES_QUERY))[0];
const result =
this.useVPC && this.vpcSchemaInspectorLambda
? await invokeSchemaInspectorLambda(this.vpcSchemaInspectorLambda, this.config, SHOW_TABLES_QUERY, this.vpcLambdaRegion)
: (await this.dbBuilder.raw(SHOW_TABLES_QUERY))[0];

const tables: string[] = result.map((row: any) => {
const [firstKey] = Object.keys(row);
Expand Down Expand Up @@ -149,9 +150,10 @@ export class MySQLDataSourceAdapter extends DataSourceAdapter {
// Query INFORMATION_SCHEMA.COLUMNS table and load fields of all the tables from the database
const LOAD_FIELDS_QUERY = `SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '${this.config.database}'`;
this.fields = [];
const columnResult = this.useVPC && this.vpcSchemaInspectorLambda
? await invokeSchemaInspectorLambda(this.vpcSchemaInspectorLambda, this.config, LOAD_FIELDS_QUERY, this.vpcLambdaRegion)
: (await this.dbBuilder.raw(LOAD_FIELDS_QUERY))[0];
const columnResult =
this.useVPC && this.vpcSchemaInspectorLambda
? await invokeSchemaInspectorLambda(this.vpcSchemaInspectorLambda, this.config, LOAD_FIELDS_QUERY, this.vpcLambdaRegion)
: (await this.dbBuilder.raw(LOAD_FIELDS_QUERY))[0];
this.setFields(columnResult);
}

Expand All @@ -172,9 +174,10 @@ export class MySQLDataSourceAdapter extends DataSourceAdapter {
// Query INFORMATION_SCHEMA.STATISTICS table and load indexes of all the tables from the database
const LOAD_INDEXES_QUERY = `SELECT * FROM INFORMATION_SCHEMA.STATISTICS WHERE TABLE_SCHEMA = '${this.config.database}'`;
this.indexes = [];
const indexResult = this.useVPC && this.vpcSchemaInspectorLambda
? await invokeSchemaInspectorLambda(this.vpcSchemaInspectorLambda, this.config, LOAD_INDEXES_QUERY, this.vpcLambdaRegion)
: (await this.dbBuilder.raw(LOAD_INDEXES_QUERY))[0];
const indexResult =
this.useVPC && this.vpcSchemaInspectorLambda
? await invokeSchemaInspectorLambda(this.vpcSchemaInspectorLambda, this.config, LOAD_INDEXES_QUERY, this.vpcLambdaRegion)
: (await this.dbBuilder.raw(LOAD_INDEXES_QUERY))[0];
this.setIndexes(indexResult);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
import {
DirectiveWrapper, EnumWrapper,
FieldWrapper, ObjectDefinitionWrapper,
} from '@aws-amplify/graphql-transformer-core';
import { DirectiveWrapper, EnumWrapper, FieldWrapper, ObjectDefinitionWrapper } from '@aws-amplify/graphql-transformer-core';
import { EnumValueDefinitionNode, Kind, print } from 'graphql';
import {
EnumType,
Field,
Index,
Model,
Schema,
} from '../schema-representation';
import { EnumType, Field, Index, Model, Schema } from '../schema-representation';

export const generateGraphQLSchema = (schema: Schema): string => {
const models = schema.getModels();
Expand Down
33 changes: 18 additions & 15 deletions packages/amplify-graphql-schema-generator/src/utils/vpc-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,12 @@ const checkHostInDBClusters = async (hostname: string, region: string): Promise<
};
};

const getSubnetIds = async (subnetGroupName: string, region: string): Promise<{
subnetIds: string[],
vpcId: string,
const getSubnetIds = async (
subnetGroupName: string,
region: string,
): Promise<{
subnetIds: string[];
vpcId: string;
}> => {
const client = new RDSClient({ region });
const command = new DescribeDBSubnetGroupsCommand({
Expand All @@ -135,7 +138,8 @@ const getSubnetIds = async (subnetGroupName: string, region: string): Promise<{
* @param hostname Hostname of the database.
* @param region AWS region.
*/
export const getHostVpc = async (hostname: string, region: string): Promise<VpcConfig | undefined> => (checkHostInDBInstances(hostname, region) ?? checkHostInDBClusters(hostname, region));
export const getHostVpc = async (hostname: string, region: string): Promise<VpcConfig | undefined> =>
checkHostInDBInstances(hostname, region) ?? checkHostInDBClusters(hostname, region);

/**
* Provisions a lambda function to introspect the database schema.
Expand All @@ -151,8 +155,9 @@ export const provisionSchemaInspectorLambda = async (lambdaName: string, vpc: Vp
spinner.start('Provisioning a function to introspect the database schema...');
try {
if (existingLambda) {
const vpcConfigMismatch = existingLambda.VpcConfig?.SecurityGroupIds?.sort().join() !== vpc.securityGroupIds.sort().join()
|| existingLambda.VpcConfig?.SubnetIds?.sort().join() !== vpc.subnetIds.sort().join();
const vpcConfigMismatch =
existingLambda.VpcConfig?.SecurityGroupIds?.sort().join() !== vpc.securityGroupIds.sort().join() ||
existingLambda.VpcConfig?.SubnetIds?.sort().join() !== vpc.subnetIds.sort().join();
if (vpcConfigMismatch) {
await deleteSchemaInspectorLambdaRole(lambdaName, region);
createLambda = true;
Expand Down Expand Up @@ -260,11 +265,7 @@ const createPolicy = async (policyName: string): Promise<Policy | undefined> =>
{
Effect: 'Allow',
Resource: '*',
Action: [
'ec2:CreateNetworkInterface',
'ec2:DescribeNetworkInterfaces',
'ec2:DeleteNetworkInterface',
],
Action: ['ec2:CreateNetworkInterface', 'ec2:DescribeNetworkInterfaces', 'ec2:DeleteNetworkInterface'],
},
],
}),
Expand Down Expand Up @@ -332,10 +333,12 @@ export const invokeSchemaInspectorLambda = async (funcName, dbConfig, query, reg
const encoder = new TextEncoder();
const command = new InvokeCommand({
FunctionName: funcName,
Payload: encoder.encode(JSON.stringify({
config: dbConfig,
query,
})),
Payload: encoder.encode(
JSON.stringify({
config: dbConfig,
query,
}),
),
LogType: LogType.Tail,
});

Expand Down
6 changes: 2 additions & 4 deletions packages/amplify-graphql-schema-generator/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
"strict": false,
"composite": false,
"allowJs": true,
"moduleResolution": "node",
"moduleResolution": "node"
},
"references": [
{"path": "../amplify-graphql-transformer-core"},
]
"references": [{ "path": "../amplify-graphql-transformer-core" }]
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ export const establishDBConnection = (config: any): any => {
},
debug: false,
});
}
catch(err) {
} catch (err) {
console.log(err);
throw err;
}
}
};

0 comments on commit 9215316

Please sign in to comment.