@contember/engine-content-api 2.1.0-rc.6 → 2.1.0-rc.8
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/CLAUDE.md +2 -0
- package/dist/development/src/mapper/ErrorUtils.cjs +7 -1
- package/dist/development/src/mapper/ErrorUtils.cjs.map +1 -1
- package/dist/development/src/mapper/ErrorUtils.js +7 -1
- package/dist/development/src/mapper/ErrorUtils.js.map +1 -1
- package/dist/development/src/mapper/Mapper.cjs +2 -1
- package/dist/development/src/mapper/Mapper.cjs.map +1 -1
- package/dist/development/src/mapper/Mapper.js +2 -1
- package/dist/development/src/mapper/Mapper.js.map +1 -1
- package/dist/development/src/mapper/select/Path.cjs +23 -3
- package/dist/development/src/mapper/select/Path.cjs.map +1 -1
- package/dist/development/src/mapper/select/Path.js +23 -3
- package/dist/development/src/mapper/select/Path.js.map +1 -1
- package/dist/development/src/mapper/select/SelectBuilder.cjs +13 -10
- package/dist/development/src/mapper/select/SelectBuilder.cjs.map +1 -1
- package/dist/development/src/mapper/select/SelectBuilder.js +13 -10
- package/dist/development/src/mapper/select/SelectBuilder.js.map +1 -1
- package/dist/development/src/mapper/select/handlers/FieldsVisitor.cjs +1 -1
- package/dist/development/src/mapper/select/handlers/FieldsVisitor.cjs.map +1 -1
- package/dist/development/src/mapper/select/handlers/FieldsVisitor.js +1 -1
- package/dist/development/src/mapper/select/handlers/FieldsVisitor.js.map +1 -1
- package/dist/development/src/mapper/select/handlers/MetaHandler.cjs +4 -3
- package/dist/development/src/mapper/select/handlers/MetaHandler.cjs.map +1 -1
- package/dist/development/src/mapper/select/handlers/MetaHandler.js +4 -3
- package/dist/development/src/mapper/select/handlers/MetaHandler.js.map +1 -1
- package/dist/development/src/resolvers/MutationResolver.cjs +1 -0
- package/dist/development/src/resolvers/MutationResolver.cjs.map +1 -1
- package/dist/development/src/resolvers/MutationResolver.js +1 -0
- package/dist/development/src/resolvers/MutationResolver.js.map +1 -1
- package/dist/production/src/mapper/ErrorUtils.cjs +7 -1
- package/dist/production/src/mapper/ErrorUtils.cjs.map +1 -1
- package/dist/production/src/mapper/ErrorUtils.js +7 -1
- package/dist/production/src/mapper/ErrorUtils.js.map +1 -1
- package/dist/production/src/mapper/Mapper.cjs +2 -1
- package/dist/production/src/mapper/Mapper.cjs.map +1 -1
- package/dist/production/src/mapper/Mapper.js +2 -1
- package/dist/production/src/mapper/Mapper.js.map +1 -1
- package/dist/production/src/mapper/select/Path.cjs +23 -3
- package/dist/production/src/mapper/select/Path.cjs.map +1 -1
- package/dist/production/src/mapper/select/Path.js +23 -3
- package/dist/production/src/mapper/select/Path.js.map +1 -1
- package/dist/production/src/mapper/select/SelectBuilder.cjs +13 -10
- package/dist/production/src/mapper/select/SelectBuilder.cjs.map +1 -1
- package/dist/production/src/mapper/select/SelectBuilder.js +13 -10
- package/dist/production/src/mapper/select/SelectBuilder.js.map +1 -1
- package/dist/production/src/mapper/select/handlers/FieldsVisitor.cjs +1 -1
- package/dist/production/src/mapper/select/handlers/FieldsVisitor.cjs.map +1 -1
- package/dist/production/src/mapper/select/handlers/FieldsVisitor.js +1 -1
- package/dist/production/src/mapper/select/handlers/FieldsVisitor.js.map +1 -1
- package/dist/production/src/mapper/select/handlers/MetaHandler.cjs +4 -3
- package/dist/production/src/mapper/select/handlers/MetaHandler.cjs.map +1 -1
- package/dist/production/src/mapper/select/handlers/MetaHandler.js +4 -3
- package/dist/production/src/mapper/select/handlers/MetaHandler.js.map +1 -1
- package/dist/production/src/resolvers/MutationResolver.cjs +1 -0
- package/dist/production/src/resolvers/MutationResolver.cjs.map +1 -1
- package/dist/production/src/resolvers/MutationResolver.js +1 -0
- package/dist/production/src/resolvers/MutationResolver.js.map +1 -1
- package/dist/tests/cases/integration/graphQlRequests/query/acl/internalColumnAliases.test.d.ts +2 -0
- package/dist/tests/cases/integration/graphQlRequests/query/acl/internalColumnAliases.test.d.ts.map +1 -0
- package/dist/tests/cases/integration/graphQlRequests/query/acl/mergedRolePredicate.test.d.ts +2 -0
- package/dist/tests/cases/integration/graphQlRequests/query/acl/mergedRolePredicate.test.d.ts.map +1 -0
- package/dist/tests/cases/integration/graphQlRequests/query/acl/nestedThroughPredicate.test.d.ts +2 -0
- package/dist/tests/cases/integration/graphQlRequests/query/acl/nestedThroughPredicate.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/internalColumnAliases.test.d.ts +2 -0
- package/dist/tests/cases/unit/internalColumnAliases.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/mutationSqlError.test.d.ts +2 -0
- package/dist/tests/cases/unit/mutationSqlError.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/pathAlias.test.d.ts +2 -0
- package/dist/tests/cases/unit/pathAlias.test.d.ts.map +1 -0
- package/dist/tests/src/test.d.ts +1 -0
- package/dist/tests/src/test.d.ts.map +1 -1
- package/dist/tests/tsconfig.tsbuildinfo +1 -1
- package/dist/types/mapper/ErrorUtils.d.ts.map +1 -1
- package/dist/types/mapper/select/Path.d.ts +1 -0
- package/dist/types/mapper/select/Path.d.ts.map +1 -1
- package/dist/types/mapper/select/SelectBuilder.d.ts.map +1 -1
- package/dist/types/mapper/select/SelectExecutionHandler.d.ts +11 -1
- package/dist/types/mapper/select/SelectExecutionHandler.d.ts.map +1 -1
- package/dist/types/mapper/select/handlers/MetaHandler.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -9
- package/src/mapper/ErrorUtils.ts +11 -1
- package/src/mapper/Mapper.ts +1 -1
- package/src/mapper/select/Path.ts +25 -5
- package/src/mapper/select/SelectBuilder.ts +22 -11
- package/src/mapper/select/SelectExecutionHandler.ts +9 -1
- package/src/mapper/select/handlers/FieldsVisitor.ts +1 -1
- package/src/mapper/select/handlers/MetaHandler.ts +8 -3
- package/tests/cases/bugs/bug102.test.ts +4 -4
- package/tests/cases/integration/graphQlRequests/delete/deleteById.test.ts +4 -3
- package/tests/cases/integration/graphQlRequests/query/acl/differentRowAndFieldPredicate.test.ts +4 -4
- package/tests/cases/integration/graphQlRequests/query/acl/fieldRestrictedByLocale.test.ts +12 -10
- package/tests/cases/integration/graphQlRequests/query/acl/internalColumnAliases.test.ts +326 -0
- package/tests/cases/integration/graphQlRequests/query/acl/mergedRolePredicate.test.ts +124 -0
- package/tests/cases/integration/graphQlRequests/query/acl/nestedPredicate.test.ts +7 -6
- package/tests/cases/integration/graphQlRequests/query/acl/nestedThroughPredicate.test.ts +345 -0
- package/tests/cases/integration/graphQlRequests/query/acl/predicateElimination.test.ts +25 -23
- package/tests/cases/integration/graphQlRequests/query/acl/relationAcl.test.ts +12 -9
- package/tests/cases/integration/graphQlRequests/query/acl/rowPredicateSubset.test.ts +6 -6
- package/tests/cases/integration/graphQlRequests/query/filter/backReferencedFilter.test.ts +3 -1
- package/tests/cases/integration/graphQlRequests/query/graphqlFeatures/alias.test.ts +2 -2
- package/tests/cases/integration/graphQlRequests/query/graphqlFeatures/fragments.test.ts +8 -8
- package/tests/cases/integration/graphQlRequests/query/misc/reducedHasMany.test.ts +10 -10
- package/tests/cases/integration/graphQlRequests/query/pagination/hasManyLimit.test.ts +8 -8
- package/tests/cases/integration/graphQlRequests/query/pagination/paginate.test.ts +5 -4
- package/tests/cases/integration/graphQlRequests/query/pagination/paginateAliased.test.ts +5 -4
- package/tests/cases/integration/graphQlRequests/query/relations/advanced.test.ts +17 -8
- package/tests/cases/integration/graphQlRequests/query/relations/manyHasManyInverse.test.ts +6 -6
- package/tests/cases/integration/graphQlRequests/query/relations/manyHasManyOwning.test.ts +6 -6
- package/tests/cases/integration/graphQlRequests/query/relations/manyHasOne.test.ts +12 -9
- package/tests/cases/integration/graphQlRequests/query/relations/oneHasMany.test.ts +12 -12
- package/tests/cases/integration/graphQlRequests/query/relations/oneHasOneInverse.test.ts +6 -4
- package/tests/cases/integration/graphQlRequests/query/relations/oneHasOneOwner.test.ts +6 -4
- package/tests/cases/integration/graphQlRequests/query/sorting/defaultOrdering.test.ts +4 -4
- package/tests/cases/integration/graphQlRequests/query/sorting/randomSort.test.ts +5 -5
- package/tests/cases/integration/graphQlRequests/query/sorting/sortedHasMany.test.ts +2 -2
- package/tests/cases/integration/graphQlRequests/query/view/view.test.ts +6 -6
- package/tests/cases/unit/internalColumnAliases.test.ts +41 -0
- package/tests/cases/unit/mutationSqlError.test.ts +30 -0
- package/tests/cases/unit/pathAlias.test.ts +26 -0
- package/tests/src/test.ts +5 -1
|
@@ -30,7 +30,7 @@ test('Sites with settings (one-has-one owning)', async () => {
|
|
|
30
30
|
select
|
|
31
31
|
"root_"."id" as "root_id",
|
|
32
32
|
"root_"."name" as "root_name",
|
|
33
|
-
"root_"."setting_id" as "
|
|
33
|
+
"root_"."setting_id" as "root_$key_setting"
|
|
34
34
|
from "public"."site" as "root_"`,
|
|
35
35
|
|
|
36
36
|
response: {
|
|
@@ -38,12 +38,12 @@ test('Sites with settings (one-has-one owning)', async () => {
|
|
|
38
38
|
{
|
|
39
39
|
root_id: testUuid(1),
|
|
40
40
|
root_name: 'Site 1',
|
|
41
|
-
|
|
41
|
+
'root_$key_setting': testUuid(2),
|
|
42
42
|
},
|
|
43
43
|
{
|
|
44
44
|
root_id: testUuid(3),
|
|
45
45
|
root_name: 'Site 2',
|
|
46
|
-
|
|
46
|
+
'root_$key_setting': testUuid(4),
|
|
47
47
|
},
|
|
48
48
|
],
|
|
49
49
|
},
|
|
@@ -51,7 +51,7 @@ test('Sites with settings (one-has-one owning)', async () => {
|
|
|
51
51
|
{
|
|
52
52
|
sql: SQL`
|
|
53
53
|
select
|
|
54
|
-
"root_"."id" as "
|
|
54
|
+
"root_"."id" as "root_$index_id",
|
|
55
55
|
"root_"."id" as "root_id",
|
|
56
56
|
"root_"."url" as "root_url"
|
|
57
57
|
from "public"."site_setting" as "root_"
|
|
@@ -62,10 +62,12 @@ test('Sites with settings (one-has-one owning)', async () => {
|
|
|
62
62
|
rows: [
|
|
63
63
|
{
|
|
64
64
|
root_id: testUuid(2),
|
|
65
|
+
'root_$index_id': testUuid(2),
|
|
65
66
|
root_url: 'http://site1.cz',
|
|
66
67
|
},
|
|
67
68
|
{
|
|
68
69
|
root_id: testUuid(4),
|
|
70
|
+
'root_$index_id': testUuid(4),
|
|
69
71
|
root_url: 'http://site2.cz',
|
|
70
72
|
},
|
|
71
73
|
],
|
|
@@ -26,10 +26,10 @@ test('one has many - default ordering', async () => {
|
|
|
26
26
|
}`,
|
|
27
27
|
executes: [
|
|
28
28
|
{
|
|
29
|
-
sql: SQL`select "root_"."id" as "root_id", "root_"."id" as "
|
|
29
|
+
sql: SQL`select "root_"."id" as "root_id", "root_"."id" as "root_$key_id" from "public"."menu" as "root_"`,
|
|
30
30
|
parameters: [],
|
|
31
31
|
response: {
|
|
32
|
-
rows: [{ root_id: testUuid(1) }, { root_id: testUuid(2) }],
|
|
32
|
+
rows: [{ root_id: testUuid(1), 'root_$key_id': testUuid(1) }, { root_id: testUuid(2), 'root_$key_id': testUuid(2) }],
|
|
33
33
|
},
|
|
34
34
|
},
|
|
35
35
|
{
|
|
@@ -97,10 +97,10 @@ test('many has many - default ordering', async () => {
|
|
|
97
97
|
}`,
|
|
98
98
|
executes: [
|
|
99
99
|
{
|
|
100
|
-
sql: SQL`select "root_"."id" as "root_id", "root_"."id" as "
|
|
100
|
+
sql: SQL`select "root_"."id" as "root_id", "root_"."id" as "root_$key_id" from "public"."post" as "root_"`,
|
|
101
101
|
parameters: [],
|
|
102
102
|
response: {
|
|
103
|
-
rows: [{ root_id: testUuid(1) }, { root_id: testUuid(2) }],
|
|
103
|
+
rows: [{ root_id: testUuid(1), 'root_$key_id': testUuid(1) }, { root_id: testUuid(2), 'root_$key_id': testUuid(2) }],
|
|
104
104
|
},
|
|
105
105
|
},
|
|
106
106
|
{
|
|
@@ -114,13 +114,13 @@ test('sorts posts by random on has many relation', async () => {
|
|
|
114
114
|
sql: SQL`select
|
|
115
115
|
"root_"."id" as "root_id",
|
|
116
116
|
"root_"."title" as "root_title",
|
|
117
|
-
"root_"."id" as "
|
|
117
|
+
"root_"."id" as "root_$key_id"
|
|
118
118
|
from "public"."category" as "root_"`,
|
|
119
119
|
parameters: [],
|
|
120
120
|
response: {
|
|
121
121
|
rows: [
|
|
122
|
-
{ root_id: testUuid(1), root_title: 'Hello' },
|
|
123
|
-
{ root_id: testUuid(2), root_title: 'World' },
|
|
122
|
+
{ root_id: testUuid(1), 'root_$key_id': testUuid(1), root_title: 'Hello' },
|
|
123
|
+
{ root_id: testUuid(2), 'root_$key_id': testUuid(2), root_title: 'World' },
|
|
124
124
|
],
|
|
125
125
|
},
|
|
126
126
|
},
|
|
@@ -273,9 +273,9 @@ test('joins the has-many target for a field key that follows a random key', asyn
|
|
|
273
273
|
}`,
|
|
274
274
|
executes: [
|
|
275
275
|
{
|
|
276
|
-
sql: SQL`select "root_"."id" as "root_id", "root_"."id" as "
|
|
276
|
+
sql: SQL`select "root_"."id" as "root_id", "root_"."id" as "root_$key_id" from "public"."category" as "root_"`,
|
|
277
277
|
parameters: [],
|
|
278
|
-
response: { rows: [{ root_id: testUuid(1) }] },
|
|
278
|
+
response: { rows: [{ root_id: testUuid(1), 'root_$key_id': testUuid(1) }] },
|
|
279
279
|
},
|
|
280
280
|
{
|
|
281
281
|
sql: SQL`
|
|
@@ -22,10 +22,10 @@ test('Post with ordered locales', async () => {
|
|
|
22
22
|
{
|
|
23
23
|
sql: SQL`select
|
|
24
24
|
"root_"."id" as "root_id",
|
|
25
|
-
"root_"."id" as "
|
|
25
|
+
"root_"."id" as "root_$key_id"
|
|
26
26
|
from "public"."post" as "root_"`,
|
|
27
27
|
response: {
|
|
28
|
-
rows: [{ root_id: testUuid(1) }, { root_id: testUuid(2) }],
|
|
28
|
+
rows: [{ root_id: testUuid(1), 'root_$key_id': testUuid(1) }, { root_id: testUuid(2), 'root_$key_id': testUuid(2) }],
|
|
29
29
|
},
|
|
30
30
|
},
|
|
31
31
|
{
|
|
@@ -31,19 +31,19 @@ test('query a view through a relation', async () => {
|
|
|
31
31
|
}`,
|
|
32
32
|
executes: [
|
|
33
33
|
{
|
|
34
|
-
sql: SQL`select "root_"."name" as "root_name", "root_"."id" as "
|
|
34
|
+
sql: SQL`select "root_"."name" as "root_name", "root_"."id" as "root_$key_id", "root_"."id" as "root_id"
|
|
35
35
|
from "public"."author" as "root_"`,
|
|
36
36
|
response: {
|
|
37
37
|
rows: [
|
|
38
|
-
{ root_id: testUuid(1), root_name: 'John' },
|
|
39
|
-
{ root_id: testUuid(2), root_name: 'Jack' },
|
|
38
|
+
{ root_id: testUuid(1), 'root_$key_id': testUuid(1), root_name: 'John' },
|
|
39
|
+
{ root_id: testUuid(2), 'root_$key_id': testUuid(2), root_name: 'Jack' },
|
|
40
40
|
],
|
|
41
41
|
},
|
|
42
42
|
parameters: [],
|
|
43
43
|
},
|
|
44
44
|
{
|
|
45
45
|
sql: SQL`
|
|
46
|
-
select "root_"."author_id" as "
|
|
46
|
+
select "root_"."author_id" as "root_$index_author", "root_"."post_count" as "root_postCount", "root_"."id" as "root_id"
|
|
47
47
|
from "public"."author_stats" as "root_"
|
|
48
48
|
where "root_"."author_id" in (?, ?)`,
|
|
49
49
|
parameters: [testUuid(1), testUuid(2)],
|
|
@@ -51,12 +51,12 @@ test('query a view through a relation', async () => {
|
|
|
51
51
|
rows: [
|
|
52
52
|
{
|
|
53
53
|
root_id: null,
|
|
54
|
-
|
|
54
|
+
'root_$index_author': testUuid(1),
|
|
55
55
|
root_postCount: 2,
|
|
56
56
|
},
|
|
57
57
|
{
|
|
58
58
|
root_id: null,
|
|
59
|
-
|
|
59
|
+
'root_$index_author': testUuid(2),
|
|
60
60
|
root_postCount: 3,
|
|
61
61
|
},
|
|
62
62
|
],
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { describe, expect, it } from 'bun:test'
|
|
2
|
+
import { PathFactory } from '../../../src/mapper'
|
|
3
|
+
|
|
4
|
+
describe('internal column aliases', () => {
|
|
5
|
+
const internalAlias = (factory: PathFactory) => factory.create([]).for('rel').forInternal('predicate').for('x').alias
|
|
6
|
+
|
|
7
|
+
it('cannot be produced by a single client alias', () => {
|
|
8
|
+
const factory = new PathFactory()
|
|
9
|
+
expect(factory.create([]).for('rel___predicate_x').alias).not.toBe(internalAlias(factory))
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
it('cannot be produced by concatenated client aliases', () => {
|
|
13
|
+
const factory = new PathFactory()
|
|
14
|
+
const internal = internalAlias(factory)
|
|
15
|
+
for (const segments of [['rel', '__predicate', 'x'], ['rel_', '_predicate_x'], ['rel', '__predicate_x'], ['rel___predicate', 'x']]) {
|
|
16
|
+
expect(segments.reduce((path, segment) => path.for(segment), factory.create([])).alias).not.toBe(internal)
|
|
17
|
+
}
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
it('stays apart from a client alias after truncation', () => {
|
|
21
|
+
const factory = new PathFactory()
|
|
22
|
+
const name = 'p'.repeat(80)
|
|
23
|
+
const internal = factory.create([]).forInternal('predicate').for(name).alias
|
|
24
|
+
const client = factory.create([]).for(`__predicate_${name}`).alias
|
|
25
|
+
expect(internal.length).toBe(63)
|
|
26
|
+
expect(client.length).toBe(63)
|
|
27
|
+
expect(client).not.toBe(internal)
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
it('stays unique within the PostgreSQL byte limit for multi-byte names', () => {
|
|
31
|
+
const factory = new PathFactory()
|
|
32
|
+
const name = 'x' + 'é'.repeat(23)
|
|
33
|
+
// 63 and 64 bytes untruncated: PostgreSQL would cut the second to the first
|
|
34
|
+
const first = factory.create([]).forInternal('predicate').for(name).alias
|
|
35
|
+
const second = factory.create([]).forInternal('predicate').for(name + 'x').alias
|
|
36
|
+
const encoder = new TextEncoder()
|
|
37
|
+
expect(encoder.encode(first).length).toBe(63)
|
|
38
|
+
expect(encoder.encode(second).length).toBe(63)
|
|
39
|
+
expect(second).not.toBe(first)
|
|
40
|
+
})
|
|
41
|
+
})
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { describe, expect, it } from 'bun:test'
|
|
2
|
+
import { emptyDatabaseMetadata, QueryError } from '@contember/database'
|
|
3
|
+
import { createLogger, TestLoggerHandler, withLogger } from '@contember/logger'
|
|
4
|
+
import { emptySchema } from '@contember/schema-utils'
|
|
5
|
+
import { convertError, MutationSqlError } from '../../../src/mapper'
|
|
6
|
+
|
|
7
|
+
const convert = (code: string, message: string) => {
|
|
8
|
+
const error = new QueryError('select 1', [], Object.assign(new Error(message), { code }))
|
|
9
|
+
const handler = new TestLoggerHandler()
|
|
10
|
+
const result = withLogger(createLogger(handler), () => convertError(emptySchema.model, emptyDatabaseMetadata, error))
|
|
11
|
+
if (!(result instanceof MutationSqlError)) {
|
|
12
|
+
throw new Error('expected a MutationSqlError')
|
|
13
|
+
}
|
|
14
|
+
return { message: result.message, logged: handler.messages.map(it => it.error), error }
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
describe('mutation SQL error', () => {
|
|
18
|
+
it('returns a generic message for an error that can quote internal identifiers, and logs the original', () => {
|
|
19
|
+
const { message, logged, error } = convert('42702', 'column reference "root_$predicate_secretRule" is ambiguous')
|
|
20
|
+
expect(message).toBe('Database query failed')
|
|
21
|
+
expect(logged).toContain(error)
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
it('keeps the message of data, integrity and trigger errors', () => {
|
|
25
|
+
expect(convert('23514', 'new row for relation "order" violates check constraint "order_total_check"').message)
|
|
26
|
+
.toBe('new row for relation "order" violates check constraint "order_total_check"')
|
|
27
|
+
expect(convert('22001', 'value too long for type character varying(10)').message).toBe('value too long for type character varying(10)')
|
|
28
|
+
expect(convert('P0001', 'Order total must be positive').message).toBe('Order total must be positive')
|
|
29
|
+
})
|
|
30
|
+
})
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { describe, expect, it } from 'bun:test'
|
|
2
|
+
import { PathFactory } from '../../../src/mapper'
|
|
3
|
+
|
|
4
|
+
describe('select path aliases', () => {
|
|
5
|
+
it('keep engine-owned columns apart from field aliases after truncation', () => {
|
|
6
|
+
const factory = new PathFactory()
|
|
7
|
+
const name = 'p'.repeat(80)
|
|
8
|
+
const internal = factory.create([]).forInternal('predicate').for(name).alias
|
|
9
|
+
const field = factory.create([]).for(name).for(name).alias
|
|
10
|
+
expect(internal.length).toBe(63)
|
|
11
|
+
expect(field.length).toBe(63)
|
|
12
|
+
expect(field).not.toBe(internal)
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
it('stay unique within the PostgreSQL byte limit for multi-byte names', () => {
|
|
16
|
+
const factory = new PathFactory()
|
|
17
|
+
const name = 'x' + 'é'.repeat(23)
|
|
18
|
+
// 63 and 64 bytes untruncated: PostgreSQL would cut the second to the first
|
|
19
|
+
const first = factory.create([]).forInternal('predicate').for(name).alias
|
|
20
|
+
const second = factory.create([]).forInternal('predicate').for(name + 'x').alias
|
|
21
|
+
const encoder = new TextEncoder()
|
|
22
|
+
expect(encoder.encode(first).length).toBe(63)
|
|
23
|
+
expect(encoder.encode(second).length).toBe(63)
|
|
24
|
+
expect(second).not.toBe(first)
|
|
25
|
+
})
|
|
26
|
+
})
|
package/tests/src/test.ts
CHANGED
|
@@ -17,6 +17,7 @@ export interface Test {
|
|
|
17
17
|
settings?: Settings.Schema
|
|
18
18
|
validation?: Validation.Schema
|
|
19
19
|
permissions?: Acl.Permissions
|
|
20
|
+
allPermissions?: Acl.Permissions
|
|
20
21
|
variables?: Acl.VariablesMap
|
|
21
22
|
query: string
|
|
22
23
|
queryVariables?: Record<string, any>
|
|
@@ -76,7 +77,9 @@ export const failedTransaction = (executes: SqlQuery[]): SqlQuery[] => {
|
|
|
76
77
|
|
|
77
78
|
export const execute = async (test: Test) => {
|
|
78
79
|
const permissions: Acl.Permissions = test.permissions || new AllowAllPermissionFactory().create(test.schema)
|
|
79
|
-
|
|
80
|
+
// Mirror production (GraphQlSchemaFactory): the GraphQL schema is built from the through-inclusive `all` set,
|
|
81
|
+
// so fields granted only through a relation are still exposed.
|
|
82
|
+
const authorizator = new Authorizator(test.allPermissions ?? permissions, false, false)
|
|
80
83
|
const builder = new GraphQlSchemaBuilderFactory().create(test.schema, authorizator)
|
|
81
84
|
const graphQLSchema = builder.build()
|
|
82
85
|
|
|
@@ -103,6 +106,7 @@ export const execute = async (test: Test) => {
|
|
|
103
106
|
executionContainer: executionContainerFactory
|
|
104
107
|
.create({
|
|
105
108
|
permissions,
|
|
109
|
+
allPermissions: test.allPermissions,
|
|
106
110
|
schema,
|
|
107
111
|
schemaMeta: {
|
|
108
112
|
id: 1,
|