@contember/engine-content-api 1.0.0-rc.13 → 1.0.0-rc.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": "v1.0.0-rc.13",
3
+ "version": "1.0.0-rc.16",
4
4
  "license": "Apache-2.0",
5
5
  "main": "dist/src/index.js",
6
6
  "typings": "dist/src/index.d.ts",
@@ -10,19 +10,19 @@
10
10
  "test": "uvu dist/tests/cases/ \\.js$"
11
11
  },
12
12
  "dependencies": {
13
- "@contember/database": "^v1.0.0-rc.13",
14
- "@contember/dic": "^v1.0.0-rc.13",
15
- "@contember/engine-common": "^v1.0.0-rc.13",
16
- "@contember/graphql-utils": "^v1.0.0-rc.13",
17
- "@contember/schema": "^v1.0.0-rc.13",
18
- "@contember/schema-utils": "^v1.0.0-rc.13",
13
+ "@contember/database": "^1.0.0-rc.16",
14
+ "@contember/dic": "^1.0.0-rc.16",
15
+ "@contember/engine-common": "^1.0.0-rc.16",
16
+ "@contember/graphql-utils": "^1.0.0-rc.16",
17
+ "@contember/schema": "^1.0.0-rc.16",
18
+ "@contember/schema-utils": "^1.0.0-rc.16",
19
19
  "@graphql-tools/schema": "^7.1.5",
20
20
  "graphql-tag": "^2.12.5"
21
21
  },
22
22
  "devDependencies": {
23
- "@contember/database-tester": "^v1.0.0-rc.13",
24
- "@contember/engine-api-tester": "^v1.0.0-rc.13",
25
- "@contember/schema-definition": "^v1.0.0-rc.13",
23
+ "@contember/database-tester": "^1.0.0-rc.16",
24
+ "@contember/engine-api-tester": "^1.0.0-rc.16",
25
+ "@contember/schema-definition": "^1.0.0-rc.16",
26
26
  "@graphql-codegen/cli": "^1.15.2",
27
27
  "@graphql-codegen/typescript": "^1.15.2",
28
28
  "@graphql-codegen/typescript-operations": "^1.15.2",
@@ -378,12 +378,13 @@ export class MutationResolver {
378
378
  if (errorResponse) {
379
379
  return errorResponse
380
380
  }
381
- const primary = getInsertPrimary(result) || getUpdatePrimary(result)
382
- if (!primary) {
381
+ const primary = getInsertPrimary(result)
382
+ const byResolved = primary ? { [entity.primary]: primary } : input.by
383
+ if (!byResolved) {
383
384
  throw new ImplementationException('MutationResolver::resolveUpsertInternal does not handle result properly')
384
385
  }
385
386
 
386
- const nodes = await this.resolveResultNodes(mapper, entity, { [entity.primary]: primary }, queryAst)
387
+ const nodes = await this.resolveResultNodes(mapper, entity, byResolved, queryAst)
387
388
  return {
388
389
  ok: true,
389
390
  validation: {
@@ -98,8 +98,54 @@ test('upsert author (exists)', async () => {
98
98
  response: { rowCount: 1 },
99
99
  },
100
100
  {
101
- sql: SQL`select "root_"."id" as "root_id" from "public"."author" as "root_" where "root_"."id" = ?`,
102
- parameters: [testUuid(2)],
101
+ sql: SQL`select "root_"."id" as "root_id" from "public"."author" as "root_" where "root_"."slug" = ?`,
102
+ parameters: ['john-doe'],
103
+ response: { rows: [{ root_id: testUuid(2) }] },
104
+ },
105
+ ]),
106
+ ],
107
+ return: {
108
+ data: {
109
+ upsertAuthor: {
110
+ ok: true,
111
+ node: {
112
+ id: testUuid(2),
113
+ },
114
+ },
115
+ },
116
+ },
117
+ })
118
+ })
119
+
120
+ test('upsert author (exists) with noop update)', async () => {
121
+ await execute({
122
+ schema: new SchemaBuilder()
123
+ .entity('Author', entity =>
124
+ entity
125
+ .column('name', c => c.type(Model.ColumnType.String))
126
+ .column('slug', c => c.type(Model.ColumnType.String).unique()),
127
+ )
128
+ .buildSchema(),
129
+ query: GQL`
130
+ mutation {
131
+ upsertAuthor(by: {slug: "john-doe"}, update: {}, create: {slug: "john-doe", name: "John Doe"}) {
132
+ ok
133
+ node {
134
+ id
135
+ }
136
+ }
137
+ }`,
138
+ executes: [
139
+ ...sqlTransaction([
140
+ {
141
+ sql: SQL`select "root_"."id"
142
+ from "public"."author" as "root_" where "root_"."slug" = ?`,
143
+ parameters: ['john-doe'],
144
+ response: { rows: [{ id: testUuid(2) }] },
145
+ },
146
+ {
147
+ sql: SQL`select "root_"."id" as "root_id" from "public"."author" as "root_" where "root_"."slug" = ?`,
148
+ parameters: ['john-doe'],
103
149
  response: { rows: [{ root_id: testUuid(2) }] },
104
150
  },
105
151
  ]),
@@ -117,3 +163,4 @@ test('upsert author (exists)', async () => {
117
163
  })
118
164
  })
119
165
  test.run()
166
+