Skip to content

Commit

Permalink
fix: runQuery function now passes global parameters to referenced query
Browse files Browse the repository at this point in the history
  • Loading branch information
csansoon committed May 22, 2024
1 parent 4153668 commit 155f9e0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/lucky-grapes-draw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latitude-data/base-connector": patch
---

Now queries ran through runQuery have access to the request's global parameters
2 changes: 1 addition & 1 deletion packages/connectors/base/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ export abstract class BaseConnector {

const compiledSubQuery = await this._compileQuery({
...context,
request: { queryPath: queryName, params: {} },
request: { queryPath: queryName, params: context.request.params },
queryConfig: {}, // Subquery config does not affect the root query
resolvedParams: [], // Subquery should not have access to parent queries' resolved parameters
})
Expand Down
7 changes: 3 additions & 4 deletions packages/connectors/base/src/supported_methods.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ describe('runQuery function', async () => {
expect(ranQueries[1]!.sql).toBe('($[[1]])($[[1]])($[[1]])')
})

it('does not have access to parent global parameters', async () => {
it('has access to parent global parameters', async () => {
const connector = new MockConnector()

const refQuerySql = "{param('foo')}"
Expand All @@ -393,8 +393,7 @@ describe('runQuery function', async () => {
const mainQuerySql = `{results = runQuery('${refQueryPath}')}`
const queryPath = addFakeQuery(mainQuerySql)

const action = () => connector.run({ queryPath })
const error = await getExpectedError(action, CompileError)
expect(error.code).toBe('function-call-error')
const action = () => connector.run({ queryPath, params: { foo: 'bar' } })
expect(action).not.toThrow()
})
})

0 comments on commit 155f9e0

Please sign in to comment.