Skip to content

Commit e487e9c

Browse files
committed
Changed gitignore to use patterns. Removed binary tarball. Changed console error messages to reference neptune-type. Changed logic which determines neptune-type from endpoint to examine the host only.
1 parent b38cbf6 commit e487e9c

8 files changed

+61
-41
lines changed

.gitignore

+2-14
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
1-
output/**
21
package-lock.json
32
.vscode/launch.json
4-
node_modules/**
5-
templates/Lambda4AppSyncHTTP/node_modules/**
6-
templates/Lambda4AppSyncSDK/node_modules/**
7-
templates/Lambda4AppSyncGraphSDK/node_modules/**
3+
**/node_modules/
84
coverage/**
9-
test/node_modules/**
10-
test/TestCases/Case01/output/**
11-
test/TestCases/Case01/output/**
12-
test/TestCases/Case02/output/**
13-
test/TestCases/Case03/output/**
14-
test/TestCases/Case04/output/**
15-
test/TestCases/Case05/output/**
16-
test/TestCases/Case06/output/**
17-
test/TestCases/Case07/output/**
5+
**/output/
186
*.iml

aws-neptune-for-graphql-1.1.0.tgz

-43.3 KB
Binary file not shown.

src/NeptuneSchema.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ import axios from "axios";
1414
import { aws4Interceptor } from "aws4-axios";
1515
import { fromNodeProviderChain } from "@aws-sdk/credential-providers";
1616
import { NeptunedataClient, ExecuteOpenCypherQueryCommand } from "@aws-sdk/client-neptunedata";
17-
import { parseNeptuneDomain, parseNeptuneGraphName } from "./util.js";
17+
import { parseNeptuneDomainFromHost, parseNeptuneGraphName } from "./util.js";
1818
import { ExecuteQueryCommand, GetGraphSummaryCommand, NeptuneGraphClient } from "@aws-sdk/client-neptune-graph";
1919

2020
const NEPTUNE_DB = 'neptune-db';
21+
const NEPTUNE_GRAPH = 'neptune-graph';
2122
const NEPTUNE_GRAPH_PROTOCOL = 'https';
2223
const HTTP_LANGUAGE = 'openCypher';
2324
const NEPTUNE_GRAPH_LANGUAGE = 'OPEN_CYPHER';
@@ -120,7 +121,7 @@ async function queryNeptuneDbSDK(query, params = '{}') {
120121
return response;
121122

122123
} catch (error) {
123-
console.error("Neptune db SDK query request failed: ", error.message);
124+
console.error(NEPTUNE_DB + ' SDK query request failed: ', error.message);
124125
process.exit(1);
125126
}
126127
}
@@ -140,7 +141,7 @@ async function queryNeptuneGraphSDK(query, params = '{}') {
140141
const response = await client.send(command);
141142
return await new Response(response.payload).json();
142143
} catch (error) {
143-
console.error('Neptune graph SDK query request failed:' + JSON.stringify(error));
144+
console.error(NEPTUNE_GRAPH + ' SDK query request failed:' + JSON.stringify(error));
144145
process.exit(1);
145146
}
146147
}
@@ -350,7 +351,7 @@ function getNeptuneGraphClient() {
350351
console.log('Instantiating NeptuneGraphClient')
351352
neptuneGraphClient = new NeptuneGraphClient({
352353
port: PORT,
353-
host: parseNeptuneDomain(HOST),
354+
host: parseNeptuneDomainFromHost(HOST),
354355
region: REGION,
355356
protocol: NEPTUNE_GRAPH_PROTOCOL,
356357
});
@@ -362,28 +363,28 @@ function getNeptuneGraphClient() {
362363
* Get a summary of a neptune analytics graph
363364
*/
364365
async function getNeptuneGraphSummary() {
365-
console.log('Retrieving neptune graph summary')
366+
console.log('Retrieving ' + NEPTUNE_GRAPH + ' summary')
366367
const client = getNeptuneGraphClient();
367368
const command = new GetGraphSummaryCommand({
368369
graphIdentifier: NAME,
369370
mode: 'detailed'
370371
});
371372
const response = await client.send(command);
372-
console.log('Retrieved neptune graph summary')
373+
console.log('Retrieved ' + NEPTUNE_GRAPH + ' summary')
373374
return response.graphSummary;
374375
}
375376

376377
/**
377378
* Get a summary of a neptune db graph
378379
*/
379380
async function getNeptuneDbSummary() {
380-
console.log('Retrieving neptune db summary')
381+
console.log('Retrieving ' + NEPTUNE_DB + ' summary')
381382
let response = await axios.get(`https://${HOST}:${PORT}/propertygraph/statistics/summary`, {
382383
params: {
383384
mode: 'detailed'
384385
}
385386
});
386-
console.log('Retrieved neptune db summary')
387+
console.log('Retrieved ' + NEPTUNE_DB + ' summary')
387388
return response.data.payload.graphSummary;
388389
}
389390

src/main.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ function yellow(text) {
3131
// find global installation dir
3232
import path from 'path';
3333
import { fileURLToPath } from 'url';
34+
import { parseNeptuneDomainFromEndpoint } from "./util.js";
3435
const __filename = fileURLToPath(import.meta.url);
3536
const __dirname = path.dirname(__filename);
3637

@@ -279,9 +280,8 @@ async function main() {
279280
}
280281

281282
// Check if Neptune target is db or graph
282-
if (inputGraphDBSchemaNeptuneEndpoint.includes(NEPTUNE_GRAPH) ||
283-
createUpdatePipelineEndpoint.includes(NEPTUNE_GRAPH) ||
284-
inputCDKpipelineEnpoint.includes(NEPTUNE_GRAPH)) {
283+
const nonEmptyEndpoints = [inputGraphDBSchemaNeptuneEndpoint, createUpdatePipelineEndpoint, inputCDKpipelineEnpoint].filter(endpoint => endpoint !== '');
284+
if (nonEmptyEndpoints.length > 0 && parseNeptuneDomainFromEndpoint(nonEmptyEndpoints[0]).includes(NEPTUNE_GRAPH)) {
285285
neptuneType = NEPTUNE_GRAPH;
286286
// neptune analytics requires IAM
287287
console.log("Detected neptune-graph from input endpoint - setting IAM auth to true as it is required for neptune analytics")
@@ -306,7 +306,7 @@ async function main() {
306306
neptuneRegion = neptuneRegionParts[1];
307307

308308
if (!quiet) console.log('Getting Neptune schema from endpoint: ' + yellow(neptuneHost + ':' + neptunePort));
309-
setGetNeptuneSchemaParameters(neptuneHost, neptunePort, neptuneRegion, true);
309+
setGetNeptuneSchemaParameters(neptuneHost, neptunePort, neptuneRegion, true, neptuneType);
310310
let startTime = performance.now();
311311
inputGraphDBSchema = await getNeptuneSchema(quiet);
312312
let endTime = performance.now();

src/pipelineResources.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ import fs from 'fs';
4747
import archiver from 'archiver';
4848
import ora from 'ora';
4949
import { exit } from "process";
50-
import { parseNeptuneDomain } from "./util.js";
50+
import { parseNeptuneDomainFromHost } from "./util.js";
5151

5252
const NEPTUNE_DB = 'neptune-db';
5353

@@ -343,7 +343,7 @@ async function createLambdaFunction() {
343343
"LOGGING_ENABLED": "false",
344344
"NEPTUNE_DB_NAME": NEPTUNE_DB_NAME,
345345
"NEPTUNE_REGION": REGION,
346-
"NEPTUNE_DOMAIN": parseNeptuneDomain(NEPTUNE_HOST),
346+
"NEPTUNE_DOMAIN": parseNeptuneDomainFromHost(NEPTUNE_HOST),
347347
"NEPTUNE_TYPE": NEPTUNE_TYPE,
348348
},
349349
},

src/test/util.test.js

+17-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
1-
import {parseNeptuneDomain, parseNeptuneGraphName} from '../util.js';
1+
import {parseNeptuneDomainFromEndpoint, parseNeptuneDomainFromHost, parseNeptuneGraphName} from '../util.js';
22

33
test('parse domain from neptune cluster host', () => {
4-
expect(parseNeptuneDomain('db-neptune-abc-def.cluster-xyz.us-west-2.neptune.amazonaws.com')).toBe('neptune.amazonaws.com');
4+
expect(parseNeptuneDomainFromHost('db-neptune-abc-def.cluster-xyz.us-west-2.neptune.amazonaws.com')).toBe('neptune.amazonaws.com');
55
});
66

77
test('parse domain from neptune analytics host', () => {
8-
expect(parseNeptuneDomain('g-abcdef.us-west-2.neptune-graph.amazonaws.com')).toBe('neptune-graph.amazonaws.com');
8+
expect(parseNeptuneDomainFromHost('g-abcdef.us-west-2.neptune-graph.amazonaws.com')).toBe('neptune-graph.amazonaws.com');
99
});
1010

1111
test('parse domain from host without enough parts throws error', () => {
12-
expect(() => parseNeptuneDomain('invalid.com')).toThrow('Cannot parse neptune host invalid.com because it has 2 parts but expected at least 5');
12+
expect(() => parseNeptuneDomainFromHost('invalid.com')).toThrow('Cannot parse neptune host invalid.com because it has 2 part(s) delimited by . but expected at least 5');
13+
});
14+
15+
test('parse domain from neptune cluster endpoint', () => {
16+
expect(parseNeptuneDomainFromEndpoint('db-neptune-abc-def.cluster-xyz.us-west-2.neptune.amazonaws.com:8182')).toBe('neptune.amazonaws.com');
17+
});
18+
19+
test('parse domain from neptune analytics endpoint', () => {
20+
expect(parseNeptuneDomainFromEndpoint('g-abcdef.us-west-2.neptune-graph.amazonaws.com:8182')).toBe('neptune-graph.amazonaws.com');
21+
});
22+
23+
test('parse domain from endpoint without enough parts throws error', () => {
24+
expect(() => parseNeptuneDomainFromEndpoint('g-abcdef.us-west-2.neptune-graph.amazonaws.com')).toThrow('Cannot parse domain from neptune endpoint g-abcdef.us-west-2.neptune-graph.amazonaws.com because it has 1 part(s) delimited by : but expected 2');
1325
});
1426

1527
test('parse name from neptune cluster host', () => {
@@ -21,5 +33,5 @@ test('parse name from neptune analytics host', () => {
2133
});
2234

2335
test('parse name from host without enough parts throws error', () => {
24-
expect(() => parseNeptuneGraphName('invalid.com')).toThrow('Cannot parse neptune host invalid.com because it has 2 parts but expected at least 5');
36+
expect(() => parseNeptuneGraphName('invalid.com')).toThrow('Cannot parse neptune host invalid.com because it has 2 part(s) delimited by . but expected at least 5');
2537
});

src/util.js

+25-6
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,19 @@ permissions and limitations under the License.
1212

1313
const MIN_HOST_PARTS = 5;
1414
const NUM_DOMAIN_PARTS = 3;
15-
const DELIMITER = '.';
15+
const HOST_DELIMITER = '.';
16+
const ENDPOINT_DELIMITER = ':';
1617

1718
/**
1819
* Splits a neptune host into its parts, throwing an Error if there are unexpected number of parts.
1920
*
2021
* @param neptuneHost
2122
*/
2223
function splitHost(neptuneHost) {
23-
let parts = neptuneHost.split(DELIMITER);
24+
let parts = neptuneHost.split(HOST_DELIMITER);
2425
if (parts.length < MIN_HOST_PARTS) {
25-
throw Error('Cannot parse neptune host ' + neptuneHost + ' because it has ' + parts.length + ' parts but expected at least ' + MIN_HOST_PARTS);
26+
throw Error('Cannot parse neptune host ' + neptuneHost + ' because it has ' + parts.length +
27+
' part(s) delimited by ' + HOST_DELIMITER + ' but expected at least ' + MIN_HOST_PARTS);
2628
}
2729
return parts;
2830
}
@@ -35,12 +37,29 @@ function splitHost(neptuneHost) {
3537
*
3638
* @param neptuneHost
3739
*/
38-
function parseNeptuneDomain(neptuneHost) {
40+
function parseNeptuneDomainFromHost(neptuneHost) {
3941
let parts = splitHost(neptuneHost);
4042
// last 3 parts of the host make up the domain
4143
// ie. neptune.amazonaws.com or neptune-graph.amazonaws.com
4244
let domainParts = parts.splice(parts.length - NUM_DOMAIN_PARTS, NUM_DOMAIN_PARTS);
43-
return domainParts.join(DELIMITER);
45+
return domainParts.join(HOST_DELIMITER);
46+
}
47+
48+
/**
49+
* Parses the domain from the given neptune db or neptune analytics endpoint.
50+
*
51+
* Example: g-abcdef.us-west-2.neptune-graph.amazonaws.com:8182 ==> neptune-graph.amazonaws.com
52+
* Example: db-neptune-abc-def.cluster-xyz.us-west-2.neptune.amazonaws.com:8182 ==> neptune.amazonaws.com
53+
*
54+
* @param neptuneEndpoint
55+
*/
56+
function parseNeptuneDomainFromEndpoint(neptuneEndpoint) {
57+
let parts = neptuneEndpoint.split(ENDPOINT_DELIMITER);
58+
if (parts.length !== 2) {
59+
throw Error('Cannot parse domain from neptune endpoint ' + neptuneEndpoint + ' because it has ' +
60+
parts.length + ' part(s) delimited by ' + ENDPOINT_DELIMITER + ' but expected 2');
61+
}
62+
return parseNeptuneDomainFromHost(parts[0]);
4463
}
4564

4665
/**
@@ -57,4 +76,4 @@ function parseNeptuneGraphName(neptuneHost) {
5776
return parts[0];
5877
}
5978

60-
export {parseNeptuneDomain, parseNeptuneGraphName};
79+
export {parseNeptuneDomainFromHost, parseNeptuneDomainFromEndpoint, parseNeptuneGraphName};

templates/CDKTemplate.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const { Stack, Duration, App } = require('aws-cdk-lib');
1414
const lambda = require( 'aws-cdk-lib/aws-lambda');
1515
const iam = require( 'aws-cdk-lib/aws-iam');
1616
const ec2 = require( 'aws-cdk-lib/aws-ec2');
17-
const { parseNeptuneDomain } = require('../src/util.js');
17+
const { parseNeptuneDomainFromHost } = require('../src/util.js');
1818
const { CfnGraphQLApi, CfnApiKey, CfnGraphQLSchema, CfnDataSource, CfnResolver, CfnFunctionConfiguration } = require( 'aws-cdk-lib/aws-appsync');
1919

2020
const NAME = '';
@@ -64,7 +64,7 @@ class AppSyncNeptuneStack extends Stack {
6464
LOGGING_ENABLED: 'false',
6565
NEPTUNE_DB_NAME: NEPTUNE_DB_NAME,
6666
NEPTUNE_REGION: REGION,
67-
NEPTUNE_DOMAIN: parseNeptuneDomain(NEPTUNE_HOST),
67+
NEPTUNE_DOMAIN: parseNeptuneDomainFromHost(NEPTUNE_HOST),
6868
NEPTUNE_TYPE: NEPTUNE_TYPE,
6969
};
7070
if (NEPTUNE_IAM_AUTH) {

0 commit comments

Comments
 (0)