diff --git a/client/packages/cli/__tests__/e2e/cli.e2e.test.ts b/client/packages/cli/__tests__/e2e/cli.e2e.test.ts index 822367c00a..1454c894eb 100644 --- a/client/packages/cli/__tests__/e2e/cli.e2e.test.ts +++ b/client/packages/cli/__tests__/e2e/cli.e2e.test.ts @@ -823,6 +823,55 @@ export default _schema; } }); + it('returns singular object for has-one relationships', async () => { + const { appId, adminToken } = await createTempApp(); + const project = await createTestProject({ + appId, + schemaFile: SCHEMA_FILE, + }); + + try { + const pushResult = await runCli(['push', 'schema', '--yes'], { + cwd: project.dir, + env: { + INSTANT_CLI_AUTH_TOKEN: adminToken, + INSTANT_APP_ID: appId, + }, + }); + expect(pushResult.exitCode).toBe(0); + + const postId = randomUUID(); + const commentId = randomUUID(); + await adminTransact(appId, adminToken, [ + ['update', 'posts', postId, { title: 'My Post', body: 'Content' }], + ['update', 'comments', commentId, { text: 'Great post!' }], + ['link', 'posts', postId, { comments: commentId }], + ]); + + // Query from the "has one" side: comments -> post + const result = await runCli( + ['query', '--admin', JSON.stringify({ comments: { post: {} } })], + { + cwd: project.dir, + env: { + INSTANT_CLI_AUTH_TOKEN: adminToken, + INSTANT_APP_ID: appId, + }, + }, + ); + + expect(result.exitCode).toBe(0); + const data = JSON.parse(result.stdout); + expect(data.comments).toHaveLength(1); + + const post = data.comments[0].post; + expect(post).not.toBeInstanceOf(Array); + expect(post.title).toBe('My Post'); + } finally { + await project.cleanup(); + } + }); + it('--as-email runs query as a specific user with perms applied', async () => { const { appId, adminToken } = await createTempApp(); diff --git a/client/packages/cli/src/index.js b/client/packages/cli/src/index.js index 7982bbef39..5ea0f76e8f 100644 --- a/client/packages/cli/src/index.js +++ b/client/packages/cli/src/index.js @@ -758,7 +758,7 @@ async function handleQuery(queryArg, opts) { const res = await fetchJson({ method: 'POST', path: '/admin/query', - body: { query }, + body: { query, 'inference?': true }, headers, debugName: 'Query', errorMessage: 'Failed to run query.', diff --git a/client/packages/version/src/version.ts b/client/packages/version/src/version.ts index 256f7f2d84..7314b12c11 100644 --- a/client/packages/version/src/version.ts +++ b/client/packages/version/src/version.ts @@ -2,6 +2,6 @@ // Update the version here and merge your code to main to // publish a new version of all of the packages to npm. -const version = 'v0.22.165'; +const version = 'v0.22.166'; export { version };