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

Change lambda template to use ECMAScripts modules #68

Merged
merged 1 commit into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
19 changes: 8 additions & 11 deletions templates/JSResolverOCHTTPSTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ express or implied. See the License for the specific language governing
permissions and limitations under the License.
*/

const { astFromValue, buildASTSchema, typeFromAST } = require('graphql');
const gql = require('graphql-tag'); // GraphQL library to parse the GraphQL query
import { astFromValue, buildASTSchema, typeFromAST } from 'graphql';
import { gql } from 'graphql-tag'; // GraphQL library to parse the GraphQL query

const useCallSubquery = false;

Expand All @@ -24,7 +24,7 @@ const schemaDataModel = JSON.parse(schemaDataModelJSON);
const schema = buildASTSchema(schemaDataModel, { assumeValidSDL: true });


function resolveGraphDBQueryFromAppSyncEvent(event) {
export function resolveGraphDBQueryFromAppSyncEvent(event) {
const fieldDef = getFieldDef(event.field);

const args = [];
Expand Down Expand Up @@ -67,9 +67,9 @@ function resolveGraphDBQueryFromAppSyncEvent(event) {
const graphQuery = resolveGraphDBQuery(obj);
return graphQuery;
}


function resolveGraphDBQueryFromApolloQueryEvent(event) {
export function resolveGraphDBQueryFromApolloQueryEvent(event) {
// TODO
}

Expand Down Expand Up @@ -977,7 +977,7 @@ function gremlinElementToJson(o, fieldsAlias) {
}


function refactorGremlinqueryOutput(queryResult, fieldsAlias) {
export function refactorGremlinqueryOutput(queryResult, fieldsAlias) {

//const r = JSON.parse(queryResult).result.data;
const r = queryResult;
Expand Down Expand Up @@ -1082,7 +1082,7 @@ function parseQueryInput(queryObjOrStr) {
* @param {(Object|string)} queryObjOrStr the GraphQL document containing an operation to resolve
* @returns {string}
*/
function resolveGraphDBQuery(queryObjOrStr) {
export function resolveGraphDBQuery(queryObjOrStr) {
let executeQuery = { query:'', parameters: {}, language: 'opencypher', refactorOutput: null };

const obj = parseQueryInput(queryObjOrStr);
Expand All @@ -1106,6 +1106,3 @@ function resolveGraphDBQuery(queryObjOrStr) {

return executeQuery;
}


module.exports = { resolveGraphDBQueryFromAppSyncEvent, resolveGraphDBQueryFromApolloQueryEvent, resolveGraphDBQuery, refactorGremlinqueryOutput };
1 change: 1 addition & 0 deletions templates/Lambda4AppSyncGraphSDK/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.1.1",
"description": "AWS Lambda function to bridge AppSync to Neptune Analytics",
"main": "index.mjs",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
Expand Down
1 change: 1 addition & 0 deletions templates/Lambda4AppSyncHTTP/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.1.1",
"description": "AWS Lambda function to bridge AppSync to Neptune or Neptune Analytics",
"main": "index.mjs",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
Expand Down
1 change: 1 addition & 0 deletions templates/Lambda4AppSyncSDK/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.1.1",
"description": "AWS Lambda function to bridge AppSync to Neptune",
"main": "index.mjs",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
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.js', './test/TestCases/Case01/queries');
2 changes: 1 addition & 1 deletion test/TestCases/Case01/Case01.04.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { readJSONFile, testResolverQueriesResults } from '../../testLib';

const casetest = readJSONFile('./test/TestCases/Case01/case.json');

await testResolverQueriesResults( './TestCases/Case01/output/output.resolver.graphql.cjs',
await testResolverQueriesResults( './TestCases/Case01/output/output.resolver.graphql.js',
'./test/TestCases/Case01/queries',
casetest.host,
casetest.port);
2 changes: 1 addition & 1 deletion test/TestCases/Case01/Case01.05.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe('AppSync resolver', () => {
let resolverModule;

beforeAll(async () => {
resolverModule = await loadResolver('./TestCases/Case01/output/output.resolver.graphql.cjs');
resolverModule = await loadResolver('./TestCases/Case01/output/output.resolver.graphql.js');
});

test('should resolve queries with a filter', () => {
Expand Down
4 changes: 2 additions & 2 deletions test/TestCases/Case01/case.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
"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.jsresolver.graphql.js",
"--output-folder-path", "./test/TestCases/Case01/output",
"--output-no-lambda-zip"],
"host": "<AIR_ROUTES_DB_HOST>",
"port": "<AIR_ROUTES_DB_PORT>",
"testOutputFilesSize": ["output.resolver.graphql.cjs", "output.resolver.graphql.js", "output.schema.graphql", "output.source.schema.graphql"],
"testOutputFilesSize": ["output.jsresolver.graphql.js", "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,12 +10,12 @@ express or implied. See the License for the specific language governing
permissions and limitations under the License.
*/

const { astFromValue, buildASTSchema, typeFromAST } = require('graphql');
const gql = require('graphql-tag'); // GraphQL library to parse the GraphQL query
import { astFromValue, buildASTSchema, typeFromAST } from 'graphql';
import { gql } from 'graphql-tag'; // GraphQL library to parse the GraphQL query

const useCallSubquery = false;

// 2025-02-04T20:17:38.303Z
// 2025-02-05T01:35:32.969Z

const schemaDataModelJSON = `{
"kind": "Document",
Expand Down Expand Up @@ -3475,7 +3475,7 @@ const schemaDataModel = JSON.parse(schemaDataModelJSON);
const schema = buildASTSchema(schemaDataModel, { assumeValidSDL: true });


function resolveGraphDBQueryFromAppSyncEvent(event) {
export function resolveGraphDBQueryFromAppSyncEvent(event) {
const fieldDef = getFieldDef(event.field);

const args = [];
Expand Down Expand Up @@ -3518,9 +3518,9 @@ function resolveGraphDBQueryFromAppSyncEvent(event) {
const graphQuery = resolveGraphDBQuery(obj);
return graphQuery;
}


function resolveGraphDBQueryFromApolloQueryEvent(event) {
export function resolveGraphDBQueryFromApolloQueryEvent(event) {
// TODO
}

Expand Down Expand Up @@ -4428,7 +4428,7 @@ function gremlinElementToJson(o, fieldsAlias) {
}


function refactorGremlinqueryOutput(queryResult, fieldsAlias) {
export function refactorGremlinqueryOutput(queryResult, fieldsAlias) {

//const r = JSON.parse(queryResult).result.data;
const r = queryResult;
Expand Down Expand Up @@ -4533,7 +4533,7 @@ function parseQueryInput(queryObjOrStr) {
* @param {(Object|string)} queryObjOrStr the GraphQL document containing an operation to resolve
* @returns {string}
*/
function resolveGraphDBQuery(queryObjOrStr) {
export function resolveGraphDBQuery(queryObjOrStr) {
let executeQuery = { query:'', parameters: {}, language: 'opencypher', refactorOutput: null };

const obj = parseQueryInput(queryObjOrStr);
Expand All @@ -4557,6 +4557,3 @@ function resolveGraphDBQuery(queryObjOrStr) {

return executeQuery;
}


module.exports = { resolveGraphDBQueryFromAppSyncEvent, resolveGraphDBQueryFromApolloQueryEvent, resolveGraphDBQuery, refactorGremlinqueryOutput };
21 changes: 9 additions & 12 deletions test/TestCases/Case01/outputReference/output.resolver.graphql.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ express or implied. See the License for the specific language governing
permissions and limitations under the License.
*/

const { astFromValue, buildASTSchema, typeFromAST } = require('graphql');
const gql = require('graphql-tag'); // GraphQL library to parse the GraphQL query
import { astFromValue, buildASTSchema, typeFromAST } from 'graphql';
import { gql } from 'graphql-tag'; // GraphQL library to parse the GraphQL query

const useCallSubquery = false;

// 2025-02-04T20:17:38.302Z
// 2025-02-05T01:35:32.969Z

const schemaDataModelJSON = `{
"kind": "Document",
Expand Down Expand Up @@ -3475,7 +3475,7 @@ const schemaDataModel = JSON.parse(schemaDataModelJSON);
const schema = buildASTSchema(schemaDataModel, { assumeValidSDL: true });


function resolveGraphDBQueryFromAppSyncEvent(event) {
export function resolveGraphDBQueryFromAppSyncEvent(event) {
const fieldDef = getFieldDef(event.field);

const args = [];
Expand Down Expand Up @@ -3518,9 +3518,9 @@ function resolveGraphDBQueryFromAppSyncEvent(event) {
const graphQuery = resolveGraphDBQuery(obj);
return graphQuery;
}


function resolveGraphDBQueryFromApolloQueryEvent(event) {
export function resolveGraphDBQueryFromApolloQueryEvent(event) {
// TODO
}

Expand Down Expand Up @@ -4428,7 +4428,7 @@ function gremlinElementToJson(o, fieldsAlias) {
}


function refactorGremlinqueryOutput(queryResult, fieldsAlias) {
export function refactorGremlinqueryOutput(queryResult, fieldsAlias) {

//const r = JSON.parse(queryResult).result.data;
const r = queryResult;
Expand Down Expand Up @@ -4533,7 +4533,7 @@ function parseQueryInput(queryObjOrStr) {
* @param {(Object|string)} queryObjOrStr the GraphQL document containing an operation to resolve
* @returns {string}
*/
function resolveGraphDBQuery(queryObjOrStr) {
export function resolveGraphDBQuery(queryObjOrStr) {
let executeQuery = { query:'', parameters: {}, language: 'opencypher', refactorOutput: null };

const obj = parseQueryInput(queryObjOrStr);
Expand All @@ -4557,6 +4557,3 @@ function resolveGraphDBQuery(queryObjOrStr) {

return executeQuery;
}


module.exports = { resolveGraphDBQueryFromAppSyncEvent, resolveGraphDBQueryFromApolloQueryEvent, resolveGraphDBQuery, refactorGremlinqueryOutput };
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.jsresolver.graphql.js",
"--output-folder-path", "./test/TestCases/Case02/output",
"--output-no-lambda-zip"],
"host": "<AIR_ROUTES_DB_HOST>",
Expand Down
21 changes: 9 additions & 12 deletions test/TestCases/Case07/outputReference/output.resolver.graphql.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ express or implied. See the License for the specific language governing
permissions and limitations under the License.
*/

const { astFromValue, buildASTSchema, typeFromAST } = require('graphql');
const gql = require('graphql-tag'); // GraphQL library to parse the GraphQL query
import { astFromValue, buildASTSchema, typeFromAST } from 'graphql';
import { gql } from 'graphql-tag'; // GraphQL library to parse the GraphQL query

const useCallSubquery = false;

// 2025-02-04T20:38:45.966Z
// 2025-02-05T01:37:03.182Z

const schemaDataModelJSON = `{
"kind": "Document",
Expand Down Expand Up @@ -3507,7 +3507,7 @@ const schemaDataModel = JSON.parse(schemaDataModelJSON);
const schema = buildASTSchema(schemaDataModel, { assumeValidSDL: true });


function resolveGraphDBQueryFromAppSyncEvent(event) {
export function resolveGraphDBQueryFromAppSyncEvent(event) {
const fieldDef = getFieldDef(event.field);

const args = [];
Expand Down Expand Up @@ -3550,9 +3550,9 @@ function resolveGraphDBQueryFromAppSyncEvent(event) {
const graphQuery = resolveGraphDBQuery(obj);
return graphQuery;
}


function resolveGraphDBQueryFromApolloQueryEvent(event) {
export function resolveGraphDBQueryFromApolloQueryEvent(event) {
// TODO
}

Expand Down Expand Up @@ -4460,7 +4460,7 @@ function gremlinElementToJson(o, fieldsAlias) {
}


function refactorGremlinqueryOutput(queryResult, fieldsAlias) {
export function refactorGremlinqueryOutput(queryResult, fieldsAlias) {

//const r = JSON.parse(queryResult).result.data;
const r = queryResult;
Expand Down Expand Up @@ -4565,7 +4565,7 @@ function parseQueryInput(queryObjOrStr) {
* @param {(Object|string)} queryObjOrStr the GraphQL document containing an operation to resolve
* @returns {string}
*/
function resolveGraphDBQuery(queryObjOrStr) {
export function resolveGraphDBQuery(queryObjOrStr) {
let executeQuery = { query:'', parameters: {}, language: 'opencypher', refactorOutput: null };

const obj = parseQueryInput(queryObjOrStr);
Expand All @@ -4589,6 +4589,3 @@ function resolveGraphDBQuery(queryObjOrStr) {

return executeQuery;
}


module.exports = { resolveGraphDBQueryFromAppSyncEvent, resolveGraphDBQueryFromApolloQueryEvent, resolveGraphDBQuery, refactorGremlinqueryOutput };