Skip to content

Commit

Permalink
fix(graphql): column with complex object could throw null pointer exc…
Browse files Browse the repository at this point in the history
…eption (#1130)

* Pass in undefined (instead of null) so TypeScript uses the default value in the parameter signature

* fix linting, null coalesce to {}

---------

Co-authored-by: Ronald Van Ryswyk <ronald.van.ryswyk@positivecircularity.com>
  • Loading branch information
Harsgalt86 and Ronald Van Ryswyk authored Oct 6, 2023
1 parent 8d6c46f commit f3c85b8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,15 @@ describe('GraphqlService', () => {

expect(removeSpaces(query)).toBe(removeSpaces(expectation));
});

it('should return a query string including a direct reference to a complex object', () => {
const expectation = `firstName, lastName, billing{address{street, zip}}`;
const columns = ['firstName', 'lastName', 'billing', 'billing.address.street', 'billing.address.zip'];

const query = service.buildFilterQuery(columns);

expect(removeSpaces(query)).toBe(removeSpaces(expectation));
});
});

describe('clearFilters method', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql/src/services/graphql.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export class GraphqlService implements BackendService {

const set = (o: any = {}, a: any) => {
const k = a.shift();
o[k] = a.length ? set(o[k], a) : null;
o[k] = a.length ? set(o[k] ?? {}, a) : null;
return o;
};

Expand Down
2 changes: 1 addition & 1 deletion packages/graphql/src/services/graphqlQueryBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* The previous lib can be found here at this Github link:
* https://github.com/codemeasandwich/graphql-query-builder
* his licence is MIT and can be found at
* This licence is MIT and can be found at
* https://github.com/codemeasandwich/graphql-query-builder/blob/master/LICENSE
*/
export default class GraphqlQueryBuilder {
Expand Down

0 comments on commit f3c85b8

Please sign in to comment.