-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(orchestrator): support pagination for /instances and /overview (#…
…1313) * feat: support pagination for /instances and /overview * refactor: isolate pagination logics from /v1 endpoints
- Loading branch information
1 parent
df868aa
commit 79d5988
Showing
15 changed files
with
459 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Pagination } from '../types/pagination'; | ||
|
||
export function buildGraphQlQuery(args: { | ||
type: 'ProcessDefinitions' | 'ProcessInstances' | 'Jobs'; | ||
queryBody: string; | ||
whereClause?: string; | ||
pagination?: Pagination; | ||
}): string { | ||
let query = `{${args.type}`; | ||
|
||
if (args.whereClause || args.pagination) { | ||
query += ` (`; | ||
|
||
if (args.whereClause) { | ||
query += `where: {${args.whereClause}}`; | ||
if (args.pagination) { | ||
query += `, `; | ||
} | ||
} | ||
if (args.pagination) { | ||
if (args.pagination.sortField) { | ||
query += `orderBy: {${ | ||
args.pagination.sortField | ||
}: ${args.pagination.order?.toUpperCase()}}, `; | ||
} | ||
query += `pagination: {limit: ${args.pagination.limit} , offset: ${args.pagination.offset}}`; | ||
} | ||
|
||
query += `) `; | ||
} | ||
query += ` {${args.queryBody} } }`; | ||
|
||
return query; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { buildPagination } from './types/pagination'; | ||
|
||
describe('buildPagination()', () => { | ||
it('should build the correct pagination obj when no query parameters are passed', () => { | ||
const mockRequest: any = { | ||
query: {}, | ||
}; | ||
expect(buildPagination(mockRequest)).toEqual({ | ||
limit: 10, | ||
offset: 0, | ||
order: 'ASC', | ||
sortField: undefined, | ||
}); | ||
}); | ||
it('should build the correct pagination obj when partial query parameters are passed', () => { | ||
const mockRequest: any = { | ||
query: { | ||
orderBy: 'lastUpdated', | ||
}, | ||
}; | ||
expect(buildPagination(mockRequest)).toEqual({ | ||
limit: 10, | ||
offset: 0, | ||
order: 'ASC', | ||
sortField: 'lastUpdated', | ||
}); | ||
}); | ||
it('should build the correct pagination obj when all query parameters are passed', () => { | ||
const mockRequest: any = { | ||
query: { | ||
page: 1, | ||
pageSize: 50, | ||
orderBy: 'lastUpdated', | ||
orderDirection: 'DESC', | ||
}, | ||
}; | ||
expect(buildPagination(mockRequest)).toEqual({ | ||
limit: 50, | ||
offset: 1, | ||
order: 'DESC', | ||
sortField: 'lastUpdated', | ||
}); | ||
}); | ||
it('should build the correct pagination obj when non numeric value passed to number fields', () => { | ||
const mockRequest: any = { | ||
query: { | ||
page: 'abc', | ||
pageSize: 'cde', | ||
}, | ||
}; | ||
expect(buildPagination(mockRequest)).toEqual({ | ||
limit: 10, | ||
offset: 0, | ||
order: 'ASC', | ||
sortField: undefined, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { buildGraphQlQuery } from './helpers/queryBuilder'; | ||
import { Pagination } from './types/pagination'; | ||
|
||
describe('GraphQL query builder', () => { | ||
it('should return properly formatted graphQL query when where clause and pagination are present', () => { | ||
const expectedQuery: string = | ||
'{ProcessInstances (where: {processId: {isNull: false}}, orderBy: {lastUpdate: DESC}, pagination: {limit: 5 , offset: 2}) {id, processName, processId, state, start, lastUpdate, end, nodes { id }, variables, parentProcessInstance {id, processName, businessKey} } }'; | ||
const pagination: Pagination = { | ||
offset: 2, | ||
limit: 5, | ||
order: 'DESC', | ||
sortField: 'lastUpdate', | ||
}; | ||
expect( | ||
buildGraphQlQuery({ | ||
type: 'ProcessInstances', | ||
queryBody: | ||
'id, processName, processId, state, start, lastUpdate, end, nodes { id }, variables, parentProcessInstance {id, processName, businessKey}', | ||
whereClause: 'processId: {isNull: false}', | ||
pagination, | ||
}), | ||
).toEqual(expectedQuery); | ||
}); | ||
|
||
it('should return properly formatted graphQL query when where clause is present', () => { | ||
const expectedQuery: string = | ||
'{ProcessInstances (where: {processId: {isNull: false}}) {id, processName, processId, state, start, lastUpdate, end, nodes { id }, variables, parentProcessInstance {id, processName, businessKey} } }'; | ||
expect( | ||
buildGraphQlQuery({ | ||
type: 'ProcessInstances', | ||
queryBody: | ||
'id, processName, processId, state, start, lastUpdate, end, nodes { id }, variables, parentProcessInstance {id, processName, businessKey}', | ||
whereClause: 'processId: {isNull: false}', | ||
}), | ||
).toEqual(expectedQuery); | ||
}); | ||
|
||
it('should return properly formatted graphQL query when where clause is NOT present', () => { | ||
const expectedQuery: string = | ||
'{ProcessInstances {id, processName, processId, state, start, lastUpdate, end, nodes { id }, variables, parentProcessInstance {id, processName, businessKey} } }'; | ||
expect( | ||
buildGraphQlQuery({ | ||
type: 'ProcessInstances', | ||
queryBody: | ||
'id, processName, processId, state, start, lastUpdate, end, nodes { id }, variables, parentProcessInstance {id, processName, businessKey}', | ||
}), | ||
).toEqual(expectedQuery); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.