@contember/engine-content-api 2.1.0-alpha.20 → 2.1.0-alpha.22
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/ExecutionContainer.cjs +1 -1
- package/dist/development/src/ExecutionContainer.cjs.map +1 -1
- package/dist/development/src/ExecutionContainer.js +1 -1
- package/dist/development/src/ExecutionContainer.js.map +1 -1
- package/dist/development/src/mapper/Result.cjs.map +1 -1
- package/dist/development/src/mapper/Result.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/production/src/ExecutionContainer.cjs +1 -1
- package/dist/production/src/ExecutionContainer.cjs.map +1 -1
- package/dist/production/src/ExecutionContainer.js +1 -1
- package/dist/production/src/ExecutionContainer.js.map +1 -1
- package/dist/production/src/mapper/Result.cjs.map +1 -1
- package/dist/production/src/mapper/Result.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/tests/tsconfig.tsbuildinfo +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/update/Updater.d.ts +1 -5
- package/dist/types/mapper/update/Updater.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +10 -10
- package/src/ExecutionContainer.ts +2 -2
- package/src/mapper/Result.ts +1 -1
- package/src/mapper/update/Updater.ts +16 -5
- package/tests/cases/integration/graphQlRequests/update/additionalFilter.test.ts +51 -2
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.22",
|
|
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.22",
|
|
30
|
+
"@contember/dic": "2.1.0-alpha.22",
|
|
31
|
+
"@contember/graphql-utils": "2.1.0-alpha.22",
|
|
32
|
+
"@contember/logger": "2.1.0-alpha.22",
|
|
33
|
+
"@contember/schema": "2.1.0-alpha.22",
|
|
34
|
+
"@contember/schema-definition": "2.1.0-alpha.22",
|
|
35
|
+
"@contember/schema-utils": "2.1.0-alpha.22",
|
|
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.22",
|
|
40
|
+
"@contember/schema-definition": "2.1.0-alpha.22",
|
|
41
41
|
"@types/node": "^20.17.22",
|
|
42
42
|
"graphql": "^16.9.0",
|
|
43
43
|
"pg": "^8.12.0"
|
|
@@ -168,8 +168,8 @@ export class ExecutionContainerFactory {
|
|
|
168
168
|
new JunctionTableManager(schema.model, predicateFactory, whereBuilder, connectJunctionHandler, disconnectJunctionHandler, pathFactory))
|
|
169
169
|
.addService('deleteExecutor', ({ predicateFactory, updateBuilderFactory, whereBuilder, pathFactory, schema }) =>
|
|
170
170
|
new DeleteExecutor(schema.model, predicateFactory, whereBuilder, updateBuilderFactory, pathFactory))
|
|
171
|
-
.addService('updater', ({
|
|
172
|
-
new Updater(schema.model,
|
|
171
|
+
.addService('updater', ({ updateBuilderFactory, schema }) =>
|
|
172
|
+
new Updater(schema.model, updateBuilderFactory))
|
|
173
173
|
.addService('inserter', ({ insertBuilderFactory, providers, schema, schemaDatabaseMetadata }) =>
|
|
174
174
|
new Inserter(schema.model, schemaDatabaseMetadata, insertBuilderFactory, providers, { uuidVersion: schema.settings.content?.uuidVersion }))
|
|
175
175
|
.addService('mapperFactory', ({ predicatesInjector, selectBuilderFactory, uniqueWhereExpander, whereBuilder, junctionTableManager, deleteExecutor, updater, inserter, pathFactory, providers, schema, schemaDatabaseMetadata }) => {
|
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
|
}
|
|
@@ -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,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
|
+
})
|