Repository navigation
Honor nested relationship filters and pagination #3279
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
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
5155f1c
Fix nested relationship selection filters and pagination
kylebernhardy e31bbdb
Close nested query validation and cancellation gaps
kylebernhardy 0b6739f
Preserve absent foreign keys under zero relationship limits
kylebernhardy 006c9c8
Keep projection-only bracket syntax compatible
kylebernhardy a08662b
Close nested selections when their parent query ends
kylebernhardy 711eaab
Resolve asynchronous nested projection arrays
kylebernhardy f56d77b
Pin permission and nested join review controls
kylebernhardy 96fb3b8
Fix nested selection composition and cancellation
kylebernhardy a3cbfbe
Exercise exact nested relationship documentation examples in CI
kylebernhardy 4456075
Check documentation contract parity with the companion repository
kylebernhardy d3db946
Discriminate nested window and sort guidance contracts
kylebernhardy 6d28dda
test: harden documentation fixture checks and cover nested OR pages
kylebernhardy 0bfccec
test: isolate fixtures and preserve HTTP failures during cleanup
kylebernhardy 8b2f0aa
fix: classify malformed nested operators as client errors
kylebernhardy 76fb612
fix: mark table read transaction helper internal
kylebernhardy 115e382
Merge main into nested relationship constraints
kylebernhardy 7b2778f
Stop pending relationship lookups after selection cancellation
kylebernhardy 87847a3
Merge main while preserving nested relationship query behavior
kylebernhardy 9ad33e1
Trim repeated resource guide introduction to fit merged documentation…
kylebernhardy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,155 @@ | ||
| import { test } from 'node:test'; | ||
| import assert from 'node:assert'; | ||
| import { createServer } from 'node:http'; | ||
| import { | ||
| discardBody, | ||
| githubHeaders, | ||
| peerRevision, | ||
| readGitHubText, | ||
| } from '../../integrationTests/resources/nested-relationship-docs/github-fixture-fetch.mjs'; | ||
|
|
||
| async function withServer(handler, run) { | ||
| const server = createServer(handler); | ||
| await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve)); | ||
| try { | ||
| await run('http://127.0.0.1:' + server.address().port + '/fixture'); | ||
| } finally { | ||
| server.closeAllConnections(); | ||
| await new Promise((resolve, reject) => server.close((error) => (error ? reject(error) : resolve()))); | ||
| } | ||
| } | ||
|
|
||
| test('credentials are attached only to the exact GitHub API origin', () => { | ||
| const token = 'test-token-not-a-credential'; | ||
| assert.strictEqual( | ||
| githubHeaders('https://api.github.com/repos/HarperFast/harper', token).Authorization, | ||
| 'Bearer ' + token | ||
| ); | ||
| for (const url of [ | ||
| 'https://raw.githubusercontent.com/HarperFast/harper/main/file', | ||
| 'http://api.github.com/file', | ||
| 'https://api.github.com.example/file', | ||
| 'http://127.0.0.1/file', | ||
| ]) | ||
| assert.strictEqual(githubHeaders(url, token).Authorization, undefined); | ||
| assert.strictEqual(githubHeaders('https://api.github.com/repos/HarperFast/harper').Authorization, undefined); | ||
| }); | ||
|
|
||
| test('discarding an already errored response body preserves HTTP failure handling', async () => { | ||
| const response = new Response( | ||
| new ReadableStream({ | ||
| start(controller) { | ||
| controller.error(new Error('discarded stream failed')); | ||
| }, | ||
| }), | ||
| { status: 503 } | ||
| ); | ||
| await assert.rejects(response.body.cancel(), /discarded stream failed/); | ||
| await assert.doesNotReject(discardBody(response)); | ||
| }); | ||
|
|
||
| test('companion revisions fail closed for closed-unmerged or malformed peers', () => { | ||
| const sha = 'a'.repeat(40); | ||
| assert.strictEqual(peerRevision({ state: 'open', head: { sha } }), sha); | ||
| assert.strictEqual(peerRevision({ state: 'closed', merged_at: '2026-10-19T00:00:00Z' }), 'main'); | ||
| assert.throws(() => peerRevision({ state: 'closed', head: { sha } }), /closed without merging/); | ||
| assert.throws(() => peerRevision({ state: 'open', head: { sha: 'invalid' } }), /Invalid companion revision/); | ||
| }); | ||
|
|
||
| test('transient HTTP failures retry and return the successful body without leaking a token', async () => { | ||
| for (const status of [408, 429, 500, 503]) { | ||
| let attempts = 0; | ||
| await withServer( | ||
| (request, response) => { | ||
| assert.strictEqual(request.headers.authorization, undefined); | ||
| response.writeHead(++attempts < 3 ? status : 200, { 'Retry-After': '0' }); | ||
| response.end(attempts < 3 ? 'temporary' : 'fixture bytes'); | ||
| }, | ||
| async (url) => { | ||
| assert.strictEqual(await readGitHubText(url, { token: 'not-for-this-origin' }), 'fixture bytes'); | ||
| assert.strictEqual(attempts, 3); | ||
| } | ||
| ); | ||
| } | ||
| }); | ||
|
|
||
| test('network disconnects retry within the same request budget', async () => { | ||
| let attempts = 0; | ||
| await withServer( | ||
| (request, response) => { | ||
| if (++attempts < 3) request.socket.destroy(); | ||
| else response.end('recovered'); | ||
| }, | ||
| async (url) => { | ||
| assert.strictEqual(await readGitHubText(url), 'recovered'); | ||
| assert.strictEqual(attempts, 3); | ||
| } | ||
| ); | ||
| }); | ||
|
|
||
| test('permanent HTTP failures do not retry or expose response bodies', async () => { | ||
| for (const status of [401, 403, 404]) { | ||
| let attempts = 0; | ||
| await withServer( | ||
| (_request, response) => { | ||
| attempts++; | ||
| response.writeHead(status, { 'Retry-After': '0' }); | ||
| response.end('sensitive-response'); | ||
| }, | ||
| async (url) => { | ||
| await assert.rejects(readGitHubText(url, { token: 'sensitive-token' }), (error) => { | ||
| assert(error.message.includes('HTTP ' + status)); | ||
| assert(error.message.includes(url)); | ||
| assert(!/sensitive|Bearer|Authorization/.test(error.message)); | ||
| return true; | ||
| }); | ||
| assert.strictEqual(attempts, 1); | ||
| } | ||
| ); | ||
| } | ||
| }); | ||
|
|
||
| test('transient failures stop after three attempts', async () => { | ||
| let attempts = 0; | ||
| await withServer( | ||
| (_request, response) => { | ||
| attempts++; | ||
| response.writeHead(503, { 'Retry-After': '0' }); | ||
| response.end('unavailable'); | ||
| }, | ||
| async (url) => { | ||
| await assert.rejects(readGitHubText(url), /HTTP 503 after 3 attempt/); | ||
| assert.strictEqual(attempts, 3); | ||
| } | ||
| ); | ||
| }); | ||
|
|
||
| test('Retry-After beyond the comparison wait budget fails rather than retrying early', async () => { | ||
| let attempts = 0; | ||
| await withServer( | ||
| (_request, response) => { | ||
| attempts++; | ||
| response.writeHead(429, { 'Retry-After': '60' }); | ||
| response.end(); | ||
| }, | ||
| async (url) => { | ||
| await assert.rejects(readGitHubText(url), /longer Retry-After/); | ||
| assert.strictEqual(attempts, 1); | ||
| } | ||
| ); | ||
| }); | ||
|
|
||
| test('the shared comparison signal terminates a stalled request without retries', async () => { | ||
| let attempts = 0; | ||
| const controller = new AbortController(); | ||
| await withServer( | ||
| () => { | ||
| attempts++; | ||
| controller.abort(); | ||
| }, | ||
| async (url) => { | ||
| await assert.rejects(readGitHubText(url, { signal: controller.signal }), /network error or timeout/); | ||
| assert.strictEqual(attempts, 1); | ||
| } | ||
| ); | ||
| }); |
13 changes: 13 additions & 0 deletions
13
.github/scripts/nested-relationship-fixture-parity.test.mjs
This file contains hidden or 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,13 @@ | ||
| import { test } from 'node:test'; | ||
| import { fileURLToPath } from 'node:url'; | ||
| import { verifyPeerFixtures } from '../../integrationTests/resources/nested-relationship-docs/github-fixture-fetch.mjs'; | ||
|
|
||
| test('paired documentation fixtures stay synchronized across repositories', { timeout: 35_000 }, async () => { | ||
| await verifyPeerFixtures({ | ||
| localRoot: fileURLToPath(new URL('../../integrationTests/resources/nested-relationship-docs/', import.meta.url)), | ||
| peerRoot: process.env.HARPER_DOCS_FIXTURE_ROOT, | ||
| repository: 'HarperFast/documentation', | ||
| pull: 736, | ||
| peerPath: 'scripts/fixtures/nested-relationship-docs', | ||
| }); | ||
| }); |
This file contains hidden or 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
132 changes: 132 additions & 0 deletions
132
integrationTests/resources/nested-relationship-docs.test.ts
This file contains hidden or 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,132 @@ | ||
| /** | ||
| * Executes the request/response examples in the nested-relationship documentation companion: | ||
| * https://github.com/HarperFast/documentation/pull/736. | ||
| * The offline fixtures in that repo are checked against the published Markdown by docs CI. | ||
| */ | ||
| import { suite, test, before, after } from 'node:test'; | ||
| import assert from 'node:assert'; | ||
| import { readFileSync } from 'node:fs'; | ||
| import { resolve } from 'node:path'; | ||
| import { setTimeout as delay } from 'node:timers/promises'; | ||
| import { | ||
| setupHarperWithFixture, | ||
| teardownHarper, | ||
| sendOperation, | ||
| DEFAULT_ADMIN_USERNAME, | ||
| DEFAULT_ADMIN_PASSWORD, | ||
| type ContextWithHarper, | ||
| } from '@harperfast/integration-testing'; | ||
|
|
||
| const fixture = resolve(import.meta.dirname, 'nested-relationship-docs'); | ||
| const examples = JSON.parse(readFileSync(resolve(fixture, 'examples.json'), 'utf8')); | ||
| suite('documented nested relationship requests and responses', { timeout: 120_000 }, (ctx: ContextWithHarper) => { | ||
| const auth = 'Basic ' + Buffer.from(DEFAULT_ADMIN_USERNAME + ':' + DEFAULT_ADMIN_PASSWORD).toString('base64'); | ||
| async function get(path: string) { | ||
| const response = await fetch(ctx.harper.httpURL + path, { | ||
| headers: { Authorization: auth }, | ||
| signal: AbortSignal.timeout(10_000), | ||
| }); | ||
| const body = await response.json(); | ||
| assert.strictEqual(response.status, 200, JSON.stringify(body)); | ||
| return body; | ||
| } | ||
| async function insert(table: string, records: unknown[]) { | ||
| await sendOperation(ctx.harper, { operation: 'insert', schema: 'data', table, records }); | ||
| } | ||
| before(async () => { | ||
| await setupHarperWithFixture(ctx, fixture, { | ||
| config: { threads: { count: 1 } }, | ||
| env: { HARPER_STORAGE_ENGINE: process.env.HARPER_STORAGE_ENGINE || 'rocksdb' }, | ||
| }); | ||
| const deadline = Date.now() + 30_000; | ||
| let ready = false; | ||
| while (Date.now() < deadline) { | ||
| try { | ||
| await get('/Brand/'); | ||
| ready = true; | ||
| break; | ||
| } catch { | ||
| await delay(50); | ||
| } | ||
| } | ||
| assert(ready, 'Brand route did not become ready'); | ||
| await insert('Brand', examples.brands); | ||
| await insert('Product', examples.products); | ||
| }); | ||
| after(async () => { | ||
| await teardownHarper(ctx); | ||
| }); | ||
| for (const example of examples.cases) | ||
| test(example.key, async () => { | ||
| assert.deepStrictEqual(await get(example.url), example.response); | ||
| }); | ||
| test('the outer limit uses an exclusive end with three eligible parents', async () => { | ||
| assert.deepStrictEqual(await get('/Brand/?sort(id)&limit(1,2)&select(id,)'), [{ id: 43 }]); | ||
| }); | ||
| test('grouped OR preserves both branches before sorting and pagination', async () => { | ||
| const example = examples.cases.find((example: { key: string }) => example.key === 'grouped_or_page'); | ||
| assert(example, 'grouped OR documentation example is missing'); | ||
| const unskipped = await get(example.url.replace('limit(1,2)', 'limit(0,3)')); | ||
| assert.deepStrictEqual( | ||
| unskipped.map((brand: { products: { id: string }[] }) => brand.products.map((product) => product.id)), | ||
| [['p3', 'p1'], ['p4'], ['p6']] | ||
| ); | ||
| const intersection = await get(example.url.replace('|', '&').replace('limit(1,2)', 'limit(0,3)')); | ||
| assert.deepStrictEqual( | ||
| intersection.map((brand: { products: unknown[] }) => brand.products), | ||
| [[], [], []] | ||
| ); | ||
| }); | ||
| test('both exact programmatic snippets produce their documented responses', async () => { | ||
| assert.deepStrictEqual(await get('/DocumentedQueries/'), { | ||
| single: examples.single, | ||
| programmatic: examples.programmatic, | ||
| }); | ||
| }); | ||
| test('repeating the inherited predicate does not change the response', async () => { | ||
| const inherited = examples.cases.find((example: { key: string }) => example.key === 'outer_inherited'); | ||
| assert.deepStrictEqual( | ||
| await get(inherited.url.replace('products[', 'products[price=ge=number:30&')), | ||
| inherited.response | ||
| ); | ||
| }); | ||
| test('the outer page bounds parents independently of child limits', async () => { | ||
| const bounded = examples.cases.find((example: { key: string }) => example.key === 'bounded_parent_page'); | ||
| assert.deepStrictEqual(await get(bounded.url.replace('limit(0,20)', 'limit(0,1)')), [bounded.response[0]]); | ||
| }); | ||
| test('nested sorting permits an unindexed child field', async () => { | ||
| const rows = await get('/Brand/?select(id,products[sort(name)&limit(1)&select(id,)])'); | ||
| assert.deepStrictEqual( | ||
| rows.map((row: { products: { id: string }[] }) => row.products), | ||
| [[{ id: 'p1' }], [{ id: 'p4' }], [{ id: 'p6' }]] | ||
| ); | ||
| }); | ||
|
|
||
| test('the unique child sort key breaks equal-price ties', async () => { | ||
| try { | ||
| await insert('Product', [{ id: 'p0', brandId: 42, name: 'Adapter', price: 35 }]); | ||
| const bounded = examples.cases.find((example: { key: string }) => example.key === 'bounded_parent_page'); | ||
| const rows = await get(bounded.url); | ||
| assert.deepStrictEqual(rows[0].products, [{ id: 'p0', name: 'Adapter', price: 35 }]); | ||
| const descending = await get(bounded.url.replace('sort(price,id)', 'sort(price,-id)')); | ||
| assert.deepStrictEqual(descending[0].products, [{ id: 'p2', name: 'Keyboard', price: 35 }]); | ||
| const window = await get(bounded.url.replace('limit(1)', 'limit(1,2)')); | ||
| assert.deepStrictEqual(window[0].products, [{ id: 'p2', name: 'Keyboard', price: 35 }]); | ||
| } finally { | ||
| await sendOperation(ctx.harper, { operation: 'delete', schema: 'data', table: 'Product', ids: ['p0'] }); | ||
| } | ||
| }); | ||
| test('the unique parent sort key breaks equal-name ties', async () => { | ||
| try { | ||
| await insert('Brand', [{ id: 45, name: 'Acme' }]); | ||
| await insert('Product', [{ id: 'p7', brandId: 45, name: 'Hub', price: 50 }]); | ||
| const bounded = examples.cases.find((example: { key: string }) => example.key === 'bounded_parent_page'); | ||
| const page = bounded.url.replace('limit(0,20)', 'limit(0,1)'); | ||
| assert.strictEqual((await get(page))[0].id, 42); | ||
| assert.strictEqual((await get(page.replace('sort(name,id)', 'sort(name,-id)')))[0].id, 45); | ||
| } finally { | ||
| await sendOperation(ctx.harper, { operation: 'delete', schema: 'data', table: 'Product', ids: ['p7'] }); | ||
| await sendOperation(ctx.harper, { operation: 'delete', schema: 'data', table: 'Brand', ids: [45] }); | ||
| } | ||
| }); | ||
| }); | ||
5 changes: 5 additions & 0 deletions
5
integrationTests/resources/nested-relationship-docs/config.yaml
This file contains hidden or 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,5 @@ | ||
| graphqlSchema: | ||
| files: '*.graphql' | ||
| jsResource: | ||
| files: resources.js | ||
| rest: true |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.