Skip to content

Commit

Permalink
FAI-9931: Better error message for Invalid GraphQL type (#234)
Browse files Browse the repository at this point in the history
  • Loading branch information
ted-faros committed Mar 1, 2024
1 parent 18f7ed0 commit 7b6c4a8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/graphql/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -754,10 +754,13 @@ export function flattenV2(
enter(node): boolean | void {
const name = node.alias?.value ?? node.name.value;
fieldPath.push(name);
const type = typeInfo.getType();
if (!rootPath.length) {
rootPath.push(...fieldPath);
if (!type) {
throw new VError('invalid type \'%s\'', name);
}
}
const type = typeInfo.getType();
if (isListType(type)) {
const listPath = fieldPath.join('.');
listPaths.push(listPath);
Expand Down
6 changes: 6 additions & 0 deletions test/graphql.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,12 @@ describe('graphql', () => {
expect(await toArray(flattenedNodes)).toMatchSnapshot();
});

test('flatten nodes V2 with invalid type', () => {
expect(() => sut.flattenV2('{foo_Bar{id}}', graphSchemaV2)).toThrow(
'invalid type \'foo_Bar\''
);
});

test('paginated relay v2 query', async () => {
const query = await loadQueryFile('commits-v2.gql');
const expectedQuery = await loadQueryFile('paginated-commits-v2.gql');
Expand Down

0 comments on commit 7b6c4a8

Please sign in to comment.