@snowtop/ent 0.1.0-alpha160-test6 → 0.1.0-alpha160
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/core/query/shared_assoc_test.d.ts +2 -0
- package/core/query/shared_assoc_test.js +804 -0
- package/core/query/shared_test.d.ts +21 -0
- package/core/query/shared_test.js +736 -0
- package/graphql/query/shared_assoc_test.d.ts +1 -0
- package/graphql/query/shared_assoc_test.js +203 -0
- package/package.json +6 -48
- package/{dist/scripts → scripts}/custom_compiler.js +0 -0
- package/{dist/scripts → scripts}/custom_graphql.js +0 -0
- package/dist/package.json +0 -64
- package/src/action/action.ts +0 -330
- package/src/action/executor.ts +0 -453
- package/src/action/experimental_action.ts +0 -277
- package/src/action/index.ts +0 -31
- package/src/action/operations.ts +0 -967
- package/src/action/orchestrator.ts +0 -1527
- package/src/action/privacy.ts +0 -37
- package/src/action/relative_value.ts +0 -242
- package/src/action/transaction.ts +0 -38
- package/src/auth/auth.ts +0 -77
- package/src/auth/index.ts +0 -8
- package/src/core/base.ts +0 -367
- package/src/core/clause.ts +0 -1065
- package/src/core/config.ts +0 -219
- package/src/core/const.ts +0 -5
- package/src/core/context.ts +0 -135
- package/src/core/convert.ts +0 -106
- package/src/core/date.ts +0 -23
- package/src/core/db.ts +0 -498
- package/src/core/ent.ts +0 -1740
- package/src/core/global_schema.ts +0 -49
- package/src/core/loaders/assoc_count_loader.ts +0 -99
- package/src/core/loaders/assoc_edge_loader.ts +0 -250
- package/src/core/loaders/index.ts +0 -12
- package/src/core/loaders/loader.ts +0 -66
- package/src/core/loaders/object_loader.ts +0 -489
- package/src/core/loaders/query_loader.ts +0 -314
- package/src/core/loaders/raw_count_loader.ts +0 -175
- package/src/core/logger.ts +0 -49
- package/src/core/privacy.ts +0 -660
- package/src/core/query/assoc_query.ts +0 -240
- package/src/core/query/custom_clause_query.ts +0 -174
- package/src/core/query/custom_query.ts +0 -302
- package/src/core/query/index.ts +0 -9
- package/src/core/query/query.ts +0 -674
- package/src/core/query_impl.ts +0 -32
- package/src/core/viewer.ts +0 -52
- package/src/ent.code-workspace +0 -73
- package/src/graphql/builtins/connection.ts +0 -25
- package/src/graphql/builtins/edge.ts +0 -16
- package/src/graphql/builtins/node.ts +0 -12
- package/src/graphql/graphql.ts +0 -891
- package/src/graphql/graphql_field_helpers.ts +0 -221
- package/src/graphql/index.ts +0 -42
- package/src/graphql/mutations/union.ts +0 -39
- package/src/graphql/node_resolver.ts +0 -122
- package/src/graphql/query/connection_type.ts +0 -113
- package/src/graphql/query/edge_connection.ts +0 -171
- package/src/graphql/query/page_info.ts +0 -34
- package/src/graphql/query/shared_edge_connection.ts +0 -287
- package/src/graphql/scalars/orderby_direction.ts +0 -13
- package/src/graphql/scalars/time.ts +0 -38
- package/src/imports/dataz/example1/_auth.ts +0 -51
- package/src/imports/dataz/example1/_viewer.ts +0 -35
- package/src/imports/index.ts +0 -213
- package/src/index.ts +0 -145
- package/src/parse_schema/parse.ts +0 -585
- package/src/schema/base_schema.ts +0 -224
- package/src/schema/field.ts +0 -1087
- package/src/schema/index.ts +0 -53
- package/src/schema/json_field.ts +0 -94
- package/src/schema/schema.ts +0 -1028
- package/src/schema/struct_field.ts +0 -234
- package/src/schema/union_field.ts +0 -105
- package/src/scripts/custom_compiler.ts +0 -331
- package/src/scripts/custom_graphql.ts +0 -550
- package/src/scripts/migrate_v0.1.ts +0 -41
- package/src/scripts/move_types.ts +0 -131
- package/src/scripts/read_schema.ts +0 -67
- package/src/setupPackage.js +0 -42
- package/src/testutils/action/complex_schemas.ts +0 -517
- package/src/testutils/builder.ts +0 -422
- package/src/testutils/context/test_context.ts +0 -25
- package/src/testutils/db/fixture.ts +0 -32
- package/src/testutils/db/temp_db.ts +0 -941
- package/src/testutils/db/value.ts +0 -294
- package/src/testutils/db_mock.ts +0 -351
- package/src/testutils/db_time_zone.ts +0 -40
- package/src/testutils/ent-graphql-tests/index.ts +0 -653
- package/src/testutils/fake_comms.ts +0 -50
- package/src/testutils/fake_data/const.ts +0 -64
- package/src/testutils/fake_data/events_query.ts +0 -145
- package/src/testutils/fake_data/fake_contact.ts +0 -150
- package/src/testutils/fake_data/fake_event.ts +0 -150
- package/src/testutils/fake_data/fake_tag.ts +0 -139
- package/src/testutils/fake_data/fake_user.ts +0 -232
- package/src/testutils/fake_data/index.ts +0 -1
- package/src/testutils/fake_data/internal.ts +0 -8
- package/src/testutils/fake_data/tag_query.ts +0 -56
- package/src/testutils/fake_data/test_helpers.ts +0 -388
- package/src/testutils/fake_data/user_query.ts +0 -524
- package/src/testutils/fake_log.ts +0 -52
- package/src/testutils/mock_date.ts +0 -10
- package/src/testutils/mock_log.ts +0 -39
- package/src/testutils/parse_sql.ts +0 -685
- package/src/testutils/test_edge_global_schema.ts +0 -49
- package/src/testutils/write.ts +0 -70
- package/src/tsc/ast.ts +0 -351
- package/src/tsc/compilerOptions.ts +0 -85
- package/src/tsc/move_generated.ts +0 -191
- package/src/tsc/transform.ts +0 -226
- package/src/tsc/transform_action.ts +0 -224
- package/src/tsc/transform_ent.ts +0 -66
- package/src/tsc/transform_schema.ts +0 -546
- package/tsconfig.json +0 -20
- /package/{dist/action → action}/action.d.ts +0 -0
- /package/{dist/action → action}/action.js +0 -0
- /package/{dist/action → action}/executor.d.ts +0 -0
- /package/{dist/action → action}/executor.js +0 -0
- /package/{dist/action → action}/experimental_action.d.ts +0 -0
- /package/{dist/action → action}/experimental_action.js +0 -0
- /package/{dist/action → action}/index.d.ts +0 -0
- /package/{dist/action → action}/index.js +0 -0
- /package/{dist/action → action}/operations.d.ts +0 -0
- /package/{dist/action → action}/operations.js +0 -0
- /package/{dist/action → action}/orchestrator.d.ts +0 -0
- /package/{dist/action → action}/orchestrator.js +0 -0
- /package/{dist/action → action}/privacy.d.ts +0 -0
- /package/{dist/action → action}/privacy.js +0 -0
- /package/{dist/action → action}/relative_value.d.ts +0 -0
- /package/{dist/action → action}/relative_value.js +0 -0
- /package/{dist/action → action}/transaction.d.ts +0 -0
- /package/{dist/action → action}/transaction.js +0 -0
- /package/{dist/auth → auth}/auth.d.ts +0 -0
- /package/{dist/auth → auth}/auth.js +0 -0
- /package/{dist/auth → auth}/index.d.ts +0 -0
- /package/{dist/auth → auth}/index.js +0 -0
- /package/{dist/core → core}/base.d.ts +0 -0
- /package/{dist/core → core}/base.js +0 -0
- /package/{dist/core → core}/clause.d.ts +0 -0
- /package/{dist/core → core}/clause.js +0 -0
- /package/{dist/core → core}/config.d.ts +0 -0
- /package/{dist/core → core}/config.js +0 -0
- /package/{dist/core → core}/const.d.ts +0 -0
- /package/{dist/core → core}/const.js +0 -0
- /package/{dist/core → core}/context.d.ts +0 -0
- /package/{dist/core → core}/context.js +0 -0
- /package/{dist/core → core}/convert.d.ts +0 -0
- /package/{dist/core → core}/convert.js +0 -0
- /package/{dist/core → core}/date.d.ts +0 -0
- /package/{dist/core → core}/date.js +0 -0
- /package/{dist/core → core}/db.d.ts +0 -0
- /package/{dist/core → core}/db.js +0 -0
- /package/{dist/core → core}/ent.d.ts +0 -0
- /package/{dist/core → core}/ent.js +0 -0
- /package/{dist/core → core}/global_schema.d.ts +0 -0
- /package/{dist/core → core}/global_schema.js +0 -0
- /package/{dist/core → core}/loaders/assoc_count_loader.d.ts +0 -0
- /package/{dist/core → core}/loaders/assoc_count_loader.js +0 -0
- /package/{dist/core → core}/loaders/assoc_edge_loader.d.ts +0 -0
- /package/{dist/core → core}/loaders/assoc_edge_loader.js +0 -0
- /package/{dist/core → core}/loaders/index.d.ts +0 -0
- /package/{dist/core → core}/loaders/index.js +0 -0
- /package/{dist/core → core}/loaders/loader.d.ts +0 -0
- /package/{dist/core → core}/loaders/loader.js +0 -0
- /package/{dist/core → core}/loaders/object_loader.d.ts +0 -0
- /package/{dist/core → core}/loaders/object_loader.js +0 -0
- /package/{dist/core → core}/loaders/query_loader.d.ts +0 -0
- /package/{dist/core → core}/loaders/query_loader.js +0 -0
- /package/{dist/core → core}/loaders/raw_count_loader.d.ts +0 -0
- /package/{dist/core → core}/loaders/raw_count_loader.js +0 -0
- /package/{dist/core → core}/logger.d.ts +0 -0
- /package/{dist/core → core}/logger.js +0 -0
- /package/{dist/core → core}/privacy.d.ts +0 -0
- /package/{dist/core → core}/privacy.js +0 -0
- /package/{dist/core → core}/query/assoc_query.d.ts +0 -0
- /package/{dist/core → core}/query/assoc_query.js +0 -0
- /package/{dist/core → core}/query/custom_clause_query.d.ts +0 -0
- /package/{dist/core → core}/query/custom_clause_query.js +0 -0
- /package/{dist/core → core}/query/custom_query.d.ts +0 -0
- /package/{dist/core → core}/query/custom_query.js +0 -0
- /package/{dist/core → core}/query/index.d.ts +0 -0
- /package/{dist/core → core}/query/index.js +0 -0
- /package/{dist/core → core}/query/query.d.ts +0 -0
- /package/{dist/core → core}/query/query.js +0 -0
- /package/{dist/core → core}/query_impl.d.ts +0 -0
- /package/{dist/core → core}/query_impl.js +0 -0
- /package/{dist/core → core}/viewer.d.ts +0 -0
- /package/{dist/core → core}/viewer.js +0 -0
- /package/{dist/graphql → graphql}/builtins/connection.d.ts +0 -0
- /package/{dist/graphql → graphql}/builtins/connection.js +0 -0
- /package/{dist/graphql → graphql}/builtins/edge.d.ts +0 -0
- /package/{dist/graphql → graphql}/builtins/edge.js +0 -0
- /package/{dist/graphql → graphql}/builtins/node.d.ts +0 -0
- /package/{dist/graphql → graphql}/builtins/node.js +0 -0
- /package/{dist/graphql → graphql}/graphql.d.ts +0 -0
- /package/{dist/graphql → graphql}/graphql.js +0 -0
- /package/{dist/graphql → graphql}/graphql_field_helpers.d.ts +0 -0
- /package/{dist/graphql → graphql}/graphql_field_helpers.js +0 -0
- /package/{dist/graphql → graphql}/index.d.ts +0 -0
- /package/{dist/graphql → graphql}/index.js +0 -0
- /package/{dist/graphql → graphql}/mutations/union.d.ts +0 -0
- /package/{dist/graphql → graphql}/mutations/union.js +0 -0
- /package/{dist/graphql → graphql}/node_resolver.d.ts +0 -0
- /package/{dist/graphql → graphql}/node_resolver.js +0 -0
- /package/{dist/graphql → graphql}/query/connection_type.d.ts +0 -0
- /package/{dist/graphql → graphql}/query/connection_type.js +0 -0
- /package/{dist/graphql → graphql}/query/edge_connection.d.ts +0 -0
- /package/{dist/graphql → graphql}/query/edge_connection.js +0 -0
- /package/{dist/graphql → graphql}/query/page_info.d.ts +0 -0
- /package/{dist/graphql → graphql}/query/page_info.js +0 -0
- /package/{dist/graphql → graphql}/query/shared_edge_connection.d.ts +0 -0
- /package/{dist/graphql → graphql}/query/shared_edge_connection.js +0 -0
- /package/{dist/graphql → graphql}/scalars/orderby_direction.d.ts +0 -0
- /package/{dist/graphql → graphql}/scalars/orderby_direction.js +0 -0
- /package/{dist/graphql → graphql}/scalars/time.d.ts +0 -0
- /package/{dist/graphql → graphql}/scalars/time.js +0 -0
- /package/{dist/imports → imports}/dataz/example1/_auth.d.ts +0 -0
- /package/{dist/imports → imports}/dataz/example1/_auth.js +0 -0
- /package/{dist/imports → imports}/dataz/example1/_viewer.d.ts +0 -0
- /package/{dist/imports → imports}/dataz/example1/_viewer.js +0 -0
- /package/{dist/imports → imports}/index.d.ts +0 -0
- /package/{dist/imports → imports}/index.js +0 -0
- /package/{dist/index.d.ts → index.d.ts} +0 -0
- /package/{dist/index.js → index.js} +0 -0
- /package/{dist/parse_schema → parse_schema}/parse.d.ts +0 -0
- /package/{dist/parse_schema → parse_schema}/parse.js +0 -0
- /package/{dist/schema → schema}/base_schema.d.ts +0 -0
- /package/{dist/schema → schema}/base_schema.js +0 -0
- /package/{dist/schema → schema}/field.d.ts +0 -0
- /package/{dist/schema → schema}/field.js +0 -0
- /package/{dist/schema → schema}/index.d.ts +0 -0
- /package/{dist/schema → schema}/index.js +0 -0
- /package/{dist/schema → schema}/json_field.d.ts +0 -0
- /package/{dist/schema → schema}/json_field.js +0 -0
- /package/{dist/schema → schema}/schema.d.ts +0 -0
- /package/{dist/schema → schema}/schema.js +0 -0
- /package/{dist/schema → schema}/struct_field.d.ts +0 -0
- /package/{dist/schema → schema}/struct_field.js +0 -0
- /package/{dist/schema → schema}/union_field.d.ts +0 -0
- /package/{dist/schema → schema}/union_field.js +0 -0
- /package/{dist/scripts → scripts}/custom_compiler.d.ts +0 -0
- /package/{dist/scripts → scripts}/custom_graphql.d.ts +0 -0
- /package/{dist/scripts → scripts}/migrate_v0.1.d.ts +0 -0
- /package/{dist/scripts → scripts}/migrate_v0.1.js +0 -0
- /package/{dist/scripts → scripts}/move_types.d.ts +0 -0
- /package/{dist/scripts → scripts}/move_types.js +0 -0
- /package/{dist/scripts → scripts}/read_schema.d.ts +0 -0
- /package/{dist/scripts → scripts}/read_schema.js +0 -0
- /package/{dist/testutils → testutils}/action/complex_schemas.d.ts +0 -0
- /package/{dist/testutils → testutils}/action/complex_schemas.js +0 -0
- /package/{dist/testutils → testutils}/builder.d.ts +0 -0
- /package/{dist/testutils → testutils}/builder.js +0 -0
- /package/{dist/testutils → testutils}/context/test_context.d.ts +0 -0
- /package/{dist/testutils → testutils}/context/test_context.js +0 -0
- /package/{dist/testutils → testutils}/db/fixture.d.ts +0 -0
- /package/{dist/testutils → testutils}/db/fixture.js +0 -0
- /package/{dist/testutils → testutils}/db/temp_db.d.ts +0 -0
- /package/{dist/testutils → testutils}/db/temp_db.js +0 -0
- /package/{dist/testutils → testutils}/db/value.d.ts +0 -0
- /package/{dist/testutils → testutils}/db/value.js +0 -0
- /package/{dist/testutils → testutils}/db_mock.d.ts +0 -0
- /package/{dist/testutils → testutils}/db_mock.js +0 -0
- /package/{dist/testutils → testutils}/db_time_zone.d.ts +0 -0
- /package/{dist/testutils → testutils}/db_time_zone.js +0 -0
- /package/{dist/testutils → testutils}/ent-graphql-tests/index.d.ts +0 -0
- /package/{dist/testutils → testutils}/ent-graphql-tests/index.js +0 -0
- /package/{dist/testutils → testutils}/fake_comms.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_comms.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/const.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/const.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/events_query.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/events_query.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/fake_contact.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/fake_contact.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/fake_event.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/fake_event.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/fake_tag.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/fake_tag.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/fake_user.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/fake_user.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/index.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/index.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/internal.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/internal.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/tag_query.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/tag_query.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/test_helpers.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/test_helpers.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/user_query.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/user_query.js +0 -0
- /package/{dist/testutils → testutils}/fake_log.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_log.js +0 -0
- /package/{dist/testutils → testutils}/mock_date.d.ts +0 -0
- /package/{dist/testutils → testutils}/mock_date.js +0 -0
- /package/{dist/testutils → testutils}/mock_log.d.ts +0 -0
- /package/{dist/testutils → testutils}/mock_log.js +0 -0
- /package/{dist/testutils → testutils}/parse_sql.d.ts +0 -0
- /package/{dist/testutils → testutils}/parse_sql.js +0 -0
- /package/{dist/testutils → testutils}/test_edge_global_schema.d.ts +0 -0
- /package/{dist/testutils → testutils}/test_edge_global_schema.js +0 -0
- /package/{dist/testutils → testutils}/write.d.ts +0 -0
- /package/{dist/testutils → testutils}/write.js +0 -0
- /package/{dist/tsc → tsc}/ast.d.ts +0 -0
- /package/{dist/tsc → tsc}/ast.js +0 -0
- /package/{dist/tsc → tsc}/compilerOptions.d.ts +0 -0
- /package/{dist/tsc → tsc}/compilerOptions.js +0 -0
- /package/{dist/tsc → tsc}/move_generated.d.ts +0 -0
- /package/{dist/tsc → tsc}/move_generated.js +0 -0
- /package/{dist/tsc → tsc}/transform.d.ts +0 -0
- /package/{dist/tsc → tsc}/transform.js +0 -0
- /package/{dist/tsc → tsc}/transform_action.d.ts +0 -0
- /package/{dist/tsc → tsc}/transform_action.js +0 -0
- /package/{dist/tsc → tsc}/transform_ent.d.ts +0 -0
- /package/{dist/tsc → tsc}/transform_ent.js +0 -0
- /package/{dist/tsc → tsc}/transform_schema.d.ts +0 -0
- /package/{dist/tsc → tsc}/transform_schema.js +0 -0
|
@@ -0,0 +1,736 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.commonTests = void 0;
|
|
4
|
+
const ent_1 = require("../ent");
|
|
5
|
+
const global_schema_1 = require("../global_schema");
|
|
6
|
+
const viewer_1 = require("../viewer");
|
|
7
|
+
const index_1 = require("../../testutils/fake_data/index");
|
|
8
|
+
const test_helpers_1 = require("../../testutils/fake_data/test_helpers");
|
|
9
|
+
const temp_db_1 = require("../../testutils/db/temp_db");
|
|
10
|
+
const test_context_1 = require("../../testutils/context/test_context");
|
|
11
|
+
const logger_1 = require("../logger");
|
|
12
|
+
const test_edge_global_schema_1 = require("../../testutils/test_edge_global_schema");
|
|
13
|
+
const builder_1 = require("../../testutils/builder");
|
|
14
|
+
const action_1 = require("../../action");
|
|
15
|
+
const clause_1 = require("../clause");
|
|
16
|
+
const query_impl_1 = require("../query_impl");
|
|
17
|
+
function getWhereClause(query) {
|
|
18
|
+
const idx = query.query.indexOf("WHERE");
|
|
19
|
+
if (idx !== -1) {
|
|
20
|
+
return query.query.substr(idx + 6);
|
|
21
|
+
}
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
const commonTests = (opts) => {
|
|
25
|
+
(0, logger_1.setLogLevels)(["query", "error"]);
|
|
26
|
+
const ml = opts.ml;
|
|
27
|
+
ml.mock();
|
|
28
|
+
function isCustomQuery(q) {
|
|
29
|
+
if (q.customQuery !== undefined) {
|
|
30
|
+
return q.customQuery;
|
|
31
|
+
}
|
|
32
|
+
// TODO sad not generic enough
|
|
33
|
+
return (q instanceof index_1.UserToContactsFkeyQuery ||
|
|
34
|
+
q instanceof index_1.UserToContactsFkeyQueryDeprecated ||
|
|
35
|
+
q instanceof index_1.UserToContactsFkeyQueryAsc);
|
|
36
|
+
}
|
|
37
|
+
class TestQueryFilter {
|
|
38
|
+
constructor(filter, newQuery, ents, defaultViewer) {
|
|
39
|
+
this.filter = filter;
|
|
40
|
+
this.newQuery = newQuery;
|
|
41
|
+
this.ents = ents;
|
|
42
|
+
this.defaultViewer = defaultViewer;
|
|
43
|
+
this.allContacts = [];
|
|
44
|
+
this.filteredContacts = [];
|
|
45
|
+
// @ts-ignore
|
|
46
|
+
const q = this.newQuery(this.defaultViewer);
|
|
47
|
+
this.customQuery = isCustomQuery(q);
|
|
48
|
+
}
|
|
49
|
+
async createData() {
|
|
50
|
+
[this.user, this.allContacts] = await (0, test_helpers_1.createAllContacts)();
|
|
51
|
+
// this.allContacts = this.allContacts.reverse();
|
|
52
|
+
this.filteredContacts = this.ents(this.allContacts);
|
|
53
|
+
ml.clear();
|
|
54
|
+
}
|
|
55
|
+
getQuery(viewer) {
|
|
56
|
+
return this.filter(this.newQuery(viewer || this.defaultViewer, this.user), this.user, this.allContacts);
|
|
57
|
+
}
|
|
58
|
+
async testIDs() {
|
|
59
|
+
const ids = await this.getQuery().queryIDs();
|
|
60
|
+
this.verifyIDs(ids);
|
|
61
|
+
}
|
|
62
|
+
verifyIDs(ids) {
|
|
63
|
+
expect(ids).toEqual(this.filteredContacts.map((contact) => contact.id));
|
|
64
|
+
}
|
|
65
|
+
// rawCount isn't affected by filters...
|
|
66
|
+
async testRawCount(expectedCount) {
|
|
67
|
+
const count = await this.getQuery().queryRawCount();
|
|
68
|
+
this.verifyRawCount(count, expectedCount);
|
|
69
|
+
}
|
|
70
|
+
verifyRawCount(count, expectedCount) {
|
|
71
|
+
expect(count).toBe(expectedCount ?? test_helpers_1.inputs.length);
|
|
72
|
+
}
|
|
73
|
+
async testCount(expectedCount) {
|
|
74
|
+
const count = await this.getQuery().queryCount();
|
|
75
|
+
this.verifyCount(count, expectedCount);
|
|
76
|
+
}
|
|
77
|
+
verifyCount(count, expectedCount) {
|
|
78
|
+
expect(count).toBe(expectedCount ?? this.filteredContacts.length);
|
|
79
|
+
}
|
|
80
|
+
async testEdges() {
|
|
81
|
+
const edges = await this.getQuery().queryEdges();
|
|
82
|
+
this.verifyEdges(edges);
|
|
83
|
+
}
|
|
84
|
+
verifyEdges(edges) {
|
|
85
|
+
// TODO sad not generic enough
|
|
86
|
+
if (this.customQuery) {
|
|
87
|
+
(0, test_helpers_1.verifyUserToContactRawData)(this.user, edges, this.filteredContacts);
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
(0, test_helpers_1.verifyUserToContactEdges)(this.user, edges, this.filteredContacts);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
async testEnts(v) {
|
|
94
|
+
const ents = await this.getQuery(v || new viewer_1.IDViewer(this.user.id)).queryEnts();
|
|
95
|
+
this.verifyEnts(ents);
|
|
96
|
+
return ents;
|
|
97
|
+
}
|
|
98
|
+
async testEntsCache() {
|
|
99
|
+
if (!this.customQuery) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
(0, logger_1.setLogLevels)(["query", "cache"]);
|
|
103
|
+
const v = new test_context_1.TestContext(new viewer_1.IDViewer(this.user.id)).getViewer();
|
|
104
|
+
const ents = await this.testEnts(v);
|
|
105
|
+
expect(ml.logs.length).toBe(1);
|
|
106
|
+
expect(ml.logs[0].query).toMatch(/SELECT (.+) FROM /);
|
|
107
|
+
await Promise.all(ents.map((ent) => index_1.FakeContact.loadX(v, ent.id)));
|
|
108
|
+
expect(ml.logs.length).toBe(this.filteredContacts.length + 1);
|
|
109
|
+
for (const log of ml.logs.slice(1)) {
|
|
110
|
+
expect(log["ent-cache-hit"]).toBeDefined();
|
|
111
|
+
}
|
|
112
|
+
// "restore" back to previous
|
|
113
|
+
(0, logger_1.setLogLevels)("query");
|
|
114
|
+
}
|
|
115
|
+
async testDataCache() {
|
|
116
|
+
if (!this.customQuery) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
(0, logger_1.setLogLevels)(["query", "cache"]);
|
|
120
|
+
const v = new test_context_1.TestContext(new viewer_1.IDViewer(this.user.id)).getViewer();
|
|
121
|
+
const ents = await this.testEnts(v);
|
|
122
|
+
expect(ml.logs.length).toBe(1);
|
|
123
|
+
expect(ml.logs[0].query).toMatch(/SELECT (.+) FROM /);
|
|
124
|
+
await Promise.all(ents.map((ent) => index_1.FakeContact.loadRawData(ent.id, v.context)));
|
|
125
|
+
expect(ml.logs.length).toBe(this.filteredContacts.length + 1);
|
|
126
|
+
for (const log of ml.logs.slice(1)) {
|
|
127
|
+
expect(log["dataloader-cache-hit"]).toBeDefined();
|
|
128
|
+
}
|
|
129
|
+
// "restore" back to previous
|
|
130
|
+
(0, logger_1.setLogLevels)("query");
|
|
131
|
+
}
|
|
132
|
+
verifyEnts(ents) {
|
|
133
|
+
(0, test_helpers_1.verifyUserToContacts)(this.user, ents, this.filteredContacts);
|
|
134
|
+
}
|
|
135
|
+
async testAll(expectedCount) {
|
|
136
|
+
const query = this.getQuery(new viewer_1.IDViewer(this.user.id));
|
|
137
|
+
const [edges, count, ids, rawCount, ents] = await Promise.all([
|
|
138
|
+
query.queryEdges(),
|
|
139
|
+
query.queryCount(),
|
|
140
|
+
query.queryIDs(),
|
|
141
|
+
query.queryRawCount(),
|
|
142
|
+
query.queryEnts(),
|
|
143
|
+
]);
|
|
144
|
+
this.verifyCount(count, expectedCount);
|
|
145
|
+
this.verifyEdges(edges);
|
|
146
|
+
this.verifyIDs(ids);
|
|
147
|
+
this.verifyRawCount(rawCount, expectedCount);
|
|
148
|
+
this.verifyEnts(ents);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
function verifyQuery(filter, { length = 1, numQueries = 1, limit = (0, ent_1.getDefaultLimit)(), disablePaginationBump = false, orderby = opts.orderby, }) {
|
|
152
|
+
const uniqCol = isCustomQuery(filter) ? "id" : "id2";
|
|
153
|
+
expect(ml.logs.length).toBe(length);
|
|
154
|
+
for (let i = 0; i < numQueries; i++) {
|
|
155
|
+
const whereClause = getWhereClause(ml.logs[i]);
|
|
156
|
+
let expLimit = disablePaginationBump ? limit : limit + 1;
|
|
157
|
+
expect(whereClause, `${i}`).toBe(
|
|
158
|
+
// default limit
|
|
159
|
+
`${opts.clause.clause(1)} ORDER BY ${(0, query_impl_1.getOrderByPhrase)(orderby)}, ${uniqCol} ${orderby[0].direction} LIMIT ${expLimit}`);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
function verifyCountQuery({ length = 1, numQueries = 1 }) {
|
|
163
|
+
expect(ml.logs.length).toBe(length);
|
|
164
|
+
for (let i = 0; i < numQueries; i++) {
|
|
165
|
+
const whereClause = getWhereClause(ml.logs[i]);
|
|
166
|
+
expect(whereClause).toBe(opts.clause.clause(1));
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
function verifyFirstAfterCursorQuery(filter, length = 1, limit = 3) {
|
|
170
|
+
// cache showing up in a few because of cross runs...
|
|
171
|
+
expect(ml.logs.length).toBeGreaterThanOrEqual(length);
|
|
172
|
+
const uniqCol = isCustomQuery(filter) ? "id" : "id2";
|
|
173
|
+
let parts = opts.clause.clause(1).split(" AND ");
|
|
174
|
+
const cmp = (0, clause_1.PaginationMultipleColsSubQuery)(opts.orderby[0].column, opts.orderby[0].direction === "DESC" ? "<" : ">", opts.tableName, uniqCol, "").clause(opts.clause.values().length + 1);
|
|
175
|
+
if (parts[parts.length - 1] === "deleted_at IS NULL") {
|
|
176
|
+
parts = parts
|
|
177
|
+
.slice(0, parts.length - 1)
|
|
178
|
+
.concat([cmp, "deleted_at IS NULL"]);
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
parts.push(cmp);
|
|
182
|
+
}
|
|
183
|
+
expect(getWhereClause(ml.logs[0])).toBe(`${parts.join(" AND ")} ORDER BY ${(0, query_impl_1.getOrderByPhrase)(opts.orderby)}, ${uniqCol} ${opts.orderby[0].direction} LIMIT ${limit + 1}`);
|
|
184
|
+
}
|
|
185
|
+
function verifyLastBeforeCursorQuery(filter, { length = 1, limit = 3, orderby = opts.orderby }) {
|
|
186
|
+
// cache showing up in a few because of cross runs...
|
|
187
|
+
expect(ml.logs.length).toBeGreaterThanOrEqual(length);
|
|
188
|
+
const uniqCol = isCustomQuery(filter) ? "id" : "id2";
|
|
189
|
+
let parts = opts.clause.clause(1).split(" AND ");
|
|
190
|
+
const cmp = (0, clause_1.PaginationMultipleColsSubQuery)(orderby[0].column, orderby[0].direction === "ASC" ? ">" : "<", opts.tableName, uniqCol, "").clause(opts.clause.values().length + 1);
|
|
191
|
+
if (parts[parts.length - 1] === "deleted_at IS NULL") {
|
|
192
|
+
parts = parts
|
|
193
|
+
.slice(0, parts.length - 1)
|
|
194
|
+
.concat([cmp, "deleted_at IS NULL"]);
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
parts.push(cmp);
|
|
198
|
+
}
|
|
199
|
+
expect(getWhereClause(ml.logs[0])).toBe(
|
|
200
|
+
// extra fetched for pagination
|
|
201
|
+
`${parts.join(" AND ")} ORDER BY ${(0, query_impl_1.getOrderByPhrase)(orderby)}, ${uniqCol} ${orderby[0].direction} LIMIT ${limit + 1}`);
|
|
202
|
+
}
|
|
203
|
+
function getViewer() {
|
|
204
|
+
return new viewer_1.LoggedOutViewer();
|
|
205
|
+
}
|
|
206
|
+
function getCursorFrom(contacts, idx) {
|
|
207
|
+
return (0, ent_1.getCursor)({
|
|
208
|
+
row: contacts[idx],
|
|
209
|
+
col: "id",
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
function getVerifyAfterEachCursor(edges, pageLength, user) {
|
|
213
|
+
let query;
|
|
214
|
+
async function verify(i, hasEdge, hasNextPage, cursor) {
|
|
215
|
+
ml.clear();
|
|
216
|
+
query = opts.newQuery(getViewer(), user);
|
|
217
|
+
const newEdges = await query.first(pageLength, cursor).queryEdges();
|
|
218
|
+
const pagination = query.paginationInfo().get(user.id);
|
|
219
|
+
if (hasEdge) {
|
|
220
|
+
expect(newEdges[0], `${i}`).toStrictEqual(edges[i]);
|
|
221
|
+
expect(newEdges.length, `${i}`).toBe(edges.length - i >= pageLength ? pageLength : edges.length - i);
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
expect(newEdges.length, `${i}`).toBe(0);
|
|
225
|
+
}
|
|
226
|
+
if (hasNextPage) {
|
|
227
|
+
expect(pagination?.hasNextPage, `${i}`).toBe(true);
|
|
228
|
+
expect(pagination?.hasPreviousPage, `${i}`).toBe(false);
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
expect(pagination?.hasNextPage, `${i}`).toBe(undefined);
|
|
232
|
+
expect(pagination?.hasNextPage, `${i}`).toBe(undefined);
|
|
233
|
+
}
|
|
234
|
+
if (cursor) {
|
|
235
|
+
verifyFirstAfterCursorQuery(query, 1, pageLength);
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
verifyQuery(query, { orderby: opts.orderby, limit: pageLength });
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
function getCursor(edge) {
|
|
242
|
+
return query.getCursor(edge);
|
|
243
|
+
}
|
|
244
|
+
return { verify, getCursor };
|
|
245
|
+
}
|
|
246
|
+
function getVerifyBeforeEachCursor(edges, pageLength, user) {
|
|
247
|
+
let query;
|
|
248
|
+
async function verify(i, hasEdge, hasPreviousPage, cursor) {
|
|
249
|
+
ml.clear();
|
|
250
|
+
query = opts.newQuery(getViewer(), user);
|
|
251
|
+
const newEdges = await query.last(pageLength, cursor).queryEdges();
|
|
252
|
+
const pagination = query.paginationInfo().get(user.id);
|
|
253
|
+
if (hasEdge) {
|
|
254
|
+
expect(newEdges.length, `${i}`).toBe(i >= pageLength ? pageLength : i + 1);
|
|
255
|
+
expect(newEdges[0], `${i}`).toStrictEqual(edges[i]);
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
expect(newEdges.length, `${i}`).toBe(0);
|
|
259
|
+
}
|
|
260
|
+
if (hasPreviousPage) {
|
|
261
|
+
expect(pagination?.hasPreviousPage, `${i}`).toBe(true);
|
|
262
|
+
expect(pagination?.hasNextPage, `${i}`).toBe(false);
|
|
263
|
+
}
|
|
264
|
+
else {
|
|
265
|
+
expect(pagination?.hasPreviousPage, `${i}`).toBe(undefined);
|
|
266
|
+
expect(pagination?.hasNextPage, `${i}`).toBe(undefined);
|
|
267
|
+
}
|
|
268
|
+
const orderby = (0, query_impl_1.reverseOrderBy)(opts.orderby);
|
|
269
|
+
if (cursor) {
|
|
270
|
+
verifyLastBeforeCursorQuery(query, {
|
|
271
|
+
length: 1,
|
|
272
|
+
limit: pageLength,
|
|
273
|
+
orderby,
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
verifyQuery(query, {
|
|
278
|
+
orderby,
|
|
279
|
+
limit: pageLength,
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
function getCursor(edge) {
|
|
284
|
+
return query.getCursor(edge);
|
|
285
|
+
}
|
|
286
|
+
return { verify, getCursor };
|
|
287
|
+
}
|
|
288
|
+
if (opts.globalSchema) {
|
|
289
|
+
(0, global_schema_1.setGlobalSchema)(test_edge_global_schema_1.testEdgeGlobalSchema);
|
|
290
|
+
}
|
|
291
|
+
let tdb;
|
|
292
|
+
if (opts.sqlite) {
|
|
293
|
+
(0, temp_db_1.setupSqlite)(`sqlite:///shared_test+${opts.uniqKey}.db`, () => (0, test_helpers_1.tempDBTables)(opts.globalSchema), {
|
|
294
|
+
disableDeleteAfterEachTest: true,
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
beforeAll(async () => {
|
|
298
|
+
if (opts.livePostgresDB) {
|
|
299
|
+
tdb = await (0, test_helpers_1.setupTempDB)(opts.globalSchema);
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
await (0, test_helpers_1.createEdges)();
|
|
303
|
+
});
|
|
304
|
+
afterAll(async () => {
|
|
305
|
+
if (opts.livePostgresDB && tdb) {
|
|
306
|
+
await tdb.afterAll();
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
describe("simple queries", () => {
|
|
310
|
+
const filter = new TestQueryFilter((q) => {
|
|
311
|
+
// no filters
|
|
312
|
+
return q;
|
|
313
|
+
}, opts.newQuery, (contacts) => {
|
|
314
|
+
// nothing to do here
|
|
315
|
+
// reverse because edges are most recent first
|
|
316
|
+
if (opts.orderby[0].direction === "DESC") {
|
|
317
|
+
return contacts.reverse();
|
|
318
|
+
}
|
|
319
|
+
return contacts;
|
|
320
|
+
}, getViewer());
|
|
321
|
+
beforeEach(async () => {
|
|
322
|
+
await filter.createData();
|
|
323
|
+
});
|
|
324
|
+
test("ids", async () => {
|
|
325
|
+
await filter.testIDs();
|
|
326
|
+
verifyQuery(filter, {});
|
|
327
|
+
});
|
|
328
|
+
test("rawCount", async () => {
|
|
329
|
+
await filter.testRawCount();
|
|
330
|
+
verifyCountQuery({});
|
|
331
|
+
});
|
|
332
|
+
test("count", async () => {
|
|
333
|
+
await filter.testCount();
|
|
334
|
+
verifyQuery(filter, {});
|
|
335
|
+
});
|
|
336
|
+
test("edges", async () => {
|
|
337
|
+
await filter.testEdges();
|
|
338
|
+
verifyQuery(filter, {});
|
|
339
|
+
});
|
|
340
|
+
test("ents", async () => {
|
|
341
|
+
await filter.testEnts();
|
|
342
|
+
verifyQuery(filter, { length: opts.entsLength });
|
|
343
|
+
});
|
|
344
|
+
test("all", async () => {
|
|
345
|
+
await filter.testAll();
|
|
346
|
+
});
|
|
347
|
+
test("ents cache", async () => {
|
|
348
|
+
await filter.testEntsCache();
|
|
349
|
+
});
|
|
350
|
+
test("data cache", async () => {
|
|
351
|
+
await filter.testDataCache();
|
|
352
|
+
});
|
|
353
|
+
});
|
|
354
|
+
describe("override default limit", () => {
|
|
355
|
+
const filter = new TestQueryFilter((q) => {
|
|
356
|
+
// no filters
|
|
357
|
+
return q;
|
|
358
|
+
}, opts.newQuery, (contacts) => {
|
|
359
|
+
// nothing to do here
|
|
360
|
+
// reverse because edges are most recent first
|
|
361
|
+
if (opts.orderby[0].direction === "DESC") {
|
|
362
|
+
return contacts.reverse();
|
|
363
|
+
}
|
|
364
|
+
return contacts;
|
|
365
|
+
}, getViewer());
|
|
366
|
+
const OUR_DEFAULT_LIMIT = 10;
|
|
367
|
+
beforeAll(async () => {
|
|
368
|
+
(0, ent_1.setDefaultLimit)(OUR_DEFAULT_LIMIT);
|
|
369
|
+
});
|
|
370
|
+
afterAll(async () => {
|
|
371
|
+
//set it back to real default
|
|
372
|
+
(0, ent_1.setDefaultLimit)(1000);
|
|
373
|
+
});
|
|
374
|
+
beforeEach(async () => {
|
|
375
|
+
await filter.createData();
|
|
376
|
+
});
|
|
377
|
+
test("ids", async () => {
|
|
378
|
+
await filter.testIDs();
|
|
379
|
+
verifyQuery(filter, {
|
|
380
|
+
limit: OUR_DEFAULT_LIMIT,
|
|
381
|
+
});
|
|
382
|
+
});
|
|
383
|
+
test("rawCount", async () => {
|
|
384
|
+
await filter.testRawCount();
|
|
385
|
+
verifyCountQuery({});
|
|
386
|
+
});
|
|
387
|
+
test("count", async () => {
|
|
388
|
+
await filter.testCount();
|
|
389
|
+
verifyQuery(filter, {
|
|
390
|
+
limit: OUR_DEFAULT_LIMIT,
|
|
391
|
+
});
|
|
392
|
+
});
|
|
393
|
+
test("edges", async () => {
|
|
394
|
+
await filter.testEdges();
|
|
395
|
+
verifyQuery(filter, {
|
|
396
|
+
limit: OUR_DEFAULT_LIMIT,
|
|
397
|
+
});
|
|
398
|
+
});
|
|
399
|
+
test("ents", async () => {
|
|
400
|
+
await filter.testEnts();
|
|
401
|
+
verifyQuery(filter, {
|
|
402
|
+
length: opts.entsLength,
|
|
403
|
+
limit: OUR_DEFAULT_LIMIT,
|
|
404
|
+
});
|
|
405
|
+
});
|
|
406
|
+
test("all", async () => {
|
|
407
|
+
await filter.testAll();
|
|
408
|
+
});
|
|
409
|
+
test("ents cache", async () => {
|
|
410
|
+
await filter.testEntsCache();
|
|
411
|
+
});
|
|
412
|
+
test("data cache", async () => {
|
|
413
|
+
await filter.testDataCache();
|
|
414
|
+
});
|
|
415
|
+
});
|
|
416
|
+
describe("after delete", () => {
|
|
417
|
+
const filter = new TestQueryFilter((q) => {
|
|
418
|
+
// no filters
|
|
419
|
+
return q;
|
|
420
|
+
}, opts.newQuery, (contacts) => {
|
|
421
|
+
// nothing expected since deleted
|
|
422
|
+
return [];
|
|
423
|
+
}, getViewer());
|
|
424
|
+
beforeEach(async () => {
|
|
425
|
+
await filter.createData();
|
|
426
|
+
const action = new builder_1.SimpleAction(filter.user.viewer, index_1.FakeUserSchema, new Map(), action_1.WriteOperation.Edit, filter.user);
|
|
427
|
+
await Promise.all(filter.allContacts.map(async (contact) => {
|
|
428
|
+
action.builder.orchestrator.removeOutboundEdge(contact.id, index_1.EdgeType.UserToContacts);
|
|
429
|
+
const action2 = new builder_1.SimpleAction(filter.user.viewer, index_1.FakeContactSchema, new Map(), action_1.WriteOperation.Delete, contact);
|
|
430
|
+
await action2.save();
|
|
431
|
+
}));
|
|
432
|
+
await action.save();
|
|
433
|
+
ml.clear();
|
|
434
|
+
});
|
|
435
|
+
test("ids", async () => {
|
|
436
|
+
await filter.testIDs();
|
|
437
|
+
verifyQuery(filter, {});
|
|
438
|
+
});
|
|
439
|
+
test("rawCount", async () => {
|
|
440
|
+
await filter.testRawCount(0);
|
|
441
|
+
verifyCountQuery({});
|
|
442
|
+
});
|
|
443
|
+
test("count", async () => {
|
|
444
|
+
await filter.testCount(0);
|
|
445
|
+
verifyQuery(filter, {});
|
|
446
|
+
});
|
|
447
|
+
test("edges", async () => {
|
|
448
|
+
await filter.testEdges();
|
|
449
|
+
verifyQuery(filter, {});
|
|
450
|
+
});
|
|
451
|
+
test("ents", async () => {
|
|
452
|
+
await filter.testEnts();
|
|
453
|
+
// no ents so no subsequent query. just the edge query
|
|
454
|
+
verifyQuery(filter, { length: 1 });
|
|
455
|
+
});
|
|
456
|
+
test("all", async () => {
|
|
457
|
+
await filter.testAll(0);
|
|
458
|
+
});
|
|
459
|
+
test("raw_data", async () => {
|
|
460
|
+
if (opts.rawDataVerify) {
|
|
461
|
+
await opts.rawDataVerify(filter.user);
|
|
462
|
+
}
|
|
463
|
+
});
|
|
464
|
+
test("ents cache", async () => {
|
|
465
|
+
await filter.testEntsCache();
|
|
466
|
+
});
|
|
467
|
+
test("data cache", async () => {
|
|
468
|
+
await filter.testDataCache();
|
|
469
|
+
});
|
|
470
|
+
});
|
|
471
|
+
describe("first. no cursor", () => {
|
|
472
|
+
const N = 2;
|
|
473
|
+
const filter = new TestQueryFilter((q) => {
|
|
474
|
+
// no filters
|
|
475
|
+
return q.first(N);
|
|
476
|
+
}, opts.newQuery, (contacts) => {
|
|
477
|
+
if (opts.orderby[0].direction === "DESC") {
|
|
478
|
+
return contacts.reverse().slice(0, N);
|
|
479
|
+
}
|
|
480
|
+
return contacts.slice(0, N);
|
|
481
|
+
}, getViewer());
|
|
482
|
+
beforeEach(async () => {
|
|
483
|
+
await filter.createData();
|
|
484
|
+
});
|
|
485
|
+
test("ids", async () => {
|
|
486
|
+
await filter.testIDs();
|
|
487
|
+
verifyQuery(filter, { limit: 2 });
|
|
488
|
+
});
|
|
489
|
+
test("rawCount", async () => {
|
|
490
|
+
await filter.testRawCount();
|
|
491
|
+
verifyCountQuery({});
|
|
492
|
+
});
|
|
493
|
+
test("count", async () => {
|
|
494
|
+
await filter.testCount();
|
|
495
|
+
verifyQuery(filter, { limit: 2 });
|
|
496
|
+
});
|
|
497
|
+
test("edges", async () => {
|
|
498
|
+
await filter.testEdges();
|
|
499
|
+
verifyQuery(filter, { limit: 2 });
|
|
500
|
+
});
|
|
501
|
+
test("ents", async () => {
|
|
502
|
+
await filter.testEnts();
|
|
503
|
+
verifyQuery(filter, { limit: 2, length: opts.entsLength });
|
|
504
|
+
});
|
|
505
|
+
test("all", async () => {
|
|
506
|
+
await filter.testAll();
|
|
507
|
+
});
|
|
508
|
+
test("ents cache", async () => {
|
|
509
|
+
await filter.testEntsCache();
|
|
510
|
+
});
|
|
511
|
+
test("data cache", async () => {
|
|
512
|
+
await filter.testDataCache();
|
|
513
|
+
});
|
|
514
|
+
});
|
|
515
|
+
describe("last", () => {
|
|
516
|
+
const N = 2;
|
|
517
|
+
const filter = new TestQueryFilter((q) => {
|
|
518
|
+
// no filters
|
|
519
|
+
return q.last(N);
|
|
520
|
+
}, opts.newQuery, (contacts) => {
|
|
521
|
+
if (opts.orderby[0].direction === "DESC") {
|
|
522
|
+
return contacts.slice(0, N);
|
|
523
|
+
}
|
|
524
|
+
else {
|
|
525
|
+
return contacts.reverse().slice(0, N);
|
|
526
|
+
}
|
|
527
|
+
}, getViewer());
|
|
528
|
+
const orderby = (0, query_impl_1.reverseOrderBy)(opts.orderby);
|
|
529
|
+
beforeEach(async () => {
|
|
530
|
+
await filter.createData();
|
|
531
|
+
});
|
|
532
|
+
test("ids", async () => {
|
|
533
|
+
await filter.testIDs();
|
|
534
|
+
verifyQuery(filter, {
|
|
535
|
+
orderby,
|
|
536
|
+
limit: N,
|
|
537
|
+
});
|
|
538
|
+
});
|
|
539
|
+
test("rawCount", async () => {
|
|
540
|
+
await filter.testRawCount();
|
|
541
|
+
verifyCountQuery({});
|
|
542
|
+
});
|
|
543
|
+
test("count", async () => {
|
|
544
|
+
await filter.testCount();
|
|
545
|
+
verifyQuery(filter, { orderby, limit: N });
|
|
546
|
+
});
|
|
547
|
+
test("edges", async () => {
|
|
548
|
+
await filter.testEdges();
|
|
549
|
+
verifyQuery(filter, { orderby, limit: N });
|
|
550
|
+
});
|
|
551
|
+
test("ents", async () => {
|
|
552
|
+
await filter.testEnts();
|
|
553
|
+
verifyQuery(filter, {
|
|
554
|
+
orderby,
|
|
555
|
+
limit: N,
|
|
556
|
+
length: opts.entsLength,
|
|
557
|
+
});
|
|
558
|
+
});
|
|
559
|
+
test("all", async () => {
|
|
560
|
+
await filter.testAll();
|
|
561
|
+
});
|
|
562
|
+
test("ents cache", async () => {
|
|
563
|
+
await filter.testEntsCache();
|
|
564
|
+
});
|
|
565
|
+
test("data cache", async () => {
|
|
566
|
+
await filter.testDataCache();
|
|
567
|
+
});
|
|
568
|
+
});
|
|
569
|
+
describe("first after cursor", () => {
|
|
570
|
+
const idx = 2;
|
|
571
|
+
const N = 3;
|
|
572
|
+
const filter = new TestQueryFilter((q, user, contacts) => {
|
|
573
|
+
return q.first(N, getCursorFrom(contacts, idx));
|
|
574
|
+
}, opts.newQuery, (contacts) => {
|
|
575
|
+
if (opts.orderby[0].direction === "DESC") {
|
|
576
|
+
// < check so we shouldn't get that index
|
|
577
|
+
return contacts.reverse().slice(idx + 1, idx + N);
|
|
578
|
+
}
|
|
579
|
+
else {
|
|
580
|
+
return contacts.slice(idx + 1, idx + N);
|
|
581
|
+
}
|
|
582
|
+
}, getViewer());
|
|
583
|
+
beforeAll(async () => {
|
|
584
|
+
await filter.createData();
|
|
585
|
+
});
|
|
586
|
+
beforeEach(() => {
|
|
587
|
+
ml.clear();
|
|
588
|
+
});
|
|
589
|
+
test("ids", async () => {
|
|
590
|
+
await filter.testIDs();
|
|
591
|
+
verifyFirstAfterCursorQuery(filter);
|
|
592
|
+
});
|
|
593
|
+
test("rawCount", async () => {
|
|
594
|
+
await filter.testRawCount();
|
|
595
|
+
verifyCountQuery({});
|
|
596
|
+
});
|
|
597
|
+
test("count", async () => {
|
|
598
|
+
await filter.testCount();
|
|
599
|
+
verifyFirstAfterCursorQuery(filter);
|
|
600
|
+
});
|
|
601
|
+
test("edges", async () => {
|
|
602
|
+
await filter.testEdges();
|
|
603
|
+
verifyFirstAfterCursorQuery(filter);
|
|
604
|
+
});
|
|
605
|
+
test("ents", async () => {
|
|
606
|
+
await filter.testEnts();
|
|
607
|
+
verifyFirstAfterCursorQuery(filter, opts.entsLength);
|
|
608
|
+
});
|
|
609
|
+
test("all", async () => {
|
|
610
|
+
await filter.testAll();
|
|
611
|
+
});
|
|
612
|
+
test("ents cache", async () => {
|
|
613
|
+
await filter.testEntsCache();
|
|
614
|
+
});
|
|
615
|
+
test("data cache", async () => {
|
|
616
|
+
await filter.testDataCache();
|
|
617
|
+
});
|
|
618
|
+
});
|
|
619
|
+
test("first. after each cursor", async () => {
|
|
620
|
+
let [user] = await (0, test_helpers_1.createAllContacts)();
|
|
621
|
+
const edges = await opts.newQuery(getViewer(), user).queryEdges();
|
|
622
|
+
const { verify, getCursor } = getVerifyAfterEachCursor(edges, 1, user);
|
|
623
|
+
await verify(0, true, true, undefined);
|
|
624
|
+
await verify(1, true, true, getCursor(edges[0]));
|
|
625
|
+
await verify(2, true, true, getCursor(edges[1]));
|
|
626
|
+
await verify(3, true, true, getCursor(edges[2]));
|
|
627
|
+
await verify(4, true, false, getCursor(edges[3]));
|
|
628
|
+
await verify(5, false, false, getCursor(edges[4]));
|
|
629
|
+
});
|
|
630
|
+
describe("last. before cursor", () => {
|
|
631
|
+
const idx = 2;
|
|
632
|
+
const N = 3;
|
|
633
|
+
const filter = new TestQueryFilter((q, user, contacts) => {
|
|
634
|
+
return q.last(N, getCursorFrom(contacts, idx));
|
|
635
|
+
}, opts.newQuery, (contacts) => {
|
|
636
|
+
// > check so we don't want that index
|
|
637
|
+
if (opts.orderby[0].direction === "DESC") {
|
|
638
|
+
return contacts.reverse().slice(0, idx).reverse(); // because of order returned
|
|
639
|
+
}
|
|
640
|
+
return contacts.slice(0, idx).reverse(); // because of order returned
|
|
641
|
+
}, getViewer());
|
|
642
|
+
const orderby = (0, query_impl_1.reverseOrderBy)(opts.orderby);
|
|
643
|
+
beforeAll(async () => {
|
|
644
|
+
if (opts.livePostgresDB || opts.sqlite) {
|
|
645
|
+
await filter.createData();
|
|
646
|
+
}
|
|
647
|
+
});
|
|
648
|
+
beforeEach(async () => {
|
|
649
|
+
ml.clear();
|
|
650
|
+
});
|
|
651
|
+
test("ids", async () => {
|
|
652
|
+
await filter.testIDs();
|
|
653
|
+
verifyLastBeforeCursorQuery(filter, { orderby });
|
|
654
|
+
});
|
|
655
|
+
test("rawCount", async () => {
|
|
656
|
+
await filter.testRawCount();
|
|
657
|
+
verifyCountQuery({});
|
|
658
|
+
});
|
|
659
|
+
test("count", async () => {
|
|
660
|
+
await filter.testCount();
|
|
661
|
+
verifyLastBeforeCursorQuery(filter, { orderby });
|
|
662
|
+
});
|
|
663
|
+
test("edges", async () => {
|
|
664
|
+
await filter.testEdges();
|
|
665
|
+
verifyLastBeforeCursorQuery(filter, { orderby });
|
|
666
|
+
});
|
|
667
|
+
test("ents", async () => {
|
|
668
|
+
await filter.testEnts();
|
|
669
|
+
verifyLastBeforeCursorQuery(filter, { orderby });
|
|
670
|
+
});
|
|
671
|
+
test("all", async () => {
|
|
672
|
+
await filter.testAll();
|
|
673
|
+
});
|
|
674
|
+
test("ents cache", async () => {
|
|
675
|
+
await filter.testEntsCache();
|
|
676
|
+
});
|
|
677
|
+
test("data cache", async () => {
|
|
678
|
+
await filter.testDataCache();
|
|
679
|
+
});
|
|
680
|
+
});
|
|
681
|
+
test("last. before each cursor", async () => {
|
|
682
|
+
let [user] = await (0, test_helpers_1.createAllContacts)();
|
|
683
|
+
const edges = await opts.newQuery(getViewer(), user).queryEdges();
|
|
684
|
+
const { verify, getCursor } = getVerifyBeforeEachCursor(edges, 1, user);
|
|
685
|
+
await verify(4, true, true, undefined);
|
|
686
|
+
await verify(3, true, true, getCursor(edges[4]));
|
|
687
|
+
await verify(2, true, true, getCursor(edges[3]));
|
|
688
|
+
await verify(1, true, true, getCursor(edges[2]));
|
|
689
|
+
await verify(0, true, false, getCursor(edges[1]));
|
|
690
|
+
await verify(-1, false, false, getCursor(edges[0]));
|
|
691
|
+
});
|
|
692
|
+
describe("with conflicts", () => {
|
|
693
|
+
let user;
|
|
694
|
+
let allEdges = [];
|
|
695
|
+
beforeEach(async () => {
|
|
696
|
+
const [u, contacts] = await (0, test_helpers_1.createAllContacts)();
|
|
697
|
+
user = u;
|
|
698
|
+
const [_, contacts2] = await (0, test_helpers_1.createAllContacts)({
|
|
699
|
+
user,
|
|
700
|
+
start: contacts[contacts.length - 1].createdAt.getTime() - 100,
|
|
701
|
+
});
|
|
702
|
+
await (0, test_helpers_1.createAllContacts)({
|
|
703
|
+
user,
|
|
704
|
+
start: contacts2[contacts.length - 1].createdAt.getTime() - 100,
|
|
705
|
+
});
|
|
706
|
+
const edges = await opts.newQuery(getViewer(), user).queryEdges();
|
|
707
|
+
// confirm there are duplicates...
|
|
708
|
+
expect(edges[4].created_at).toStrictEqual(edges[5].created_at);
|
|
709
|
+
expect(edges[9].created_at).toStrictEqual(edges[10].created_at);
|
|
710
|
+
allEdges = edges;
|
|
711
|
+
});
|
|
712
|
+
test("first after each cursor", async () => {
|
|
713
|
+
const { verify, getCursor } = getVerifyAfterEachCursor(allEdges, 5, user);
|
|
714
|
+
// regular pagination
|
|
715
|
+
await verify(0, true, true, undefined);
|
|
716
|
+
await verify(5, true, true, getCursor(allEdges[4]));
|
|
717
|
+
await verify(10, true, false, getCursor(allEdges[9]));
|
|
718
|
+
await verify(15, false, false, getCursor(allEdges[14]));
|
|
719
|
+
// one without duplicates work if we were paginating at a different place...
|
|
720
|
+
await verify(6, true, true, getCursor(allEdges[5]));
|
|
721
|
+
await verify(11, true, false, getCursor(allEdges[10]));
|
|
722
|
+
});
|
|
723
|
+
test("last before each cursor", async () => {
|
|
724
|
+
const { verify, getCursor } = getVerifyBeforeEachCursor(allEdges, 5, user);
|
|
725
|
+
await verify(14, true, true, undefined);
|
|
726
|
+
await verify(13, true, true, getCursor(allEdges[14]));
|
|
727
|
+
await verify(8, true, true, getCursor(allEdges[9]));
|
|
728
|
+
await verify(9, true, true, getCursor(allEdges[10]));
|
|
729
|
+
await verify(3, true, false, getCursor(allEdges[4]));
|
|
730
|
+
await verify(4, true, false, getCursor(allEdges[5]));
|
|
731
|
+
});
|
|
732
|
+
});
|
|
733
|
+
};
|
|
734
|
+
exports.commonTests = commonTests;
|
|
735
|
+
// TODO parse_sql group by...
|
|
736
|
+
// or test it with real db...
|