@contember/client-content 2.1.0-rc.2 → 2.1.0-rc.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/development/src/nodes/ContentEntitySelection.cjs +60 -26
- package/dist/development/src/nodes/ContentEntitySelection.cjs.map +1 -1
- package/dist/development/src/nodes/ContentEntitySelection.js +60 -26
- package/dist/development/src/nodes/ContentEntitySelection.js.map +1 -1
- package/dist/production/src/nodes/ContentEntitySelection.cjs +60 -26
- package/dist/production/src/nodes/ContentEntitySelection.cjs.map +1 -1
- package/dist/production/src/nodes/ContentEntitySelection.js +60 -26
- package/dist/production/src/nodes/ContentEntitySelection.js.map +1 -1
- package/dist/types/nodes/ContentEntitySelection.d.ts +6 -5
- package/dist/types/nodes/ContentEntitySelection.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -5
- package/src/nodes/ContentEntitySelection.ts +66 -26
- package/tests/cases/unit/query.test.ts +243 -0
- package/tests/cases/unit/types.test.ts +9 -0
|
@@ -444,6 +444,249 @@ describe('queries', () => {
|
|
|
444
444
|
expect(calls).toHaveLength(1)
|
|
445
445
|
})
|
|
446
446
|
|
|
447
|
+
test('meta after has-many keeps the connection unwrapped', async () => {
|
|
448
|
+
const [client, calls] = createClient({
|
|
449
|
+
author: {
|
|
450
|
+
name: 'John',
|
|
451
|
+
posts: {
|
|
452
|
+
edges: [
|
|
453
|
+
{ node: { publishedAt: '2021-01-01T00:00:00Z' } },
|
|
454
|
+
],
|
|
455
|
+
},
|
|
456
|
+
_meta: {
|
|
457
|
+
name: { readable: true, updatable: false },
|
|
458
|
+
},
|
|
459
|
+
},
|
|
460
|
+
})
|
|
461
|
+
const result = await client.query({
|
|
462
|
+
author: qb.get('Author', { by: { id: '123' } }, it =>
|
|
463
|
+
it
|
|
464
|
+
.$('name')
|
|
465
|
+
.$('posts', {}, it => it.$('publishedAt'))
|
|
466
|
+
.meta('name', ['readable', 'updatable'])),
|
|
467
|
+
})
|
|
468
|
+
expect(result as any).toStrictEqual({
|
|
469
|
+
author: {
|
|
470
|
+
name: 'John',
|
|
471
|
+
posts: [
|
|
472
|
+
{ publishedAt: '2021-01-01T00:00:00Z' },
|
|
473
|
+
],
|
|
474
|
+
_meta: {
|
|
475
|
+
name: { readable: true, updatable: false },
|
|
476
|
+
},
|
|
477
|
+
},
|
|
478
|
+
})
|
|
479
|
+
expect(calls).toHaveLength(1)
|
|
480
|
+
})
|
|
481
|
+
|
|
482
|
+
test('omit after has-many keeps the connection unwrapped', async () => {
|
|
483
|
+
const [client] = createClient({
|
|
484
|
+
author: {
|
|
485
|
+
posts: {
|
|
486
|
+
edges: [
|
|
487
|
+
{ node: { publishedAt: '2021-01-01T00:00:00Z' } },
|
|
488
|
+
],
|
|
489
|
+
},
|
|
490
|
+
},
|
|
491
|
+
})
|
|
492
|
+
const result = await client.query({
|
|
493
|
+
author: qb.get('Author', { by: { id: '123' } }, it =>
|
|
494
|
+
it
|
|
495
|
+
.$('name')
|
|
496
|
+
.$('posts', {}, it => it.$('publishedAt'))
|
|
497
|
+
.omit('name')),
|
|
498
|
+
})
|
|
499
|
+
expect(result as any).toStrictEqual({
|
|
500
|
+
author: {
|
|
501
|
+
posts: [
|
|
502
|
+
{ publishedAt: '2021-01-01T00:00:00Z' },
|
|
503
|
+
],
|
|
504
|
+
},
|
|
505
|
+
})
|
|
506
|
+
})
|
|
507
|
+
|
|
508
|
+
test('omit of has-many drops its transform', async () => {
|
|
509
|
+
const [client, calls] = createClient({
|
|
510
|
+
author: {
|
|
511
|
+
name: 'John',
|
|
512
|
+
},
|
|
513
|
+
})
|
|
514
|
+
const result = await client.query({
|
|
515
|
+
author: qb.get('Author', { by: { id: '123' } }, it =>
|
|
516
|
+
it
|
|
517
|
+
.$('name')
|
|
518
|
+
.$('posts', {}, it => it.$('publishedAt'))
|
|
519
|
+
.omit('posts')),
|
|
520
|
+
})
|
|
521
|
+
expect(result as any).toStrictEqual({
|
|
522
|
+
author: {
|
|
523
|
+
name: 'John',
|
|
524
|
+
},
|
|
525
|
+
})
|
|
526
|
+
expect(calls[0].query).not.toContain('paginatePosts')
|
|
527
|
+
})
|
|
528
|
+
|
|
529
|
+
test('$$ after has-many keeps the connection unwrapped', async () => {
|
|
530
|
+
const [client] = createClient({
|
|
531
|
+
author: {
|
|
532
|
+
name: 'John',
|
|
533
|
+
email: 'foo@localhost',
|
|
534
|
+
posts: {
|
|
535
|
+
edges: [
|
|
536
|
+
{ node: { publishedAt: '2021-01-01T00:00:00Z' } },
|
|
537
|
+
],
|
|
538
|
+
},
|
|
539
|
+
},
|
|
540
|
+
})
|
|
541
|
+
const result = await client.query({
|
|
542
|
+
author: qb.get('Author', { by: { id: '123' } }, it =>
|
|
543
|
+
it
|
|
544
|
+
.$('posts', {}, it => it.$('publishedAt'))
|
|
545
|
+
.$$()),
|
|
546
|
+
})
|
|
547
|
+
expect(result as any).toStrictEqual({
|
|
548
|
+
author: {
|
|
549
|
+
name: 'John',
|
|
550
|
+
email: 'foo@localhost',
|
|
551
|
+
posts: [
|
|
552
|
+
{ publishedAt: '2021-01-01T00:00:00Z' },
|
|
553
|
+
],
|
|
554
|
+
},
|
|
555
|
+
})
|
|
556
|
+
})
|
|
557
|
+
|
|
558
|
+
test('has-one selected twice keeps both nested transforms', async () => {
|
|
559
|
+
const [client] = createClient({
|
|
560
|
+
post: {
|
|
561
|
+
author: {
|
|
562
|
+
name: 'John',
|
|
563
|
+
posts: {
|
|
564
|
+
edges: [
|
|
565
|
+
{ node: { publishedAt: '2021-01-01T00:00:00Z' } },
|
|
566
|
+
],
|
|
567
|
+
},
|
|
568
|
+
},
|
|
569
|
+
},
|
|
570
|
+
})
|
|
571
|
+
const result = await client.query({
|
|
572
|
+
post: qb.get('Post', { by: { id: '123' } }, it =>
|
|
573
|
+
it
|
|
574
|
+
.$('author', {}, it => it.$('posts', {}, it => it.$('publishedAt')))
|
|
575
|
+
.$('author', {}, it =>
|
|
576
|
+
it.$('name').transform(it => ({
|
|
577
|
+
...it,
|
|
578
|
+
label: `by ${it.name}`,
|
|
579
|
+
})))),
|
|
580
|
+
})
|
|
581
|
+
expect(result as any).toStrictEqual({
|
|
582
|
+
post: {
|
|
583
|
+
author: {
|
|
584
|
+
name: 'John',
|
|
585
|
+
label: 'by John',
|
|
586
|
+
posts: [
|
|
587
|
+
{ publishedAt: '2021-01-01T00:00:00Z' },
|
|
588
|
+
],
|
|
589
|
+
},
|
|
590
|
+
},
|
|
591
|
+
})
|
|
592
|
+
})
|
|
593
|
+
|
|
594
|
+
test('transforms around meta and omit are kept', async () => {
|
|
595
|
+
const [client] = createClient({
|
|
596
|
+
author: {
|
|
597
|
+
name: 'John',
|
|
598
|
+
_meta: {
|
|
599
|
+
name: { readable: true },
|
|
600
|
+
},
|
|
601
|
+
},
|
|
602
|
+
})
|
|
603
|
+
const result = await client.query({
|
|
604
|
+
author: qb.get('Author', { by: { id: '123' } }, it =>
|
|
605
|
+
it
|
|
606
|
+
.$('name')
|
|
607
|
+
.$('email')
|
|
608
|
+
.transform(it => ({ ...it, before: true }))
|
|
609
|
+
.meta('name', ['readable'])
|
|
610
|
+
.omit('email')
|
|
611
|
+
.transform(it => ({ ...it, after: true }))),
|
|
612
|
+
})
|
|
613
|
+
expect(result as any).toStrictEqual({
|
|
614
|
+
author: {
|
|
615
|
+
name: 'John',
|
|
616
|
+
_meta: {
|
|
617
|
+
name: { readable: true },
|
|
618
|
+
},
|
|
619
|
+
before: true,
|
|
620
|
+
after: true,
|
|
621
|
+
},
|
|
622
|
+
})
|
|
623
|
+
})
|
|
624
|
+
|
|
625
|
+
test('omit inside a nested has-many keeps the inner connection unwrapped', async () => {
|
|
626
|
+
const [client] = createClient({
|
|
627
|
+
author: {
|
|
628
|
+
posts: {
|
|
629
|
+
edges: [
|
|
630
|
+
{
|
|
631
|
+
node: {
|
|
632
|
+
tags: {
|
|
633
|
+
edges: [
|
|
634
|
+
{ node: { name: 'news' } },
|
|
635
|
+
],
|
|
636
|
+
},
|
|
637
|
+
},
|
|
638
|
+
},
|
|
639
|
+
],
|
|
640
|
+
},
|
|
641
|
+
},
|
|
642
|
+
})
|
|
643
|
+
const result = await client.query({
|
|
644
|
+
author: qb.get('Author', { by: { id: '123' } }, it =>
|
|
645
|
+
it.$('posts', {}, it =>
|
|
646
|
+
it
|
|
647
|
+
.$('publishedAt')
|
|
648
|
+
.$('tags', {}, it => it.$('name'))
|
|
649
|
+
.omit('publishedAt'))),
|
|
650
|
+
})
|
|
651
|
+
expect(result as any).toStrictEqual({
|
|
652
|
+
author: {
|
|
653
|
+
posts: [
|
|
654
|
+
{
|
|
655
|
+
tags: [
|
|
656
|
+
{ name: 'news' },
|
|
657
|
+
],
|
|
658
|
+
},
|
|
659
|
+
],
|
|
660
|
+
},
|
|
661
|
+
})
|
|
662
|
+
})
|
|
663
|
+
|
|
664
|
+
test('omit keeps an aliased has-many unwrapped', async () => {
|
|
665
|
+
const [client] = createClient({
|
|
666
|
+
author: {
|
|
667
|
+
articles: {
|
|
668
|
+
edges: [
|
|
669
|
+
{ node: { publishedAt: '2021-01-01T00:00:00Z' } },
|
|
670
|
+
],
|
|
671
|
+
},
|
|
672
|
+
},
|
|
673
|
+
})
|
|
674
|
+
const result = await client.query({
|
|
675
|
+
author: qb.get('Author', { by: { id: '123' } }, it =>
|
|
676
|
+
it
|
|
677
|
+
.$('name')
|
|
678
|
+
.$('posts', { as: 'articles' }, it => it.$('publishedAt'))
|
|
679
|
+
.omit('name')),
|
|
680
|
+
})
|
|
681
|
+
expect(result as any).toStrictEqual({
|
|
682
|
+
author: {
|
|
683
|
+
articles: [
|
|
684
|
+
{ publishedAt: '2021-01-01T00:00:00Z' },
|
|
685
|
+
],
|
|
686
|
+
},
|
|
687
|
+
})
|
|
688
|
+
})
|
|
689
|
+
|
|
447
690
|
test('omit', async () => {
|
|
448
691
|
const [client, calls] = createClient({
|
|
449
692
|
authors: [
|
|
@@ -3,6 +3,7 @@ import { describe, expect, test } from 'bun:test'
|
|
|
3
3
|
import { ContentClientInput } from '../../../src'
|
|
4
4
|
import { ContemberClientEntities, FragmentOf, FragmentType, PostStatus, queryBuilder } from '../../client'
|
|
5
5
|
import { expectTypeOf } from 'expect-type'
|
|
6
|
+
import { Input, JSONValue, Value } from '@contember/schema'
|
|
6
7
|
|
|
7
8
|
const qb = queryBuilder
|
|
8
9
|
describe('ts types', () => {
|
|
@@ -146,4 +147,12 @@ describe('ts types', () => {
|
|
|
146
147
|
type fragmentType = FragmentType<typeof fragment>
|
|
147
148
|
expectTypeOf<fragmentType>().toEqualTypeOf<{ id: string; status: PostStatus | null }>()
|
|
148
149
|
})
|
|
150
|
+
|
|
151
|
+
test('includes condition', async () => {
|
|
152
|
+
expectTypeOf<Input.Condition<string[]>['includes']>().toEqualTypeOf<string | undefined>()
|
|
153
|
+
expectTypeOf<Input.Condition<readonly string[]>['includes']>().toEqualTypeOf<string | undefined>()
|
|
154
|
+
expectTypeOf<Input.Condition<JSONValue | null>['includes']>().toEqualTypeOf<JSONValue | undefined>()
|
|
155
|
+
expectTypeOf<Input.Condition['includes']>().toEqualTypeOf<Value.FieldValue | undefined>()
|
|
156
|
+
expectTypeOf<Input.Condition<string>['includes']>().toEqualTypeOf<undefined>()
|
|
157
|
+
})
|
|
149
158
|
})
|