@contember/engine-content-api 2.1.0-alpha.2 → 2.1.0-alpha.21

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 (60) hide show
  1. package/dist/development/src/ExecutionContainer.cjs +1 -1
  2. package/dist/development/src/ExecutionContainer.cjs.map +1 -1
  3. package/dist/development/src/ExecutionContainer.js +1 -1
  4. package/dist/development/src/ExecutionContainer.js.map +1 -1
  5. package/dist/development/src/mapper/Result.cjs +1 -1
  6. package/dist/development/src/mapper/Result.cjs.map +1 -1
  7. package/dist/development/src/mapper/Result.js +1 -1
  8. package/dist/development/src/mapper/Result.js.map +1 -1
  9. package/dist/development/src/mapper/update/Updater.cjs +15 -3
  10. package/dist/development/src/mapper/update/Updater.cjs.map +1 -1
  11. package/dist/development/src/mapper/update/Updater.js +16 -4
  12. package/dist/development/src/mapper/update/Updater.js.map +1 -1
  13. package/dist/development/src/resolvers/RefreshViewResolver.cjs +3 -2
  14. package/dist/development/src/resolvers/RefreshViewResolver.cjs.map +1 -1
  15. package/dist/development/src/resolvers/RefreshViewResolver.js +3 -2
  16. package/dist/development/src/resolvers/RefreshViewResolver.js.map +1 -1
  17. package/dist/development/src/schema/RefreshViewMutationProvider.cjs +9 -2
  18. package/dist/development/src/schema/RefreshViewMutationProvider.cjs.map +1 -1
  19. package/dist/development/src/schema/RefreshViewMutationProvider.js +10 -3
  20. package/dist/development/src/schema/RefreshViewMutationProvider.js.map +1 -1
  21. package/dist/production/src/ExecutionContainer.cjs +1 -1
  22. package/dist/production/src/ExecutionContainer.cjs.map +1 -1
  23. package/dist/production/src/ExecutionContainer.js +1 -1
  24. package/dist/production/src/ExecutionContainer.js.map +1 -1
  25. package/dist/production/src/mapper/Result.cjs +1 -1
  26. package/dist/production/src/mapper/Result.cjs.map +1 -1
  27. package/dist/production/src/mapper/Result.js +1 -1
  28. package/dist/production/src/mapper/Result.js.map +1 -1
  29. package/dist/production/src/mapper/update/Updater.cjs +15 -3
  30. package/dist/production/src/mapper/update/Updater.cjs.map +1 -1
  31. package/dist/production/src/mapper/update/Updater.js +16 -4
  32. package/dist/production/src/mapper/update/Updater.js.map +1 -1
  33. package/dist/production/src/resolvers/RefreshViewResolver.cjs +3 -2
  34. package/dist/production/src/resolvers/RefreshViewResolver.cjs.map +1 -1
  35. package/dist/production/src/resolvers/RefreshViewResolver.js +3 -2
  36. package/dist/production/src/resolvers/RefreshViewResolver.js.map +1 -1
  37. package/dist/production/src/schema/RefreshViewMutationProvider.cjs +9 -2
  38. package/dist/production/src/schema/RefreshViewMutationProvider.cjs.map +1 -1
  39. package/dist/production/src/schema/RefreshViewMutationProvider.js +10 -3
  40. package/dist/production/src/schema/RefreshViewMutationProvider.js.map +1 -1
  41. package/dist/tests/cases/integration/graphQlRequests/insert/subOperationFail.test.d.ts +2 -0
  42. package/dist/tests/cases/integration/graphQlRequests/insert/subOperationFail.test.d.ts.map +1 -0
  43. package/dist/tests/tsconfig.tsbuildinfo +1 -1
  44. package/dist/types/mapper/Result.d.ts +2 -2
  45. package/dist/types/mapper/Result.d.ts.map +1 -1
  46. package/dist/types/mapper/update/Updater.d.ts +1 -5
  47. package/dist/types/mapper/update/Updater.d.ts.map +1 -1
  48. package/dist/types/resolvers/RefreshViewResolver.d.ts +3 -1
  49. package/dist/types/resolvers/RefreshViewResolver.d.ts.map +1 -1
  50. package/dist/types/schema/RefreshViewMutationProvider.d.ts.map +1 -1
  51. package/dist/types/tsconfig.tsbuildinfo +1 -1
  52. package/graphql.codegen.yml +1 -1
  53. package/package.json +10 -10
  54. package/src/ExecutionContainer.ts +2 -2
  55. package/src/mapper/Result.ts +2 -2
  56. package/src/mapper/update/Updater.ts +16 -5
  57. package/src/resolvers/RefreshViewResolver.ts +3 -3
  58. package/src/schema/RefreshViewMutationProvider.ts +9 -2
  59. package/tests/cases/integration/graphQlRequests/insert/subOperationFail.test.ts +105 -0
  60. package/tests/cases/integration/graphQlRequests/update/additionalFilter.test.ts +51 -2
@@ -12,4 +12,4 @@ generates:
12
12
  - "typescript-operations"
13
13
  hooks:
14
14
  afterAllFileWrite:
15
- - bun run -T eslint --fix
15
+ - bun run eslint --fix
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contember/engine-content-api",
3
- "version": "2.1.0-alpha.2",
3
+ "version": "2.1.0-alpha.21",
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.2",
30
- "@contember/dic": "2.1.0-alpha.2",
31
- "@contember/graphql-utils": "2.1.0-alpha.2",
32
- "@contember/logger": "2.1.0-alpha.2",
33
- "@contember/schema": "2.1.0-alpha.2",
34
- "@contember/schema-definition": "2.1.0-alpha.2",
35
- "@contember/schema-utils": "2.1.0-alpha.2",
29
+ "@contember/database": "2.1.0-alpha.21",
30
+ "@contember/dic": "2.1.0-alpha.21",
31
+ "@contember/graphql-utils": "2.1.0-alpha.21",
32
+ "@contember/logger": "2.1.0-alpha.21",
33
+ "@contember/schema": "2.1.0-alpha.21",
34
+ "@contember/schema-definition": "2.1.0-alpha.21",
35
+ "@contember/schema-utils": "2.1.0-alpha.21",
36
36
  "fast-deep-equal": "^3.1.3"
37
37
  },
38
38
  "devDependencies": {
39
- "@contember/database-tester": "2.1.0-alpha.2",
40
- "@contember/schema-definition": "2.1.0-alpha.2",
39
+ "@contember/database-tester": "2.1.0-alpha.21",
40
+ "@contember/schema-definition": "2.1.0-alpha.21",
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', ({ predicateFactory, updateBuilderFactory, schema, schemaDatabaseMetadata }) =>
172
- new Updater(schema.model, schemaDatabaseMetadata, predicateFactory, updateBuilderFactory))
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 }) => {
@@ -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.Where) {
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
@@ -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
- await mapper.db.query(`REFRESH MATERIALIZED VIEW ${wrapIdentifier(entityModel.tableName)}`)
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
+
@@ -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
+ })