@snowtop/ent 0.1.0-alpha1 → 0.1.0-alpha100
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/action/action.d.ts +38 -30
- package/action/action.js +22 -7
- package/action/executor.d.ts +4 -4
- package/action/executor.js +8 -3
- package/action/experimental_action.d.ts +32 -22
- package/action/experimental_action.js +35 -9
- package/action/index.d.ts +2 -0
- package/action/index.js +7 -1
- package/action/orchestrator.d.ts +48 -16
- package/action/orchestrator.js +343 -81
- package/action/privacy.d.ts +2 -2
- package/action/relative_value.d.ts +47 -0
- package/action/relative_value.js +125 -0
- package/action/transaction.d.ts +10 -0
- package/action/transaction.js +23 -0
- package/auth/auth.d.ts +1 -1
- package/core/base.d.ts +54 -27
- package/core/base.js +23 -1
- package/core/clause.d.ts +105 -3
- package/core/clause.js +563 -30
- package/core/config.d.ts +30 -1
- package/core/config.js +24 -1
- package/core/context.d.ts +5 -3
- package/core/context.js +20 -2
- package/core/convert.d.ts +1 -1
- package/core/date.js +1 -5
- package/core/db.d.ts +14 -11
- package/core/db.js +22 -8
- package/core/ent.d.ts +82 -28
- package/core/ent.js +692 -202
- package/core/loaders/assoc_count_loader.d.ts +3 -2
- package/core/loaders/assoc_count_loader.js +10 -2
- package/core/loaders/assoc_edge_loader.d.ts +3 -3
- package/core/loaders/assoc_edge_loader.js +13 -15
- package/core/loaders/index.d.ts +1 -1
- package/core/loaders/index.js +1 -3
- package/core/loaders/index_loader.d.ts +2 -2
- package/core/loaders/index_loader.js +1 -0
- package/core/loaders/loader.js +5 -5
- package/core/loaders/object_loader.d.ts +13 -7
- package/core/loaders/object_loader.js +95 -32
- package/core/loaders/query_loader.d.ts +6 -12
- package/core/loaders/query_loader.js +52 -11
- package/core/loaders/raw_count_loader.d.ts +2 -2
- package/core/loaders/raw_count_loader.js +5 -1
- package/core/logger.d.ts +1 -1
- package/core/logger.js +1 -0
- package/core/privacy.d.ts +26 -25
- package/core/privacy.js +23 -24
- package/core/query/assoc_query.d.ts +7 -6
- package/core/query/assoc_query.js +9 -1
- package/core/query/custom_clause_query.d.ts +26 -0
- package/core/query/custom_clause_query.js +78 -0
- package/core/query/custom_query.d.ts +20 -5
- package/core/query/custom_query.js +87 -12
- package/core/query/index.d.ts +1 -0
- package/core/query/index.js +3 -1
- package/core/query/query.d.ts +8 -4
- package/core/query/query.js +101 -53
- package/core/query/shared_assoc_test.d.ts +2 -1
- package/core/query/shared_assoc_test.js +35 -45
- package/core/query/shared_test.d.ts +8 -1
- package/core/query/shared_test.js +469 -236
- package/core/viewer.d.ts +4 -3
- package/core/viewer.js +5 -1
- package/graphql/builtins/connection.js +3 -3
- package/graphql/builtins/edge.js +2 -2
- package/graphql/builtins/node.js +1 -1
- package/graphql/graphql.d.ts +17 -9
- package/graphql/graphql.js +47 -30
- package/graphql/index.d.ts +1 -1
- package/graphql/index.js +3 -4
- package/graphql/mutations/union.d.ts +2 -0
- package/graphql/mutations/union.js +35 -0
- package/graphql/node_resolver.d.ts +0 -1
- package/graphql/query/connection_type.d.ts +9 -9
- package/graphql/query/connection_type.js +6 -6
- package/graphql/query/edge_connection.d.ts +9 -9
- package/graphql/query/page_info.d.ts +1 -1
- package/graphql/query/page_info.js +4 -4
- package/graphql/query/shared_assoc_test.js +3 -3
- package/graphql/query/shared_edge_connection.js +1 -19
- package/graphql/scalars/time.d.ts +1 -1
- package/imports/index.d.ts +6 -1
- package/imports/index.js +19 -4
- package/index.d.ts +23 -1
- package/index.js +32 -6
- package/package.json +18 -17
- package/parse_schema/parse.d.ts +45 -8
- package/parse_schema/parse.js +193 -15
- package/schema/base_schema.d.ts +38 -1
- package/schema/base_schema.js +53 -2
- package/schema/field.d.ts +75 -21
- package/schema/field.js +185 -72
- package/schema/index.d.ts +4 -2
- package/schema/index.js +15 -2
- package/schema/json_field.d.ts +13 -1
- package/schema/json_field.js +28 -1
- package/schema/schema.d.ts +125 -10
- package/schema/schema.js +133 -5
- package/schema/struct_field.d.ts +27 -0
- package/schema/struct_field.js +138 -0
- package/schema/union_field.d.ts +23 -0
- package/schema/union_field.js +79 -0
- package/scripts/custom_compiler.js +10 -6
- package/scripts/custom_graphql.js +224 -36
- package/scripts/{transform_schema.d.ts → migrate_v0.1.d.ts} +0 -0
- package/scripts/migrate_v0.1.js +36 -0
- package/scripts/move_types.d.ts +1 -0
- package/scripts/move_types.js +117 -0
- package/scripts/read_schema.js +35 -6
- package/testutils/action/complex_schemas.d.ts +69 -0
- package/testutils/action/complex_schemas.js +398 -0
- package/testutils/builder.d.ts +52 -49
- package/testutils/builder.js +143 -44
- package/testutils/context/test_context.d.ts +2 -2
- package/testutils/context/test_context.js +7 -1
- package/testutils/db/fixture.d.ts +10 -0
- package/testutils/db/fixture.js +26 -0
- package/testutils/db/{test_db.d.ts → temp_db.d.ts} +26 -9
- package/testutils/db/{test_db.js → temp_db.js} +190 -46
- package/testutils/db/value.d.ts +7 -0
- package/testutils/db/value.js +251 -0
- package/testutils/db_mock.d.ts +16 -4
- package/testutils/db_mock.js +51 -6
- package/testutils/db_time_zone.d.ts +4 -0
- package/testutils/db_time_zone.js +41 -0
- package/testutils/ent-graphql-tests/index.d.ts +9 -1
- package/testutils/ent-graphql-tests/index.js +53 -25
- package/testutils/fake_data/const.d.ts +2 -1
- package/testutils/fake_data/const.js +3 -0
- package/testutils/fake_data/fake_contact.d.ts +10 -10
- package/testutils/fake_data/fake_contact.js +23 -21
- package/testutils/fake_data/fake_event.d.ts +8 -9
- package/testutils/fake_data/fake_event.js +25 -28
- package/testutils/fake_data/fake_tag.d.ts +36 -0
- package/testutils/fake_data/fake_tag.js +89 -0
- package/testutils/fake_data/fake_user.d.ts +10 -11
- package/testutils/fake_data/fake_user.js +20 -23
- package/testutils/fake_data/index.js +5 -1
- package/testutils/fake_data/internal.d.ts +2 -0
- package/testutils/fake_data/internal.js +7 -1
- package/testutils/fake_data/tag_query.d.ts +13 -0
- package/testutils/fake_data/tag_query.js +43 -0
- package/testutils/fake_data/test_helpers.d.ts +11 -4
- package/testutils/fake_data/test_helpers.js +29 -13
- package/testutils/fake_data/user_query.d.ts +13 -6
- package/testutils/fake_data/user_query.js +54 -22
- package/testutils/fake_log.d.ts +3 -3
- package/testutils/parse_sql.d.ts +6 -0
- package/testutils/parse_sql.js +16 -2
- package/testutils/test_edge_global_schema.d.ts +15 -0
- package/testutils/test_edge_global_schema.js +62 -0
- package/testutils/write.d.ts +2 -2
- package/testutils/write.js +33 -7
- package/tsc/ast.d.ts +44 -0
- package/tsc/ast.js +277 -0
- package/tsc/compilerOptions.d.ts +6 -0
- package/tsc/compilerOptions.js +45 -2
- package/tsc/move_generated.d.ts +1 -0
- package/tsc/move_generated.js +164 -0
- package/tsc/transform.d.ts +22 -0
- package/tsc/transform.js +181 -0
- package/tsc/transform_action.d.ts +22 -0
- package/tsc/transform_action.js +183 -0
- package/tsc/transform_ent.d.ts +17 -0
- package/tsc/transform_ent.js +59 -0
- package/tsc/transform_schema.d.ts +27 -0
- package/tsc/transform_schema.js +383 -0
- package/graphql/enums.d.ts +0 -3
- package/graphql/enums.js +0 -25
- package/scripts/transform_schema.js +0 -288
package/testutils/db_mock.js
CHANGED
|
@@ -29,7 +29,11 @@ var queryType;
|
|
|
29
29
|
queryType[queryType["BEGIN"] = 3] = "BEGIN";
|
|
30
30
|
queryType[queryType["COMMIT"] = 4] = "COMMIT";
|
|
31
31
|
queryType[queryType["ROLLBACK"] = 5] = "ROLLBACK";
|
|
32
|
+
queryType[queryType["DELETE"] = 6] = "DELETE";
|
|
32
33
|
})(queryType = exports.queryType || (exports.queryType = {}));
|
|
34
|
+
/**
|
|
35
|
+
* @deprecated
|
|
36
|
+
*/
|
|
33
37
|
class QueryRecorder {
|
|
34
38
|
// TODO kill use AST or just throw away
|
|
35
39
|
static getQueryStructure(query) {
|
|
@@ -76,6 +80,36 @@ class QueryRecorder {
|
|
|
76
80
|
};
|
|
77
81
|
}
|
|
78
82
|
}
|
|
83
|
+
if (/^DELETE/.test(query)) {
|
|
84
|
+
// regex can't do returning
|
|
85
|
+
let execArray = /^DELETE FROM (.+) WHERE (.+) /.exec(query);
|
|
86
|
+
if (execArray) {
|
|
87
|
+
return {
|
|
88
|
+
tableName: execArray[1],
|
|
89
|
+
whereClause: execArray[2],
|
|
90
|
+
type: queryType.DELETE,
|
|
91
|
+
query: execArray[0],
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (/^BEGIN/.test(query)) {
|
|
96
|
+
return {
|
|
97
|
+
type: queryType.BEGIN,
|
|
98
|
+
query: query,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
if (/^COMMIT/.test(query)) {
|
|
102
|
+
return {
|
|
103
|
+
type: queryType.COMMIT,
|
|
104
|
+
query: query,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
if (/^ROLLBACK/.test(query)) {
|
|
108
|
+
return {
|
|
109
|
+
type: queryType.ROLLBACK,
|
|
110
|
+
query: query,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
79
113
|
return null;
|
|
80
114
|
}
|
|
81
115
|
static recordQuery(query, values) {
|
|
@@ -131,7 +165,12 @@ class QueryRecorder {
|
|
|
131
165
|
static getCurrentQueries() {
|
|
132
166
|
return QueryRecorder.queries;
|
|
133
167
|
}
|
|
134
|
-
|
|
168
|
+
/**
|
|
169
|
+
* @deprecated will keep this since it's just using ml.logs
|
|
170
|
+
* which we still want around (I think) but we should eventually
|
|
171
|
+
* probably stop using this
|
|
172
|
+
*/
|
|
173
|
+
static validateQueryStructuresFromLogs(ml, expected, opts) {
|
|
135
174
|
const queries = ml.logs.map((log) => {
|
|
136
175
|
const qs = QueryRecorder.getQueryStructure(log.query);
|
|
137
176
|
if (!qs) {
|
|
@@ -142,12 +181,16 @@ class QueryRecorder {
|
|
|
142
181
|
qs,
|
|
143
182
|
};
|
|
144
183
|
});
|
|
145
|
-
QueryRecorder.
|
|
184
|
+
QueryRecorder.validateQueryStructuresImpl(expected, queries, opts);
|
|
146
185
|
}
|
|
147
|
-
static
|
|
148
|
-
if (skipSelect) {
|
|
186
|
+
static validateQueryStructuresImpl(expected, queries, opts) {
|
|
187
|
+
if (opts?.skipSelect) {
|
|
149
188
|
queries = queries.filter((query) => query.qs?.type !== queryType.SELECT);
|
|
150
189
|
}
|
|
190
|
+
if (!opts?.flagBeginCommit) {
|
|
191
|
+
queries = queries.filter((query) => query.qs?.type !== queryType.BEGIN &&
|
|
192
|
+
query.qs?.type !== queryType.COMMIT);
|
|
193
|
+
}
|
|
151
194
|
// console.log(queries, expected);
|
|
152
195
|
expect(queries.length).toBe(expected.length);
|
|
153
196
|
for (let i = 0; i < expected.length; i++) {
|
|
@@ -167,7 +210,7 @@ class QueryRecorder {
|
|
|
167
210
|
expect(query.values).toBe(undefined);
|
|
168
211
|
break;
|
|
169
212
|
case queryType.SELECT:
|
|
170
|
-
if (!skipSelect) {
|
|
213
|
+
if (!opts?.skipSelect) {
|
|
171
214
|
console.error("validating select query structure not supported yet");
|
|
172
215
|
}
|
|
173
216
|
// TODO INSERT and UPDATE tests here...
|
|
@@ -185,7 +228,9 @@ class QueryRecorder {
|
|
|
185
228
|
}
|
|
186
229
|
}
|
|
187
230
|
static mockPool(pool) {
|
|
188
|
-
const mockedPool = (0, jest_mock_1.mocked)(pool
|
|
231
|
+
const mockedPool = (0, jest_mock_1.mocked)(pool);
|
|
232
|
+
// @ts-ignore
|
|
233
|
+
// TODO what changed in mockImplementation?
|
|
189
234
|
mockedPool.mockImplementation(() => {
|
|
190
235
|
return {
|
|
191
236
|
totalCount: 1,
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DBTimeZone = void 0;
|
|
7
|
+
const luxon_1 = require("luxon");
|
|
8
|
+
const schema_1 = require("../schema");
|
|
9
|
+
const db_1 = __importDefault(require("../core/db"));
|
|
10
|
+
let dbCurrentZone = undefined;
|
|
11
|
+
class DBTimeZone {
|
|
12
|
+
static async getVal() {
|
|
13
|
+
if (dbCurrentZone !== undefined) {
|
|
14
|
+
return dbCurrentZone;
|
|
15
|
+
}
|
|
16
|
+
const r = await db_1.default.getInstance()
|
|
17
|
+
.getPool()
|
|
18
|
+
.query("SELECT current_setting('TIMEZONE');");
|
|
19
|
+
if (r.rows.length) {
|
|
20
|
+
dbCurrentZone = r.rows[0].current_setting;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
dbCurrentZone = null;
|
|
24
|
+
}
|
|
25
|
+
return dbCurrentZone;
|
|
26
|
+
}
|
|
27
|
+
static async getDateOffset(d) {
|
|
28
|
+
let zone = await DBTimeZone.getVal();
|
|
29
|
+
let dt = luxon_1.DateTime.fromJSDate(d);
|
|
30
|
+
if (zone) {
|
|
31
|
+
dt = dt.setZone(zone);
|
|
32
|
+
}
|
|
33
|
+
// use
|
|
34
|
+
const val = (0, schema_1.leftPad)(dt.get("offset") / 60);
|
|
35
|
+
if (val == "00") {
|
|
36
|
+
return "+00";
|
|
37
|
+
}
|
|
38
|
+
return val;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.DBTimeZone = DBTimeZone;
|
|
@@ -2,7 +2,7 @@ import { Express, RequestHandler } from "express";
|
|
|
2
2
|
import { Viewer } from "../../core/base";
|
|
3
3
|
import { GraphQLSchema } from "graphql";
|
|
4
4
|
import supertest from "supertest";
|
|
5
|
-
export
|
|
5
|
+
export type Option = [string, any];
|
|
6
6
|
interface queryConfig {
|
|
7
7
|
viewer?: Viewer;
|
|
8
8
|
init?: (app: Express) => void;
|
|
@@ -11,11 +11,19 @@ interface queryConfig {
|
|
|
11
11
|
headers?: object;
|
|
12
12
|
debugMode?: boolean;
|
|
13
13
|
args: {};
|
|
14
|
+
extraVariables?: {
|
|
15
|
+
[key: string]: {
|
|
16
|
+
graphqlType: string;
|
|
17
|
+
value: string;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
14
20
|
expectedStatus?: number;
|
|
15
21
|
expectedError?: string | RegExp;
|
|
16
22
|
callback?: (res: supertest.Response) => void;
|
|
17
23
|
inlineFragmentRoot?: string;
|
|
18
24
|
customHandlers?: RequestHandler[];
|
|
25
|
+
server?: any;
|
|
26
|
+
graphQLPath?: string;
|
|
19
27
|
}
|
|
20
28
|
export interface queryRootConfig extends queryConfig {
|
|
21
29
|
root: string;
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -26,11 +30,12 @@ exports.expectMutation = exports.expectQueryFromRoot = void 0;
|
|
|
26
30
|
// NB: this is copied from ent-graphql-tests package until I have time to figure out how to share code here effectively
|
|
27
31
|
// the circular dependencies btw this package and ent-graphql-tests seems to imply something needs to change
|
|
28
32
|
const express_1 = __importDefault(require("express"));
|
|
29
|
-
const
|
|
33
|
+
const graphql_helix_1 = require("graphql-helix");
|
|
30
34
|
const graphql_1 = require("graphql");
|
|
31
35
|
const auth_1 = require("../../auth");
|
|
32
36
|
const supertest_1 = __importDefault(require("supertest"));
|
|
33
37
|
const fs = __importStar(require("fs"));
|
|
38
|
+
const util_1 = require("util");
|
|
34
39
|
function server(config) {
|
|
35
40
|
const viewer = config.viewer;
|
|
36
41
|
if (viewer) {
|
|
@@ -45,18 +50,26 @@ function server(config) {
|
|
|
45
50
|
if (config.init) {
|
|
46
51
|
config.init(app);
|
|
47
52
|
}
|
|
53
|
+
// @ts-ignore something changed. come back
|
|
54
|
+
app.use(express_1.default.json());
|
|
48
55
|
let handlers = config.customHandlers || [];
|
|
49
|
-
handlers.push(
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
handlers.push(async (req, res) => {
|
|
57
|
+
const { operationName, query, variables } = (0, graphql_helix_1.getGraphQLParameters)(req);
|
|
58
|
+
const result = await (0, graphql_helix_1.processRequest)({
|
|
59
|
+
operationName,
|
|
60
|
+
query,
|
|
61
|
+
variables,
|
|
62
|
+
request: req,
|
|
63
|
+
schema: config.schema,
|
|
64
|
+
contextFactory: async (executionContext) => {
|
|
65
|
+
// @ts-ignore something changed. come back
|
|
66
|
+
return (0, auth_1.buildContext)(req, res);
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
// @ts-ignore something changed. come back
|
|
70
|
+
await (0, graphql_helix_1.sendResult)(result, res);
|
|
71
|
+
});
|
|
72
|
+
app.use(config.graphQLPath || "/graphql", ...handlers);
|
|
60
73
|
return app;
|
|
61
74
|
}
|
|
62
75
|
function getInnerType(typ, list) {
|
|
@@ -72,14 +85,14 @@ function makeGraphQLRequest(config, query, fieldArgs) {
|
|
|
72
85
|
let test;
|
|
73
86
|
if (config.test) {
|
|
74
87
|
if (typeof config.test === "function") {
|
|
75
|
-
test = config.test(server(config));
|
|
88
|
+
test = config.test(config.server ? config.server : server(config));
|
|
76
89
|
}
|
|
77
90
|
else {
|
|
78
91
|
test = config.test;
|
|
79
92
|
}
|
|
80
93
|
}
|
|
81
94
|
else {
|
|
82
|
-
test = (0, supertest_1.default)(server(config));
|
|
95
|
+
test = (0, supertest_1.default)(config.server ? config.server : server(config));
|
|
83
96
|
}
|
|
84
97
|
let files = new Map();
|
|
85
98
|
// handle files
|
|
@@ -103,15 +116,23 @@ function makeGraphQLRequest(config, query, fieldArgs) {
|
|
|
103
116
|
}
|
|
104
117
|
}
|
|
105
118
|
});
|
|
119
|
+
let variables = {
|
|
120
|
+
...config.args,
|
|
121
|
+
};
|
|
122
|
+
for (const k in config.extraVariables) {
|
|
123
|
+
variables[k] = config.extraVariables[k].value;
|
|
124
|
+
}
|
|
106
125
|
if (files.size) {
|
|
107
|
-
let ret = test
|
|
126
|
+
let ret = test
|
|
127
|
+
.post(config.graphQLPath || "/graphql")
|
|
128
|
+
.set(config.headers || {});
|
|
108
129
|
ret.field("operations", JSON.stringify({
|
|
109
130
|
query: query,
|
|
110
|
-
variables:
|
|
131
|
+
variables: variables,
|
|
111
132
|
}));
|
|
112
133
|
let m = {};
|
|
113
134
|
let idx = 0;
|
|
114
|
-
for (const [key
|
|
135
|
+
for (const [key] of files) {
|
|
115
136
|
m[idx] = [`variables.${key}`];
|
|
116
137
|
idx++;
|
|
117
138
|
}
|
|
@@ -130,11 +151,11 @@ function makeGraphQLRequest(config, query, fieldArgs) {
|
|
|
130
151
|
return [
|
|
131
152
|
test,
|
|
132
153
|
test
|
|
133
|
-
.post("/graphql")
|
|
154
|
+
.post(config.graphQLPath || "/graphql")
|
|
134
155
|
.set(config.headers || {})
|
|
135
156
|
.send({
|
|
136
157
|
query: query,
|
|
137
|
-
variables: JSON.stringify(
|
|
158
|
+
variables: JSON.stringify(variables),
|
|
138
159
|
}),
|
|
139
160
|
];
|
|
140
161
|
}
|
|
@@ -150,7 +171,7 @@ function buildTreeFromQueryPaths(schema, fieldType, ...options) {
|
|
|
150
171
|
let parts = [];
|
|
151
172
|
let match = fragmentRegex.exec(path);
|
|
152
173
|
if (match) {
|
|
153
|
-
// fragment, keep the part of the fragment e.g.
|
|
174
|
+
// fragment, keep the part of the fragment e.g. `...on User`, and then split the rest....
|
|
154
175
|
parts = [match[0], ...match[2].split(".")];
|
|
155
176
|
const typ = schema.getType(match[1]);
|
|
156
177
|
if (!typ) {
|
|
@@ -209,7 +230,7 @@ function buildTreeFromQueryPaths(schema, fieldType, ...options) {
|
|
|
209
230
|
}
|
|
210
231
|
// only spread out if an object
|
|
211
232
|
const [typ, _] = getInnerType(subField.type, true);
|
|
212
|
-
return (0, graphql_1.isScalarType)(typ);
|
|
233
|
+
return (0, graphql_1.isScalarType)(typ) || (0, graphql_1.isEnumType)(typ);
|
|
213
234
|
}
|
|
214
235
|
if (i === parts.length - 1 && typeof option[1] === "object") {
|
|
215
236
|
if (!isScalarField(part)) {
|
|
@@ -295,13 +316,18 @@ async function expectFromRoot(config, ...options) {
|
|
|
295
316
|
let fieldArgs = field.args;
|
|
296
317
|
let queryParams = [];
|
|
297
318
|
fieldArgs.forEach((fieldArg) => {
|
|
298
|
-
|
|
319
|
+
const arg = config.args[fieldArg.name];
|
|
299
320
|
// let the graphql runtime handle this (it may be optional for example)
|
|
300
321
|
if (arg === undefined) {
|
|
301
322
|
return;
|
|
302
323
|
}
|
|
303
324
|
queryParams.push(`$${fieldArg.name}: ${fieldArg.type}`);
|
|
304
325
|
});
|
|
326
|
+
// add extra variables in queryArgs...
|
|
327
|
+
for (const key in config.extraVariables) {
|
|
328
|
+
const v = config.extraVariables[key];
|
|
329
|
+
queryParams.push(`$${key}: ${v.graphqlType}`);
|
|
330
|
+
}
|
|
305
331
|
let params = [];
|
|
306
332
|
for (let key in config.args) {
|
|
307
333
|
params.push(`${key}: $${key}`);
|
|
@@ -340,7 +366,7 @@ async function expectFromRoot(config, ...options) {
|
|
|
340
366
|
let [st, temp] = makeGraphQLRequest(config, q, fieldArgs);
|
|
341
367
|
const res = await temp.expect("Content-Type", /json/);
|
|
342
368
|
if (config.debugMode) {
|
|
343
|
-
console.log(res.body);
|
|
369
|
+
console.log((0, util_1.inspect)(res.body, false, 3));
|
|
344
370
|
}
|
|
345
371
|
// if there's a callback, let everything be done there and we're done
|
|
346
372
|
if (config.callback) {
|
|
@@ -353,7 +379,9 @@ async function expectFromRoot(config, ...options) {
|
|
|
353
379
|
else {
|
|
354
380
|
expect(res.ok, `expected ok response. instead got ${res.status} and result ${JSON.stringify(res.body)}`);
|
|
355
381
|
}
|
|
356
|
-
|
|
382
|
+
// res.ok = true in graphql-helix when there's errors...
|
|
383
|
+
// res.ok = false in express-graphql when there's errors...
|
|
384
|
+
if (!res.ok || (res.body.errors && res.body.errors.length > 0)) {
|
|
357
385
|
let errors = res.body.errors;
|
|
358
386
|
expect(errors.length).toBeGreaterThan(0);
|
|
359
387
|
if (config.expectedError) {
|
|
@@ -18,7 +18,8 @@ export declare enum EdgeType {
|
|
|
18
18
|
export declare enum NodeType {
|
|
19
19
|
FakeUser = "user",
|
|
20
20
|
FakeContact = "contact",
|
|
21
|
-
FakeEvent = "event"
|
|
21
|
+
FakeEvent = "event",
|
|
22
|
+
FakeTag = "tag"
|
|
22
23
|
}
|
|
23
24
|
export declare const SymmetricEdges: Set<string>;
|
|
24
25
|
export declare const InverseEdges: Map<EdgeType, EdgeType>;
|
|
@@ -27,6 +27,7 @@ var NodeType;
|
|
|
27
27
|
NodeType["FakeUser"] = "user";
|
|
28
28
|
NodeType["FakeContact"] = "contact";
|
|
29
29
|
NodeType["FakeEvent"] = "event";
|
|
30
|
+
NodeType["FakeTag"] = "tag";
|
|
30
31
|
})(NodeType = exports.NodeType || (exports.NodeType = {}));
|
|
31
32
|
exports.SymmetricEdges = new Set();
|
|
32
33
|
exports.SymmetricEdges.add(EdgeType.UserToFriends);
|
|
@@ -48,6 +49,8 @@ function getLoaderOptions(type) {
|
|
|
48
49
|
return internal_1.FakeUser.loaderOptions();
|
|
49
50
|
case NodeType.FakeEvent:
|
|
50
51
|
return internal_1.FakeEvent.loaderOptions();
|
|
52
|
+
case NodeType.FakeTag:
|
|
53
|
+
return internal_1.FakeTag.loaderOptions();
|
|
51
54
|
}
|
|
52
55
|
}
|
|
53
56
|
exports.getLoaderOptions = getLoaderOptions;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { ID, Ent, Viewer, Data, LoadEntOptions, PrivacyPolicy } from "../../core/base";
|
|
2
|
-
import {
|
|
3
|
-
import { BaseEntSchema, FieldMap } from "../../schema";
|
|
1
|
+
import { ID, Ent, Viewer, Data, LoadEntOptions, PrivacyPolicy, Context } from "../../core/base";
|
|
2
|
+
import { SimpleBuilder } from "../builder";
|
|
4
3
|
import { NodeType } from "./const";
|
|
5
4
|
import { ObjectLoaderFactory } from "../../core/loaders";
|
|
6
5
|
export declare class FakeContact implements Ent {
|
|
@@ -14,24 +13,25 @@ export declare class FakeContact implements Ent {
|
|
|
14
13
|
readonly lastName: string;
|
|
15
14
|
readonly emailAddress: string;
|
|
16
15
|
readonly userID: ID;
|
|
17
|
-
|
|
16
|
+
getPrivacyPolicy(): PrivacyPolicy<this>;
|
|
18
17
|
constructor(viewer: Viewer, data: Data);
|
|
18
|
+
__setRawDBData(data: Data): void;
|
|
19
19
|
static getFields(): string[];
|
|
20
|
-
static getTestTable(): import("../db/
|
|
20
|
+
static getTestTable(): import("../db/temp_db").Table;
|
|
21
21
|
static loaderOptions(): LoadEntOptions<FakeContact>;
|
|
22
22
|
static load(v: Viewer, id: ID): Promise<FakeContact | null>;
|
|
23
23
|
static loadX(v: Viewer, id: ID): Promise<FakeContact>;
|
|
24
|
+
static loadRawData(id: ID, context?: Context): Promise<Data | null>;
|
|
24
25
|
}
|
|
25
|
-
export declare
|
|
26
|
-
ent: typeof FakeContact;
|
|
27
|
-
fields: FieldMap;
|
|
28
|
-
}
|
|
26
|
+
export declare const FakeContactSchema: import("../builder").BuilderSchema<FakeContact>;
|
|
29
27
|
export interface ContactCreateInput {
|
|
30
28
|
firstName: string;
|
|
31
29
|
lastName: string;
|
|
32
30
|
emailAddress: string;
|
|
33
31
|
userID: ID;
|
|
32
|
+
createdAt?: Date;
|
|
33
|
+
updatedAt?: Date;
|
|
34
34
|
}
|
|
35
|
-
export declare function getContactBuilder(viewer: Viewer, input: ContactCreateInput): SimpleBuilder<FakeContact>;
|
|
35
|
+
export declare function getContactBuilder(viewer: Viewer, input: ContactCreateInput): SimpleBuilder<FakeContact, null>;
|
|
36
36
|
export declare function createContact(viewer: Viewer, input: ContactCreateInput): Promise<void>;
|
|
37
37
|
export declare const contactLoader: ObjectLoaderFactory<unknown>;
|
|
@@ -6,16 +6,19 @@ const privacy_1 = require("../../core/privacy");
|
|
|
6
6
|
const builder_1 = require("../builder");
|
|
7
7
|
const schema_1 = require("../../schema");
|
|
8
8
|
const const_1 = require("./const");
|
|
9
|
-
const
|
|
9
|
+
const temp_db_1 = require("../db/temp_db");
|
|
10
10
|
const loaders_1 = require("../../core/loaders");
|
|
11
11
|
const convert_1 = require("../../core/convert");
|
|
12
|
+
const action_1 = require("../../action");
|
|
12
13
|
class FakeContact {
|
|
14
|
+
getPrivacyPolicy() {
|
|
15
|
+
return {
|
|
16
|
+
rules: [new privacy_1.AllowIfViewerIsRule("userID"), privacy_1.AlwaysDenyRule],
|
|
17
|
+
};
|
|
18
|
+
}
|
|
13
19
|
constructor(viewer, data) {
|
|
14
20
|
this.viewer = viewer;
|
|
15
21
|
this.nodeType = const_1.NodeType.FakeContact;
|
|
16
|
-
this.privacyPolicy = {
|
|
17
|
-
rules: [new privacy_1.AllowIfViewerIsRule("userID"), privacy_1.AlwaysDenyRule],
|
|
18
|
-
};
|
|
19
22
|
this.data = data;
|
|
20
23
|
this.id = data.id;
|
|
21
24
|
this.createdAt = (0, convert_1.convertDate)(data.created_at);
|
|
@@ -25,6 +28,7 @@ class FakeContact {
|
|
|
25
28
|
this.emailAddress = data.email_address;
|
|
26
29
|
this.userID = data.user_id;
|
|
27
30
|
}
|
|
31
|
+
__setRawDBData(data) { }
|
|
28
32
|
static getFields() {
|
|
29
33
|
return [
|
|
30
34
|
"id",
|
|
@@ -37,7 +41,7 @@ class FakeContact {
|
|
|
37
41
|
];
|
|
38
42
|
}
|
|
39
43
|
static getTestTable() {
|
|
40
|
-
return (0,
|
|
44
|
+
return (0, temp_db_1.table)("fake_contacts", (0, temp_db_1.uuid)("id", { primaryKey: true }), (0, temp_db_1.timestamptz)("created_at"), (0, temp_db_1.timestamptz)("updated_at"), (0, temp_db_1.text)("first_name"), (0, temp_db_1.text)("last_name"), (0, temp_db_1.text)("email_address"), (0, temp_db_1.uuid)("user_id"));
|
|
41
45
|
}
|
|
42
46
|
static loaderOptions() {
|
|
43
47
|
return {
|
|
@@ -57,23 +61,21 @@ class FakeContact {
|
|
|
57
61
|
static async loadX(v, id) {
|
|
58
62
|
return (0, ent_1.loadEntX)(v, id, FakeContact.loaderOptions());
|
|
59
63
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
super(...arguments);
|
|
65
|
-
this.ent = FakeContact;
|
|
66
|
-
this.fields = {
|
|
67
|
-
firstName: (0, schema_1.StringType)(),
|
|
68
|
-
lastName: (0, schema_1.StringType)(),
|
|
69
|
-
emailAddress: (0, schema_1.StringType)(),
|
|
70
|
-
userID: (0, schema_1.UUIDType)({
|
|
71
|
-
foreignKey: { schema: "User", column: "ID" },
|
|
72
|
-
}),
|
|
73
|
-
};
|
|
64
|
+
static async loadRawData(id, context) {
|
|
65
|
+
return FakeContact.loaderOptions()
|
|
66
|
+
.loaderFactory.createLoader(context)
|
|
67
|
+
.load(id);
|
|
74
68
|
}
|
|
75
69
|
}
|
|
76
|
-
exports.
|
|
70
|
+
exports.FakeContact = FakeContact;
|
|
71
|
+
exports.FakeContactSchema = (0, builder_1.getBuilderSchemaFromFields)({
|
|
72
|
+
firstName: (0, schema_1.StringType)(),
|
|
73
|
+
lastName: (0, schema_1.StringType)(),
|
|
74
|
+
emailAddress: (0, schema_1.StringType)(),
|
|
75
|
+
userID: (0, schema_1.UUIDType)({
|
|
76
|
+
foreignKey: { schema: "User", column: "ID" },
|
|
77
|
+
}),
|
|
78
|
+
}, FakeContact);
|
|
77
79
|
function getContactBuilder(viewer, input) {
|
|
78
80
|
const m = new Map();
|
|
79
81
|
for (const key in input) {
|
|
@@ -82,7 +84,7 @@ function getContactBuilder(viewer, input) {
|
|
|
82
84
|
//To lock in the value of Date now incase of advanceTo/advanceBy
|
|
83
85
|
m.set("createdAt", new Date());
|
|
84
86
|
m.set("updatedAt", new Date());
|
|
85
|
-
return new builder_1.SimpleBuilder(viewer,
|
|
87
|
+
return new builder_1.SimpleBuilder(viewer, exports.FakeContactSchema, m, action_1.WriteOperation.Insert, null);
|
|
86
88
|
}
|
|
87
89
|
exports.getContactBuilder = getContactBuilder;
|
|
88
90
|
async function createContact(viewer, input) {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ID, Ent, Viewer, Data, LoadEntOptions, PrivacyPolicy } from "../../core/base";
|
|
2
|
-
import {
|
|
3
|
-
import { BaseEntSchema, FieldMap } from "../../schema";
|
|
2
|
+
import { SimpleBuilder } from "../builder";
|
|
4
3
|
import { NodeType } from "./const";
|
|
5
4
|
export declare class FakeEvent implements Ent {
|
|
6
5
|
viewer: Viewer;
|
|
@@ -15,19 +14,19 @@ export declare class FakeEvent implements Ent {
|
|
|
15
14
|
readonly title: string;
|
|
16
15
|
readonly description: string | null;
|
|
17
16
|
readonly userID: ID;
|
|
18
|
-
|
|
17
|
+
getPrivacyPolicy(): PrivacyPolicy<this>;
|
|
19
18
|
constructor(viewer: Viewer, data: Data);
|
|
19
|
+
__setRawDBData(data: Data): void;
|
|
20
20
|
private static getFields;
|
|
21
|
-
static getTestTable(): import("../db/
|
|
21
|
+
static getTestTable(): import("../db/temp_db").Table;
|
|
22
22
|
static loaderOptions(): LoadEntOptions<FakeEvent>;
|
|
23
23
|
static load(v: Viewer, id: ID): Promise<FakeEvent | null>;
|
|
24
24
|
static loadX(v: Viewer, id: ID): Promise<FakeEvent>;
|
|
25
25
|
}
|
|
26
|
-
export declare
|
|
27
|
-
ent: typeof FakeEvent;
|
|
28
|
-
fields: FieldMap;
|
|
29
|
-
}
|
|
26
|
+
export declare const FakeEventSchema: import("../builder").BuilderSchema<FakeEvent>;
|
|
30
27
|
export interface EventCreateInput {
|
|
28
|
+
createdAt?: Date;
|
|
29
|
+
updatedAt?: Date;
|
|
31
30
|
startTime: Date;
|
|
32
31
|
endTime?: Date | null;
|
|
33
32
|
location: string;
|
|
@@ -35,5 +34,5 @@ export interface EventCreateInput {
|
|
|
35
34
|
description?: string | null;
|
|
36
35
|
userID: ID;
|
|
37
36
|
}
|
|
38
|
-
export declare function getEventBuilder(viewer: Viewer, input: EventCreateInput): SimpleBuilder<FakeEvent>;
|
|
37
|
+
export declare function getEventBuilder(viewer: Viewer, input: EventCreateInput): SimpleBuilder<FakeEvent, null>;
|
|
39
38
|
export declare function createEvent(viewer: Viewer, input: EventCreateInput): Promise<void>;
|
|
@@ -6,14 +6,17 @@ const privacy_1 = require("../../core/privacy");
|
|
|
6
6
|
const builder_1 = require("../builder");
|
|
7
7
|
const schema_1 = require("../../schema");
|
|
8
8
|
const const_1 = require("./const");
|
|
9
|
-
const
|
|
9
|
+
const temp_db_1 = require("../db/temp_db");
|
|
10
10
|
const loaders_1 = require("../../core/loaders");
|
|
11
11
|
const convert_1 = require("../../core/convert");
|
|
12
|
+
const action_1 = require("../../action");
|
|
12
13
|
class FakeEvent {
|
|
14
|
+
getPrivacyPolicy() {
|
|
15
|
+
return privacy_1.AlwaysAllowPrivacyPolicy;
|
|
16
|
+
}
|
|
13
17
|
constructor(viewer, data) {
|
|
14
18
|
this.viewer = viewer;
|
|
15
19
|
this.nodeType = const_1.NodeType.FakeEvent;
|
|
16
|
-
this.privacyPolicy = privacy_1.AlwaysAllowPrivacyPolicy;
|
|
17
20
|
this.data = data;
|
|
18
21
|
this.id = data.id;
|
|
19
22
|
this.createdAt = (0, convert_1.convertDate)(data.created_at);
|
|
@@ -25,6 +28,7 @@ class FakeEvent {
|
|
|
25
28
|
this.description = data.description;
|
|
26
29
|
this.userID = data.user_id;
|
|
27
30
|
}
|
|
31
|
+
__setRawDBData(data) { }
|
|
28
32
|
static getFields() {
|
|
29
33
|
return [
|
|
30
34
|
"id",
|
|
@@ -39,9 +43,9 @@ class FakeEvent {
|
|
|
39
43
|
];
|
|
40
44
|
}
|
|
41
45
|
static getTestTable() {
|
|
42
|
-
return (0,
|
|
46
|
+
return (0, temp_db_1.table)("fake_events", (0, temp_db_1.uuid)("id", { primaryKey: true }), (0, temp_db_1.timestamptz)("created_at"), (0, temp_db_1.timestamptz)("updated_at"),
|
|
43
47
|
// TODO index:true
|
|
44
|
-
(0,
|
|
48
|
+
(0, temp_db_1.timestamptz)("start_time"), (0, temp_db_1.timestamptz)("end_time", { nullable: true }), (0, temp_db_1.text)("location"), (0, temp_db_1.text)("title"), (0, temp_db_1.text)("description", { nullable: true }), (0, temp_db_1.uuid)("user_id"));
|
|
45
49
|
}
|
|
46
50
|
static loaderOptions() {
|
|
47
51
|
return {
|
|
@@ -63,35 +67,28 @@ class FakeEvent {
|
|
|
63
67
|
}
|
|
64
68
|
}
|
|
65
69
|
exports.FakeEvent = FakeEvent;
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
userID: (0, schema_1.UUIDType)({
|
|
83
|
-
foreignKey: { schema: "User", column: "ID" },
|
|
84
|
-
}),
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
exports.FakeEventSchema = FakeEventSchema;
|
|
70
|
+
exports.FakeEventSchema = (0, builder_1.getBuilderSchemaFromFields)({
|
|
71
|
+
startTime: (0, schema_1.TimestampType)({
|
|
72
|
+
index: true,
|
|
73
|
+
}),
|
|
74
|
+
endTime: (0, schema_1.TimestampType)({
|
|
75
|
+
nullable: true,
|
|
76
|
+
}),
|
|
77
|
+
title: (0, schema_1.StringType)(),
|
|
78
|
+
location: (0, schema_1.StringType)(),
|
|
79
|
+
description: (0, schema_1.StringType)({
|
|
80
|
+
nullable: true,
|
|
81
|
+
}),
|
|
82
|
+
userID: (0, schema_1.UUIDType)({
|
|
83
|
+
foreignKey: { schema: "User", column: "ID" },
|
|
84
|
+
}),
|
|
85
|
+
}, FakeEvent);
|
|
89
86
|
function getEventBuilder(viewer, input) {
|
|
90
87
|
const m = new Map();
|
|
91
88
|
for (const key in input) {
|
|
92
89
|
m.set(key, input[key]);
|
|
93
90
|
}
|
|
94
|
-
return new builder_1.SimpleBuilder(viewer,
|
|
91
|
+
return new builder_1.SimpleBuilder(viewer, exports.FakeEventSchema, m, action_1.WriteOperation.Insert, null);
|
|
95
92
|
}
|
|
96
93
|
exports.getEventBuilder = getEventBuilder;
|
|
97
94
|
async function createEvent(viewer, input) {
|