@contember/engine-content-api 2.1.0-alpha.3 → 2.1.0-alpha.30
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/index.cjs +0 -2
- package/dist/development/index.cjs.map +1 -1
- package/dist/development/index.js +0 -2
- package/dist/development/index.js.map +1 -1
- package/dist/development/src/ExecutionContainer.cjs +5 -4
- package/dist/development/src/ExecutionContainer.cjs.map +1 -1
- package/dist/development/src/ExecutionContainer.js +5 -4
- package/dist/development/src/ExecutionContainer.js.map +1 -1
- 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/mapper/select/ConditionBuilder.cjs +6 -2
- package/dist/development/src/mapper/select/ConditionBuilder.cjs.map +1 -1
- package/dist/development/src/mapper/select/ConditionBuilder.js +7 -3
- package/dist/development/src/mapper/select/ConditionBuilder.js.map +1 -1
- package/dist/development/src/mapper/select/optimizer/WhereOptimizer.cjs +6 -2
- package/dist/development/src/mapper/select/optimizer/WhereOptimizer.cjs.map +1 -1
- package/dist/development/src/mapper/select/optimizer/WhereOptimizer.js +6 -2
- package/dist/development/src/mapper/select/optimizer/WhereOptimizer.js.map +1 -1
- package/dist/development/src/mapper/update/Updater.cjs +15 -3
- package/dist/development/src/mapper/update/Updater.cjs.map +1 -1
- package/dist/development/src/mapper/update/Updater.js +16 -4
- package/dist/development/src/mapper/update/Updater.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/ConditionTypeProvider.cjs +2 -0
- package/dist/development/src/schema/ConditionTypeProvider.cjs.map +1 -1
- package/dist/development/src/schema/ConditionTypeProvider.js +2 -0
- package/dist/development/src/schema/ConditionTypeProvider.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/index.cjs +0 -2
- package/dist/production/index.cjs.map +1 -1
- package/dist/production/index.js +0 -2
- package/dist/production/index.js.map +1 -1
- package/dist/production/src/ExecutionContainer.cjs +5 -4
- package/dist/production/src/ExecutionContainer.cjs.map +1 -1
- package/dist/production/src/ExecutionContainer.js +5 -4
- package/dist/production/src/ExecutionContainer.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/mapper/select/ConditionBuilder.cjs +6 -2
- package/dist/production/src/mapper/select/ConditionBuilder.cjs.map +1 -1
- package/dist/production/src/mapper/select/ConditionBuilder.js +7 -3
- package/dist/production/src/mapper/select/ConditionBuilder.js.map +1 -1
- package/dist/production/src/mapper/select/optimizer/WhereOptimizer.cjs +6 -2
- package/dist/production/src/mapper/select/optimizer/WhereOptimizer.cjs.map +1 -1
- package/dist/production/src/mapper/select/optimizer/WhereOptimizer.js +6 -2
- package/dist/production/src/mapper/select/optimizer/WhereOptimizer.js.map +1 -1
- package/dist/production/src/mapper/update/Updater.cjs +15 -3
- package/dist/production/src/mapper/update/Updater.cjs.map +1 -1
- package/dist/production/src/mapper/update/Updater.js +16 -4
- package/dist/production/src/mapper/update/Updater.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/ConditionTypeProvider.cjs +2 -0
- package/dist/production/src/schema/ConditionTypeProvider.cjs.map +1 -1
- package/dist/production/src/schema/ConditionTypeProvider.js +2 -0
- package/dist/production/src/schema/ConditionTypeProvider.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/src/test.d.ts.map +1 -1
- package/dist/tests/tsconfig.tsbuildinfo +1 -1
- package/dist/types/ExecutionContainer.d.ts +13 -3
- package/dist/types/ExecutionContainer.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/mapper/Result.d.ts +2 -2
- package/dist/types/mapper/Result.d.ts.map +1 -1
- package/dist/types/mapper/select/ConditionBuilder.d.ts.map +1 -1
- package/dist/types/mapper/select/optimizer/WhereOptimizer.d.ts +6 -1
- package/dist/types/mapper/select/optimizer/WhereOptimizer.d.ts.map +1 -1
- package/dist/types/mapper/update/Updater.d.ts +1 -5
- package/dist/types/mapper/update/Updater.d.ts.map +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/ConditionTypeProvider.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/ExecutionContainer.ts +9 -5
- package/src/index.ts +2 -1
- package/src/mapper/Result.ts +2 -2
- package/src/mapper/select/ConditionBuilder.ts +11 -5
- package/src/mapper/select/optimizer/WhereOptimizer.ts +10 -1
- package/src/mapper/update/Updater.ts +16 -5
- package/src/resolvers/RefreshViewResolver.ts +3 -3
- package/src/schema/ConditionTypeProvider.ts +3 -0
- package/src/schema/RefreshViewMutationProvider.ts +9 -2
- package/tests/cases/integration/graphQlRequests/insert/subOperationFail.test.ts +105 -0
- package/tests/cases/integration/graphQlRequests/update/additionalFilter.test.ts +51 -2
- package/tests/cases/integration/graphQlSchema/schema-column-types.gql +1 -0
- package/tests/src/test.ts +1 -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.30",
|
|
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.30",
|
|
30
|
+
"@contember/dic": "2.1.0-alpha.30",
|
|
31
|
+
"@contember/graphql-utils": "2.1.0-alpha.30",
|
|
32
|
+
"@contember/logger": "2.1.0-alpha.30",
|
|
33
|
+
"@contember/schema": "2.1.0-alpha.30",
|
|
34
|
+
"@contember/schema-definition": "2.1.0-alpha.30",
|
|
35
|
+
"@contember/schema-utils": "2.1.0-alpha.30",
|
|
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.30",
|
|
40
|
+
"@contember/schema-definition": "2.1.0-alpha.30",
|
|
41
41
|
"@types/node": "^20.17.22",
|
|
42
42
|
"graphql": "^16.9.0",
|
|
43
43
|
"pg": "^8.12.0"
|
|
@@ -31,7 +31,7 @@ import { Client, DatabaseMetadata, SelectBuilder as DbSelectBuilder } from '@con
|
|
|
31
31
|
import { ParsedMembership, Providers } from '@contember/schema-utils'
|
|
32
32
|
import { PaginatedHasManyExecutionHandler } from './extensions/paginatedHasMany/PaginatedHasManyExecutionHandler'
|
|
33
33
|
import { PaginatedHasManyFieldProvider } from './extensions/paginatedHasMany/PaginatedHasManyFieldProvider'
|
|
34
|
-
import { WhereOptimizer } from './mapper/select/optimizer/WhereOptimizer'
|
|
34
|
+
import { WhereOptimizer, WhereOptimizerOptions } from './mapper/select/optimizer/WhereOptimizer'
|
|
35
35
|
import { ConditionOptimizer } from './mapper/select/optimizer/ConditionOptimizer'
|
|
36
36
|
import { GraphQlQueryAstFactory, MutationResolver, ReadResolver, ValidationResolver } from './resolvers'
|
|
37
37
|
import {
|
|
@@ -54,6 +54,7 @@ export type ExecutionContainerArgs = {
|
|
|
54
54
|
systemSchema: string
|
|
55
55
|
project: { slug: string }
|
|
56
56
|
stage: { id: string; slug: string }
|
|
57
|
+
userInfo: { ipAddress: string | null; userAgent: string | null }
|
|
57
58
|
}
|
|
58
59
|
|
|
59
60
|
export interface ExecutionContainer {
|
|
@@ -71,6 +72,7 @@ export class ExecutionContainerFactory {
|
|
|
71
72
|
|
|
72
73
|
constructor(
|
|
73
74
|
private readonly providers: Providers,
|
|
75
|
+
private readonly whereOptimizerOptions?: WhereOptimizerOptions,
|
|
74
76
|
) {
|
|
75
77
|
}
|
|
76
78
|
|
|
@@ -79,7 +81,7 @@ export class ExecutionContainerFactory {
|
|
|
79
81
|
return this.hooks.reduce((acc, cb) => cb(acc), builder)
|
|
80
82
|
}
|
|
81
83
|
|
|
82
|
-
createBuilderInternal({ permissions, identityVariables, identityId, db, schema, schemaMeta, systemSchema, stage, project, schemaDatabaseMetadata }: ExecutionContainerArgs) {
|
|
84
|
+
createBuilderInternal({ permissions, identityVariables, identityId, db, schema, schemaMeta, systemSchema, stage, project, schemaDatabaseMetadata, userInfo }: ExecutionContainerArgs) {
|
|
83
85
|
return new Builder({})
|
|
84
86
|
.addService('systemSchema', () =>
|
|
85
87
|
systemSchema)
|
|
@@ -95,6 +97,8 @@ export class ExecutionContainerFactory {
|
|
|
95
97
|
schemaMeta)
|
|
96
98
|
.addService('schemaDatabaseMetadata', () =>
|
|
97
99
|
schemaDatabaseMetadata)
|
|
100
|
+
.addService('userInfo', () =>
|
|
101
|
+
userInfo)
|
|
98
102
|
.addService('providers', () =>
|
|
99
103
|
this.providers)
|
|
100
104
|
.addService('variableInjector', ({ schema }) =>
|
|
@@ -110,7 +114,7 @@ export class ExecutionContainerFactory {
|
|
|
110
114
|
.addService('pathFactory', () =>
|
|
111
115
|
new PathFactory())
|
|
112
116
|
.addService('whereOptimized', ({ schema }) =>
|
|
113
|
-
new WhereOptimizer(schema.model, new ConditionOptimizer()))
|
|
117
|
+
new WhereOptimizer(schema.model, new ConditionOptimizer(), this.whereOptimizerOptions))
|
|
114
118
|
.addService('whereBuilder', ({ joinBuilder, conditionBuilder, pathFactory, whereOptimized, schema }) =>
|
|
115
119
|
new WhereBuilder(
|
|
116
120
|
schema.model,
|
|
@@ -168,8 +172,8 @@ export class ExecutionContainerFactory {
|
|
|
168
172
|
new JunctionTableManager(schema.model, predicateFactory, whereBuilder, connectJunctionHandler, disconnectJunctionHandler, pathFactory))
|
|
169
173
|
.addService('deleteExecutor', ({ predicateFactory, updateBuilderFactory, whereBuilder, pathFactory, schema }) =>
|
|
170
174
|
new DeleteExecutor(schema.model, predicateFactory, whereBuilder, updateBuilderFactory, pathFactory))
|
|
171
|
-
.addService('updater', ({
|
|
172
|
-
new Updater(schema.model,
|
|
175
|
+
.addService('updater', ({ updateBuilderFactory, schema }) =>
|
|
176
|
+
new Updater(schema.model, updateBuilderFactory))
|
|
173
177
|
.addService('inserter', ({ insertBuilderFactory, providers, schema, schemaDatabaseMetadata }) =>
|
|
174
178
|
new Inserter(schema.model, schemaDatabaseMetadata, insertBuilderFactory, providers, { uuidVersion: schema.settings.content?.uuidVersion }))
|
|
175
179
|
.addService('mapperFactory', ({ predicatesInjector, selectBuilderFactory, uniqueWhereExpander, whereBuilder, junctionTableManager, deleteExecutor, updater, inserter, pathFactory, providers, schema, schemaDatabaseMetadata }) => {
|
package/src/index.ts
CHANGED
package/src/mapper/Result.ts
CHANGED
|
@@ -178,7 +178,7 @@ export class MutationEntryNotFoundError implements MutationResultInterface {
|
|
|
178
178
|
hints: MutationResultHint[] = []
|
|
179
179
|
message: string
|
|
180
180
|
|
|
181
|
-
constructor(public readonly paths: Path[], public readonly where: Input.UniqueWhere | Input.
|
|
181
|
+
constructor(public readonly paths: Path[], public readonly where: Input.UniqueWhere | Input.OptionalWhere) {
|
|
182
182
|
this.message = 'for input ' + JSON.stringify(where)
|
|
183
183
|
}
|
|
184
184
|
}
|
|
@@ -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
|
|
@@ -49,12 +49,18 @@ export class ConditionBuilder {
|
|
|
49
49
|
gt: (builder, value) => builder.compare(columnIdentifier, Operator.gt, value),
|
|
50
50
|
gte: (builder, value) => builder.compare(columnIdentifier, Operator.gte, value),
|
|
51
51
|
|
|
52
|
-
includes: (builder, value) => {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
includes: (builder, value: any) => {
|
|
53
|
+
if (columnType.type === Model.ColumnType.Json) {
|
|
54
|
+
// For JSON columns, use @> operator to check if JSON contains the value
|
|
55
|
+
return builder.raw(`${formatColumnIdentifier(columnIdentifier)} @> ?::jsonb`, JSON.stringify(value))
|
|
56
|
+
} else {
|
|
57
|
+
// For array columns, use @> operator with array casting
|
|
58
|
+
const cast = columnType.type === Model.ColumnType.Enum
|
|
59
|
+
? `${Compiler.SCHEMA_PLACEHOLDER}."${columnType.columnType}"`
|
|
60
|
+
: columnType.columnType
|
|
56
61
|
|
|
57
|
-
|
|
62
|
+
return builder.raw(`${formatColumnIdentifier(columnIdentifier)} @> ARRAY[?]::${cast}[]`, value)
|
|
63
|
+
}
|
|
58
64
|
},
|
|
59
65
|
maxLength: (builder, value) => builder.raw(`array_length(${formatColumnIdentifier(columnIdentifier)}, 1) <= ?`, value),
|
|
60
66
|
minLength: (builder, value) => builder.raw(`array_length(${formatColumnIdentifier(columnIdentifier)}, 1) >= ?`, value),
|
|
@@ -18,16 +18,25 @@ export interface WhereOptimizationHints {
|
|
|
18
18
|
|
|
19
19
|
type OptimizedOperand = Input.OptionalWhere | undefined | boolean
|
|
20
20
|
|
|
21
|
+
export type WhereOptimizerOptions = {
|
|
22
|
+
disable?: boolean
|
|
23
|
+
maxCrossOptimizationInput?: number
|
|
24
|
+
}
|
|
25
|
+
|
|
21
26
|
export class WhereOptimizer {
|
|
22
27
|
private static eliminableRelations = new Set<Model.AnyRelationContext['type']>(['oneHasMany', 'oneHasOneInverse', 'oneHasOneOwning'])
|
|
23
28
|
|
|
24
29
|
constructor(
|
|
25
30
|
private readonly model: Model.Schema,
|
|
26
31
|
private readonly conditionOptimizer: ConditionOptimizer,
|
|
32
|
+
private readonly options?: WhereOptimizerOptions,
|
|
27
33
|
) {
|
|
28
34
|
}
|
|
29
35
|
|
|
30
36
|
public optimize(where: Input.OptionalWhere, entity: Model.Entity, { relationPath = [], evaluatedPredicates = [] }: WhereOptimizationHints = {}): Input.OptionalWhere {
|
|
37
|
+
if (this.options?.disable) {
|
|
38
|
+
return where
|
|
39
|
+
}
|
|
31
40
|
let processedRelationPath: ExtendedRelationContext[] = []
|
|
32
41
|
for (const i in relationPath) {
|
|
33
42
|
const el = relationPath[i]
|
|
@@ -134,7 +143,7 @@ export class WhereOptimizer {
|
|
|
134
143
|
private crossOptimize(operands: Input.OptionalWhere[], entity: Model.Entity, replacement: Input.Condition, relationPath: ExtendedRelationContext[]): (Input.OptionalWhere | boolean)[] {
|
|
135
144
|
let result: (Input.OptionalWhere | boolean)[] = operands
|
|
136
145
|
let copied = false
|
|
137
|
-
const count = result.length
|
|
146
|
+
const count = Math.min(result.length, this.options?.maxCrossOptimizationInput ?? 50)
|
|
138
147
|
for (let i = 0; i < count; i++) {
|
|
139
148
|
for (let j = 0; j < count; j++) {
|
|
140
149
|
const a = result[j]
|
|
@@ -1,21 +1,17 @@
|
|
|
1
1
|
import { SqlUpdateInputProcessor, SqlUpdateInputProcessorResult } from './SqlUpdateInputProcessor'
|
|
2
2
|
import { UpdateInputVisitor } from '../../inputProcessing'
|
|
3
3
|
import { Input, Model } from '@contember/schema'
|
|
4
|
-
import { PredicateFactory } from '../../acl'
|
|
5
4
|
import { UpdateBuilderFactory } from './UpdateBuilderFactory'
|
|
6
5
|
import { Mapper } from '../Mapper'
|
|
7
6
|
import { acceptFieldVisitor } from '@contember/schema-utils'
|
|
8
|
-
import { MutationNoResultError, MutationNothingToDo, MutationResultList, MutationUpdateOk, NothingToDoReason } from '../Result'
|
|
7
|
+
import { MutationEntryNotFoundError, MutationNoResultError, MutationNothingToDo, MutationResultList, MutationUpdateOk, NothingToDoReason } from '../Result'
|
|
9
8
|
import { UpdateBuilder } from './UpdateBuilder'
|
|
10
9
|
import { rowDataToFieldValues } from '../ColumnValue'
|
|
11
|
-
import { DatabaseMetadata } from '@contember/database'
|
|
12
10
|
import { MapperInput } from '../types'
|
|
13
11
|
|
|
14
12
|
export class Updater {
|
|
15
13
|
constructor(
|
|
16
14
|
private readonly schema: Model.Schema,
|
|
17
|
-
private readonly schemaDatabaseMetadata: DatabaseMetadata,
|
|
18
|
-
private readonly predicateFactory: PredicateFactory,
|
|
19
15
|
private readonly updateBuilderFactory: UpdateBuilderFactory,
|
|
20
16
|
) {}
|
|
21
17
|
|
|
@@ -66,6 +62,21 @@ export class Updater {
|
|
|
66
62
|
const result = await updateBuilder.execute(mapper)
|
|
67
63
|
|
|
68
64
|
if (!result.executed) {
|
|
65
|
+
if (filter && Object.keys(filter).length > 0) {
|
|
66
|
+
// direct update was not invoked, but we still need to check if the row matches the filter
|
|
67
|
+
const where: Input.OptionalWhere = {
|
|
68
|
+
and: [
|
|
69
|
+
filter,
|
|
70
|
+
{
|
|
71
|
+
[entity.primary]: { eq: primaryValue },
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
}
|
|
75
|
+
const count = await mapper.count(entity, where)
|
|
76
|
+
if (!count) {
|
|
77
|
+
return [new MutationEntryNotFoundError([], where)]
|
|
78
|
+
}
|
|
79
|
+
}
|
|
69
80
|
resultList.unshift(new MutationNothingToDo([], NothingToDoReason.noData))
|
|
70
81
|
} else if (result.affectedRows !== 1) {
|
|
71
82
|
return [new MutationNoResultError([])]
|
|
@@ -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
|
}
|
|
@@ -60,6 +60,9 @@ export class ConditionTypeProvider {
|
|
|
60
60
|
conditions.lte = { type: type }
|
|
61
61
|
conditions.gt = { type: type }
|
|
62
62
|
conditions.gte = { type: type }
|
|
63
|
+
} else {
|
|
64
|
+
// For JSON columns, add the includes operator
|
|
65
|
+
conditions.includes = { type: type }
|
|
63
66
|
}
|
|
64
67
|
if (column.type === Model.ColumnType.String) {
|
|
65
68
|
conditions.contains = { type: GraphQLString }
|
|
@@ -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
|
+
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { test } from 'bun:test'
|
|
2
|
-
import { execute, sqlTransaction } from '../../../../src/test'
|
|
3
|
-
import { SchemaBuilder } from '@contember/schema-definition'
|
|
2
|
+
import { execute, failedTransaction, sqlTransaction } from '../../../../src/test'
|
|
3
|
+
import { c, createSchema, SchemaBuilder } from '@contember/schema-definition'
|
|
4
4
|
import { Model } from '@contember/schema'
|
|
5
5
|
import { GQL, SQL } from '../../../../src/tags'
|
|
6
6
|
import { testUuid } from '../../../../src/testUuid'
|
|
@@ -59,3 +59,52 @@ test('applies a filter', async () => {
|
|
|
59
59
|
})
|
|
60
60
|
})
|
|
61
61
|
|
|
62
|
+
|
|
63
|
+
namespace FilterModel {
|
|
64
|
+
export class Article {
|
|
65
|
+
publishedAt = c.dateTimeColumn()
|
|
66
|
+
tags = c.manyHasMany(Tag)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export class Tag {
|
|
70
|
+
name = c.stringColumn()
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
test('applies a filter with only relation update', async () => {
|
|
75
|
+
await execute({
|
|
76
|
+
schema: createSchema(FilterModel).model,
|
|
77
|
+
query: GQL`mutation {
|
|
78
|
+
updateArticle(
|
|
79
|
+
by: {id: "${testUuid(1)}"},
|
|
80
|
+
filter: {publishedAt: {isNull: false}},
|
|
81
|
+
data: {tags: {connect: {id: "${testUuid(2)}"}}}
|
|
82
|
+
) {
|
|
83
|
+
ok
|
|
84
|
+
errorMessage
|
|
85
|
+
}
|
|
86
|
+
}`,
|
|
87
|
+
executes: [
|
|
88
|
+
...failedTransaction([
|
|
89
|
+
{
|
|
90
|
+
sql: SQL`select "root_"."id" from "public"."article" as "root_" where "root_"."id" = ?`,
|
|
91
|
+
parameters: [testUuid(1)],
|
|
92
|
+
response: { rows: [{ id: testUuid(1) }] },
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
sql: SQL`select count(*) as "row_count" from "public"."article" as "root_" where not("root_"."published_at" is null) and "root_"."id" = ?`,
|
|
96
|
+
parameters: [testUuid(1)],
|
|
97
|
+
response: { rows: [{ row_count: 0 }] },
|
|
98
|
+
},
|
|
99
|
+
]),
|
|
100
|
+
],
|
|
101
|
+
return: {
|
|
102
|
+
data: {
|
|
103
|
+
updateArticle: {
|
|
104
|
+
ok: false,
|
|
105
|
+
errorMessage: `Execution has failed:\nunknown field: NotFoundOrDenied (for input {\"and\":[{\"publishedAt\":{\"isNull\":false}},{\"id\":{\"eq\":\"123e4567-e89b-12d3-a456-000000000001\"}}]})`,
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
})
|
|
110
|
+
})
|
package/tests/src/test.ts
CHANGED
|
@@ -113,6 +113,7 @@ export const execute = async (test: Test) => {
|
|
|
113
113
|
stage: { id: '00000000-0000-0000-0000-000000000000', slug: 'live' },
|
|
114
114
|
project: { slug: 'test' },
|
|
115
115
|
schemaDatabaseMetadata: emptyDatabaseMetadata,
|
|
116
|
+
userInfo: { ipAddress: null, userAgent: null },
|
|
116
117
|
}),
|
|
117
118
|
timer: (label: any, cb: any) => cb(),
|
|
118
119
|
},
|