@contember/engine-content-api 1.2.0-alpha.18 → 1.2.0-alpha.19

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 (119) hide show
  1. package/dist/src/mapper/MapperContainer.js +1 -1
  2. package/dist/src/mapper/MapperContainer.js.map +1 -1
  3. package/dist/src/mapper/delete/DeleteExecutor.js +2 -2
  4. package/dist/src/mapper/delete/DeleteExecutor.js.map +1 -1
  5. package/dist/src/mapper/select/Path.d.ts +1 -0
  6. package/dist/src/mapper/select/Path.d.ts.map +1 -1
  7. package/dist/src/mapper/select/Path.js +4 -1
  8. package/dist/src/mapper/select/Path.js.map +1 -1
  9. package/dist/src/mapper/select/WhereBuilder.d.ts +2 -1
  10. package/dist/src/mapper/select/WhereBuilder.d.ts.map +1 -1
  11. package/dist/src/mapper/select/WhereBuilder.js +85 -27
  12. package/dist/src/mapper/select/WhereBuilder.js.map +1 -1
  13. package/dist/src/resolvers/ExecutionContainerFactory.d.ts +1 -1
  14. package/dist/src/resolvers/ExecutionContainerFactory.d.ts.map +1 -1
  15. package/dist/src/resolvers/GraphQlQueryAstFactory.d.ts +1 -2
  16. package/dist/src/resolvers/GraphQlQueryAstFactory.d.ts.map +1 -1
  17. package/dist/src/resolvers/GraphQlQueryAstFactory.js +2 -2
  18. package/dist/src/resolvers/GraphQlQueryAstFactory.js.map +1 -1
  19. package/dist/src/resolvers/MutationResolver.d.ts.map +1 -1
  20. package/dist/src/resolvers/MutationResolver.js +10 -0
  21. package/dist/src/resolvers/MutationResolver.js.map +1 -1
  22. package/dist/src/schema/EnumsProvider.d.ts.map +1 -1
  23. package/dist/src/schema/EnumsProvider.js +1 -2
  24. package/dist/src/schema/EnumsProvider.js.map +1 -1
  25. package/dist/src/schema/OrderByTypeProvider.d.ts +1 -1
  26. package/dist/src/schema/OrderByTypeProvider.d.ts.map +1 -1
  27. package/dist/src/schema/OrderByTypeProvider.js +1 -1
  28. package/dist/src/schema/OrderByTypeProvider.js.map +1 -1
  29. package/dist/src/schema/WhereTypeProvider.d.ts +1 -2
  30. package/dist/src/schema/WhereTypeProvider.d.ts.map +1 -1
  31. package/dist/src/schema/WhereTypeProvider.js.map +1 -1
  32. package/dist/src/schema/entities/FieldArgsVisitor.d.ts +1 -2
  33. package/dist/src/schema/entities/FieldArgsVisitor.d.ts.map +1 -1
  34. package/dist/src/schema/entities/FieldArgsVisitor.js.map +1 -1
  35. package/dist/src/schema/mutations/CreateEntityRelationInputFieldVisitor.d.ts.map +1 -1
  36. package/dist/src/schema/mutations/CreateEntityRelationInputFieldVisitor.js.map +1 -1
  37. package/dist/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.d.ts.map +1 -1
  38. package/dist/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.js.map +1 -1
  39. package/dist/src/schema/utils.d.ts +1 -1
  40. package/dist/src/schema/utils.d.ts.map +1 -1
  41. package/dist/src/tsconfig.tsbuildinfo +1 -1
  42. package/dist/tests/cases/bugs/bug102.test.js +6 -6
  43. package/dist/tests/cases/bugs/bug102.test.js.map +1 -1
  44. package/dist/tests/cases/integration/graphQlRequests/delete/aclDelete.test.js +5 -5
  45. package/dist/tests/cases/integration/graphQlRequests/delete/aclDelete.test.js.map +1 -1
  46. package/dist/tests/cases/integration/graphQlRequests/delete/additionalDeleteFilter.test.js +5 -5
  47. package/dist/tests/cases/integration/graphQlRequests/delete/additionalDeleteFilter.test.js.map +1 -1
  48. package/dist/tests/cases/integration/graphQlRequests/delete/cascadeDelete.test.js +5 -5
  49. package/dist/tests/cases/integration/graphQlRequests/delete/cascadeDelete.test.js.map +1 -1
  50. package/dist/tests/cases/integration/graphQlRequests/delete/deleteById.test.js +5 -5
  51. package/dist/tests/cases/integration/graphQlRequests/delete/deleteById.test.js.map +1 -1
  52. package/dist/tests/cases/integration/graphQlRequests/delete/orphanRemoval.test.js +5 -5
  53. package/dist/tests/cases/integration/graphQlRequests/delete/orphanRemoval.test.js.map +1 -1
  54. package/dist/tests/cases/integration/graphQlRequests/delete/setNullOnDelete.test.js +5 -5
  55. package/dist/tests/cases/integration/graphQlRequests/delete/setNullOnDelete.test.js.map +1 -1
  56. package/dist/tests/cases/integration/graphQlRequests/query/filter/manyHasManyOwnerRelation.test.js +17 -15
  57. package/dist/tests/cases/integration/graphQlRequests/query/filter/manyHasManyOwnerRelation.test.js.map +1 -1
  58. package/dist/tests/cases/integration/graphQlRequests/query/filter/oneHasManyRelation.test.js +4 -5
  59. package/dist/tests/cases/integration/graphQlRequests/query/filter/oneHasManyRelation.test.js.map +1 -1
  60. package/dist/tests/cases/integration/graphQlRequests/query/unique/oneHasManyUnique.test.js +5 -3
  61. package/dist/tests/cases/integration/graphQlRequests/query/unique/oneHasManyUnique.test.js.map +1 -1
  62. package/dist/tests/cases/integration/graphQlRequests/update/manyHasManyInverse/delete.test.js +5 -5
  63. package/dist/tests/cases/integration/graphQlRequests/update/manyHasManyInverse/delete.test.js.map +1 -1
  64. package/dist/tests/cases/integration/graphQlRequests/update/manyHasManyOwning/delete.test.js +5 -5
  65. package/dist/tests/cases/integration/graphQlRequests/update/manyHasManyOwning/delete.test.js.map +1 -1
  66. package/dist/tests/cases/integration/graphQlRequests/update/manyHasOne/delete.test.js +10 -10
  67. package/dist/tests/cases/integration/graphQlRequests/update/manyHasOne/delete.test.js.map +1 -1
  68. package/dist/tests/cases/integration/graphQlRequests/update/oneHasMany/combination.test.js +5 -5
  69. package/dist/tests/cases/integration/graphQlRequests/update/oneHasMany/combination.test.js.map +1 -1
  70. package/dist/tests/cases/integration/graphQlRequests/update/oneHasMany/delete.test.js +5 -5
  71. package/dist/tests/cases/integration/graphQlRequests/update/oneHasMany/delete.test.js.map +1 -1
  72. package/dist/tests/cases/integration/graphQlRequests/update/oneHasOneInverse/delete.test.js +5 -5
  73. package/dist/tests/cases/integration/graphQlRequests/update/oneHasOneInverse/delete.test.js.map +1 -1
  74. package/dist/tests/cases/integration/graphQlSchema/graphQlSchemaBuilder.test.js +4 -4
  75. package/dist/tests/cases/integration/graphQlSchema/graphQlSchemaBuilder.test.js.map +1 -1
  76. package/dist/tests/cases/unit/whereBuilder.test.js +60 -4
  77. package/dist/tests/cases/unit/whereBuilder.test.js.map +1 -1
  78. package/dist/tests/src/test.js +2 -2
  79. package/dist/tests/src/test.js.map +1 -1
  80. package/dist/tests/src/testGraphql.d.ts.map +1 -1
  81. package/dist/tests/src/testGraphql.js +9 -5
  82. package/dist/tests/src/testGraphql.js.map +1 -1
  83. package/dist/tests/tsconfig.tsbuildinfo +1 -1
  84. package/package.json +12 -11
  85. package/src/mapper/MapperContainer.ts +1 -1
  86. package/src/mapper/delete/DeleteExecutor.ts +2 -2
  87. package/src/mapper/select/Path.ts +4 -1
  88. package/src/mapper/select/WhereBuilder.ts +97 -48
  89. package/src/resolvers/ExecutionContainerFactory.ts +1 -1
  90. package/src/resolvers/GraphQlQueryAstFactory.ts +5 -4
  91. package/src/resolvers/MutationResolver.ts +9 -1
  92. package/src/schema/EnumsProvider.ts +2 -4
  93. package/src/schema/OrderByTypeProvider.ts +9 -2
  94. package/src/schema/WhereTypeProvider.ts +1 -2
  95. package/src/schema/entities/FieldArgsVisitor.ts +1 -2
  96. package/src/schema/mutations/CreateEntityRelationInputFieldVisitor.ts +1 -2
  97. package/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.ts +7 -2
  98. package/src/schema/utils.ts +1 -1
  99. package/src/tsconfig.json +0 -3
  100. package/tests/cases/bugs/bug102.test.ts +6 -6
  101. package/tests/cases/integration/graphQlRequests/delete/aclDelete.test.ts +5 -5
  102. package/tests/cases/integration/graphQlRequests/delete/additionalDeleteFilter.test.ts +5 -5
  103. package/tests/cases/integration/graphQlRequests/delete/cascadeDelete.test.ts +5 -5
  104. package/tests/cases/integration/graphQlRequests/delete/deleteById.test.ts +5 -5
  105. package/tests/cases/integration/graphQlRequests/delete/orphanRemoval.test.ts +5 -5
  106. package/tests/cases/integration/graphQlRequests/delete/setNullOnDelete.test.ts +5 -5
  107. package/tests/cases/integration/graphQlRequests/query/filter/manyHasManyOwnerRelation.test.ts +17 -15
  108. package/tests/cases/integration/graphQlRequests/query/filter/oneHasManyRelation.test.ts +4 -5
  109. package/tests/cases/integration/graphQlRequests/query/unique/oneHasManyUnique.test.ts +5 -3
  110. package/tests/cases/integration/graphQlRequests/update/manyHasManyInverse/delete.test.ts +5 -5
  111. package/tests/cases/integration/graphQlRequests/update/manyHasManyOwning/delete.test.ts +5 -5
  112. package/tests/cases/integration/graphQlRequests/update/manyHasOne/delete.test.ts +10 -10
  113. package/tests/cases/integration/graphQlRequests/update/oneHasMany/combination.test.ts +5 -5
  114. package/tests/cases/integration/graphQlRequests/update/oneHasMany/delete.test.ts +5 -5
  115. package/tests/cases/integration/graphQlRequests/update/oneHasOneInverse/delete.test.ts +5 -5
  116. package/tests/cases/integration/graphQlSchema/graphQlSchemaBuilder.test.ts +2 -3
  117. package/tests/cases/unit/whereBuilder.test.ts +68 -4
  118. package/tests/src/test.ts +1 -1
  119. package/tests/src/testGraphql.ts +9 -5
@@ -33,12 +33,12 @@ test('delete post and orphaned content', async () => {
33
33
  ],
34
34
  },
35
35
  },
36
+ {
37
+ sql: SQL`select "root_"."id" from "public"."post" as "root_" where "root_"."id" = ?`,
38
+ parameters: [testUuid(1)],
39
+ response: { rows: [{ id: testUuid(1) }] },
40
+ },
36
41
  ...sqlDeferred([
37
- {
38
- sql: SQL`select "root_"."id" from "public"."post" as "root_" where "root_"."id" = ?`,
39
- parameters: [testUuid(1)],
40
- response: { rows: [{ id: testUuid(1) }] },
41
- },
42
42
  {
43
43
  sql: SQL`delete from "public"."post"
44
44
  where "id" in (select "root_"."id"
@@ -36,12 +36,12 @@ test('delete author and set null on posts', async () => {
36
36
  ],
37
37
  },
38
38
  },
39
+ {
40
+ sql: SQL`select "root_"."id" from "public"."author" as "root_" where "root_"."id" = ?`,
41
+ parameters: [testUuid(1)],
42
+ response: { rows: [{ id: testUuid(1) }] },
43
+ },
39
44
  ...sqlDeferred([
40
- {
41
- sql: SQL`select "root_"."id" from "public"."author" as "root_" where "root_"."id" = ?`,
42
- parameters: [testUuid(1)],
43
- response: { rows: [{ id: testUuid(1) }] },
44
- },
45
45
  {
46
46
  sql: SQL`delete from "public"."author"
47
47
  where "id" in (select "root_"."id"
@@ -22,11 +22,13 @@ test('Post by category name (where many has many owning)', async () => {
22
22
  }`,
23
23
  executes: [
24
24
  {
25
- sql: SQL`select "root_"."id" as "root_id"
26
- from "public"."post" as "root_"
27
- where exists (select 1
28
- from "public"."post_categories" as "junction_" inner join "public"."category" as "sub_" on "junction_"."category_id" = "sub_"."id"
29
- where "root_"."id" = "junction_"."post_id" and "sub_"."name" = ?)`,
25
+ sql: SQL`
26
+ select "root_"."id" as "root_id"
27
+ from "public"."post" as "root_"
28
+ where exists (select 1
29
+ from "public"."post_categories" as "root_categories_junction_"
30
+ inner join "public"."category" as "root_categories" on "root_categories_junction_"."category_id" = "root_categories"."id"
31
+ where "root_"."id" = "root_categories_junction_"."post_id" and "root_categories"."name" = ?)`,
30
32
  parameters: ['Stuff'],
31
33
  response: {
32
34
  rows: [
@@ -73,10 +75,11 @@ test('Post by category ids (where many has many owning)', async () => {
73
75
  executes: [
74
76
  {
75
77
  sql: SQL`select "root_"."id" as "root_id"
76
- from "public"."post" as "root_"
77
- where exists (select 1
78
- from "public"."post_categories" as "junction_"
79
- where "root_"."id" = "junction_"."post_id" and "junction_"."category_id" in (?, ?))`,
78
+ from "public"."post" as "root_"
79
+ where exists (select 1
80
+ from "public"."post_categories" as "root_categories_junction_"
81
+ where "root_"."id" = "root_categories_junction_"."post_id" and "root_categories_junction_"."category_id" in (?, ?))
82
+ `,
80
83
  parameters: [testUuid(10), testUuid(11)],
81
84
  response: {
82
85
  rows: [
@@ -131,12 +134,11 @@ test('Post by category tag name (where multiple many has many owning)', async ()
131
134
  {
132
135
  sql: SQL`
133
136
  select "root_"."id" as "root_id" from "public"."post" as "root_"
134
- where exists (select 1
135
- from "public"."post_categories" as "junction_"
136
- inner join "public"."category" as "sub_" on "junction_"."category_id" = "sub_"."id"
137
- left join "public"."category_tags_but_with_very_very_very_long_name_so_it_reaches_postgresql_alias_length_limit" as "sub_x_sub_tagsButWithVeryVeryVeryLongNameSoItReachesPostgresq_2" on "sub_"."id" = "sub_x_sub_tagsButWithVeryVeryVeryLongNameSoItReachesPostgresq_2"."category_id"
138
- left join "public"."tag" as "sub_tagsButWithVeryVeryVeryLongNameSoItReachesPostgresqlAlias_1" on "sub_x_sub_tagsButWithVeryVeryVeryLongNameSoItReachesPostgresq_2"."tag_id" = "sub_tagsButWithVeryVeryVeryLongNameSoItReachesPostgresqlAlias_1"."id"
139
- where "root_"."id" = "junction_"."post_id" and "sub_tagsButWithVeryVeryVeryLongNameSoItReachesPostgresqlAlias_1"."name" = ?)`,
137
+ where exists (select 1 from "public"."post_categories" as "root_categories_junction_"
138
+ inner join "public"."category" as "root_categories" on "root_categories_junction_"."category_id" = "root_categories"."id"
139
+ left join "public"."category_tags_but_with_very_very_very_long_name_so_it_reaches_postgresql_alias_length_limit" as "root_categoriesx_root_categoriestagsButWithVeryVeryVeryLongNa_3" on "root_categories"."id" = "root_categoriesx_root_categoriestagsButWithVeryVeryVeryLongNa_3"."category_id"
140
+ left join "public"."tag" as "root_categoriestagsButWithVeryVeryVeryLongNameSoItReachesPost_1" on "root_categoriesx_root_categoriestagsButWithVeryVeryVeryLongNa_3"."tag_id" = "root_categoriestagsButWithVeryVeryVeryLongNameSoItReachesPost_1"."id"
141
+ where "root_"."id" = "root_categories_junction_"."post_id" and "root_categoriestagsButWithVeryVeryVeryLongNameSoItReachesPost_1"."name" = ?)`,
140
142
  parameters: ['Stuff'],
141
143
  response: {
142
144
  rows: [
@@ -23,11 +23,10 @@ test('Author by post title (where one has many)', async () => {
23
23
  }`,
24
24
  executes: [
25
25
  {
26
- sql: SQL`select "root_"."id" as "root_id"
27
- from "public"."author" as "root_"
28
- where exists (select 1
29
- from "public"."post" as "sub_"
30
- where "root_"."id" = "sub_"."author_id" and "sub_"."title" = ?)`,
26
+ sql: SQL`select "root_"."id" as "root_id" from "public"."author" as "root_"
27
+ where exists (select 1
28
+ from "public"."post" as "root_posts"
29
+ where "root_"."id" = "root_posts"."author_id" and "root_posts"."title" = ?)`,
31
30
  parameters: ['Hello'],
32
31
  response: {
33
32
  rows: [
@@ -28,9 +28,11 @@ test('Post by post locale (one-has-many unique)', async () => {
28
28
  }`,
29
29
  executes: [
30
30
  {
31
- sql: SQL`SELECT "root_"."id" AS "root_id"
32
- FROM "public"."post" AS "root_"
33
- WHERE EXISTS (SELECT 1 FROM "public"."post_locale" AS "sub_" WHERE "root_"."id" = "sub_"."post_id" AND "sub_"."id" = ?)`,
31
+ sql: SQL`select "root_"."id" as "root_id"
32
+ from "public"."post" as "root_"
33
+ where exists (select 1
34
+ from "public"."post_locale" as "root_locales"
35
+ where "root_"."id" = "root_locales"."post_id" and "root_locales"."id" = ?)`,
34
36
  parameters: [testUuid(1)],
35
37
  response: { rows: [{ root_id: testUuid(2) }] },
36
38
  },
@@ -22,12 +22,12 @@ test('delete', async () => {
22
22
  parameters: [testUuid(2)],
23
23
  response: { rows: [{ id: testUuid(2) }] },
24
24
  },
25
+ {
26
+ sql: SQL`select "root_"."id" from "public"."post" as "root_" where "root_"."id" = ?`,
27
+ parameters: [testUuid(1)],
28
+ response: { rows: [{ id: testUuid(1) }] },
29
+ },
25
30
  ...sqlDeferred([
26
- {
27
- sql: SQL`select "root_"."id" from "public"."post" as "root_" where "root_"."id" = ?`,
28
- parameters: [testUuid(1)],
29
- response: { rows: [{ id: testUuid(1) }] },
30
- },
31
31
  {
32
32
  sql: SQL`delete from "public"."post"
33
33
  where "id" in (select "root_"."id"
@@ -22,12 +22,12 @@ test('delete', async () => {
22
22
  parameters: [testUuid(2)],
23
23
  response: { rows: [{ id: testUuid(2) }] },
24
24
  },
25
+ {
26
+ sql: SQL`select "root_"."id" from "public"."category" as "root_" where "root_"."id" = ?`,
27
+ parameters: [testUuid(1)],
28
+ response: { rows: [{ id: testUuid(1) }] },
29
+ },
25
30
  ...sqlDeferred([
26
- {
27
- sql: SQL`select "root_"."id" from "public"."category" as "root_" where "root_"."id" = ?`,
28
- parameters: [testUuid(1)],
29
- response: { rows: [{ id: testUuid(1) }] },
30
- },
31
31
  {
32
32
  sql: SQL`delete from "public"."category"
33
33
  where "id" in (select "root_"."id"
@@ -31,12 +31,12 @@ test('delete', async () => {
31
31
  rows: [{ author_id: testUuid(1) }],
32
32
  },
33
33
  },
34
+ {
35
+ sql: SQL`select "root_"."id" from "public"."author" as "root_" where "root_"."id" = ?`,
36
+ parameters: [testUuid(1)],
37
+ response: { rows: [{ id: testUuid(1) }] },
38
+ },
34
39
  ...sqlDeferred([
35
- {
36
- sql: SQL`select "root_"."id" from "public"."author" as "root_" where "root_"."id" = ?`,
37
- parameters: [testUuid(1)],
38
- response: { rows: [{ id: testUuid(1) }] },
39
- },
40
40
  {
41
41
  sql: SQL`delete from "public"."author"
42
42
  where "id" in (select "root_"."id"
@@ -99,12 +99,12 @@ test('delete with cascade', async () => {
99
99
  rows: [{ author_id: testUuid(1) }],
100
100
  },
101
101
  },
102
+ {
103
+ sql: SQL`select "root_"."id" from "public"."author" as "root_" where "root_"."id" = ?`,
104
+ parameters: [testUuid(1)],
105
+ response: { rows: [{ id: testUuid(1) }] },
106
+ },
102
107
  ...sqlDeferred([
103
- {
104
- sql: SQL`select "root_"."id" from "public"."author" as "root_" where "root_"."id" = ?`,
105
- parameters: [testUuid(1)],
106
- response: { rows: [{ id: testUuid(1) }] },
107
- },
108
108
  {
109
109
  sql: SQL`delete from "public"."author"
110
110
  where "id" in (select "root_"."id"
@@ -22,12 +22,12 @@ test('delete and create', async () => {
22
22
  parameters: [testUuid(2)],
23
23
  response: { rows: [{ id: testUuid(2) }] },
24
24
  },
25
+ {
26
+ sql: SQL`select "root_"."id" from "public"."post_locale" as "root_" where "root_"."locale" = ? and "root_"."post_id" = ?`,
27
+ parameters: ['cs', testUuid(2)],
28
+ response: { rows: [{ id: testUuid(9) }] },
29
+ },
25
30
  ...sqlDeferred([
26
- {
27
- sql: SQL`select "root_"."id" from "public"."post_locale" as "root_" where "root_"."locale" = ? and "root_"."post_id" = ?`,
28
- parameters: ['cs', testUuid(2)],
29
- response: { rows: [{ id: testUuid(9) }] },
30
- },
31
31
  {
32
32
  sql: SQL`delete from "public"."post_locale"
33
33
  where "id" in (select "root_"."id"
@@ -22,12 +22,12 @@ test('delete', async () => {
22
22
  parameters: [testUuid(2)],
23
23
  response: { rows: [{ id: testUuid(2) }] },
24
24
  },
25
+ {
26
+ sql: SQL`select "root_"."id" from "public"."post_locale" as "root_" where "root_"."locale" = ? and "root_"."post_id" = ?`,
27
+ parameters: ['cs', testUuid(2)],
28
+ response: { rows: [{ id: testUuid(1) }] },
29
+ },
25
30
  ...sqlDeferred([
26
- {
27
- sql: SQL`select "root_"."id" from "public"."post_locale" as "root_" where "root_"."locale" = ? and "root_"."post_id" = ?`,
28
- parameters: ['cs', testUuid(2)],
29
- response: { rows: [{ id: testUuid(1) }] },
30
- },
31
31
  {
32
32
  sql: SQL`delete from "public"."post_locale"
33
33
  where "id" in (select "root_"."id"
@@ -22,12 +22,12 @@ test('delete', async () => {
22
22
  parameters: [testUuid(2)],
23
23
  response: { rows: [{ id: testUuid(2) }] },
24
24
  },
25
+ {
26
+ sql: SQL`select "root_"."id" from "public"."site" as "root_" where "root_"."setting_id" = ?`,
27
+ parameters: [testUuid(2)],
28
+ response: { rows: [{ id: testUuid(1) }] },
29
+ },
25
30
  ...sqlDeferred([
26
- {
27
- sql: SQL`select "root_"."id" from "public"."site" as "root_" where "root_"."setting_id" = ?`,
28
- parameters: [testUuid(2)],
29
- response: { rows: [{ id: testUuid(1) }] },
30
- },
31
31
  {
32
32
  sql: SQL`delete from "public"."site"
33
33
  where "id" in (select "root_"."id"
@@ -1,7 +1,7 @@
1
1
  import { graphql, printSchema } from 'graphql'
2
2
  import { Acl, Model } from '@contember/schema'
3
- import * as path from 'path'
4
-
3
+ import * as fs from 'node:fs/promises'
4
+ import * as path from 'node:path'
5
5
  import {
6
6
  AllowAllPermissionFactory,
7
7
  SchemaBuilder,
@@ -10,7 +10,6 @@ import {
10
10
  } from '@contember/schema-definition'
11
11
  import { Authorizator, GraphQlSchemaBuilderFactory } from '../../../../src'
12
12
  import * as model from './model'
13
- import { promises as fs } from 'fs'
14
13
  import { assert, describe, it } from 'vitest'
15
14
 
16
15
  interface Test {
@@ -17,6 +17,11 @@ namespace WhereBuilderModel {
17
17
  title = def.stringColumn()
18
18
  isPublic = def.boolColumn().notNull()
19
19
  author = def.manyHasOne(Author, 'articles')
20
+ tags = def.manyHasMany(Tag)
21
+ }
22
+
23
+ export class Tag {
24
+ name = def.stringColumn()
20
25
  }
21
26
  }
22
27
 
@@ -25,7 +30,7 @@ const createWhere = (schema: Schema, where: Input.Where) => {
25
30
  const joinBuilder = new JoinBuilder(schema.model)
26
31
  const conditionBuilder = new ConditionBuilder()
27
32
  const whereOptimizer = new WhereOptimizer(schema.model, new ConditionOptimizer())
28
- const whereBuilder = new WhereBuilder(schema.model, joinBuilder, conditionBuilder, pathFactory, whereOptimizer)
33
+ const whereBuilder = new WhereBuilder(schema.model, joinBuilder, conditionBuilder, pathFactory, whereOptimizer, schema.settings.useExistsInHasManyFilter === true)
29
34
 
30
35
  const qb = SelectBuilder.create()
31
36
  .from('author', 'root_')
@@ -48,7 +53,7 @@ describe('where builder', () => {
48
53
  })
49
54
  assert.equal(
50
55
  where,
51
- ' where exists (select 1 from "__SCHEMA__"."article" as "sub_" where "root_"."id" = "sub_"."author_id" and "sub_"."is_public" = ?) and exists (select 1 from "__SCHEMA__"."article" as "sub_" where "root_"."id" = "sub_"."author_id" and "sub_"."title" = ?)',
56
+ ' where exists (select 1 from "__SCHEMA__"."article" as "root_articles" where "root_"."id" = "root_articles"."author_id" and "root_articles"."is_public" = ?) and exists (select 1 from "__SCHEMA__"."article" as "root_articles" where "root_"."id" = "root_articles"."author_id" and "root_articles"."title" = ?)',
52
57
  )
53
58
  })
54
59
 
@@ -64,7 +69,7 @@ describe('where builder', () => {
64
69
  })
65
70
  assert.equal(
66
71
  where,
67
- ' where exists (select 1 from "__SCHEMA__"."article" as "sub_" where "root_"."id" = "sub_"."author_id" and "sub_"."is_public" = ? and "sub_"."title" = ?)',
72
+ ' where exists (select 1 from "__SCHEMA__"."article" as "root_articles" where "root_"."id" = "root_articles"."author_id" and "root_articles"."is_public" = ? and "root_articles"."title" = ?)',
68
73
  )
69
74
  })
70
75
 
@@ -78,7 +83,66 @@ describe('where builder', () => {
78
83
  })
79
84
  assert.equal(
80
85
  where,
81
- ' where exists (select 1 from (select "root_"."id") as "sub2_" left join "__SCHEMA__"."article" as "sub_" on "sub2_"."id" = "sub_"."author_id" where "sub_"."id" is null)',
86
+ ' where exists (select 1 from (select "root_"."id") as "root_articles_tmp_" left join "__SCHEMA__"."article" as "root_articles" on "root_articles_tmp_"."id" = "root_articles"."author_id" where "root_articles"."id" is null)',
87
+ )
88
+ })
89
+
90
+ it('where with nested has-many', () => {
91
+ const schema: Schema = { ...createSchema(WhereBuilderModel), settings: { useExistsInHasManyFilter: true } }
92
+ const where = createWhere(schema, {
93
+ articles: {
94
+ and: [
95
+ { tags: { name: { eq: 'Hello' } } },
96
+ { tags: { name: { eq: 'World' } } },
97
+ ],
98
+ },
99
+ })
100
+ compareWhere(
101
+ where,
102
+ `where exists (select 1
103
+ from "__SCHEMA__"."article" as "root_articles"
104
+ where "root_"."id" = "root_articles"."author_id"
105
+ and exists (select 1
106
+ from "__SCHEMA__"."article_tags" as "root_articles_tags_junction_"
107
+ inner join "__SCHEMA__"."tag" as "root_articles_tags" on "root_articles_tags_junction_"."tag_id" = "root_articles_tags"."id"
108
+ where "root_articles"."id" = "root_articles_tags_junction_"."article_id" and "root_articles_tags"."name" = ?)
109
+ and exists (select 1
110
+ from "__SCHEMA__"."article_tags" as "root_articles_tags_junction_"
111
+ inner join "__SCHEMA__"."tag" as "root_articles_tags" on "root_articles_tags_junction_"."tag_id" = "root_articles_tags"."id"
112
+ where "root_articles"."id" = "root_articles_tags_junction_"."article_id" and "root_articles_tags"."name" = ?))`,
113
+ )
114
+ })
115
+
116
+
117
+ it('where without nested has-many', () => {
118
+ const schema: Schema = { ...createSchema(WhereBuilderModel) }
119
+ const where = createWhere(schema, {
120
+ articles: {
121
+ and: [
122
+ { tags: { name: { eq: 'Hello' } } },
123
+ { tags: { name: { eq: 'World' } } },
124
+ ],
125
+ },
126
+ })
127
+ compareWhere(
128
+ where,
129
+ `where exists (select 1
130
+ from "__SCHEMA__"."article" as "root_articles"
131
+ left join "__SCHEMA__"."article_tags" as "root_articles_x_root_articles_tags" on "root_articles"."id" = "root_articles_x_root_articles_tags"."article_id"
132
+ left join "__SCHEMA__"."tag" as "root_articles_tags" on "root_articles_x_root_articles_tags"."tag_id" = "root_articles_tags"."id"
133
+ where "root_"."id" = "root_articles"."author_id" and "root_articles_tags"."name" = ? and "root_articles_tags"."name" = ?)`,
82
134
  )
83
135
  })
84
136
  })
137
+
138
+
139
+ const compareWhere = (actual: string, expected: string) => {
140
+ const normalize = (s: string) => s.replaceAll(/\s+/g, ' ').trim()
141
+ try {
142
+ assert.equal(normalize(actual), normalize(expected))
143
+ } catch (e) {
144
+ console.log(normalize(actual))
145
+ console.log(normalize(expected))
146
+ throw e
147
+ }
148
+ }
package/tests/src/test.ts CHANGED
@@ -5,7 +5,7 @@ import { executeGraphQlTest } from './testGraphql'
5
5
  import { Client } from '@contember/database'
6
6
  import { createConnectionMock } from '@contember/database-tester'
7
7
  import { createUuidGenerator } from '@contember/engine-api-tester'
8
- import { getArgumentValues } from 'graphql/execution/values'
8
+ import { getArgumentValues } from 'graphql'
9
9
  import { SQL } from './tags'
10
10
 
11
11
  export interface SqlQuery {
@@ -1,3 +1,4 @@
1
+ import { NullLoggerHandler, withLogger, createLogger } from '@contember/logger'
1
2
  import { graphql, GraphQLSchema } from 'graphql'
2
3
  import { assert } from 'vitest'
3
4
 
@@ -10,11 +11,14 @@ export interface Test {
10
11
  }
11
12
 
12
13
  export const executeGraphQlTest = async (test: Test) => {
13
- const rawResponse = await graphql({
14
- schema: test.schema,
15
- source: test.query,
16
- contextValue: test.context,
17
- variableValues: test.queryVariables,
14
+ const logger = createLogger(new NullLoggerHandler())
15
+ const rawResponse = await withLogger(logger, () => {
16
+ return graphql({
17
+ schema: test.schema,
18
+ source: test.query,
19
+ contextValue: test.context,
20
+ variableValues: test.queryVariables,
21
+ })
18
22
  })
19
23
  const response = JSON.parse(JSON.stringify(rawResponse))
20
24
  if ('errors' in rawResponse) {