Skip to content

Commit

Permalink
Increased logging to console and introduced file logging to facilitat…
Browse files Browse the repository at this point in the history
…e troubleshooting.

File logging:

-uses pino and pino-pretty logging libraries
-log level is controlled via the --log-verbose option which will output more information to the file (default log level is INFO)
-queries and node/edge data are logged at DEBUG level and not logged by default

Console output:

-added more messages and spinners to indicate what the utility is doing and its progress
-yellow text is used to highlight some information for the user

Other:

-fixed sample TODO schema which had extra data that causes it to fail when used as an import schema
-deleted unused test case input graphql schema files
  • Loading branch information
andreachild committed Oct 16, 2024
1 parent e0656ae commit ee6578b
Show file tree
Hide file tree
Showing 15 changed files with 507 additions and 612 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@
"graphql": "^16.8.1",
"graphql-tag": "2.12.6",
"ora": "7.0.1",
"semver": "7.5.4"
"semver": "7.5.4",
"pino": "9.4.0",
"pino-pretty": "11.2.2"
},
"devDependencies": {
"@jest/test-sequencer": "^29.7.0",
Expand Down
4 changes: 0 additions & 4 deletions samples/todo.schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,4 @@ type Todo {

type Comment {
content: String
}

input Options {
limit: Int
}
31 changes: 14 additions & 17 deletions src/CDKPipelineApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { readFile, writeFile } from 'fs/promises';
import fs from 'fs';
import archiver from 'archiver';
import ora from 'ora';
import { loggerDebug, loggerError, loggerInfo, yellow } from "./logger.js";

let NAME = '';
let REGION = '';
Expand All @@ -34,11 +35,6 @@ let APPSYNC_ATTACH_MUTATION = [];
let SCHEMA_MODEL = null;
let thisOutputFolderPath = './output';


function yellow(text) {
return '\x1b[33m' + text + '\x1b[0m';
}

async function getSchemaFields(typeName) {
/* To be updated as:
SCHEMA_MODEL.definitions
Expand Down Expand Up @@ -69,7 +65,7 @@ async function createDeploymentFile(folderPath, zipFilePath) {
archive.file('./output/output.resolver.graphql.js', { name: 'output.resolver.graphql.js' })
await archive.finalize();
} catch (err) {
console.error('Creating deployment zip file: ' + err);
loggerError('Error creating deployment zip file', err);
}
}

Expand Down Expand Up @@ -107,32 +103,32 @@ async function createAWSpipelineCDK({

if (neptuneType === 'neptune-db') {
try {
if (!quiet) console.log('Get Neptune Cluster Info');
loggerInfo('Getting Neptune Cluster Info');
if (!quiet) spinner = ora('Getting ...').start();
neptuneClusterInfo = await getNeptuneClusterDbInfoBy(NEPTUNE_DB_NAME, REGION);
if (!quiet) spinner.succeed('Got Neptune Cluster Info');
if (isNeptuneIAMAuth) {
if (!neptuneClusterInfo.isIAMauth) {
console.error("The Neptune database authentication is set to VPC.");
console.error("Remove the --output-aws-pipeline-cdk-neptune-IAM option.");
loggerError("The Neptune database authentication is set to VPC.");
loggerError("Remove the --output-aws-pipeline-cdk-neptune-IAM option.");
process.exit(1);
}
} else {
if (neptuneClusterInfo.isIAMauth) {
console.error("The Neptune database authentication is set to IAM.");
console.error("Add the --output-aws-pipeline-cdk-neptune-IAM option.");
loggerError("The Neptune database authentication is set to IAM.");
loggerError("Add the --output-aws-pipeline-cdk-neptune-IAM option.");
process.exit(1);
} else {
if (!quiet) console.log(`Subnet Group: ` + yellow(neptuneClusterInfo.dbSubnetGroup));
loggerDebug(`Subnet Group: ` + neptuneClusterInfo.dbSubnetGroup, {toConsole: true});
}
}

if (neptuneClusterInfo.version != '') {
const v = neptuneClusterInfo.version;
if (lambdaFilesPath.includes('SDK') == true && //semver.satisfies(v, '>=1.2.1.0') ) {
(v == '1.2.1.0' || v == '1.2.0.2' || v == '1.2.0.1' || v == '1.2.0.0' || v == '1.1.1.0' || v == '1.1.0.0')) {
console.error("Neptune SDK query is supported starting with Neptune versions 1.2.1.0.R5");
console.error("Switch to Neptune HTTPS query with option --output-resolver-query-https");
(v == '1.2.1.0' || v == '1.2.0.2' || v == '1.2.0.1' || v == '1.2.0.0' || v == '1.1.1.0' || v == '1.1.0.0')) {
loggerError("Neptune SDK query is supported starting with Neptune versions 1.2.1.0.R5");
loggerError("Switch to Neptune HTTPS query with option --output-resolver-query-https");
process.exit(1);
}
}
Expand All @@ -143,13 +139,14 @@ async function createAWSpipelineCDK({
NEPTUNE_IAM_POLICY_RESOURCE = neptuneClusterInfo.iamPolicyResource;

} catch (error) {
loggerError('Error getting Neptune Cluster Info', error);
if (!quiet) spinner.fail("Error getting Neptune Cluster Info.");
if (!isNeptuneIAMAuth) {
spinner.clear();
console.error("VPC data is not available to proceed.");
loggerError("VPC data is not available to proceed.");
process.exit(1);
} else {
if (!quiet) console.log("Proceeding without getting Neptune Cluster info.");
loggerInfo("Proceeding without getting Neptune Cluster info.", {toConsole: true});
}
}
}
Expand Down
Loading

0 comments on commit ee6578b

Please sign in to comment.