@snowtop/ent 0.1.0-alpha → 0.1.0-alpha12
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 +2 -0
- package/action/executor.d.ts +1 -1
- package/action/orchestrator.d.ts +16 -3
- package/action/orchestrator.js +157 -47
- package/core/base.d.ts +6 -2
- package/core/base.js +16 -0
- package/core/clause.d.ts +24 -3
- package/core/clause.js +246 -5
- package/core/config.d.ts +18 -0
- package/core/config.js +17 -0
- package/core/db.d.ts +3 -3
- package/core/db.js +2 -0
- package/core/ent.d.ts +2 -4
- package/core/ent.js +72 -25
- package/core/loaders/assoc_edge_loader.d.ts +1 -1
- package/core/loaders/assoc_edge_loader.js +5 -4
- package/core/loaders/index_loader.js +1 -0
- package/core/loaders/object_loader.d.ts +7 -2
- package/core/loaders/object_loader.js +59 -4
- package/core/privacy.d.ts +1 -1
- package/core/privacy.js +3 -0
- package/core/viewer.d.ts +1 -0
- package/core/viewer.js +4 -0
- 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 +3 -2
- package/graphql/graphql.js +24 -23
- package/graphql/index.d.ts +1 -0
- package/graphql/index.js +3 -1
- 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.js +6 -6
- package/graphql/query/page_info.js +4 -4
- package/graphql/query/shared_assoc_test.js +2 -2
- package/graphql/scalars/time.d.ts +1 -1
- package/imports/index.d.ts +0 -1
- package/imports/index.js +3 -36
- package/index.d.ts +16 -1
- package/index.js +18 -5
- package/package.json +3 -3
- package/parse_schema/parse.d.ts +23 -4
- package/parse_schema/parse.js +87 -8
- package/schema/base_schema.d.ts +36 -1
- package/schema/base_schema.js +63 -17
- package/schema/field.d.ts +25 -25
- package/schema/field.js +42 -33
- package/schema/index.d.ts +4 -2
- package/schema/index.js +10 -1
- package/schema/json_field.d.ts +6 -6
- package/schema/json_field.js +2 -2
- package/schema/schema.d.ts +70 -6
- package/schema/schema.js +142 -10
- package/schema/struct_field.d.ts +17 -0
- package/schema/struct_field.js +102 -0
- package/schema/union_field.d.ts +23 -0
- package/schema/union_field.js +79 -0
- package/scripts/custom_compiler.js +2 -19
- package/scripts/custom_graphql.js +122 -15
- package/scripts/move_generated.d.ts +1 -0
- package/scripts/move_generated.js +142 -0
- package/scripts/read_schema.js +15 -1
- package/scripts/transform_code.d.ts +1 -0
- package/scripts/transform_code.js +113 -0
- package/scripts/transform_schema.d.ts +1 -0
- package/scripts/transform_schema.js +355 -0
- package/testutils/builder.d.ts +16 -9
- package/testutils/builder.js +80 -8
- package/testutils/context/test_context.d.ts +2 -2
- package/testutils/context/test_context.js +7 -1
- package/testutils/db/test_db.d.ts +2 -1
- package/testutils/db/test_db.js +22 -13
- package/testutils/ent-graphql-tests/index.d.ts +2 -0
- package/testutils/ent-graphql-tests/index.js +26 -17
- package/testutils/fake_data/fake_contact.d.ts +3 -7
- package/testutils/fake_data/fake_contact.js +14 -26
- package/testutils/fake_data/fake_event.d.ts +3 -7
- package/testutils/fake_data/fake_event.js +20 -33
- package/testutils/fake_data/fake_user.d.ts +3 -7
- package/testutils/fake_data/fake_user.js +22 -36
- package/testutils/fake_data/test_helpers.js +1 -1
- package/tsc/ast.d.ts +21 -0
- package/tsc/ast.js +154 -0
- package/tsc/compilerOptions.d.ts +8 -0
- package/tsc/compilerOptions.js +100 -0
package/testutils/builder.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.SimpleAction = exports.SimpleBuilder = exports.getTableName = exports.getSchemaName = exports.Address = exports.Message = exports.Group = exports.Contact = exports.Event = exports.User = void 0;
|
|
6
|
+
exports.SimpleAction = exports.SimpleBuilder = exports.getFieldInfo = exports.getTableName = exports.getSchemaName = exports.getBuilderSchemaTZFromFields = exports.getBuilderSchemaFromFields = exports.getBuilderSchema = exports.Address = exports.Message = exports.Group = exports.Contact = exports.Event = exports.User = void 0;
|
|
7
7
|
const privacy_1 = require("../core/privacy");
|
|
8
8
|
const orchestrator_1 = require("../action/orchestrator");
|
|
9
9
|
const action_1 = require("../action");
|
|
@@ -14,18 +14,22 @@ const snake_case_1 = require("snake-case");
|
|
|
14
14
|
const loaders_1 = require("../core/loaders");
|
|
15
15
|
const convert_1 = require("../core/convert");
|
|
16
16
|
const camel_case_1 = require("camel-case");
|
|
17
|
+
const base_schema_1 = require("../schema/base_schema");
|
|
18
|
+
const schema_2 = require("../schema/schema");
|
|
17
19
|
class User {
|
|
18
20
|
constructor(viewer, data) {
|
|
19
21
|
this.viewer = viewer;
|
|
20
22
|
this.data = data;
|
|
21
23
|
this.accountID = "";
|
|
22
24
|
this.nodeType = "User";
|
|
23
|
-
this.privacyPolicy = privacy_1.AlwaysAllowPrivacyPolicy;
|
|
24
25
|
this.data.created_at = (0, convert_1.convertDate)(data.created_at);
|
|
25
26
|
this.data.updated_at = (0, convert_1.convertDate)(data.updated_at);
|
|
26
27
|
this.id = data.id;
|
|
27
28
|
this.firstName = data.first_name;
|
|
28
29
|
}
|
|
30
|
+
getPrivacyPolicy() {
|
|
31
|
+
return privacy_1.AlwaysAllowPrivacyPolicy;
|
|
32
|
+
}
|
|
29
33
|
}
|
|
30
34
|
exports.User = User;
|
|
31
35
|
class Event {
|
|
@@ -34,9 +38,11 @@ class Event {
|
|
|
34
38
|
this.data = data;
|
|
35
39
|
this.accountID = "";
|
|
36
40
|
this.nodeType = "Event";
|
|
37
|
-
this.privacyPolicy = privacy_1.AlwaysAllowPrivacyPolicy;
|
|
38
41
|
this.id = data.id;
|
|
39
42
|
}
|
|
43
|
+
getPrivacyPolicy() {
|
|
44
|
+
return privacy_1.AlwaysAllowPrivacyPolicy;
|
|
45
|
+
}
|
|
40
46
|
}
|
|
41
47
|
exports.Event = Event;
|
|
42
48
|
class Contact {
|
|
@@ -45,11 +51,13 @@ class Contact {
|
|
|
45
51
|
this.data = data;
|
|
46
52
|
this.accountID = "";
|
|
47
53
|
this.nodeType = "Contact";
|
|
48
|
-
this.privacyPolicy = privacy_1.AlwaysAllowPrivacyPolicy;
|
|
49
54
|
this.data.created_at = (0, convert_1.convertDate)(data.created_at);
|
|
50
55
|
this.data.updated_at = (0, convert_1.convertDate)(data.updated_at);
|
|
51
56
|
this.id = data.id;
|
|
52
57
|
}
|
|
58
|
+
getPrivacyPolicy() {
|
|
59
|
+
return privacy_1.AlwaysAllowPrivacyPolicy;
|
|
60
|
+
}
|
|
53
61
|
}
|
|
54
62
|
exports.Contact = Contact;
|
|
55
63
|
class Group {
|
|
@@ -58,9 +66,11 @@ class Group {
|
|
|
58
66
|
this.data = data;
|
|
59
67
|
this.accountID = "";
|
|
60
68
|
this.nodeType = "Group";
|
|
61
|
-
this.privacyPolicy = privacy_1.AlwaysAllowPrivacyPolicy;
|
|
62
69
|
this.id = data.id;
|
|
63
70
|
}
|
|
71
|
+
getPrivacyPolicy() {
|
|
72
|
+
return privacy_1.AlwaysAllowPrivacyPolicy;
|
|
73
|
+
}
|
|
64
74
|
}
|
|
65
75
|
exports.Group = Group;
|
|
66
76
|
class Message {
|
|
@@ -69,9 +79,11 @@ class Message {
|
|
|
69
79
|
this.data = data;
|
|
70
80
|
this.accountID = "";
|
|
71
81
|
this.nodeType = "Message";
|
|
72
|
-
this.privacyPolicy = privacy_1.AlwaysAllowPrivacyPolicy;
|
|
73
82
|
this.id = data.id;
|
|
74
83
|
}
|
|
84
|
+
getPrivacyPolicy() {
|
|
85
|
+
return privacy_1.AlwaysAllowPrivacyPolicy;
|
|
86
|
+
}
|
|
75
87
|
}
|
|
76
88
|
exports.Message = Message;
|
|
77
89
|
class Address {
|
|
@@ -80,11 +92,34 @@ class Address {
|
|
|
80
92
|
this.data = data;
|
|
81
93
|
this.accountID = "";
|
|
82
94
|
this.nodeType = "Address";
|
|
83
|
-
this.privacyPolicy = privacy_1.AlwaysAllowPrivacyPolicy;
|
|
84
95
|
this.id = data.id;
|
|
85
96
|
}
|
|
97
|
+
getPrivacyPolicy() {
|
|
98
|
+
return privacy_1.AlwaysAllowPrivacyPolicy;
|
|
99
|
+
}
|
|
86
100
|
}
|
|
87
101
|
exports.Address = Address;
|
|
102
|
+
function getBuilderSchema(cfg, ent) {
|
|
103
|
+
return {
|
|
104
|
+
...new base_schema_1.EntSchema(cfg),
|
|
105
|
+
ent,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
exports.getBuilderSchema = getBuilderSchema;
|
|
109
|
+
function getBuilderSchemaFromFields(fields, ent) {
|
|
110
|
+
return {
|
|
111
|
+
...new base_schema_1.EntSchema({ fields }),
|
|
112
|
+
ent,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
exports.getBuilderSchemaFromFields = getBuilderSchemaFromFields;
|
|
116
|
+
function getBuilderSchemaTZFromFields(fields, ent) {
|
|
117
|
+
return {
|
|
118
|
+
...new base_schema_1.EntSchemaWithTZ({ fields }),
|
|
119
|
+
ent,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
exports.getBuilderSchemaTZFromFields = getBuilderSchemaTZFromFields;
|
|
88
123
|
function getSchemaName(value) {
|
|
89
124
|
return value.ent.name;
|
|
90
125
|
}
|
|
@@ -96,6 +131,18 @@ exports.getTableName = getTableName;
|
|
|
96
131
|
function randomNum() {
|
|
97
132
|
return Math.random().toString(10).substring(2);
|
|
98
133
|
}
|
|
134
|
+
function getFieldInfo(value) {
|
|
135
|
+
const fields = (0, schema_1.getFields)(value);
|
|
136
|
+
let ret = {};
|
|
137
|
+
for (const [k, f] of fields) {
|
|
138
|
+
ret[k] = {
|
|
139
|
+
dbCol: (0, schema_2.getStorageKey)(f, k),
|
|
140
|
+
inputKey: (0, camel_case_1.camelCase)(k),
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
return ret;
|
|
144
|
+
}
|
|
145
|
+
exports.getFieldInfo = getFieldInfo;
|
|
99
146
|
// reuses orchestrator and standard things
|
|
100
147
|
class SimpleBuilder {
|
|
101
148
|
constructor(viewer, schema, fields, operation = action_1.WriteOperation.Insert, existingEnt = undefined, action) {
|
|
@@ -128,11 +175,13 @@ class SimpleBuilder {
|
|
|
128
175
|
this.ent = schema.ent;
|
|
129
176
|
const tableName = getTableName(schema);
|
|
130
177
|
this.nodeType = (0, camel_case_1.camelCase)(schema.ent.name);
|
|
178
|
+
const fieldInfo = getFieldInfo(schema);
|
|
131
179
|
this.orchestrator = new orchestrator_1.Orchestrator({
|
|
132
180
|
viewer: this.viewer,
|
|
133
181
|
operation: operation,
|
|
134
182
|
tableName: tableName,
|
|
135
183
|
key,
|
|
184
|
+
fieldInfo,
|
|
136
185
|
loaderOptions: {
|
|
137
186
|
loaderFactory: new loaders_1.ObjectLoaderFactory({
|
|
138
187
|
tableName: tableName,
|
|
@@ -142,15 +191,38 @@ class SimpleBuilder {
|
|
|
142
191
|
ent: schema.ent,
|
|
143
192
|
tableName: tableName,
|
|
144
193
|
fields: [],
|
|
194
|
+
fieldPrivacy: (0, schema_1.getFieldsWithPrivacy)(schema, fieldInfo),
|
|
145
195
|
},
|
|
146
196
|
builder: this,
|
|
147
197
|
action: action,
|
|
148
198
|
schema: this.schema,
|
|
149
199
|
editedFields: () => {
|
|
150
|
-
return
|
|
200
|
+
// to simulate what we do in generated builders where we return a new Map
|
|
201
|
+
const m = new Map();
|
|
202
|
+
for (const [k, v] of this.fields) {
|
|
203
|
+
m.set(k, v);
|
|
204
|
+
}
|
|
205
|
+
return m;
|
|
151
206
|
},
|
|
207
|
+
updateInput: this.updateInput.bind(this),
|
|
152
208
|
});
|
|
153
209
|
}
|
|
210
|
+
updateInput(input) {
|
|
211
|
+
const knownFields = (0, schema_1.getFields)(this.schema);
|
|
212
|
+
for (const k in input) {
|
|
213
|
+
if (knownFields.has(k)) {
|
|
214
|
+
this.fields.set(k, input[k]);
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
// related to #510. we do camelCase to pass fields in here but fields may be snakeCase and we want that to pass in tests
|
|
218
|
+
// we do camelCase in
|
|
219
|
+
const sc = (0, snake_case_1.snakeCase)(k);
|
|
220
|
+
if (knownFields.has(sc)) {
|
|
221
|
+
this.fields.set(sc, input[k]);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
154
226
|
build() {
|
|
155
227
|
return this.orchestrator.build();
|
|
156
228
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Context, Viewer } from "../../core/base";
|
|
2
2
|
import { ContextCache } from "../../core/context";
|
|
3
|
-
import { LoggedOutViewer } from "../../core/viewer";
|
|
4
3
|
export declare class TestContext implements Context {
|
|
4
|
+
constructor(viewer?: Viewer);
|
|
5
5
|
cache: ContextCache;
|
|
6
|
-
viewer:
|
|
6
|
+
viewer: Viewer;
|
|
7
7
|
getViewer(): Viewer;
|
|
8
8
|
}
|
|
@@ -4,9 +4,15 @@ exports.TestContext = void 0;
|
|
|
4
4
|
const context_1 = require("../../core/context");
|
|
5
5
|
const viewer_1 = require("../../core/viewer");
|
|
6
6
|
class TestContext {
|
|
7
|
-
constructor() {
|
|
7
|
+
constructor(viewer) {
|
|
8
8
|
this.cache = new context_1.ContextCache();
|
|
9
9
|
this.viewer = new viewer_1.LoggedOutViewer(this);
|
|
10
|
+
if (viewer) {
|
|
11
|
+
this.viewer = viewer;
|
|
12
|
+
if (viewer.setContext !== undefined) {
|
|
13
|
+
viewer.setContext(this);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
10
16
|
}
|
|
11
17
|
getViewer() {
|
|
12
18
|
return this.viewer;
|
|
@@ -71,10 +71,11 @@ export declare class TempDB {
|
|
|
71
71
|
constructor(tables: CoreConcept[]);
|
|
72
72
|
getDialect(): Dialect;
|
|
73
73
|
getTables(): Map<string, CoreConcept>;
|
|
74
|
-
beforeAll(): Promise<void>;
|
|
74
|
+
beforeAll(setupConnString?: boolean): Promise<void>;
|
|
75
75
|
getSqliteClient(): SqliteDatabase;
|
|
76
76
|
getPostgresClient(): PGClient;
|
|
77
77
|
afterAll(): Promise<void>;
|
|
78
|
+
getDB(): string;
|
|
78
79
|
dropAll(): Promise<void>;
|
|
79
80
|
drop(...tables: string[]): Promise<void>;
|
|
80
81
|
create(...tables: CoreConcept[]): Promise<void>;
|
package/testutils/db/test_db.js
CHANGED
|
@@ -336,7 +336,7 @@ class TempDB {
|
|
|
336
336
|
getTables() {
|
|
337
337
|
return this.tables;
|
|
338
338
|
}
|
|
339
|
-
async beforeAll() {
|
|
339
|
+
async beforeAll(setupConnString = true) {
|
|
340
340
|
if (this.dialect === db_1.Dialect.Postgres) {
|
|
341
341
|
const user = process.env.POSTGRES_USER || "";
|
|
342
342
|
const password = process.env.POSTGRES_PASSWORD || "";
|
|
@@ -348,11 +348,17 @@ class TempDB {
|
|
|
348
348
|
await this.client.connect();
|
|
349
349
|
this.db = randomDB();
|
|
350
350
|
await this.client.query(`CREATE DATABASE ${this.db}`);
|
|
351
|
-
if (
|
|
352
|
-
|
|
351
|
+
if (setupConnString) {
|
|
352
|
+
if (user && password) {
|
|
353
|
+
process.env.DB_CONNECTION_STRING = `postgres://${user}:${password}@localhost:5432/${this.db}`;
|
|
354
|
+
}
|
|
355
|
+
else {
|
|
356
|
+
process.env.DB_CONNECTION_STRING = `postgres://localhost/${this.db}?`;
|
|
357
|
+
}
|
|
353
358
|
}
|
|
354
359
|
else {
|
|
355
|
-
|
|
360
|
+
// will probably be setup via loadConfig
|
|
361
|
+
delete process.env.DB_CONNECTION_STRING;
|
|
356
362
|
}
|
|
357
363
|
this.dbClient = new pg_1.Client({
|
|
358
364
|
host: "localhost",
|
|
@@ -397,6 +403,9 @@ class TempDB {
|
|
|
397
403
|
await this.client.query(`DROP DATABASE ${this.db}`);
|
|
398
404
|
await this.client.end();
|
|
399
405
|
}
|
|
406
|
+
getDB() {
|
|
407
|
+
return this.db;
|
|
408
|
+
}
|
|
400
409
|
async dropAll() {
|
|
401
410
|
for (const [t, _] of this.tables) {
|
|
402
411
|
await this.drop(t);
|
|
@@ -479,8 +488,8 @@ exports.setupSqlite = setupSqlite;
|
|
|
479
488
|
function getSchemaTable(schema, dialect) {
|
|
480
489
|
const fields = (0, schema_1.getFields)(schema);
|
|
481
490
|
const columns = [];
|
|
482
|
-
for (const [
|
|
483
|
-
columns.push(getColumnFromField(field, dialect));
|
|
491
|
+
for (const [fieldName, field] of fields) {
|
|
492
|
+
columns.push(getColumnFromField(fieldName, field, dialect));
|
|
484
493
|
}
|
|
485
494
|
return table((0, builder_1.getTableName)(schema), ...columns);
|
|
486
495
|
}
|
|
@@ -520,7 +529,7 @@ function getColumnForDbType(t, dialect) {
|
|
|
520
529
|
return undefined;
|
|
521
530
|
}
|
|
522
531
|
}
|
|
523
|
-
function getColumnFromField(f, dialect) {
|
|
532
|
+
function getColumnFromField(fieldName, f, dialect) {
|
|
524
533
|
switch (f.type.dbType) {
|
|
525
534
|
case schema_1.DBType.List:
|
|
526
535
|
const elemType = f.type.listElemType;
|
|
@@ -531,17 +540,17 @@ function getColumnFromField(f, dialect) {
|
|
|
531
540
|
if (elemFn === undefined) {
|
|
532
541
|
throw new Error(`unsupported type for ${elemType}`);
|
|
533
542
|
}
|
|
534
|
-
return list(storageKey(f), elemFn("ignore"), buildOpts(f));
|
|
543
|
+
return list(storageKey(fieldName, f), elemFn("ignore"), buildOpts(f));
|
|
535
544
|
default:
|
|
536
545
|
const fn = getColumnForDbType(f.type.dbType, dialect);
|
|
537
546
|
if (fn === undefined) {
|
|
538
547
|
throw new Error(`unsupported type ${f.type.dbType}`);
|
|
539
548
|
}
|
|
540
|
-
return getColumn(f, fn);
|
|
549
|
+
return getColumn(fieldName, f, fn);
|
|
541
550
|
}
|
|
542
551
|
}
|
|
543
|
-
function getColumn(f, col) {
|
|
544
|
-
return col(storageKey(f), buildOpts(f));
|
|
552
|
+
function getColumn(fieldName, f, col) {
|
|
553
|
+
return col(storageKey(fieldName, f), buildOpts(f));
|
|
545
554
|
}
|
|
546
555
|
function buildOpts(f) {
|
|
547
556
|
let ret = {};
|
|
@@ -560,11 +569,11 @@ function buildOpts(f) {
|
|
|
560
569
|
}
|
|
561
570
|
return ret;
|
|
562
571
|
}
|
|
563
|
-
function storageKey(f) {
|
|
572
|
+
function storageKey(fieldName, f) {
|
|
564
573
|
if (f.storageKey) {
|
|
565
574
|
return f.storageKey;
|
|
566
575
|
}
|
|
567
|
-
return (0, snake_case_1.snakeCase)(
|
|
576
|
+
return (0, snake_case_1.snakeCase)(fieldName);
|
|
568
577
|
}
|
|
569
578
|
function isSyncClient(client) {
|
|
570
579
|
return client.execSync !== undefined;
|
|
@@ -16,6 +16,8 @@ interface queryConfig {
|
|
|
16
16
|
callback?: (res: supertest.Response) => void;
|
|
17
17
|
inlineFragmentRoot?: string;
|
|
18
18
|
customHandlers?: RequestHandler[];
|
|
19
|
+
server?: any;
|
|
20
|
+
graphQLPath?: string;
|
|
19
21
|
}
|
|
20
22
|
export interface queryRootConfig extends queryConfig {
|
|
21
23
|
root: string;
|
|
@@ -26,7 +26,7 @@ exports.expectMutation = exports.expectQueryFromRoot = void 0;
|
|
|
26
26
|
// NB: this is copied from ent-graphql-tests package until I have time to figure out how to share code here effectively
|
|
27
27
|
// the circular dependencies btw this package and ent-graphql-tests seems to imply something needs to change
|
|
28
28
|
const express_1 = __importDefault(require("express"));
|
|
29
|
-
const
|
|
29
|
+
const graphql_helix_1 = require("graphql-helix");
|
|
30
30
|
const graphql_1 = require("graphql");
|
|
31
31
|
const auth_1 = require("../../auth");
|
|
32
32
|
const supertest_1 = __importDefault(require("supertest"));
|
|
@@ -45,18 +45,23 @@ function server(config) {
|
|
|
45
45
|
if (config.init) {
|
|
46
46
|
config.init(app);
|
|
47
47
|
}
|
|
48
|
+
app.use(express_1.default.json());
|
|
48
49
|
let handlers = config.customHandlers || [];
|
|
49
|
-
handlers.push(
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
50
|
+
handlers.push(async (req, res) => {
|
|
51
|
+
const { operationName, query, variables } = (0, graphql_helix_1.getGraphQLParameters)(req);
|
|
52
|
+
const result = await (0, graphql_helix_1.processRequest)({
|
|
53
|
+
operationName,
|
|
54
|
+
query,
|
|
55
|
+
variables,
|
|
56
|
+
request: req,
|
|
57
|
+
schema: config.schema,
|
|
58
|
+
contextFactory: async (executionContext) => {
|
|
59
|
+
return (0, auth_1.buildContext)(req, res);
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
await (0, graphql_helix_1.sendResult)(result, res);
|
|
63
|
+
});
|
|
64
|
+
app.use(config.graphQLPath || "/graphql", ...handlers);
|
|
60
65
|
return app;
|
|
61
66
|
}
|
|
62
67
|
function getInnerType(typ, list) {
|
|
@@ -72,14 +77,14 @@ function makeGraphQLRequest(config, query, fieldArgs) {
|
|
|
72
77
|
let test;
|
|
73
78
|
if (config.test) {
|
|
74
79
|
if (typeof config.test === "function") {
|
|
75
|
-
test = config.test(server(config));
|
|
80
|
+
test = config.test(config.server ? config.server : server(config));
|
|
76
81
|
}
|
|
77
82
|
else {
|
|
78
83
|
test = config.test;
|
|
79
84
|
}
|
|
80
85
|
}
|
|
81
86
|
else {
|
|
82
|
-
test = (0, supertest_1.default)(server(config));
|
|
87
|
+
test = (0, supertest_1.default)(config.server ? config.server : server(config));
|
|
83
88
|
}
|
|
84
89
|
let files = new Map();
|
|
85
90
|
// handle files
|
|
@@ -104,7 +109,9 @@ function makeGraphQLRequest(config, query, fieldArgs) {
|
|
|
104
109
|
}
|
|
105
110
|
});
|
|
106
111
|
if (files.size) {
|
|
107
|
-
let ret = test
|
|
112
|
+
let ret = test
|
|
113
|
+
.post(config.graphQLPath || "/graphql")
|
|
114
|
+
.set(config.headers || {});
|
|
108
115
|
ret.field("operations", JSON.stringify({
|
|
109
116
|
query: query,
|
|
110
117
|
variables: config.args,
|
|
@@ -130,7 +137,7 @@ function makeGraphQLRequest(config, query, fieldArgs) {
|
|
|
130
137
|
return [
|
|
131
138
|
test,
|
|
132
139
|
test
|
|
133
|
-
.post("/graphql")
|
|
140
|
+
.post(config.graphQLPath || "/graphql")
|
|
134
141
|
.set(config.headers || {})
|
|
135
142
|
.send({
|
|
136
143
|
query: query,
|
|
@@ -353,7 +360,9 @@ async function expectFromRoot(config, ...options) {
|
|
|
353
360
|
else {
|
|
354
361
|
expect(res.ok, `expected ok response. instead got ${res.status} and result ${JSON.stringify(res.body)}`);
|
|
355
362
|
}
|
|
356
|
-
|
|
363
|
+
// res.ok = true in graphql-helix when there's errors...
|
|
364
|
+
// res.ok = false in express-graphql when there's errors...
|
|
365
|
+
if (!res.ok || (res.body.errors && res.body.errors.length > 0)) {
|
|
357
366
|
let errors = res.body.errors;
|
|
358
367
|
expect(errors.length).toBeGreaterThan(0);
|
|
359
368
|
if (config.expectedError) {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ID, Ent, Viewer, Data, LoadEntOptions, PrivacyPolicy } from "../../core/base";
|
|
2
|
-
import {
|
|
3
|
-
import { Field, BaseEntSchema } from "../../schema";
|
|
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,7 +13,7 @@ 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);
|
|
19
18
|
static getFields(): string[];
|
|
20
19
|
static getTestTable(): import("../db/test_db").Table;
|
|
@@ -22,10 +21,7 @@ export declare class FakeContact implements Ent {
|
|
|
22
21
|
static load(v: Viewer, id: ID): Promise<FakeContact | null>;
|
|
23
22
|
static loadX(v: Viewer, id: ID): Promise<FakeContact>;
|
|
24
23
|
}
|
|
25
|
-
export declare
|
|
26
|
-
ent: typeof FakeContact;
|
|
27
|
-
fields: Field[];
|
|
28
|
-
}
|
|
24
|
+
export declare const FakeContactSchema: import("../builder").BuilderSchema<FakeContact>;
|
|
29
25
|
export interface ContactCreateInput {
|
|
30
26
|
firstName: string;
|
|
31
27
|
lastName: string;
|
|
@@ -13,9 +13,6 @@ class FakeContact {
|
|
|
13
13
|
constructor(viewer, data) {
|
|
14
14
|
this.viewer = viewer;
|
|
15
15
|
this.nodeType = const_1.NodeType.FakeContact;
|
|
16
|
-
this.privacyPolicy = {
|
|
17
|
-
rules: [new privacy_1.AllowIfViewerIsRule("userID"), privacy_1.AlwaysDenyRule],
|
|
18
|
-
};
|
|
19
16
|
this.data = data;
|
|
20
17
|
this.id = data.id;
|
|
21
18
|
this.createdAt = (0, convert_1.convertDate)(data.created_at);
|
|
@@ -25,6 +22,11 @@ class FakeContact {
|
|
|
25
22
|
this.emailAddress = data.email_address;
|
|
26
23
|
this.userID = data.user_id;
|
|
27
24
|
}
|
|
25
|
+
getPrivacyPolicy() {
|
|
26
|
+
return {
|
|
27
|
+
rules: [new privacy_1.AllowIfViewerIsRule("userID"), privacy_1.AlwaysDenyRule],
|
|
28
|
+
};
|
|
29
|
+
}
|
|
28
30
|
static getFields() {
|
|
29
31
|
return [
|
|
30
32
|
"id",
|
|
@@ -59,28 +61,14 @@ class FakeContact {
|
|
|
59
61
|
}
|
|
60
62
|
}
|
|
61
63
|
exports.FakeContact = FakeContact;
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
(0, schema_1.StringType)({
|
|
71
|
-
name: "lastName",
|
|
72
|
-
}),
|
|
73
|
-
(0, schema_1.StringType)({
|
|
74
|
-
name: "emailAddress",
|
|
75
|
-
}),
|
|
76
|
-
(0, schema_1.UUIDType)({
|
|
77
|
-
name: "userID",
|
|
78
|
-
foreignKey: { schema: "User", column: "ID" },
|
|
79
|
-
}),
|
|
80
|
-
];
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
exports.FakeContactSchema = FakeContactSchema;
|
|
64
|
+
exports.FakeContactSchema = (0, builder_1.getBuilderSchemaFromFields)({
|
|
65
|
+
firstName: (0, schema_1.StringType)(),
|
|
66
|
+
lastName: (0, schema_1.StringType)(),
|
|
67
|
+
emailAddress: (0, schema_1.StringType)(),
|
|
68
|
+
userID: (0, schema_1.UUIDType)({
|
|
69
|
+
foreignKey: { schema: "User", column: "ID" },
|
|
70
|
+
}),
|
|
71
|
+
}, FakeContact);
|
|
84
72
|
function getContactBuilder(viewer, input) {
|
|
85
73
|
const m = new Map();
|
|
86
74
|
for (const key in input) {
|
|
@@ -89,7 +77,7 @@ function getContactBuilder(viewer, input) {
|
|
|
89
77
|
//To lock in the value of Date now incase of advanceTo/advanceBy
|
|
90
78
|
m.set("createdAt", new Date());
|
|
91
79
|
m.set("updatedAt", new Date());
|
|
92
|
-
return new builder_1.SimpleBuilder(viewer,
|
|
80
|
+
return new builder_1.SimpleBuilder(viewer, exports.FakeContactSchema, m);
|
|
93
81
|
}
|
|
94
82
|
exports.getContactBuilder = getContactBuilder;
|
|
95
83
|
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 { Field, BaseEntSchema } 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,7 +14,7 @@ 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);
|
|
20
19
|
private static getFields;
|
|
21
20
|
static getTestTable(): import("../db/test_db").Table;
|
|
@@ -23,10 +22,7 @@ export declare class FakeEvent implements Ent {
|
|
|
23
22
|
static load(v: Viewer, id: ID): Promise<FakeEvent | null>;
|
|
24
23
|
static loadX(v: Viewer, id: ID): Promise<FakeEvent>;
|
|
25
24
|
}
|
|
26
|
-
export declare
|
|
27
|
-
ent: typeof FakeEvent;
|
|
28
|
-
fields: Field[];
|
|
29
|
-
}
|
|
25
|
+
export declare const FakeEventSchema: import("../builder").BuilderSchema<FakeEvent>;
|
|
30
26
|
export interface EventCreateInput {
|
|
31
27
|
startTime: Date;
|
|
32
28
|
endTime?: Date | null;
|
|
@@ -13,7 +13,6 @@ class FakeEvent {
|
|
|
13
13
|
constructor(viewer, data) {
|
|
14
14
|
this.viewer = viewer;
|
|
15
15
|
this.nodeType = const_1.NodeType.FakeEvent;
|
|
16
|
-
this.privacyPolicy = privacy_1.AlwaysAllowPrivacyPolicy;
|
|
17
16
|
this.data = data;
|
|
18
17
|
this.id = data.id;
|
|
19
18
|
this.createdAt = (0, convert_1.convertDate)(data.created_at);
|
|
@@ -25,6 +24,9 @@ class FakeEvent {
|
|
|
25
24
|
this.description = data.description;
|
|
26
25
|
this.userID = data.user_id;
|
|
27
26
|
}
|
|
27
|
+
getPrivacyPolicy() {
|
|
28
|
+
return privacy_1.AlwaysAllowPrivacyPolicy;
|
|
29
|
+
}
|
|
28
30
|
static getFields() {
|
|
29
31
|
return [
|
|
30
32
|
"id",
|
|
@@ -63,43 +65,28 @@ class FakeEvent {
|
|
|
63
65
|
}
|
|
64
66
|
}
|
|
65
67
|
exports.FakeEvent = FakeEvent;
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
(0, schema_1.StringType)({
|
|
83
|
-
name: "location",
|
|
84
|
-
}),
|
|
85
|
-
(0, schema_1.StringType)({
|
|
86
|
-
name: "description",
|
|
87
|
-
nullable: true,
|
|
88
|
-
}),
|
|
89
|
-
(0, schema_1.UUIDType)({
|
|
90
|
-
name: "userID",
|
|
91
|
-
foreignKey: { schema: "User", column: "ID" },
|
|
92
|
-
}),
|
|
93
|
-
];
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
exports.FakeEventSchema = FakeEventSchema;
|
|
68
|
+
exports.FakeEventSchema = (0, builder_1.getBuilderSchemaFromFields)({
|
|
69
|
+
startTime: (0, schema_1.TimestampType)({
|
|
70
|
+
index: true,
|
|
71
|
+
}),
|
|
72
|
+
endTime: (0, schema_1.TimestampType)({
|
|
73
|
+
nullable: true,
|
|
74
|
+
}),
|
|
75
|
+
title: (0, schema_1.StringType)(),
|
|
76
|
+
location: (0, schema_1.StringType)(),
|
|
77
|
+
description: (0, schema_1.StringType)({
|
|
78
|
+
nullable: true,
|
|
79
|
+
}),
|
|
80
|
+
userID: (0, schema_1.UUIDType)({
|
|
81
|
+
foreignKey: { schema: "User", column: "ID" },
|
|
82
|
+
}),
|
|
83
|
+
}, FakeEvent);
|
|
97
84
|
function getEventBuilder(viewer, input) {
|
|
98
85
|
const m = new Map();
|
|
99
86
|
for (const key in input) {
|
|
100
87
|
m.set(key, input[key]);
|
|
101
88
|
}
|
|
102
|
-
return new builder_1.SimpleBuilder(viewer,
|
|
89
|
+
return new builder_1.SimpleBuilder(viewer, exports.FakeEventSchema, m);
|
|
103
90
|
}
|
|
104
91
|
exports.getEventBuilder = getEventBuilder;
|
|
105
92
|
async function createEvent(viewer, input) {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ID, Ent, Viewer, Data, LoadEntOptions, PrivacyPolicy } from "../../core/base";
|
|
2
|
-
import {
|
|
3
|
-
import { Field, BaseEntSchema } from "../../schema";
|
|
2
|
+
import { SimpleAction } from "../builder";
|
|
4
3
|
import { NodeType } from "./const";
|
|
5
4
|
import { IDViewer, IDViewerOptions } from "../../core/viewer";
|
|
6
5
|
import { ObjectLoaderFactory } from "../../core/loaders";
|
|
@@ -24,7 +23,7 @@ export declare class FakeUser implements Ent {
|
|
|
24
23
|
readonly emailAddress: string;
|
|
25
24
|
readonly phoneNumber: string | null;
|
|
26
25
|
protected readonly password: string | null;
|
|
27
|
-
|
|
26
|
+
getPrivacyPolicy(): PrivacyPolicy<this>;
|
|
28
27
|
constructor(viewer: Viewer, data: Data);
|
|
29
28
|
static getFields(): string[];
|
|
30
29
|
static getTestTable(): import("../db/test_db").Table;
|
|
@@ -32,10 +31,7 @@ export declare class FakeUser implements Ent {
|
|
|
32
31
|
static load(v: Viewer, id: ID): Promise<FakeUser | null>;
|
|
33
32
|
static loadX(v: Viewer, id: ID): Promise<FakeUser>;
|
|
34
33
|
}
|
|
35
|
-
export declare
|
|
36
|
-
ent: typeof FakeUser;
|
|
37
|
-
fields: Field[];
|
|
38
|
-
}
|
|
34
|
+
export declare const FakeUserSchema: import("../builder").BuilderSchema<FakeUser>;
|
|
39
35
|
export interface UserCreateInput {
|
|
40
36
|
firstName: string;
|
|
41
37
|
lastName: string;
|