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

Fix Unit Test Case01.04 #9

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"files": [
"neptune-for-graphql.mjs",
"./templates/CDKTemplate.js",
"./templates/JSResolverOCHTTPSTemplate.js",
sophiadt marked this conversation as resolved.
Show resolved Hide resolved
"./templates/JSResolverOCHTTPSTemplate.mjs",
"./templates/Lambda4AppSyncHTTP/index.mjs",
"./templates/Lambda4AppSyncHTTP/package.json",
"./templates/Lambda4AppSyncSDK/index.mjs",
Expand Down
2 changes: 1 addition & 1 deletion src/resolverJS.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function resolverJS (schemaModel, queryLanguage, queryClient, __dirname) {

if (queryLanguage == 'opencypher') {
try {
code = readFileSync(__dirname + '/../templates/JSResolverOCHTTPSTemplate.js');
code = readFileSync(__dirname + '/../templates/JSResolverOCHTTPSTemplate.mjs');
code = code.toString().replace('TIMESTAMP HERE', (new Date()).toISOString());
code = code.toString().replace('INSERT SCHEMA DATA MODEL HERE', queryDataModelJSON);
} catch (err) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ express or implied. See the License for the specific language governing
permissions and limitations under the License.
*/

const gql = require('graphql-tag'); // GraphQL library to parse the GraphQL query
import gql from 'graphql-tag'; // GraphQL library to parse the GraphQL query

const useCallSubquery = false;

Expand Down Expand Up @@ -1017,7 +1017,6 @@ function resolveGremlinQuery(obj, querySchemaInfo) {
return gremlinQuery;
}


// Function takes the graphql query and output the graphDB query
function resolveGraphDBQuery(query) {
let executeQuery = { query:'', parameters: {}, language: 'opencypher', refactorOutput: null };
Expand Down Expand Up @@ -1048,4 +1047,5 @@ function resolveGraphDBQuery(query) {
}


module.exports = { resolveGraphDBQueryFromAppSyncEvent, resolveGraphDBQueryFromApolloQueryEvent, resolveGraphDBQuery, refactorGremlinqueryOutput };
export default { resolveGraphDBQueryFromAppSyncEvent, resolveGraphDBQueryFromApolloQueryEvent };
sophiadt marked this conversation as resolved.
Show resolved Hide resolved
export { resolveGraphDBQuery, refactorGremlinqueryOutput };
3 changes: 2 additions & 1 deletion templates/Lambda4AppSyncHTTP/index.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import axios from "axios";
import * as rax from 'retry-axios';
import { aws4Interceptor } from "aws4-axios";
import {resolveGraphDBQueryFromAppSyncEvent, refactorGremlinqueryOutput} from './output.resolver.graphql.js';
import pkg from './output.resolver.graphql.js';
const {resolveGraphDBQueryFromAppSyncEvent, refactorGremlinqueryOutput} = pkg;
sophiadt marked this conversation as resolved.
Show resolved Hide resolved

const LOGGING_ENABLED = process.env.LOGGING_ENABLED;

Expand Down
1 change: 1 addition & 0 deletions templates/Lambda4AppSyncHTTP/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
},
"author": "",
"license": "ISC",
"type": "module",
sophiadt marked this conversation as resolved.
Show resolved Hide resolved
"dependencies": {
"aws4-axios": "3.3.0",
"axios": "1.7.4",
Expand Down
3 changes: 2 additions & 1 deletion templates/Lambda4AppSyncSDK/index.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { NeptunedataClient, ExecuteOpenCypherQueryCommand, ExecuteGremlinQueryCommand } from "@aws-sdk/client-neptunedata";
import {resolveGraphDBQueryFromAppSyncEvent, refactorGremlinqueryOutput} from './output.resolver.graphql.js';
import pkg from './output.resolver.graphql.js';
const {resolveGraphDBQueryFromAppSyncEvent, refactorGremlinqueryOutput} = pkg;

const LOGGING_ENABLED = process.env.LOGGING_ENABLED;

Expand Down
1 change: 1 addition & 0 deletions templates/Lambda4AppSyncSDK/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
},
"author": "AWS",
"license": "Apache-2.0",
"type": "module",
"dependencies": {
"@aws-sdk/client-neptunedata": "3.403.0",
"graphql-tag": "2.12.6"
Expand Down
2 changes: 1 addition & 1 deletion test/TestCases/Case01/Case01.03.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ import { jest } from '@jest/globals';
import { testResolverQueries } from '../../testLib';


await testResolverQueries('./TestCases/Case01/output/output.resolver.graphql.cjs', './test/TestCases/Case01/queries');
await testResolverQueries('./TestCases/Case01/output/output.resolver.graphql.mjs', './test/TestCases/Case01/queries');
2 changes: 1 addition & 1 deletion test/TestCases/Case01/case.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"argv":["--quiet",
"--input-schema-file", "./test/TestCases/airports.source.schema.graphql",
"--input-schema-changes-file", "./test/TestCases/Case01/input/changesAirport.json",
"--output-js-resolver-file", "./test/TestCases/Case01/output/output.resolver.graphql.cjs",
"--output-js-resolver-file", "./test/TestCases/Case01/output/output.resolver.graphql.mjs",
"--output-folder-path", "./test/TestCases/Case01/output",
"--output-no-lambda-zip"],
"host": "<AIR_ROUTES_DB_HOST>",
Expand Down
12 changes: 6 additions & 6 deletions test/TestCases/Case01/outputReference/output.resolver.graphql.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ express or implied. See the License for the specific language governing
permissions and limitations under the License.
*/

const gql = require('graphql-tag'); // GraphQL library to parse the GraphQL query
import gql from 'graphql-tag'; // GraphQL library to parse the GraphQL query

const useCallSubquery = false;

// 2024-11-19T00:06:35.400Z
// 2024-12-04T00:38:40.575Z

const schemaDataModelJSON = `{
"kind": "Document",
Expand Down Expand Up @@ -2000,7 +2000,7 @@ const schemaDataModelJSON = `{
},
"value": {
"kind": "StringValue",
"value": "MATCH (:airport{code: '$fromCode'})-[:route]->(this:airport)-[:route]->(:airport{code:'$toCode'})",
"value": "MATCH (:airport{code: '$fromCode'})-[:route]->(this:airport{country:'$country'})-[:route]->(:airport{code:'$toCode'})",
"block": false
}
}
Expand Down Expand Up @@ -3465,7 +3465,7 @@ const schemaDataModelJSON = `{
],
"loc": {
"start": 0,
"end": 4710
"end": 4730
}
}`;

Expand Down Expand Up @@ -4468,7 +4468,6 @@ function resolveGremlinQuery(obj, querySchemaInfo) {
return gremlinQuery;
}


// Function takes the graphql query and output the graphDB query
function resolveGraphDBQuery(query) {
let executeQuery = { query:'', parameters: {}, language: 'opencypher', refactorOutput: null };
Expand Down Expand Up @@ -4499,4 +4498,5 @@ function resolveGraphDBQuery(query) {
}


module.exports = { resolveGraphDBQueryFromAppSyncEvent, resolveGraphDBQueryFromApolloQueryEvent, resolveGraphDBQuery, refactorGremlinqueryOutput };
export default { resolveGraphDBQueryFromAppSyncEvent, resolveGraphDBQueryFromApolloQueryEvent };
export { resolveGraphDBQuery, refactorGremlinqueryOutput };
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ express or implied. See the License for the specific language governing
permissions and limitations under the License.
*/

const gql = require('graphql-tag'); // GraphQL library to parse the GraphQL query
import gql from 'graphql-tag'; // GraphQL library to parse the GraphQL query

const useCallSubquery = false;

// 2024-11-19T00:06:35.400Z
// 2024-12-04T00:38:40.575Z

const schemaDataModelJSON = `{
"kind": "Document",
Expand Down Expand Up @@ -2000,7 +2000,7 @@ const schemaDataModelJSON = `{
},
"value": {
"kind": "StringValue",
"value": "MATCH (:airport{code: '$fromCode'})-[:route]->(this:airport)-[:route]->(:airport{code:'$toCode'})",
"value": "MATCH (:airport{code: '$fromCode'})-[:route]->(this:airport{country:'$country'})-[:route]->(:airport{code:'$toCode'})",
"block": false
}
}
Expand Down Expand Up @@ -3465,7 +3465,7 @@ const schemaDataModelJSON = `{
],
"loc": {
"start": 0,
"end": 4710
"end": 4730
}
}`;

Expand Down Expand Up @@ -4468,7 +4468,6 @@ function resolveGremlinQuery(obj, querySchemaInfo) {
return gremlinQuery;
}


// Function takes the graphql query and output the graphDB query
function resolveGraphDBQuery(query) {
let executeQuery = { query:'', parameters: {}, language: 'opencypher', refactorOutput: null };
Expand Down Expand Up @@ -4499,4 +4498,5 @@ function resolveGraphDBQuery(query) {
}


module.exports = { resolveGraphDBQueryFromAppSyncEvent, resolveGraphDBQueryFromApolloQueryEvent, resolveGraphDBQuery, refactorGremlinqueryOutput };
export default { resolveGraphDBQueryFromAppSyncEvent, resolveGraphDBQueryFromApolloQueryEvent };
export { resolveGraphDBQuery, refactorGremlinqueryOutput };
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ input Options {

type Query {
getAirport(code: String): Airport
getAirportConnection(fromCode: String!, toCode: String!): Airport @cypher(statement: "MATCH (:airport{code: '$fromCode'})-[:route]->(this:airport)-[:route]->(:airport{code:'$toCode'})")
getAirportConnection(fromCode: String!, toCode: String!): Airport @cypher(statement: "MATCH (:airport{code: '$fromCode'})-[:route]->(this:airport{country:'$country'})-[:route]->(:airport{code:'$toCode'})")
getAirportWithGremlin(code: String): Airport @graphQuery(statement: "g.V().has('airport', 'code', '$code').elementMap()")
getContinentsWithGremlin: [Continent] @graphQuery(statement: "g.V().hasLabel('continent').elementMap().fold()")
getCountriesCountGremlin: Int @graphQuery(statement: "g.V().hasLabel('country').count()")
Expand Down
10 changes: 5 additions & 5 deletions test/TestCases/Case01/queries/Query0007.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "graphQuery type",
"description": "Query using a graphQuery returing a type",
"graphql": "query MyQuery {\n getAirportConnection(fromCode: \"SEA\", toCode: \"BLQ\") {\n city\n code\n }\n }\n",
"description": "Query using a graphQuery returning a type",
"graphql": "query MyQuery {\n getAirportConnection(fromCode: \"SEA\", country: \"US\", toCode: \"BLQ\") {\n city\n code\n }\n }\n",
"parameters": {},
"resolved": "MATCH (:airport{code: 'SEA'})-[:route]->(getAirportConnection_Airport:airport)-[:route]->(:airport{code:'BLQ'})\nRETURN {city: getAirportConnection_Airport.`city`, code: getAirportConnection_Airport.`code`} LIMIT 1",
"resolved": "MATCH (:airport{code: 'SEA'})-[:route]->(getAirportConnection_Airport:airport{country:'US'})-[:route]->(:airport{code:'BLQ'})\nRETURN {city: getAirportConnection_Airport.`city`, code: getAirportConnection_Airport.`code`} LIMIT 1",
"result":{
"code": "LHR",
"city": "London"
"code": "PHL",
"city": "Philadelphia"
}
}
2 changes: 1 addition & 1 deletion test/TestCases/Case02/case.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description":"Start from graph db json, from Air Routes db",
"argv":[ "--quiet",
"--input-graphdb-schema-file", "./test/TestCases/Case02/input/airports.graphdb.json",
"--output-js-resolver-file", "./test/TestCases/Case02/output/output.resolver.graphql.cjs",
"--output-js-resolver-file", "./test/TestCases/Case02/output/output.resolver.graphql.mjs",
"--output-folder-path", "./test/TestCases/Case02/output",
"--output-no-lambda-zip"],
"host": "<AIR_ROUTES_DB_HOST>",
Expand Down
2 changes: 1 addition & 1 deletion test/TestCases/Case05/case02.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"--remove-aws-pipeline-name", "AirportsJestTest",
"--output-folder-path", "./test/TestCases/Case05/output"],
"host": "<AIR_ROUTES_DB_HOST>",
"port": "<AIR_ROUTES_DB_HOST>",
"port": "<AIR_ROUTES_DB_PORT>",
"testOutputFilesSize": ["output.resolver.graphql.js", "output.schema.graphql", "output.source.schema.graphql"],
"testOutputFilesContent": ["output.schema.graphql", "output.source.schema.graphql"]
}
12 changes: 6 additions & 6 deletions test/TestCases/Case07/outputReference/output.resolver.graphql.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ express or implied. See the License for the specific language governing
permissions and limitations under the License.
*/

const gql = require('graphql-tag'); // GraphQL library to parse the GraphQL query
import gql from 'graphql-tag'; // GraphQL library to parse the GraphQL query

const useCallSubquery = false;

// 2024-11-19T00:07:26.413Z
// 2024-12-04T00:39:19.017Z

const schemaDataModelJSON = `{
"kind": "Document",
Expand Down Expand Up @@ -1962,7 +1962,7 @@ const schemaDataModelJSON = `{
},
"value": {
"kind": "StringValue",
"value": "MATCH (:airport{code: '$fromCode'})-[:route]->(this:airport)-[:route]->(:airport{code:'$toCode'})",
"value": "MATCH (:airport{code: '$fromCode'})-[:route]->(this:airport{country:'$country'})-[:route]->(:airport{code:'$toCode'})",
"block": false
}
}
Expand Down Expand Up @@ -3497,7 +3497,7 @@ const schemaDataModelJSON = `{
],
"loc": {
"start": 0,
"end": 4915
"end": 4935
}
}`;

Expand Down Expand Up @@ -4500,7 +4500,6 @@ function resolveGremlinQuery(obj, querySchemaInfo) {
return gremlinQuery;
}


// Function takes the graphql query and output the graphDB query
function resolveGraphDBQuery(query) {
let executeQuery = { query:'', parameters: {}, language: 'opencypher', refactorOutput: null };
Expand Down Expand Up @@ -4531,4 +4530,5 @@ function resolveGraphDBQuery(query) {
}


module.exports = { resolveGraphDBQueryFromAppSyncEvent, resolveGraphDBQueryFromApolloQueryEvent, resolveGraphDBQuery, refactorGremlinqueryOutput };
export default { resolveGraphDBQueryFromAppSyncEvent, resolveGraphDBQueryFromApolloQueryEvent };
export { resolveGraphDBQuery, refactorGremlinqueryOutput };
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ input Options {

type Query {
getAirport(code: String): Airport
getAirportConnection(fromCode: String!, toCode: String!): Airport @cypher(statement: "MATCH (:airport{code: '$fromCode'})-[:route]->(this:airport)-[:route]->(:airport{code:'$toCode'})")
getAirportConnection(fromCode: String!, toCode: String!): Airport @cypher(statement: "MATCH (:airport{code: '$fromCode'})-[:route]->(this:airport{country:'$country'})-[:route]->(:airport{code:'$toCode'})")
getAirportWithGremlin(code: String): Airport @graphQuery(statement: "g.V().has('airport', 'code', '$code').elementMap()")
getContinentsWithGremlin: [Continent] @graphQuery(statement: "g.V().hasLabel('continent').elementMap().fold()")
getCountriesCountGremlin: Int @graphQuery(statement: "g.V().hasLabel('country').count()")
Expand Down
2 changes: 1 addition & 1 deletion test/TestCases/airports.source.schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ input Options {

type Query {
getAirport(code: String): Airport
getAirportConnection(fromCode: String!, toCode: String!): Airport @cypher(statement: "MATCH (:airport{code: '$fromCode'})-[:route]->(this:airport)-[:route]->(:airport{code:'$toCode'})")
getAirportConnection(fromCode: String!, toCode: String!): Airport @cypher(statement: "MATCH (:airport{code: '$fromCode'})-[:route]->(this:airport{country:'$country'})-[:route]->(:airport{code:'$toCode'})")
getAirportWithGremlin(code:String): Airport @graphQuery(statement: "g.V().has('airport', 'code', '$code').elementMap()")
getContinentsWithGremlin: [Continent] @graphQuery(statement: "g.V().hasLabel('continent').elementMap().fold()")
getCountriesCountGremlin: Int @graphQuery(statement: "g.V().hasLabel('country').count()")
Expand Down
20 changes: 15 additions & 5 deletions test/testLib.js → test/testLib.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,13 @@ async function testResolverQueriesResults(resolverFile, queriesReferenceFolder,
const query = JSON.parse(fs.readFileSync(queriesReferenceFolder + "/" +queryFile));
if (query.graphql != "") {
const result = resolverModule.resolveGraphDBQuery(query.graphql);

const httpResult = await queryNeptune(query.resolved, result.language, host, port, result.parameters);

let data = null;
if (result.language == 'opencypher')
if (result.language == 'opencypher') {
data = httpResult.results[0][Object.keys(httpResult.results[0])[0]];
}
else {
const input = httpResult.result.data;
data = JSON.parse(resolverModule.refactorGremlinqueryOutput(input, result.fieldsAlias));
Expand All @@ -141,12 +143,20 @@ async function testResolverQueriesResults(resolverFile, queriesReferenceFolder,
if (JSON.stringify(data, null, 2) != JSON.stringify(query.result, null, 2))
console.log(JSON.stringify(data, null, 2));

test(`Resolver Neptune result, ${queryFile}: ${query.name}`, async () => {
expect(JSON.stringify(data, null, 2)).toBe(JSON.stringify(query.result, null, 2));
test(`Resolver Neptune result, ${queryFile}: ${query.name}`, async () => {
if(typeof query.result === 'number') { // if number
expect(data).toBe(query.result);
}
else if (Object.keys(query.result).length === 1 && Array.isArray(Object.values(query.result)[0])) { // if ONLY single array of objects
expect(data[Object.keys(query.result)[0]]).toEqual(expect.arrayContaining(query.result[Object.keys(query.result)[0]]));
}
else { // if objects or array + objects
expect(data).toEqual(query.result);
}
});
}
}
}


export { readJSONFile, checkFileContains, checkOutputFilesSize, checkOutputFilesContent, testResolverQueries, testResolverQueriesResults, checkOutputZipLambdaUsesSdk };
export { readJSONFile, checkFileContains, checkOutputFilesSize, checkOutputFilesContent, testResolverQueries, testResolverQueriesResults, checkOutputZipLambdaUsesSdk };