mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
* type for neo4j and neode * fix build * remove flakyness * wait for neode to install schema * remove flakyness * explain why we wait for a non-promise * refactor context missing change missing change * adjust test setup proper cleanup after test * lint fixes * fix failing test to use new context
50 lines
1.1 KiB
TypeScript
50 lines
1.1 KiB
TypeScript
import { getDriver, getNeode } from '@db/neo4j'
|
|
|
|
import type { Driver } from 'neo4j-driver'
|
|
|
|
export const query =
|
|
(driver: Driver) =>
|
|
async ({ query, variables = {} }: { driver; query: string; variables: object }) => {
|
|
const session = driver.session()
|
|
|
|
const result = session.readTransaction(async (transaction) => {
|
|
const response = await transaction.run(query, variables)
|
|
return response
|
|
})
|
|
|
|
try {
|
|
return await result
|
|
} finally {
|
|
await session.close()
|
|
}
|
|
}
|
|
|
|
export const mutate =
|
|
(driver: Driver) =>
|
|
async ({ query, variables = {} }: { driver; query: string; variables: object }) => {
|
|
const session = driver.session()
|
|
|
|
const result = session.writeTransaction(async (transaction) => {
|
|
const response = await transaction.run(query, variables)
|
|
return response
|
|
})
|
|
|
|
try {
|
|
return await result
|
|
} finally {
|
|
await session.close()
|
|
}
|
|
}
|
|
|
|
export default () => {
|
|
const driver = getDriver()
|
|
const neode = getNeode()
|
|
|
|
return {
|
|
driver,
|
|
neode,
|
|
query: query(driver),
|
|
mutate: mutate(driver),
|
|
}
|
|
}
|