Skip to content

Fix executeQuery default return type #1055

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/core/src/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ class Driver {
* @see {@link resultTransformers} for provided result transformers.
* @see https://github.com/neo4j/neo4j-javascript-driver/discussions/1052
*/
async executeQuery<T> (query: Query, parameters?: any, config: QueryConfig<T> = {}): Promise<T> {
async executeQuery<T = EagerResult> (query: Query, parameters?: any, config: QueryConfig<T> = {}): Promise<T> {
const bookmarkManager = config.bookmarkManager === null ? undefined : (config.bookmarkManager ?? this.queryBookmarkManager)
const resultTransformer = (config.resultTransformer ?? resultTransformers.eagerResultTransformer()) as ResultTransformer<T>
const routingConfig: string = config.routing ?? routing.WRITERS
Expand Down
26 changes: 26 additions & 0 deletions packages/core/test/driver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,32 @@ describe('Driver', () => {
}, query, params)
})

it('should be able to destruct the result in records, keys and summary', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it('should be able to destruct the result in records, keys and summary', async () => {
it('should be able to destructure the result in records, keys and summary', async () => {

const query = 'Query'
const params = {}
const spiedExecute = jest.spyOn(queryExecutor, 'execute')
const expected: EagerResult = {
keys: ['a'],
records: [],
summary: new ResultSummary(query, params, {}, 5.0)
}
spiedExecute.mockResolvedValue(expected)

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const { records, keys, summary } = await driver!.executeQuery(query, params)

expect(records).toEqual(expected.records)
expect(keys).toEqual(expected.keys)
expect(summary).toEqual(expected.summary)
expect(spiedExecute).toBeCalledWith({
resultTransformer: resultTransformers.eagerResultTransformer(),
bookmarkManager: driver?.queryBookmarkManager,
routing: routing.WRITERS,
database: undefined,
impersonatedUser: undefined
}, query, params)
})

it('should be able get type-safe Records', async () => {
interface Person {
name: string
Expand Down
2 changes: 1 addition & 1 deletion packages/neo4j-driver-deno/lib/core/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ class Driver {
* @see {@link resultTransformers} for provided result transformers.
* @see https://github.com/neo4j/neo4j-javascript-driver/discussions/1052
*/
async executeQuery<T> (query: Query, parameters?: any, config: QueryConfig<T> = {}): Promise<T> {
async executeQuery<T = EagerResult> (query: Query, parameters?: any, config: QueryConfig<T> = {}): Promise<T> {
const bookmarkManager = config.bookmarkManager === null ? undefined : (config.bookmarkManager ?? this.queryBookmarkManager)
const resultTransformer = (config.resultTransformer ?? resultTransformers.eagerResultTransformer()) as ResultTransformer<T>
const routingConfig: string = config.routing ?? routing.WRITERS
Expand Down