Skip to content

Commit 92f3514

Browse files
authored
Numeric graphQL query parameter values were inadvertently being set as strings upon conversion to the equivalent open cypher query. Fixed transformFunctionInputParameters which converts the graphQL request fields into a parameters object by converting the field value to a Number if the type is IntValue or FloatValue. (#63)
1 parent 3fd9c84 commit 92f3514

File tree

6 files changed

+61
-15
lines changed

6 files changed

+61
-15
lines changed

templates/JSResolverOCHTTPSTemplate.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const schemaDataModel = JSON.parse(schemaDataModelJSON);
2424
const schema = buildASTSchema(schemaDataModel, { assumeValidSDL: true });
2525

2626

27-
function resolveGraphDBQueryFromAppSyncEvent(event) {
27+
function resolveGraphDBQueryFromAppSyncEvent(event) {
2828
const fieldDef = getFieldDef(event.field);
2929

3030
const args = [];
@@ -67,8 +67,8 @@ function resolveGraphDBQueryFromAppSyncEvent(event) {
6767
const graphQuery = resolveGraphDBQuery(obj);
6868
return graphQuery;
6969
}
70-
71-
70+
71+
7272
function resolveGraphDBQueryFromApolloQueryEvent(event) {
7373
// TODO
7474
}
@@ -749,6 +749,9 @@ function transformFunctionInputParameters(fields, schemaInfo) {
749749
fields.forEach(field => {
750750
if (field.name.value === arg.name) {
751751
let value = field.value.value;
752+
if (field.value.kind === 'IntValue' || field.value.kind === 'FloatValue') {
753+
value = Number(value);
754+
}
752755
if (arg.name === schemaInfo.graphDBIdArgName) {
753756
r.graphIdValue = value
754757
} else if (arg.alias != null) {

test/TestCases/Case01/Case01.05.test.js

+16
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,22 @@ describe('AppSync resolver', () => {
5757
});
5858
});
5959

60+
test('should resolve queries with a filter that contains numeric and string values', () => {
61+
const result = resolve({
62+
field: 'getNodeAirports',
63+
arguments: { filter: { country: 'US', runways: 3 } },
64+
selectionSetGraphQL: '{ city }'
65+
});
66+
67+
expect(result).toEqual({
68+
query: 'MATCH (getNodeAirports_Airport:`airport`{country: $getNodeAirports_Airport_country, runways: $getNodeAirports_Airport_runways})\n' +
69+
'RETURN collect({city: getNodeAirports_Airport.`city`})',
70+
parameters: { getNodeAirports_Airport_country: 'US', getNodeAirports_Airport_runways: 3},
71+
language: 'opencypher',
72+
refactorOutput: null
73+
});
74+
});
75+
6076
function resolve(event) {
6177
return resolverModule.resolveGraphDBQueryFromAppSyncEvent(event);
6278
}

test/TestCases/Case01/outputReference/output.resolver.graphql.cjs

+7-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const gql = require('graphql-tag'); // GraphQL library to parse the GraphQL quer
1515

1616
const useCallSubquery = false;
1717

18-
// 2025-01-31T06:40:58.761Z
18+
// 2025-02-04T20:17:38.303Z
1919

2020
const schemaDataModelJSON = `{
2121
"kind": "Document",
@@ -3475,7 +3475,7 @@ const schemaDataModel = JSON.parse(schemaDataModelJSON);
34753475
const schema = buildASTSchema(schemaDataModel, { assumeValidSDL: true });
34763476

34773477

3478-
function resolveGraphDBQueryFromAppSyncEvent(event) {
3478+
function resolveGraphDBQueryFromAppSyncEvent(event) {
34793479
const fieldDef = getFieldDef(event.field);
34803480

34813481
const args = [];
@@ -3518,8 +3518,8 @@ function resolveGraphDBQueryFromAppSyncEvent(event) {
35183518
const graphQuery = resolveGraphDBQuery(obj);
35193519
return graphQuery;
35203520
}
3521-
3522-
3521+
3522+
35233523
function resolveGraphDBQueryFromApolloQueryEvent(event) {
35243524
// TODO
35253525
}
@@ -4200,6 +4200,9 @@ function transformFunctionInputParameters(fields, schemaInfo) {
42004200
fields.forEach(field => {
42014201
if (field.name.value === arg.name) {
42024202
let value = field.value.value;
4203+
if (field.value.kind === 'IntValue' || field.value.kind === 'FloatValue') {
4204+
value = Number(value);
4205+
}
42034206
if (arg.name === schemaInfo.graphDBIdArgName) {
42044207
r.graphIdValue = value
42054208
} else if (arg.alias != null) {

test/TestCases/Case01/outputReference/output.resolver.graphql.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const gql = require('graphql-tag'); // GraphQL library to parse the GraphQL quer
1515

1616
const useCallSubquery = false;
1717

18-
// 2025-01-31T06:40:58.760Z
18+
// 2025-02-04T20:17:38.302Z
1919

2020
const schemaDataModelJSON = `{
2121
"kind": "Document",
@@ -3475,7 +3475,7 @@ const schemaDataModel = JSON.parse(schemaDataModelJSON);
34753475
const schema = buildASTSchema(schemaDataModel, { assumeValidSDL: true });
34763476

34773477

3478-
function resolveGraphDBQueryFromAppSyncEvent(event) {
3478+
function resolveGraphDBQueryFromAppSyncEvent(event) {
34793479
const fieldDef = getFieldDef(event.field);
34803480

34813481
const args = [];
@@ -3518,8 +3518,8 @@ function resolveGraphDBQueryFromAppSyncEvent(event) {
35183518
const graphQuery = resolveGraphDBQuery(obj);
35193519
return graphQuery;
35203520
}
3521-
3522-
3521+
3522+
35233523
function resolveGraphDBQueryFromApolloQueryEvent(event) {
35243524
// TODO
35253525
}
@@ -4200,6 +4200,9 @@ function transformFunctionInputParameters(fields, schemaInfo) {
42004200
fields.forEach(field => {
42014201
if (field.name.value === arg.name) {
42024202
let value = field.value.value;
4203+
if (field.value.kind === 'IntValue' || field.value.kind === 'FloatValue') {
4204+
value = Number(value);
4205+
}
42034206
if (arg.name === schemaInfo.graphDBIdArgName) {
42044207
r.graphIdValue = value
42054208
} else if (arg.alias != null) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "Filter by parameter with numeric value and return mix of numeric value types",
3+
"description": "",
4+
"graphql": "query MyQuery {\n getNodeAirports(filter: { city: \"Seattle\", runways: 3 }) {\n code\n lat\n lon\n elev\n}\n }",
5+
"parameters": {
6+
"getNodeAirports_Airport_city": "Seattle",
7+
"getNodeAirports_Airport_runways": 3
8+
},
9+
"resolved": "MATCH (getNodeAirports_Airport:`airport`{city: $getNodeAirports_Airport_city, runways: $getNodeAirports_Airport_runways})\nRETURN collect({code: getNodeAirports_Airport.`code`, lat: getNodeAirports_Airport.`lat`, lon: getNodeAirports_Airport.`lon`, elev: getNodeAirports_Airport.`elev`})",
10+
"result": [
11+
{
12+
"code": "SEA",
13+
"elev": 432,
14+
"lon": -122.30899810791,
15+
"lat": 47.4490013122559
16+
}
17+
]
18+
}

test/TestCases/Case07/outputReference/output.resolver.graphql.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const gql = require('graphql-tag'); // GraphQL library to parse the GraphQL quer
1515

1616
const useCallSubquery = false;
1717

18-
// 2025-01-31T06:47:04.494Z
18+
// 2025-02-04T20:38:45.966Z
1919

2020
const schemaDataModelJSON = `{
2121
"kind": "Document",
@@ -3507,7 +3507,7 @@ const schemaDataModel = JSON.parse(schemaDataModelJSON);
35073507
const schema = buildASTSchema(schemaDataModel, { assumeValidSDL: true });
35083508

35093509

3510-
function resolveGraphDBQueryFromAppSyncEvent(event) {
3510+
function resolveGraphDBQueryFromAppSyncEvent(event) {
35113511
const fieldDef = getFieldDef(event.field);
35123512

35133513
const args = [];
@@ -3550,8 +3550,8 @@ function resolveGraphDBQueryFromAppSyncEvent(event) {
35503550
const graphQuery = resolveGraphDBQuery(obj);
35513551
return graphQuery;
35523552
}
3553-
3554-
3553+
3554+
35553555
function resolveGraphDBQueryFromApolloQueryEvent(event) {
35563556
// TODO
35573557
}
@@ -4232,6 +4232,9 @@ function transformFunctionInputParameters(fields, schemaInfo) {
42324232
fields.forEach(field => {
42334233
if (field.name.value === arg.name) {
42344234
let value = field.value.value;
4235+
if (field.value.kind === 'IntValue' || field.value.kind === 'FloatValue') {
4236+
value = Number(value);
4237+
}
42354238
if (arg.name === schemaInfo.graphDBIdArgName) {
42364239
r.graphIdValue = value
42374240
} else if (arg.alias != null) {

0 commit comments

Comments
 (0)