@snowtop/ent 0.1.0-alpha7 → 0.1.0-alpha75
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 +28 -24
- package/action/executor.d.ts +4 -4
- package/action/executor.js +2 -2
- package/action/experimental_action.d.ts +29 -22
- package/action/experimental_action.js +29 -6
- package/action/orchestrator.d.ts +44 -16
- package/action/orchestrator.js +287 -73
- package/action/privacy.d.ts +2 -2
- package/core/base.d.ts +43 -23
- package/core/base.js +16 -0
- package/core/clause.d.ts +82 -3
- package/core/clause.js +463 -27
- package/core/config.d.ts +26 -0
- package/core/config.js +17 -0
- package/core/context.d.ts +5 -3
- package/core/context.js +7 -2
- package/core/convert.d.ts +1 -1
- package/core/db.d.ts +3 -4
- package/core/db.js +2 -0
- package/core/ent.d.ts +71 -27
- package/core/ent.js +458 -97
- package/core/loaders/assoc_count_loader.d.ts +2 -2
- package/core/loaders/assoc_count_loader.js +6 -1
- package/core/loaders/assoc_edge_loader.d.ts +3 -3
- package/core/loaders/assoc_edge_loader.js +5 -4
- package/core/loaders/index_loader.js +1 -0
- package/core/loaders/loader.js +5 -5
- package/core/loaders/object_loader.d.ts +11 -5
- package/core/loaders/object_loader.js +70 -4
- package/core/loaders/query_loader.d.ts +2 -2
- package/core/loaders/raw_count_loader.d.ts +2 -2
- 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 +6 -6
- package/core/query/custom_query.d.ts +5 -5
- package/core/query/query.d.ts +1 -1
- package/core/query/shared_assoc_test.d.ts +1 -1
- package/core/query/shared_assoc_test.js +17 -5
- package/core/query/shared_test.d.ts +3 -0
- package/core/query/shared_test.js +95 -17
- 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 +3 -2
- package/graphql/graphql.js +30 -23
- package/graphql/node_resolver.d.ts +0 -1
- 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 +2 -2
- package/graphql/scalars/time.d.ts +1 -1
- package/index.d.ts +21 -1
- package/index.js +24 -5
- package/package.json +3 -3
- package/parse_schema/parse.d.ts +24 -5
- package/parse_schema/parse.js +90 -8
- package/schema/base_schema.d.ts +36 -1
- package/schema/base_schema.js +51 -2
- package/schema/field.d.ts +34 -6
- package/schema/field.js +67 -2
- package/schema/index.d.ts +2 -2
- package/schema/index.js +8 -1
- package/schema/json_field.d.ts +13 -1
- package/schema/json_field.js +28 -1
- package/schema/schema.d.ts +101 -2
- package/schema/schema.js +127 -5
- package/schema/struct_field.d.ts +11 -1
- package/schema/struct_field.js +43 -4
- package/scripts/custom_graphql.js +127 -16
- package/scripts/{transform_schema.d.ts → migrate_v0.1.d.ts} +0 -0
- package/scripts/migrate_v0.1.js +36 -0
- package/scripts/read_schema.js +25 -2
- package/testutils/builder.d.ts +36 -22
- package/testutils/builder.js +110 -13
- package/testutils/context/test_context.d.ts +2 -2
- package/testutils/context/test_context.js +7 -1
- package/testutils/db/{test_db.d.ts → temp_db.d.ts} +17 -4
- package/testutils/db/{test_db.js → temp_db.js} +76 -19
- 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 +5 -9
- package/testutils/fake_data/fake_contact.js +17 -21
- package/testutils/fake_data/fake_event.d.ts +5 -9
- package/testutils/fake_data/fake_event.js +24 -28
- package/testutils/fake_data/fake_user.d.ts +6 -10
- package/testutils/fake_data/fake_user.js +25 -29
- package/testutils/fake_data/test_helpers.d.ts +2 -2
- package/testutils/fake_data/test_helpers.js +6 -6
- package/testutils/fake_data/user_query.d.ts +2 -2
- 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 +58 -0
- package/testutils/write.d.ts +2 -2
- package/testutils/write.js +3 -3
- package/tsc/ast.d.ts +44 -0
- package/tsc/ast.js +267 -0
- package/tsc/compilerOptions.d.ts +6 -0
- package/tsc/compilerOptions.js +40 -1
- package/tsc/move_generated.d.ts +1 -0
- package/tsc/move_generated.js +160 -0
- package/tsc/transform.d.ts +21 -0
- package/tsc/transform.js +167 -0
- package/tsc/transform_action.d.ts +22 -0
- package/tsc/transform_action.js +179 -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 +379 -0
- package/scripts/transform_schema.js +0 -288
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Client as PGClient } from "pg";
|
|
2
2
|
import { Dialect } from "../../core/db";
|
|
3
3
|
import { Database as SqliteDatabase } from "better-sqlite3";
|
|
4
|
+
import { Field } from "../../schema";
|
|
4
5
|
import { BuilderSchema } from "../builder";
|
|
5
6
|
import { Ent } from "../../core/base";
|
|
6
7
|
interface SchemaItem {
|
|
@@ -12,6 +13,7 @@ interface Column extends SchemaItem {
|
|
|
12
13
|
primaryKey?: boolean;
|
|
13
14
|
unique?: boolean;
|
|
14
15
|
default?: string;
|
|
16
|
+
index?: boolean | indexOptions;
|
|
15
17
|
foreignKey?: {
|
|
16
18
|
table: string;
|
|
17
19
|
col: string;
|
|
@@ -20,21 +22,29 @@ interface Column extends SchemaItem {
|
|
|
20
22
|
interface Constraint extends SchemaItem {
|
|
21
23
|
generate(): string;
|
|
22
24
|
}
|
|
25
|
+
interface Index extends SchemaItem {
|
|
26
|
+
generate(): string;
|
|
27
|
+
}
|
|
23
28
|
export interface CoreConcept {
|
|
24
29
|
name: string;
|
|
25
30
|
create(): string;
|
|
31
|
+
postCreate?(): string[];
|
|
26
32
|
drop(): string;
|
|
27
33
|
}
|
|
28
34
|
export interface Table extends CoreConcept {
|
|
29
35
|
columns: Column[];
|
|
30
36
|
constraints?: Constraint[];
|
|
31
37
|
}
|
|
32
|
-
declare type options = Pick<Column, "nullable" | "primaryKey" | "default" | "foreignKey" | "unique">;
|
|
38
|
+
declare type options = Pick<Column, "nullable" | "primaryKey" | "default" | "foreignKey" | "unique" | "index">;
|
|
33
39
|
export declare function primaryKey(name: string, cols: string[]): Constraint;
|
|
34
40
|
export declare function foreignKey(name: string, cols: string[], fkey: {
|
|
35
41
|
table: string;
|
|
36
42
|
cols: string[];
|
|
37
43
|
}): Constraint;
|
|
44
|
+
interface indexOptions {
|
|
45
|
+
type: string;
|
|
46
|
+
}
|
|
47
|
+
export declare function index(tableName: string, cols: string[], opts?: indexOptions): Index;
|
|
38
48
|
export declare function uniqueIndex(name: string): Constraint;
|
|
39
49
|
export declare function uuid(name: string, opts?: options): Column;
|
|
40
50
|
export declare function text(name: string, opts?: options): Column;
|
|
@@ -71,19 +81,22 @@ export declare class TempDB {
|
|
|
71
81
|
constructor(tables: CoreConcept[]);
|
|
72
82
|
getDialect(): Dialect;
|
|
73
83
|
getTables(): Map<string, CoreConcept>;
|
|
74
|
-
beforeAll(): Promise<void>;
|
|
84
|
+
beforeAll(setupConnString?: boolean): Promise<void>;
|
|
85
|
+
createImpl(table: CoreConcept): Promise<void>;
|
|
75
86
|
getSqliteClient(): SqliteDatabase;
|
|
76
87
|
getPostgresClient(): PGClient;
|
|
77
88
|
afterAll(): Promise<void>;
|
|
89
|
+
getDB(): string;
|
|
78
90
|
dropAll(): Promise<void>;
|
|
79
91
|
drop(...tables: string[]): Promise<void>;
|
|
80
92
|
create(...tables: CoreConcept[]): Promise<void>;
|
|
81
93
|
}
|
|
82
94
|
export declare function assoc_edge_config_table(): Table;
|
|
83
|
-
export declare function assoc_edge_table(name: string): Table;
|
|
95
|
+
export declare function assoc_edge_table(name: string, global?: boolean): Table;
|
|
84
96
|
interface sqliteSetupOptions {
|
|
85
97
|
disableDeleteAfterEachTest?: boolean;
|
|
86
98
|
}
|
|
87
|
-
export declare function setupSqlite(connString: string, tables: () => Table[], opts?: sqliteSetupOptions):
|
|
99
|
+
export declare function setupSqlite(connString: string, tables: () => Table[], opts?: sqliteSetupOptions): TempDB;
|
|
88
100
|
export declare function getSchemaTable(schema: BuilderSchema<Ent>, dialect: Dialect): Table;
|
|
101
|
+
export declare function getColumnFromField(fieldName: string, f: Field, dialect: Dialect): Column;
|
|
89
102
|
export {};
|
|
@@ -22,7 +22,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
22
22
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
23
|
};
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.getSchemaTable = exports.setupSqlite = exports.assoc_edge_table = exports.assoc_edge_config_table = exports.TempDB = exports.enumType = exports.table = exports.boolList = exports.dateList = exports.timetzList = exports.timeList = exports.timestamptzList = exports.timestampList = exports.uuidList = exports.integerList = exports.textList = exports.jsonb = exports.json = exports.float = exports.integer = exports.bool = exports.date = exports.timetz = exports.time = exports.timestamptz = exports.timestamp = exports.enumCol = exports.text = exports.uuid = exports.uniqueIndex = exports.foreignKey = exports.primaryKey = void 0;
|
|
25
|
+
exports.getColumnFromField = exports.getSchemaTable = exports.setupSqlite = exports.assoc_edge_table = exports.assoc_edge_config_table = exports.TempDB = exports.enumType = exports.table = exports.boolList = exports.dateList = exports.timetzList = exports.timeList = exports.timestamptzList = exports.timestampList = exports.uuidList = exports.integerList = exports.textList = exports.jsonb = exports.json = exports.float = exports.integer = exports.bool = exports.date = exports.timetz = exports.time = exports.timestamptz = exports.timestamp = exports.enumCol = exports.text = exports.uuid = exports.uniqueIndex = exports.index = exports.foreignKey = exports.primaryKey = void 0;
|
|
26
26
|
const pg_1 = require("pg");
|
|
27
27
|
const db_1 = __importStar(require("../../core/db"));
|
|
28
28
|
// this should only be used in tests so we expect to be able to import without shenanigans
|
|
@@ -32,6 +32,7 @@ const fs = __importStar(require("fs"));
|
|
|
32
32
|
const schema_1 = require("../../schema");
|
|
33
33
|
const snake_case_1 = require("snake-case");
|
|
34
34
|
const builder_1 = require("../builder");
|
|
35
|
+
const test_edge_global_schema_1 = require("../test_edge_global_schema");
|
|
35
36
|
function primaryKey(name, cols) {
|
|
36
37
|
return {
|
|
37
38
|
name: name,
|
|
@@ -50,6 +51,16 @@ function foreignKey(name, cols, fkey) {
|
|
|
50
51
|
};
|
|
51
52
|
}
|
|
52
53
|
exports.foreignKey = foreignKey;
|
|
54
|
+
function index(tableName, cols, opts) {
|
|
55
|
+
const name = `${tableName}_${cols.join("_")}_idx`;
|
|
56
|
+
return {
|
|
57
|
+
name,
|
|
58
|
+
generate() {
|
|
59
|
+
return `CREATE INDEX ${name} ON ${tableName} USING ${opts?.type || "btree"} (${cols.join(",")});`;
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
exports.index = index;
|
|
53
64
|
function uniqueIndex(name) {
|
|
54
65
|
return {
|
|
55
66
|
name: "",
|
|
@@ -248,9 +259,24 @@ exports.boolList = boolList;
|
|
|
248
259
|
function table(name, ...items) {
|
|
249
260
|
let cols = [];
|
|
250
261
|
let constraints = [];
|
|
262
|
+
let indexes = [];
|
|
251
263
|
for (const item of items) {
|
|
252
264
|
if (item.datatype !== undefined) {
|
|
253
265
|
const col = item;
|
|
266
|
+
if (col.index) {
|
|
267
|
+
let opts = {
|
|
268
|
+
type: "btree",
|
|
269
|
+
};
|
|
270
|
+
if (col.index === true) {
|
|
271
|
+
opts = {
|
|
272
|
+
type: "btree",
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
opts = col.index;
|
|
277
|
+
}
|
|
278
|
+
indexes.push(index(name, [col.name], opts));
|
|
279
|
+
}
|
|
254
280
|
// add it as a constraint
|
|
255
281
|
if (col.foreignKey) {
|
|
256
282
|
constraints.push(foreignKey(`${name}_${col.name}_fkey`, [col.name], {
|
|
@@ -288,6 +314,9 @@ function table(name, ...items) {
|
|
|
288
314
|
constraints.forEach((constraint) => schemaStr.push(constraint.generate()));
|
|
289
315
|
return `CREATE TABLE IF NOT EXISTS ${name} (\n ${schemaStr})`;
|
|
290
316
|
},
|
|
317
|
+
postCreate() {
|
|
318
|
+
return indexes.map((index) => index.generate());
|
|
319
|
+
},
|
|
291
320
|
drop() {
|
|
292
321
|
return `DROP TABLE IF EXISTS ${name}`;
|
|
293
322
|
},
|
|
@@ -336,7 +365,7 @@ class TempDB {
|
|
|
336
365
|
getTables() {
|
|
337
366
|
return this.tables;
|
|
338
367
|
}
|
|
339
|
-
async beforeAll() {
|
|
368
|
+
async beforeAll(setupConnString = true) {
|
|
340
369
|
if (this.dialect === db_1.Dialect.Postgres) {
|
|
341
370
|
const user = process.env.POSTGRES_USER || "";
|
|
342
371
|
const password = process.env.POSTGRES_PASSWORD || "";
|
|
@@ -348,11 +377,17 @@ class TempDB {
|
|
|
348
377
|
await this.client.connect();
|
|
349
378
|
this.db = randomDB();
|
|
350
379
|
await this.client.query(`CREATE DATABASE ${this.db}`);
|
|
351
|
-
if (
|
|
352
|
-
|
|
380
|
+
if (setupConnString) {
|
|
381
|
+
if (user && password) {
|
|
382
|
+
process.env.DB_CONNECTION_STRING = `postgres://${user}:${password}@localhost:5432/${this.db}`;
|
|
383
|
+
}
|
|
384
|
+
else {
|
|
385
|
+
process.env.DB_CONNECTION_STRING = `postgres://localhost/${this.db}?`;
|
|
386
|
+
}
|
|
353
387
|
}
|
|
354
388
|
else {
|
|
355
|
-
|
|
389
|
+
// will probably be setup via loadConfig
|
|
390
|
+
delete process.env.DB_CONNECTION_STRING;
|
|
356
391
|
}
|
|
357
392
|
this.dbClient = new pg_1.Client({
|
|
358
393
|
host: "localhost",
|
|
@@ -370,11 +405,24 @@ class TempDB {
|
|
|
370
405
|
this.sqlite = (0, better_sqlite3_1.default)(filePath);
|
|
371
406
|
}
|
|
372
407
|
for (const [_, table] of this.tables) {
|
|
373
|
-
|
|
374
|
-
|
|
408
|
+
await this.createImpl(table);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
async createImpl(table) {
|
|
412
|
+
if (this.dialect == db_1.Dialect.Postgres) {
|
|
413
|
+
await this.dbClient.query(table.create());
|
|
414
|
+
if (table.postCreate) {
|
|
415
|
+
for (const q of table.postCreate()) {
|
|
416
|
+
await this.dbClient.query(q);
|
|
417
|
+
}
|
|
375
418
|
}
|
|
376
|
-
|
|
377
|
-
|
|
419
|
+
}
|
|
420
|
+
else {
|
|
421
|
+
this.sqlite.exec(table.create());
|
|
422
|
+
if (table.postCreate) {
|
|
423
|
+
for (const q of table.postCreate()) {
|
|
424
|
+
this.sqlite.exec(q);
|
|
425
|
+
}
|
|
378
426
|
}
|
|
379
427
|
}
|
|
380
428
|
}
|
|
@@ -397,6 +445,9 @@ class TempDB {
|
|
|
397
445
|
await this.client.query(`DROP DATABASE ${this.db}`);
|
|
398
446
|
await this.client.end();
|
|
399
447
|
}
|
|
448
|
+
getDB() {
|
|
449
|
+
return this.db;
|
|
450
|
+
}
|
|
400
451
|
async dropAll() {
|
|
401
452
|
for (const [t, _] of this.tables) {
|
|
402
453
|
await this.drop(t);
|
|
@@ -422,12 +473,7 @@ class TempDB {
|
|
|
422
473
|
if (this.tables.has(table.name)) {
|
|
423
474
|
throw new Error(`table with name ${table.name} already exists`);
|
|
424
475
|
}
|
|
425
|
-
|
|
426
|
-
await this.dbClient.query(table.create());
|
|
427
|
-
}
|
|
428
|
-
else {
|
|
429
|
-
this.sqlite.exec(table.create());
|
|
430
|
-
}
|
|
476
|
+
await this.createImpl(table);
|
|
431
477
|
this.tables.set(table.name, table);
|
|
432
478
|
}
|
|
433
479
|
}
|
|
@@ -439,18 +485,26 @@ function assoc_edge_config_table() {
|
|
|
439
485
|
text("edge_type", { primaryKey: true }), text("edge_name"), bool("symmetric_edge", { default: "FALSE" }), text("inverse_edge_type", { nullable: true }), text("edge_table"), timestamptz("created_at"), timestamptz("updated_at"));
|
|
440
486
|
}
|
|
441
487
|
exports.assoc_edge_config_table = assoc_edge_config_table;
|
|
442
|
-
|
|
443
|
-
|
|
488
|
+
// if global flag is true, add any column from testEdgeGlobalSchema
|
|
489
|
+
// up to caller to set/clear that as needed
|
|
490
|
+
function assoc_edge_table(name, global) {
|
|
491
|
+
const t = table(name, uuid("id1"), text("id1_type"),
|
|
444
492
|
// same as in assoc_edge_config_table
|
|
445
493
|
text("edge_type"), uuid("id2"), text("id2_type"), timestamptz("time"), text("data", { nullable: true }), primaryKey(`${name}_pkey`, ["id1", "id2", "edge_type"]));
|
|
494
|
+
if (global) {
|
|
495
|
+
for (const k in test_edge_global_schema_1.testEdgeGlobalSchema.extraEdgeFields) {
|
|
496
|
+
const col = getColumnFromField(k, test_edge_global_schema_1.testEdgeGlobalSchema.extraEdgeFields[k], db_1.Dialect.Postgres);
|
|
497
|
+
t.columns.push(col);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
return t;
|
|
446
501
|
}
|
|
447
502
|
exports.assoc_edge_table = assoc_edge_table;
|
|
448
503
|
function setupSqlite(connString, tables, opts) {
|
|
449
|
-
let tdb;
|
|
504
|
+
let tdb = new TempDB(db_1.Dialect.SQLite, tables());
|
|
450
505
|
beforeAll(async () => {
|
|
451
506
|
process.env.DB_CONNECTION_STRING = connString;
|
|
452
507
|
(0, config_1.loadConfig)();
|
|
453
|
-
tdb = new TempDB(db_1.Dialect.SQLite, tables());
|
|
454
508
|
await tdb.beforeAll();
|
|
455
509
|
const conn = db_1.default.getInstance().getConnection();
|
|
456
510
|
expect(conn.db.memory).toBe(false);
|
|
@@ -473,7 +527,9 @@ function setupSqlite(connString, tables, opts) {
|
|
|
473
527
|
afterAll(async () => {
|
|
474
528
|
await tdb.afterAll();
|
|
475
529
|
fs.rmSync(tdb.getSqliteClient().name);
|
|
530
|
+
delete process.env.DB_CONNECTION_STRING;
|
|
476
531
|
});
|
|
532
|
+
return tdb;
|
|
477
533
|
}
|
|
478
534
|
exports.setupSqlite = setupSqlite;
|
|
479
535
|
function getSchemaTable(schema, dialect) {
|
|
@@ -540,6 +596,7 @@ function getColumnFromField(fieldName, f, dialect) {
|
|
|
540
596
|
return getColumn(fieldName, f, fn);
|
|
541
597
|
}
|
|
542
598
|
}
|
|
599
|
+
exports.getColumnFromField = getColumnFromField;
|
|
543
600
|
function getColumn(fieldName, f, col) {
|
|
544
601
|
return col(storageKey(fieldName, f), buildOpts(f));
|
|
545
602
|
}
|
|
@@ -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 { BaseEntSchema, FieldMap } 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,24 +13,21 @@ 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
|
-
static getTestTable(): import("../db/
|
|
19
|
+
static getTestTable(): import("../db/temp_db").Table;
|
|
21
20
|
static loaderOptions(): LoadEntOptions<FakeContact>;
|
|
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: FieldMap;
|
|
28
|
-
}
|
|
24
|
+
export declare const FakeContactSchema: import("../builder").BuilderSchema<FakeContact>;
|
|
29
25
|
export interface ContactCreateInput {
|
|
30
26
|
firstName: string;
|
|
31
27
|
lastName: string;
|
|
32
28
|
emailAddress: string;
|
|
33
29
|
userID: ID;
|
|
34
30
|
}
|
|
35
|
-
export declare function getContactBuilder(viewer: Viewer, input: ContactCreateInput): SimpleBuilder<FakeContact>;
|
|
31
|
+
export declare function getContactBuilder(viewer: Viewer, input: ContactCreateInput): SimpleBuilder<FakeContact, null>;
|
|
36
32
|
export declare function createContact(viewer: Viewer, input: ContactCreateInput): Promise<void>;
|
|
37
33
|
export declare const contactLoader: ObjectLoaderFactory<unknown>;
|
|
@@ -6,16 +6,14 @@ 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 {
|
|
13
14
|
constructor(viewer, data) {
|
|
14
15
|
this.viewer = viewer;
|
|
15
16
|
this.nodeType = const_1.NodeType.FakeContact;
|
|
16
|
-
this.privacyPolicy = {
|
|
17
|
-
rules: [new privacy_1.AllowIfViewerIsRule("userID"), privacy_1.AlwaysDenyRule],
|
|
18
|
-
};
|
|
19
17
|
this.data = data;
|
|
20
18
|
this.id = data.id;
|
|
21
19
|
this.createdAt = (0, convert_1.convertDate)(data.created_at);
|
|
@@ -25,6 +23,11 @@ class FakeContact {
|
|
|
25
23
|
this.emailAddress = data.email_address;
|
|
26
24
|
this.userID = data.user_id;
|
|
27
25
|
}
|
|
26
|
+
getPrivacyPolicy() {
|
|
27
|
+
return {
|
|
28
|
+
rules: [new privacy_1.AllowIfViewerIsRule("userID"), privacy_1.AlwaysDenyRule],
|
|
29
|
+
};
|
|
30
|
+
}
|
|
28
31
|
static getFields() {
|
|
29
32
|
return [
|
|
30
33
|
"id",
|
|
@@ -37,7 +40,7 @@ class FakeContact {
|
|
|
37
40
|
];
|
|
38
41
|
}
|
|
39
42
|
static getTestTable() {
|
|
40
|
-
return (0,
|
|
43
|
+
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
44
|
}
|
|
42
45
|
static loaderOptions() {
|
|
43
46
|
return {
|
|
@@ -59,21 +62,14 @@ class FakeContact {
|
|
|
59
62
|
}
|
|
60
63
|
}
|
|
61
64
|
exports.FakeContact = FakeContact;
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
userID: (0, schema_1.UUIDType)({
|
|
71
|
-
foreignKey: { schema: "User", column: "ID" },
|
|
72
|
-
}),
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
exports.FakeContactSchema = FakeContactSchema;
|
|
65
|
+
exports.FakeContactSchema = (0, builder_1.getBuilderSchemaFromFields)({
|
|
66
|
+
firstName: (0, schema_1.StringType)(),
|
|
67
|
+
lastName: (0, schema_1.StringType)(),
|
|
68
|
+
emailAddress: (0, schema_1.StringType)(),
|
|
69
|
+
userID: (0, schema_1.UUIDType)({
|
|
70
|
+
foreignKey: { schema: "User", column: "ID" },
|
|
71
|
+
}),
|
|
72
|
+
}, FakeContact);
|
|
77
73
|
function getContactBuilder(viewer, input) {
|
|
78
74
|
const m = new Map();
|
|
79
75
|
for (const key in input) {
|
|
@@ -82,7 +78,7 @@ function getContactBuilder(viewer, input) {
|
|
|
82
78
|
//To lock in the value of Date now incase of advanceTo/advanceBy
|
|
83
79
|
m.set("createdAt", new Date());
|
|
84
80
|
m.set("updatedAt", new Date());
|
|
85
|
-
return new builder_1.SimpleBuilder(viewer,
|
|
81
|
+
return new builder_1.SimpleBuilder(viewer, exports.FakeContactSchema, m, action_1.WriteOperation.Insert, null);
|
|
86
82
|
}
|
|
87
83
|
exports.getContactBuilder = getContactBuilder;
|
|
88
84
|
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,18 +14,15 @@ 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
|
-
static getTestTable(): import("../db/
|
|
20
|
+
static getTestTable(): import("../db/temp_db").Table;
|
|
22
21
|
static loaderOptions(): LoadEntOptions<FakeEvent>;
|
|
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: FieldMap;
|
|
29
|
-
}
|
|
25
|
+
export declare const FakeEventSchema: import("../builder").BuilderSchema<FakeEvent>;
|
|
30
26
|
export interface EventCreateInput {
|
|
31
27
|
startTime: Date;
|
|
32
28
|
endTime?: Date | null;
|
|
@@ -35,5 +31,5 @@ export interface EventCreateInput {
|
|
|
35
31
|
description?: string | null;
|
|
36
32
|
userID: ID;
|
|
37
33
|
}
|
|
38
|
-
export declare function getEventBuilder(viewer: Viewer, input: EventCreateInput): SimpleBuilder<FakeEvent>;
|
|
34
|
+
export declare function getEventBuilder(viewer: Viewer, input: EventCreateInput): SimpleBuilder<FakeEvent, null>;
|
|
39
35
|
export declare function createEvent(viewer: Viewer, input: EventCreateInput): Promise<void>;
|
|
@@ -6,14 +6,14 @@ 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 {
|
|
13
14
|
constructor(viewer, data) {
|
|
14
15
|
this.viewer = viewer;
|
|
15
16
|
this.nodeType = const_1.NodeType.FakeEvent;
|
|
16
|
-
this.privacyPolicy = privacy_1.AlwaysAllowPrivacyPolicy;
|
|
17
17
|
this.data = data;
|
|
18
18
|
this.id = data.id;
|
|
19
19
|
this.createdAt = (0, convert_1.convertDate)(data.created_at);
|
|
@@ -25,6 +25,9 @@ class FakeEvent {
|
|
|
25
25
|
this.description = data.description;
|
|
26
26
|
this.userID = data.user_id;
|
|
27
27
|
}
|
|
28
|
+
getPrivacyPolicy() {
|
|
29
|
+
return privacy_1.AlwaysAllowPrivacyPolicy;
|
|
30
|
+
}
|
|
28
31
|
static getFields() {
|
|
29
32
|
return [
|
|
30
33
|
"id",
|
|
@@ -39,9 +42,9 @@ class FakeEvent {
|
|
|
39
42
|
];
|
|
40
43
|
}
|
|
41
44
|
static getTestTable() {
|
|
42
|
-
return (0,
|
|
45
|
+
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
46
|
// TODO index:true
|
|
44
|
-
(0,
|
|
47
|
+
(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
48
|
}
|
|
46
49
|
static loaderOptions() {
|
|
47
50
|
return {
|
|
@@ -63,35 +66,28 @@ class FakeEvent {
|
|
|
63
66
|
}
|
|
64
67
|
}
|
|
65
68
|
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;
|
|
69
|
+
exports.FakeEventSchema = (0, builder_1.getBuilderSchemaFromFields)({
|
|
70
|
+
startTime: (0, schema_1.TimestampType)({
|
|
71
|
+
index: true,
|
|
72
|
+
}),
|
|
73
|
+
endTime: (0, schema_1.TimestampType)({
|
|
74
|
+
nullable: true,
|
|
75
|
+
}),
|
|
76
|
+
title: (0, schema_1.StringType)(),
|
|
77
|
+
location: (0, schema_1.StringType)(),
|
|
78
|
+
description: (0, schema_1.StringType)({
|
|
79
|
+
nullable: true,
|
|
80
|
+
}),
|
|
81
|
+
userID: (0, schema_1.UUIDType)({
|
|
82
|
+
foreignKey: { schema: "User", column: "ID" },
|
|
83
|
+
}),
|
|
84
|
+
}, FakeEvent);
|
|
89
85
|
function getEventBuilder(viewer, input) {
|
|
90
86
|
const m = new Map();
|
|
91
87
|
for (const key in input) {
|
|
92
88
|
m.set(key, input[key]);
|
|
93
89
|
}
|
|
94
|
-
return new builder_1.SimpleBuilder(viewer,
|
|
90
|
+
return new builder_1.SimpleBuilder(viewer, exports.FakeEventSchema, m, action_1.WriteOperation.Insert, null);
|
|
95
91
|
}
|
|
96
92
|
exports.getEventBuilder = getEventBuilder;
|
|
97
93
|
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 { BaseEntSchema, FieldMap } 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,18 +23,15 @@ 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
|
-
static getTestTable(): import("../db/
|
|
29
|
+
static getTestTable(): import("../db/temp_db").Table;
|
|
31
30
|
static loaderOptions(): LoadEntOptions<FakeUser>;
|
|
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: FieldMap;
|
|
38
|
-
}
|
|
34
|
+
export declare const FakeUserSchema: import("../builder").BuilderSchema<FakeUser>;
|
|
39
35
|
export interface UserCreateInput {
|
|
40
36
|
firstName: string;
|
|
41
37
|
lastName: string;
|
|
@@ -44,8 +40,8 @@ export interface UserCreateInput {
|
|
|
44
40
|
password: string | null;
|
|
45
41
|
}
|
|
46
42
|
export declare type UserEditInput = Partial<UserCreateInput>;
|
|
47
|
-
export declare function getUserBuilder(viewer: Viewer, input: UserCreateInput): import("../builder").SimpleBuilder<FakeUser>;
|
|
48
|
-
export declare function getUserAction(viewer: Viewer, input: UserCreateInput): SimpleAction<FakeUser>;
|
|
43
|
+
export declare function getUserBuilder(viewer: Viewer, input: UserCreateInput): import("../builder").SimpleBuilder<FakeUser, null>;
|
|
44
|
+
export declare function getUserAction(viewer: Viewer, input: UserCreateInput): SimpleAction<FakeUser, null>;
|
|
49
45
|
export declare function createUser(viewer: Viewer, input: UserCreateInput): Promise<FakeUser>;
|
|
50
46
|
export declare const userLoader: ObjectLoaderFactory<unknown>;
|
|
51
47
|
export declare const userEmailLoader: ObjectLoaderFactory<unknown>;
|