@contember/engine-content-api 2.0.0-alpha.16 → 2.0.0-alpha.17

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.
Files changed (36) hide show
  1. package/dist/development/src/inputProcessing/UpdateInputVisitor.cjs +3 -0
  2. package/dist/development/src/inputProcessing/UpdateInputVisitor.cjs.map +1 -1
  3. package/dist/development/src/inputProcessing/UpdateInputVisitor.js +3 -0
  4. package/dist/development/src/inputProcessing/UpdateInputVisitor.js.map +1 -1
  5. package/dist/development/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.cjs +2 -0
  6. package/dist/development/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.cjs.map +1 -1
  7. package/dist/development/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.js +2 -0
  8. package/dist/development/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.js.map +1 -1
  9. package/dist/production/src/inputProcessing/UpdateInputVisitor.cjs +3 -0
  10. package/dist/production/src/inputProcessing/UpdateInputVisitor.cjs.map +1 -1
  11. package/dist/production/src/inputProcessing/UpdateInputVisitor.js +3 -0
  12. package/dist/production/src/inputProcessing/UpdateInputVisitor.js.map +1 -1
  13. package/dist/production/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.cjs +2 -0
  14. package/dist/production/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.cjs.map +1 -1
  15. package/dist/production/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.js +2 -0
  16. package/dist/production/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.js.map +1 -1
  17. package/dist/tests/cases/integration/graphQlRequests/update/manyHasManyOwning/connectOrCreate.test.d.ts +2 -0
  18. package/dist/tests/cases/integration/graphQlRequests/update/manyHasManyOwning/connectOrCreate.test.d.ts.map +1 -0
  19. package/dist/tests/cases/integration/graphQlRequests/update/oneHasMany/connectOrCreate.test.d.ts +2 -0
  20. package/dist/tests/cases/integration/graphQlRequests/update/oneHasMany/connectOrCreate.test.d.ts.map +1 -0
  21. package/dist/tests/tsconfig.tsbuildinfo +1 -1
  22. package/dist/types/inputProcessing/UpdateInputVisitor.d.ts.map +1 -1
  23. package/dist/types/schema/mutations/UpdateEntityRelationInputFieldVisitor.d.ts.map +1 -1
  24. package/dist/types/tsconfig.tsbuildinfo +1 -1
  25. package/package.json +10 -10
  26. package/src/inputProcessing/UpdateInputVisitor.ts +3 -0
  27. package/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.ts +5 -0
  28. package/tests/cases/integration/graphQlRequests/update/manyHasManyOwning/connectOrCreate.test.ts +100 -0
  29. package/tests/cases/integration/graphQlRequests/update/oneHasMany/connectOrCreate.test.ts +90 -0
  30. package/tests/cases/integration/graphQlSchema/schema-acl-allowed.gql +1 -0
  31. package/tests/cases/integration/graphQlSchema/schema-acl-restricted-delete.gql +1 -0
  32. package/tests/cases/integration/graphQlSchema/schema-basic.gql +4 -0
  33. package/tests/cases/integration/graphQlSchema/schema-bug-66.gql +1 -0
  34. package/tests/cases/integration/graphQlSchema/schema-custom-primary.gql +4 -0
  35. package/tests/cases/integration/graphQlSchema/schema-has-many-reduction.gql +1 -0
  36. package/tests/cases/integration/graphQlSchema/schema-new-builder.gql +4 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contember/engine-content-api",
3
- "version": "2.0.0-alpha.16",
3
+ "version": "2.0.0-alpha.17",
4
4
  "license": "Apache-2.0",
5
5
  "main": "./dist/production/index.js",
6
6
  "typings": "./dist/types/index.d.ts",
@@ -26,18 +26,18 @@
26
26
  "generate": "gql-gen --config graphql.codegen.yml"
27
27
  },
28
28
  "dependencies": {
29
- "@contember/database": "2.0.0-alpha.16",
30
- "@contember/dic": "2.0.0-alpha.16",
31
- "@contember/graphql-utils": "2.0.0-alpha.16",
32
- "@contember/logger": "2.0.0-alpha.16",
33
- "@contember/schema": "2.0.0-alpha.16",
34
- "@contember/schema-definition": "2.0.0-alpha.16",
35
- "@contember/schema-utils": "2.0.0-alpha.16",
29
+ "@contember/database": "2.0.0-alpha.17",
30
+ "@contember/dic": "2.0.0-alpha.17",
31
+ "@contember/graphql-utils": "2.0.0-alpha.17",
32
+ "@contember/logger": "2.0.0-alpha.17",
33
+ "@contember/schema": "2.0.0-alpha.17",
34
+ "@contember/schema-definition": "2.0.0-alpha.17",
35
+ "@contember/schema-utils": "2.0.0-alpha.17",
36
36
  "fast-deep-equal": "^3.1.3"
37
37
  },
38
38
  "devDependencies": {
39
- "@contember/database-tester": "2.0.0-alpha.16",
40
- "@contember/schema-definition": "2.0.0-alpha.16",
39
+ "@contember/database-tester": "2.0.0-alpha.17",
40
+ "@contember/schema-definition": "2.0.0-alpha.17",
41
41
  "@types/node": "^20.16.5",
42
42
  "graphql": "^16.9.0",
43
43
  "pg": "^8.12.0"
@@ -124,6 +124,9 @@ export class UpdateInputVisitor<Result> implements
124
124
  if (isIt<Input.CreateRelationInput>(element, 'create')) {
125
125
  result = processor.create({ ...context, input: element.create, index: i, alias })
126
126
  }
127
+ if (isIt<Input.ConnectOrCreateRelationInput>(element, 'connectOrCreate')) {
128
+ result = processor.connectOrCreate({ ...context, input: element.connectOrCreate, index: i, alias })
129
+ }
127
130
  if (isIt<Input.DeleteSpecifiedRelationInput>(element, 'delete')) {
128
131
  result = processor.delete({ ...context, input: element.delete, index: i, alias })
129
132
  }
@@ -123,11 +123,16 @@ export class UpdateEntityRelationInputFieldVisitor implements Model.ColumnVisito
123
123
  }
124
124
  : undefined
125
125
 
126
+ const connectOrCreateInput = createInput && whereInputType
127
+ ? { type: this.connectOrCreateRelationInputProvider.getInput(entity.name, relation.name) }
128
+ : undefined
129
+
126
130
  const fields = {
127
131
  [Input.UpdateRelationOperation.create]: createInput,
128
132
  [Input.UpdateRelationOperation.update]: updateSpecifiedInput,
129
133
  [Input.UpdateRelationOperation.upsert]: upsertInput,
130
134
  [Input.UpdateRelationOperation.connect]: whereInput,
135
+ [Input.UpdateRelationOperation.connectOrCreate]: connectOrCreateInput,
131
136
  [Input.UpdateRelationOperation.disconnect]: whereInput,
132
137
  [Input.UpdateRelationOperation.delete]: whereInput,
133
138
  }
@@ -0,0 +1,100 @@
1
+ import { test } from 'vitest'
2
+ import { execute, sqlTransaction } from '../../../../../src/test'
3
+ import { GQL, SQL } from '../../../../../src/tags'
4
+ import { testUuid } from '../../../../../src/testUuid'
5
+ import { postWithCategories } from './schema'
6
+
7
+ test('connectOrCreate - exists', async () => {
8
+ await execute({
9
+ schema: postWithCategories,
10
+ query: GQL`mutation {
11
+ updatePost(
12
+ by: {id: "${testUuid(2)}"},
13
+ data: {categories: [{connectOrCreate: {connect: {id: "${testUuid(1)}"}, create: {name: "Ipsum"}}}]}
14
+ ) {
15
+ ok
16
+ }
17
+ }`,
18
+ executes: [
19
+ ...sqlTransaction([
20
+ {
21
+ sql: SQL`select "root_"."id" from "public"."post" as "root_" where "root_"."id" = ?`,
22
+ parameters: [testUuid(2)],
23
+ response: { rows: [{ id: testUuid(2) }] },
24
+ },
25
+ {
26
+ sql: SQL`select "root_"."id" from "public"."category" as "root_" where "root_"."id" = ?`,
27
+ parameters: [testUuid(1)],
28
+ response: { rows: [{ id: testUuid(1) }] },
29
+ },
30
+ {
31
+ sql: SQL`insert into "public"."post_categories" ("post_id", "category_id")
32
+ values (?, ?)
33
+ on conflict do nothing`,
34
+ parameters: [testUuid(2), testUuid(1)],
35
+ response: { rowCount: 1 },
36
+ },
37
+ ]),
38
+ ],
39
+ return: {
40
+ data: {
41
+ updatePost: {
42
+ ok: true,
43
+ },
44
+ },
45
+ },
46
+ })
47
+ })
48
+ test('connectOrCreate - not exists', async () => {
49
+ await execute({
50
+ schema: postWithCategories,
51
+ query: GQL`mutation {
52
+ updatePost(
53
+ by: {id: "${testUuid(2)}"},
54
+ data: {categories: [{connectOrCreate: {connect: {id: "${testUuid(1)}"}, create: {name: "Ipsum"}}}]}
55
+ ) {
56
+ ok
57
+ }
58
+ }`,
59
+ executes: [
60
+ ...sqlTransaction([
61
+ {
62
+ sql: SQL`select "root_"."id" from "public"."post" as "root_" where "root_"."id" = ?`,
63
+ parameters: [testUuid(2)],
64
+ response: { rows: [{ id: testUuid(2) }] },
65
+ },
66
+ {
67
+ sql: SQL`select "root_"."id" from "public"."category" as "root_" where "root_"."id" = ?`,
68
+ parameters: [testUuid(1)],
69
+ response: { rows: [] },
70
+ },
71
+ {
72
+ sql: SQL`with "root_" as
73
+ (select ? :: uuid as "id", ? :: text as "name")
74
+ insert into "public"."category" ("id", "name")
75
+ select "root_"."id", "root_"."name"
76
+ from "root_"
77
+ returning "id"`,
78
+ parameters: [testUuid(1), 'Ipsum'],
79
+ response: { rows: [{ id: testUuid(1) }] },
80
+ },
81
+ {
82
+ sql: SQL`insert into "public"."post_categories" ("post_id", "category_id")
83
+ values (?, ?)
84
+ on conflict do nothing`,
85
+ parameters: [testUuid(2), testUuid(1)],
86
+ response: { rowCount: 1 },
87
+ },
88
+ ]),
89
+ ],
90
+ return: {
91
+ data: {
92
+ updatePost: {
93
+ ok: true,
94
+ },
95
+ },
96
+ },
97
+ })
98
+ })
99
+
100
+
@@ -0,0 +1,90 @@
1
+ import { test } from 'vitest'
2
+ import { execute, sqlTransaction } from '../../../../../src/test'
3
+ import { GQL, SQL } from '../../../../../src/tags'
4
+ import { testUuid } from '../../../../../src/testUuid'
5
+ import { postWithLocale } from './schema'
6
+
7
+ test('connectOrCreate - exists', async () => {
8
+ await execute({
9
+ schema: postWithLocale,
10
+ query: GQL`mutation {
11
+ updatePost(
12
+ by: {id: "${testUuid(2)}"},
13
+ data: {locales: [{connectOrCreate: {connect: {id: "${testUuid(10)}"}, create: {title: "World"}}}]}
14
+ ) {
15
+ ok
16
+ }
17
+ }`,
18
+ executes: [
19
+ ...sqlTransaction([
20
+ {
21
+ sql: SQL`select "root_"."id" from "public"."post" as "root_" where "root_"."id" = ?`,
22
+ parameters: [testUuid(2)],
23
+ response: { rows: [{ id: testUuid(2) }] },
24
+ },
25
+ {
26
+ sql: SQL`select "root_"."id" from "public"."post_locale" as "root_" where "root_"."id" = ?`,
27
+ parameters: [testUuid(10)],
28
+ response: { rows: [{ id: testUuid(10) }] },
29
+ },
30
+ {
31
+ sql: SQL`with "newData_" as (select ? :: uuid as "post_id", "root_"."post_id" as "post_id_old__", "root_"."id", "root_"."title", "root_"."locale" from "public"."post_locale" as "root_" where "root_"."id" = ?) update "public"."post_locale" set "post_id" = "newData_"."post_id" from "newData_" where "post_locale"."id" = "newData_"."id" returning "post_id_old__"`,
32
+ parameters: [testUuid(2), testUuid(10)],
33
+ response: { rows: [{ post_id_old__: testUuid(1) }] },
34
+ },
35
+ ]),
36
+ ],
37
+ return: {
38
+ data: {
39
+ updatePost: {
40
+ ok: true,
41
+ },
42
+ },
43
+ },
44
+ })
45
+ })
46
+ test('upsert - not exists (composed unique)', async () => {
47
+ await execute({
48
+ schema: postWithLocale,
49
+ query: GQL`mutation {
50
+ updatePost(
51
+ by: {id: "${testUuid(2)}"},
52
+ data: {locales: [{connectOrCreate: {connect: {id: "${testUuid(10)}"}, create: {title: "World"}}}]}
53
+ ) {
54
+ ok
55
+ }
56
+ }`,
57
+ executes: [
58
+ ...sqlTransaction([
59
+ {
60
+ sql: SQL`select "root_"."id" from "public"."post" as "root_" where "root_"."id" = ?`,
61
+ parameters: [testUuid(2)],
62
+ response: { rows: [{ id: testUuid(2) }] },
63
+ },
64
+ {
65
+ sql: SQL`select "root_"."id" from "public"."post_locale" as "root_" where "root_"."id" = ?`,
66
+ parameters: [testUuid(10)],
67
+ response: { rows: [] },
68
+ },
69
+ {
70
+ sql: SQL`with "root_" as
71
+ (select ? :: uuid as "id", ? :: text as "title", ? :: text as "locale", ? :: uuid as "post_id")
72
+ insert into "public"."post_locale" ("id", "title", "locale", "post_id")
73
+ select "root_"."id", "root_"."title", "root_"."locale", "root_"."post_id"
74
+ from "root_"
75
+ returning "id"`,
76
+ parameters: [testUuid(1), 'World', null, testUuid(2)],
77
+ response: { rows: [{ id: testUuid(1) }] },
78
+ },
79
+ ]),
80
+ ],
81
+ return: {
82
+ data: {
83
+ updatePost: {
84
+ ok: true,
85
+ },
86
+ },
87
+ },
88
+ })
89
+ })
90
+
@@ -263,6 +263,7 @@ input RootUpdateREntityRelationInput {
263
263
  update: RootUpdateRRelationInput
264
264
  upsert: RootUpsertRRelationInput
265
265
  connect: OneHasManyEntityUniqueWhere
266
+ connectOrCreate: RootConnectOrCreateRRelationInput
266
267
  disconnect: OneHasManyEntityUniqueWhere
267
268
  delete: OneHasManyEntityUniqueWhere
268
269
  alias: String
@@ -255,6 +255,7 @@ input RootUpdateREntityRelationInput {
255
255
  update: RootUpdateRRelationInput
256
256
  upsert: RootUpsertRRelationInput
257
257
  connect: OneHasManyEntityUniqueWhere
258
+ connectOrCreate: RootConnectOrCreateRRelationInput
258
259
  disconnect: OneHasManyEntityUniqueWhere
259
260
  alias: String
260
261
  }
@@ -379,6 +379,7 @@ input AuthorUpdatePostsEntityRelationInput {
379
379
  update: AuthorUpdatePostsRelationInput
380
380
  upsert: AuthorUpsertPostsRelationInput
381
381
  connect: PostUniqueWhere
382
+ connectOrCreate: AuthorConnectOrCreatePostsRelationInput
382
383
  disconnect: PostUniqueWhere
383
384
  delete: PostUniqueWhere
384
385
  alias: String
@@ -401,6 +402,7 @@ input PostUpdateLocalesEntityRelationInput {
401
402
  update: PostUpdateLocalesRelationInput
402
403
  upsert: PostUpsertLocalesRelationInput
403
404
  connect: PostLocaleUniqueWhere
405
+ connectOrCreate: PostConnectOrCreateLocalesRelationInput
404
406
  disconnect: PostLocaleUniqueWhere
405
407
  delete: PostLocaleUniqueWhere
406
408
  alias: String
@@ -427,6 +429,7 @@ input PostUpdateCategoriesEntityRelationInput {
427
429
  update: PostUpdateCategoriesRelationInput
428
430
  upsert: PostUpsertCategoriesRelationInput
429
431
  connect: CategoryUniqueWhere
432
+ connectOrCreate: PostConnectOrCreateCategoriesRelationInput
430
433
  disconnect: CategoryUniqueWhere
431
434
  delete: CategoryUniqueWhere
432
435
  alias: String
@@ -506,6 +509,7 @@ input CategoryUpdatePostsEntityRelationInput {
506
509
  update: CategoryUpdatePostsRelationInput
507
510
  upsert: CategoryUpsertPostsRelationInput
508
511
  connect: PostUniqueWhere
512
+ connectOrCreate: CategoryConnectOrCreatePostsRelationInput
509
513
  disconnect: PostUniqueWhere
510
514
  delete: PostUniqueWhere
511
515
  alias: String
@@ -312,6 +312,7 @@ input FrontPageUpdateInHouseVideosEntityRelationInput {
312
312
  update: FrontPageUpdateInHouseVideosRelationInput
313
313
  upsert: FrontPageUpsertInHouseVideosRelationInput
314
314
  connect: VideoUniqueWhere
315
+ connectOrCreate: FrontPageConnectOrCreateInHouseVideosRelationInput
315
316
  disconnect: VideoUniqueWhere
316
317
  delete: VideoUniqueWhere
317
318
  alias: String
@@ -383,6 +383,7 @@ input AuthorUpdatePostsEntityRelationInput {
383
383
  update: AuthorUpdatePostsRelationInput
384
384
  upsert: AuthorUpsertPostsRelationInput
385
385
  connect: PostUniqueWhere
386
+ connectOrCreate: AuthorConnectOrCreatePostsRelationInput
386
387
  disconnect: PostUniqueWhere
387
388
  delete: PostUniqueWhere
388
389
  alias: String
@@ -405,6 +406,7 @@ input PostUpdateLocalesEntityRelationInput {
405
406
  update: PostUpdateLocalesRelationInput
406
407
  upsert: PostUpsertLocalesRelationInput
407
408
  connect: PostLocaleUniqueWhere
409
+ connectOrCreate: PostConnectOrCreateLocalesRelationInput
408
410
  disconnect: PostLocaleUniqueWhere
409
411
  delete: PostLocaleUniqueWhere
410
412
  alias: String
@@ -431,6 +433,7 @@ input PostUpdateCategoriesEntityRelationInput {
431
433
  update: PostUpdateCategoriesRelationInput
432
434
  upsert: PostUpsertCategoriesRelationInput
433
435
  connect: CategoryUniqueWhere
436
+ connectOrCreate: PostConnectOrCreateCategoriesRelationInput
434
437
  disconnect: CategoryUniqueWhere
435
438
  delete: CategoryUniqueWhere
436
439
  alias: String
@@ -513,6 +516,7 @@ input CategoryUpdatePostsEntityRelationInput {
513
516
  update: CategoryUpdatePostsRelationInput
514
517
  upsert: CategoryUpsertPostsRelationInput
515
518
  connect: PostUniqueWhere
519
+ connectOrCreate: CategoryConnectOrCreatePostsRelationInput
516
520
  disconnect: PostUniqueWhere
517
521
  delete: PostUniqueWhere
518
522
  alias: String
@@ -295,6 +295,7 @@ input PostUpdateLocalesEntityRelationInput {
295
295
  update: PostUpdateLocalesRelationInput
296
296
  upsert: PostUpsertLocalesRelationInput
297
297
  connect: PostLocaleUniqueWhere
298
+ connectOrCreate: PostConnectOrCreateLocalesRelationInput
298
299
  disconnect: PostLocaleUniqueWhere
299
300
  delete: PostLocaleUniqueWhere
300
301
  alias: String
@@ -440,6 +440,7 @@ input AuthorUpdatePostsEntityRelationInput {
440
440
  update: AuthorUpdatePostsRelationInput
441
441
  upsert: AuthorUpsertPostsRelationInput
442
442
  connect: PostUniqueWhere
443
+ connectOrCreate: AuthorConnectOrCreatePostsRelationInput
443
444
  disconnect: PostUniqueWhere
444
445
  delete: PostUniqueWhere
445
446
  alias: String
@@ -463,6 +464,7 @@ input PostUpdateCategoriesEntityRelationInput {
463
464
  update: PostUpdateCategoriesRelationInput
464
465
  upsert: PostUpsertCategoriesRelationInput
465
466
  connect: CategoryUniqueWhere
467
+ connectOrCreate: PostConnectOrCreateCategoriesRelationInput
466
468
  disconnect: CategoryUniqueWhere
467
469
  delete: CategoryUniqueWhere
468
470
  alias: String
@@ -489,6 +491,7 @@ input PostUpdateLocalesEntityRelationInput {
489
491
  update: PostUpdateLocalesRelationInput
490
492
  upsert: PostUpsertLocalesRelationInput
491
493
  connect: PostLocaleUniqueWhere
494
+ connectOrCreate: PostConnectOrCreateLocalesRelationInput
492
495
  disconnect: PostLocaleUniqueWhere
493
496
  delete: PostLocaleUniqueWhere
494
497
  alias: String
@@ -664,6 +667,7 @@ input CategoryUpdatePostsEntityRelationInput {
664
667
  update: CategoryUpdatePostsRelationInput
665
668
  upsert: CategoryUpsertPostsRelationInput
666
669
  connect: PostUniqueWhere
670
+ connectOrCreate: CategoryConnectOrCreatePostsRelationInput
667
671
  disconnect: PostUniqueWhere
668
672
  delete: PostUniqueWhere
669
673
  alias: String