@contember/engine-content-api 2.1.0-alpha.14 → 2.1.0-alpha.16

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contember/engine-content-api",
3
- "version": "2.1.0-alpha.14",
3
+ "version": "2.1.0-alpha.16",
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.1.0-alpha.14",
30
- "@contember/dic": "2.1.0-alpha.14",
31
- "@contember/graphql-utils": "2.1.0-alpha.14",
32
- "@contember/logger": "2.1.0-alpha.14",
33
- "@contember/schema": "2.1.0-alpha.14",
34
- "@contember/schema-definition": "2.1.0-alpha.14",
35
- "@contember/schema-utils": "2.1.0-alpha.14",
29
+ "@contember/database": "2.1.0-alpha.15",
30
+ "@contember/dic": "2.1.0-alpha.15",
31
+ "@contember/graphql-utils": "2.1.0-alpha.15",
32
+ "@contember/logger": "2.1.0-alpha.15",
33
+ "@contember/schema": "2.1.0-alpha.15",
34
+ "@contember/schema-definition": "2.1.0-alpha.15",
35
+ "@contember/schema-utils": "2.1.0-alpha.15",
36
36
  "fast-deep-equal": "^3.1.3"
37
37
  },
38
38
  "devDependencies": {
39
- "@contember/database-tester": "2.1.0-alpha.14",
40
- "@contember/schema-definition": "2.1.0-alpha.14",
39
+ "@contember/database-tester": "2.1.0-alpha.15",
40
+ "@contember/schema-definition": "2.1.0-alpha.15",
41
41
  "@types/node": "^20.17.22",
42
42
  "graphql": "^16.9.0",
43
43
  "pg": "^8.12.0"
@@ -202,6 +202,6 @@ export const prependPath = (path: Path, results: MutationResultList): MutationRe
202
202
  }))
203
203
 
204
204
  export const getInsertPrimary = (result: MutationResultList) =>
205
- result[0] && result[0].result === MutationResultType.ok && result[0].type === ModificationType.create
205
+ !result.some(it => it.error) && result[0] && result[0].result === MutationResultType.ok && result[0].type === ModificationType.create
206
206
  ? result[0].primary
207
207
  : undefined
@@ -0,0 +1,105 @@
1
+ import { test } from 'bun:test'
2
+ import { execute, failedTransaction, sqlTransaction } from '../../../../src/test'
3
+ import { c, createSchema } from '@contember/schema-definition'
4
+ import { Model } from '@contember/schema'
5
+ import { GQL, SQL } from '../../../../src/tags'
6
+ import { testUuid } from '../../../../src/testUuid'
7
+
8
+ namespace TestModel {
9
+ export class Article {
10
+ content = c.manyHasOne(ArticleContent)
11
+ }
12
+
13
+ export class ArticleContent {
14
+ locales = c.oneHasMany(ArticleContentLocale, 'content')
15
+ }
16
+
17
+ export class ArticleContentLocale {
18
+ content = c.manyHasOne(ArticleContent, 'locales')
19
+ title = c.stringColumn()
20
+ locale = c.stringColumn()
21
+ }
22
+ }
23
+
24
+ test('failed to insert in sub-operation', async () => {
25
+ await execute({
26
+ schema: createSchema(TestModel).model,
27
+ query: GQL`
28
+ mutation {
29
+ createArticle(data: {content: {create: {locales: [{create: {locale: "en", title: "Title"}}]}}}) {
30
+ ok
31
+ }
32
+ }`,
33
+ executes: [
34
+ ...failedTransaction([
35
+ {
36
+ sql: SQL`with "root_" as (select ? :: uuid as "id") insert into "public"."article_content" ("id") select "root_"."id" from "root_" returning "id"`,
37
+ parameters: [testUuid(2)],
38
+ response: {
39
+ rows: [{ id: testUuid(2) }],
40
+ },
41
+ },
42
+ {
43
+ sql: SQL`with "root_" as (select ? :: uuid as "id", ? :: text as "title", ? :: text as "locale", ? :: uuid as "content_id") insert into "public"."article_content_locale" ("id", "title", "locale", "content_id") select "root_"."id", "root_"."title", "root_"."locale", "root_"."content_id" from "root_" returning "id"`,
44
+ parameters: [testUuid(3), 'Title', 'en', testUuid(2)],
45
+ response: {
46
+ rows: [],
47
+ },
48
+ },
49
+ ]),
50
+ ],
51
+ return: {
52
+ data: {
53
+ createArticle: {
54
+ ok: false,
55
+ },
56
+ },
57
+ },
58
+ })
59
+ })
60
+
61
+
62
+ test('failed to insert in sub-operation in update', async () => {
63
+ await execute({
64
+ schema: createSchema(TestModel).model,
65
+ query: GQL`
66
+ mutation {
67
+ updateArticle(by: {id: "${testUuid(10)}"}, data: {content: {create: {locales: [{create: {locale: "en", title: "Title"}}]}}}) {
68
+ ok
69
+ }
70
+ }`,
71
+ executes: [
72
+ ...failedTransaction([
73
+ {
74
+ sql: `select "root_"."id" from "public"."article" as "root_" where "root_"."id" = ?`,
75
+ parameters: [testUuid(10)],
76
+ response: {
77
+ rows: [{ id: testUuid(10) }],
78
+ },
79
+ },
80
+ {
81
+ sql: SQL`with "root_" as (select ? :: uuid as "id") insert into "public"."article_content" ("id") select "root_"."id" from "root_" returning "id"`,
82
+ parameters: [testUuid(1)],
83
+ response: {
84
+ rows: [{ id: testUuid(1) }],
85
+ },
86
+ },
87
+ {
88
+ sql: SQL`with "root_" as (select ? :: uuid as "id", ? :: text as "title", ? :: text as "locale", ? :: uuid as "content_id") insert into "public"."article_content_locale" ("id", "title", "locale", "content_id") select "root_"."id", "root_"."title", "root_"."locale", "root_"."content_id" from "root_" returning "id"`,
89
+ parameters: [testUuid(2), 'Title', 'en', testUuid(1)],
90
+ response: {
91
+ rows: [],
92
+ },
93
+ },
94
+ ]),
95
+ ],
96
+ return: {
97
+ data: {
98
+ updateArticle: {
99
+ ok: false,
100
+ },
101
+ },
102
+ },
103
+ })
104
+ })
105
+