@contember/engine-content-api 2.1.0-alpha.2 → 2.1.0-alpha.20
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/mapper/Result.cjs +1 -1
- package/dist/development/src/mapper/Result.cjs.map +1 -1
- package/dist/development/src/mapper/Result.js +1 -1
- package/dist/development/src/mapper/Result.js.map +1 -1
- package/dist/development/src/resolvers/RefreshViewResolver.cjs +3 -2
- package/dist/development/src/resolvers/RefreshViewResolver.cjs.map +1 -1
- package/dist/development/src/resolvers/RefreshViewResolver.js +3 -2
- package/dist/development/src/resolvers/RefreshViewResolver.js.map +1 -1
- package/dist/development/src/schema/RefreshViewMutationProvider.cjs +9 -2
- package/dist/development/src/schema/RefreshViewMutationProvider.cjs.map +1 -1
- package/dist/development/src/schema/RefreshViewMutationProvider.js +10 -3
- package/dist/development/src/schema/RefreshViewMutationProvider.js.map +1 -1
- package/dist/production/src/mapper/Result.cjs +1 -1
- package/dist/production/src/mapper/Result.cjs.map +1 -1
- package/dist/production/src/mapper/Result.js +1 -1
- package/dist/production/src/mapper/Result.js.map +1 -1
- package/dist/production/src/resolvers/RefreshViewResolver.cjs +3 -2
- package/dist/production/src/resolvers/RefreshViewResolver.cjs.map +1 -1
- package/dist/production/src/resolvers/RefreshViewResolver.js +3 -2
- package/dist/production/src/resolvers/RefreshViewResolver.js.map +1 -1
- package/dist/production/src/schema/RefreshViewMutationProvider.cjs +9 -2
- package/dist/production/src/schema/RefreshViewMutationProvider.cjs.map +1 -1
- package/dist/production/src/schema/RefreshViewMutationProvider.js +10 -3
- package/dist/production/src/schema/RefreshViewMutationProvider.js.map +1 -1
- package/dist/tests/cases/integration/graphQlRequests/insert/subOperationFail.test.d.ts +2 -0
- package/dist/tests/cases/integration/graphQlRequests/insert/subOperationFail.test.d.ts.map +1 -0
- package/dist/tests/tsconfig.tsbuildinfo +1 -1
- package/dist/types/resolvers/RefreshViewResolver.d.ts +3 -1
- package/dist/types/resolvers/RefreshViewResolver.d.ts.map +1 -1
- package/dist/types/schema/RefreshViewMutationProvider.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/graphql.codegen.yml +1 -1
- package/package.json +10 -10
- package/src/mapper/Result.ts +1 -1
- package/src/resolvers/RefreshViewResolver.ts +3 -3
- package/src/schema/RefreshViewMutationProvider.ts +9 -2
- package/tests/cases/integration/graphQlRequests/insert/subOperationFail.test.ts +105 -0
package/graphql.codegen.yml
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contember/engine-content-api",
|
|
3
|
-
"version": "2.1.0-alpha.
|
|
3
|
+
"version": "2.1.0-alpha.20",
|
|
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.
|
|
30
|
-
"@contember/dic": "2.1.0-alpha.
|
|
31
|
-
"@contember/graphql-utils": "2.1.0-alpha.
|
|
32
|
-
"@contember/logger": "2.1.0-alpha.
|
|
33
|
-
"@contember/schema": "2.1.0-alpha.
|
|
34
|
-
"@contember/schema-definition": "2.1.0-alpha.
|
|
35
|
-
"@contember/schema-utils": "2.1.0-alpha.
|
|
29
|
+
"@contember/database": "2.1.0-alpha.20",
|
|
30
|
+
"@contember/dic": "2.1.0-alpha.20",
|
|
31
|
+
"@contember/graphql-utils": "2.1.0-alpha.20",
|
|
32
|
+
"@contember/logger": "2.1.0-alpha.20",
|
|
33
|
+
"@contember/schema": "2.1.0-alpha.20",
|
|
34
|
+
"@contember/schema-definition": "2.1.0-alpha.20",
|
|
35
|
+
"@contember/schema-utils": "2.1.0-alpha.20",
|
|
36
36
|
"fast-deep-equal": "^3.1.3"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@contember/database-tester": "2.1.0-alpha.
|
|
40
|
-
"@contember/schema-definition": "2.1.0-alpha.
|
|
39
|
+
"@contember/database-tester": "2.1.0-alpha.20",
|
|
40
|
+
"@contember/schema-definition": "2.1.0-alpha.20",
|
|
41
41
|
"@types/node": "^20.17.22",
|
|
42
42
|
"graphql": "^16.9.0",
|
|
43
43
|
"pg": "^8.12.0"
|
package/src/mapper/Result.ts
CHANGED
|
@@ -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
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Schema } from '@contember/schema'
|
|
2
2
|
import { MapperFactory } from '../mapper'
|
|
3
3
|
import { wrapIdentifier } from '@contember/database'
|
|
4
|
-
import { Authorizator } from '../acl'
|
|
5
4
|
|
|
6
5
|
export class RefreshViewResolver {
|
|
7
6
|
constructor(
|
|
@@ -10,13 +9,14 @@ export class RefreshViewResolver {
|
|
|
10
9
|
) {
|
|
11
10
|
}
|
|
12
11
|
|
|
13
|
-
public async resolve(entity: string): Promise<{ ok: boolean }> {
|
|
12
|
+
public async resolve(entity: string, options?: { concurrently?: boolean }): Promise<{ ok: boolean }> {
|
|
14
13
|
const mapper = this.mapperFactory.create()
|
|
15
14
|
const entityModel = this.schema.model.entities[entity]
|
|
16
15
|
if (!entityModel) {
|
|
17
16
|
throw new Error(`Entity ${entity} not found`)
|
|
18
17
|
}
|
|
19
|
-
|
|
18
|
+
const concurrently = options?.concurrently ? ' CONCURRENTLY' : ''
|
|
19
|
+
await mapper.db.query(`REFRESH MATERIALIZED VIEW${concurrently} ${wrapIdentifier(mapper.db.schema)}.${wrapIdentifier(entityModel.tableName)}`)
|
|
20
20
|
|
|
21
21
|
return { ok: true }
|
|
22
22
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Model } from '@contember/schema'
|
|
2
|
-
import { GraphQLBoolean, GraphQLEnumType, GraphQLFieldConfig, GraphQLObjectType } from 'graphql'
|
|
2
|
+
import { GraphQLBoolean, GraphQLEnumType, GraphQLFieldConfig, GraphQLInputObjectType, GraphQLObjectType } from 'graphql'
|
|
3
3
|
import { Context } from '../types'
|
|
4
4
|
import { Authorizator } from '../acl'
|
|
5
5
|
|
|
@@ -22,6 +22,12 @@ export class RefreshViewMutationProvider {
|
|
|
22
22
|
values: Object.fromEntries(materializedViews.map(it => [it.name, { value: it.name }])),
|
|
23
23
|
})
|
|
24
24
|
|
|
25
|
+
const refreshViewOptions = new GraphQLInputObjectType({
|
|
26
|
+
name: 'RefreshMaterializedViewOptions',
|
|
27
|
+
fields: {
|
|
28
|
+
concurrently: { type: GraphQLBoolean },
|
|
29
|
+
},
|
|
30
|
+
})
|
|
25
31
|
return {
|
|
26
32
|
type: new GraphQLObjectType({
|
|
27
33
|
name: 'RefreshMaterializedViewResponse',
|
|
@@ -31,9 +37,10 @@ export class RefreshViewMutationProvider {
|
|
|
31
37
|
}),
|
|
32
38
|
args: {
|
|
33
39
|
name: { type: materializedViewsEnum },
|
|
40
|
+
options: { type: refreshViewOptions },
|
|
34
41
|
},
|
|
35
42
|
resolve: async (parent, args, context) => {
|
|
36
|
-
return await context.executionContainer.refreshViewResolver.resolve(args.name)
|
|
43
|
+
return await context.executionContainer.refreshViewResolver.resolve(args.name, args.options)
|
|
37
44
|
},
|
|
38
45
|
}
|
|
39
46
|
}
|
|
@@ -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
|
+
|