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

Improve string delimiter escaping in schemaDataModelJSON #66

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ module.exports = {
"files": [
".eslintrc.{js,cjs}",
"./src/test/**",
"./templates/**",
"./test/**"
],
"parserOptions": {
"sourceType": "module"
}
}
],
"ignorePatterns": ["**/output/"],
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
},
"scripts": {
"postinstall": "cd templates/Lambda4AppSyncHTTP && npm install && cd ../Lambda4AppSyncSDK && npm install && cd ../Lambda4AppSyncGraphSDK && npm install",
"lint": "eslint neptune-for-graphql.mjs ./src",
"lint": "eslint neptune-for-graphql.mjs ./{src,templates}",
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage --runInBand --detectOpenHandles --config .jest.js",
"test:sdk": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage --runInBand --detectOpenHandles --config .jest.js --testPathPattern=test/TestCases/Case07",
"test:resolver": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage --runInBand --detectOpenHandles --config .jest.js --testPathPattern=test/TestCases/Case01"
Expand Down
3 changes: 2 additions & 1 deletion src/resolverJS.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ import { loggerError } from "./logger.js";

function resolverJS (schemaModel, queryLanguage, queryClient, __dirname) {
let code = '';
const queryDataModelJSON = JSON.stringify(schemaModel, null, 2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @danielfinke, I wanted to ask about the reasoning for dropping the space argument from the call to JSON.stringify(). I think there is some value lost in the legibility of the formatted output.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Cole-Greer this is a caveat of using ' as the delimiter: multi-line strings are not available


if (queryLanguage == 'opencypher') {
try {
code = readFileSync(__dirname + '/../templates/JSResolverOCHTTPSTemplate.js');
code = code.toString().replace('TIMESTAMP HERE', (new Date()).toISOString());

const queryDataModelJSON = JSON.stringify(schemaModel).replaceAll('\'', '\\\'');
code = code.toString().replace('INSERT SCHEMA DATA MODEL HERE', queryDataModelJSON);
} catch (err) {
loggerError('No resolver template found.', err);
Expand Down
2 changes: 1 addition & 1 deletion templates/CDKTemplate.js
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 { Stack, Duration, App } = require('aws-cdk-lib');
const { Stack, Duration } = require('aws-cdk-lib');
const lambda = require( 'aws-cdk-lib/aws-lambda');
const iam = require( 'aws-cdk-lib/aws-iam');
const ec2 = require( 'aws-cdk-lib/aws-ec2');
Expand Down
18 changes: 8 additions & 10 deletions templates/JSResolverOCHTTPSTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const useCallSubquery = false;

// TIMESTAMP HERE

const schemaDataModelJSON = `INSERT SCHEMA DATA MODEL HERE`;
const schemaDataModelJSON = 'INSERT SCHEMA DATA MODEL HERE';

const schemaDataModel = JSON.parse(schemaDataModelJSON);

Expand Down Expand Up @@ -69,6 +69,7 @@ export function resolveGraphDBQueryFromAppSyncEvent(event) {
}


// eslint-disable-next-line no-unused-vars
export function resolveGraphDBQueryFromApolloQueryEvent(event) {
// TODO
}
Expand Down Expand Up @@ -605,7 +606,7 @@ function createTypeFieldStatementAndRecurse(e, fieldSchemaInfo, lastNamePath, la
}


let { queryArguments, where } = getQueryArguments(e.arguments, fieldSchemaInfo);
let { queryArguments } = getQueryArguments(e.arguments, fieldSchemaInfo);
if (queryArguments != '')
queryArguments = '{' + queryArguments + '}';

Expand Down Expand Up @@ -676,7 +677,7 @@ function selectionsRecurse(s, lastNamePath, lastType) {

createTypeFieldStatementAndRecurse(e, fieldSchemaInfo, lastNamePath, lastType)
});
};
}


function finalizeGraphQuery(matchStatements, withStatements, returnString) {
Expand Down Expand Up @@ -984,21 +985,18 @@ export function refactorGremlinqueryOutput(queryResult, fieldsAlias) {

let data = '';
let isScalar = false;
let isOneElement = false;
let isArray = false;

if (r['@value'].length == 1) {
if (r['@value'][0]['@type'] == 'g:Map')
isOneElement = true;
else if (r['@value'][0]['@type'] == 'g:List')
if (r['@value'][0]['@type'] == 'g:List')
isArray = true;
else
else if (r['@value'][0]['@type'] != 'g:Map')
isScalar = true
}

if (isScalar) {
data = r['@value'][0]['@value'];
} else if (isOneElement) {
} else if (!isArray) {
data += gremlinElementToJson(r['@value'][0], fieldsAlias);
} else {
data += '[';
Expand All @@ -1007,7 +1005,7 @@ export function refactorGremlinqueryOutput(queryResult, fieldsAlias) {
try {
data += gremlinElementToJson(e, fieldsAlias);
data +=',\n';
} catch {}
} catch { /* empty */ }
});

data = data.substring(0, data.length - 2);
Expand Down
Loading