Skip to content

Commit 7d3b10a

Browse files
authored
Improved error when selection or query field types cannot be determined (aws#132)
Improved error details when a selection field type cannot be found. Throw error if query return type cannot be found as the return type is required to determine the cypher query.
1 parent 49bf4a5 commit 7d3b10a

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ permissions and limitations under the License.
7373
* Improved API error message for failed requests ([#129](https://github.com/aws/amazon-neptune-for-graphql/pull/129))
7474
* Documented custom query to filter nodes by connected nodes'
7575
properties ([#130](https://github.com/aws/amazon-neptune-for-graphql/pull/130))
76+
* Improved error messaging if query field or selection field types cannot be
77+
determined ([#132](https://github.com/aws/amazon-neptune-for-graphql/pull/132))
7678

7779
### Bug Fixes
7880

src/test/templates/JSResolverOCHTTPS.test.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {schemaParser} from "../../schemaParser.js";
44
import {validatedSchemaModel} from "../../schemaModelValidator.js";
55
import {injectAwsScalarDefinitions} from "../../../templates/util.mjs";
66
import { gql } from "graphql-tag";
7+
import { jest } from "@jest/globals";
78

89
beforeAll(() => {
910
// Initialize resolver
@@ -1524,4 +1525,26 @@ test('should resolve multiple app sync events with updated variable values', ()
15241525
language: 'opencypher',
15251526
refactorOutput: null
15261527
});
1527-
});
1528+
});
1529+
1530+
test('should log detailed error when GraphQL selection set field type cannot be resolved', () => {
1531+
const consoleSpy = jest.spyOn(console, 'log').mockImplementation();
1532+
1533+
try {
1534+
resolveGraphDBQueryFromEvent({
1535+
field: 'getAirport',
1536+
arguments: {},
1537+
selectionSet: gql`{ invalid }`.definitions[0].selectionSet,
1538+
fragments: {}
1539+
});
1540+
} catch (error) {
1541+
// Expected to fail due to unhandled type
1542+
console.log(error);
1543+
}
1544+
1545+
expect(consoleSpy).toHaveBeenCalledWith(
1546+
'GraphQL field type not found - field: invalid type: Airport path: getAirport_Airport.'
1547+
);
1548+
1549+
consoleSpy.mockRestore();
1550+
});

templates/JSResolverOCHTTPS.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,11 @@ function getSchemaQueryInfo(name) {
299299

300300
});
301301

302-
if (r.returnType == '') {
303-
console.error('GraphQL query not found.');
304-
302+
if (!r.returnType) {
303+
// if we ended up here it means there's an unhandled field type
304+
const message = `GraphQL query return type not found for ${name}`;
305+
console.error(message);
306+
throw new Error(message);
305307
}
306308

307309
return r;
@@ -449,8 +451,10 @@ function getSchemaFieldInfo(typeName, fieldName, pathName) {
449451
}
450452
});
451453

452-
if (r.type == '') {
453-
console.error('GraphQL field not found.');
454+
if (!r.type) {
455+
// not throwing error here as the type is not currently used to determine the cypher query
456+
// but logging for troubleshooting purposes
457+
console.log(`GraphQL field type not found - field: ${fieldName} type: ${typeName} path: ${pathName}.`);
454458
}
455459

456460
return r;

0 commit comments

Comments
 (0)