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 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
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,4 @@ function resolveGraphDBQuery(query) {
}


module.exports = { resolveGraphDBQueryFromAppSyncEvent, resolveGraphDBQueryFromApolloQueryEvent, resolveGraphDBQuery, refactorGremlinqueryOutput };
export { resolveGraphDBQueryFromAppSyncEvent, resolveGraphDBQueryFromApolloQueryEvent, resolveGraphDBQuery, refactorGremlinqueryOutput };
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
11 changes: 5 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-11-23T01:16:20.126Z

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,4 @@ function resolveGraphDBQuery(query) {
}


module.exports = { resolveGraphDBQueryFromAppSyncEvent, resolveGraphDBQueryFromApolloQueryEvent, resolveGraphDBQuery, refactorGremlinqueryOutput };
export { resolveGraphDBQueryFromAppSyncEvent, resolveGraphDBQueryFromApolloQueryEvent, 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-11-23T01:16:20.126Z

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,4 @@ function resolveGraphDBQuery(query) {
}


module.exports = { resolveGraphDBQueryFromAppSyncEvent, resolveGraphDBQueryFromApolloQueryEvent, resolveGraphDBQuery, refactorGremlinqueryOutput };
export { resolveGraphDBQueryFromAppSyncEvent, resolveGraphDBQueryFromApolloQueryEvent, 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"]
}
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-11-21T20:36:37.948Z

const schemaDataModelJSON = `{
"kind": "Document",
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,4 @@ function resolveGraphDBQuery(query) {
}


module.exports = { resolveGraphDBQueryFromAppSyncEvent, resolveGraphDBQueryFromApolloQueryEvent, resolveGraphDBQuery, refactorGremlinqueryOutput };
export { resolveGraphDBQueryFromAppSyncEvent, resolveGraphDBQueryFromApolloQueryEvent, resolveGraphDBQuery, refactorGremlinqueryOutput };
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
21 changes: 16 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,21 @@ 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(JSON.stringify(data, null, 2)).toBe(JSON.stringify(query.result, null, 2));
sophiadt marked this conversation as resolved.
Show resolved Hide resolved
}
else if (Object.keys(query.result).length === 1 && Array.isArray(Object.values(query.result)[0])) { // if ONLY single array of objects
expect(data.airportRoutesOut).toEqual(expect.arrayContaining(query.result.airportRoutesOut));
sophiadt marked this conversation as resolved.
Show resolved Hide resolved
}
else { // if objects or array + objects
expect(data).toEqual(query.result);
expect(data).toEqual(expect.objectContaining(query.result));
sophiadt marked this conversation as resolved.
Show resolved Hide resolved
}
});
}
}
}


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