@snowtop/ent 0.1.0-alpha6 → 0.1.0-alpha9
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 +10 -2
- package/action/orchestrator.js +128 -34
- package/core/base.d.ts +5 -1
- 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 +70 -23
- 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.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/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/index.d.ts +16 -1
- package/index.js +18 -5
- package/package.json +3 -3
- package/parse_schema/parse.d.ts +16 -5
- package/parse_schema/parse.js +51 -6
- package/schema/base_schema.d.ts +36 -1
- package/schema/base_schema.js +48 -2
- package/schema/field.js +1 -1
- package/schema/index.d.ts +2 -2
- package/schema/index.js +8 -1
- package/schema/schema.d.ts +50 -1
- package/schema/schema.js +113 -5
- package/scripts/custom_graphql.js +122 -15
- package/scripts/read_schema.js +15 -1
- package/scripts/transform_schema.js +212 -55
- package/testutils/builder.d.ts +5 -1
- package/testutils/builder.js +46 -2
- 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 +13 -4
- 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 +2 -6
- package/testutils/fake_data/fake_contact.js +9 -16
- package/testutils/fake_data/fake_event.d.ts +2 -6
- package/testutils/fake_data/fake_event.js +17 -24
- package/testutils/fake_data/fake_user.d.ts +2 -6
- package/testutils/fake_data/fake_user.js +10 -17
- package/testutils/fake_data/test_helpers.js +1 -1
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);
|
|
@@ -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 {
|
|
@@ -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: FieldMap;
|
|
28
|
-
}
|
|
24
|
+
export declare const FakeContactSchema: import("../builder").BuilderSchema<FakeContact>;
|
|
29
25
|
export interface ContactCreateInput {
|
|
30
26
|
firstName: string;
|
|
31
27
|
lastName: string;
|
|
@@ -59,21 +59,14 @@ class FakeContact {
|
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
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;
|
|
62
|
+
exports.FakeContactSchema = (0, builder_1.getBuilderSchemaFromFields)({
|
|
63
|
+
firstName: (0, schema_1.StringType)(),
|
|
64
|
+
lastName: (0, schema_1.StringType)(),
|
|
65
|
+
emailAddress: (0, schema_1.StringType)(),
|
|
66
|
+
userID: (0, schema_1.UUIDType)({
|
|
67
|
+
foreignKey: { schema: "User", column: "ID" },
|
|
68
|
+
}),
|
|
69
|
+
}, FakeContact);
|
|
77
70
|
function getContactBuilder(viewer, input) {
|
|
78
71
|
const m = new Map();
|
|
79
72
|
for (const key in input) {
|
|
@@ -82,7 +75,7 @@ function getContactBuilder(viewer, input) {
|
|
|
82
75
|
//To lock in the value of Date now incase of advanceTo/advanceBy
|
|
83
76
|
m.set("createdAt", new Date());
|
|
84
77
|
m.set("updatedAt", new Date());
|
|
85
|
-
return new builder_1.SimpleBuilder(viewer,
|
|
78
|
+
return new builder_1.SimpleBuilder(viewer, exports.FakeContactSchema, m);
|
|
86
79
|
}
|
|
87
80
|
exports.getContactBuilder = getContactBuilder;
|
|
88
81
|
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;
|
|
@@ -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: 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;
|
|
@@ -63,35 +63,28 @@ class FakeEvent {
|
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
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;
|
|
66
|
+
exports.FakeEventSchema = (0, builder_1.getBuilderSchemaFromFields)({
|
|
67
|
+
startTime: (0, schema_1.TimestampType)({
|
|
68
|
+
index: true,
|
|
69
|
+
}),
|
|
70
|
+
endTime: (0, schema_1.TimestampType)({
|
|
71
|
+
nullable: true,
|
|
72
|
+
}),
|
|
73
|
+
title: (0, schema_1.StringType)(),
|
|
74
|
+
location: (0, schema_1.StringType)(),
|
|
75
|
+
description: (0, schema_1.StringType)({
|
|
76
|
+
nullable: true,
|
|
77
|
+
}),
|
|
78
|
+
userID: (0, schema_1.UUIDType)({
|
|
79
|
+
foreignKey: { schema: "User", column: "ID" },
|
|
80
|
+
}),
|
|
81
|
+
}, FakeEvent);
|
|
89
82
|
function getEventBuilder(viewer, input) {
|
|
90
83
|
const m = new Map();
|
|
91
84
|
for (const key in input) {
|
|
92
85
|
m.set(key, input[key]);
|
|
93
86
|
}
|
|
94
|
-
return new builder_1.SimpleBuilder(viewer,
|
|
87
|
+
return new builder_1.SimpleBuilder(viewer, exports.FakeEventSchema, m);
|
|
95
88
|
}
|
|
96
89
|
exports.getEventBuilder = getEventBuilder;
|
|
97
90
|
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";
|
|
@@ -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: FieldMap;
|
|
38
|
-
}
|
|
34
|
+
export declare const FakeUserSchema: import("../builder").BuilderSchema<FakeUser>;
|
|
39
35
|
export interface UserCreateInput {
|
|
40
36
|
firstName: string;
|
|
41
37
|
lastName: string;
|
|
@@ -89,22 +89,15 @@ class FakeUser {
|
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
exports.FakeUser = FakeUser;
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
password: (0, schema_1.StringType)({
|
|
102
|
-
nullable: true,
|
|
103
|
-
}),
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
exports.FakeUserSchema = FakeUserSchema;
|
|
92
|
+
exports.FakeUserSchema = (0, builder_1.getBuilderSchemaFromFields)({
|
|
93
|
+
firstName: (0, schema_1.StringType)(),
|
|
94
|
+
lastName: (0, schema_1.StringType)(),
|
|
95
|
+
emailAddress: (0, schema_1.StringType)(),
|
|
96
|
+
phoneNumber: (0, schema_1.StringType)(),
|
|
97
|
+
password: (0, schema_1.StringType)({
|
|
98
|
+
nullable: true,
|
|
99
|
+
}),
|
|
100
|
+
}, FakeUser);
|
|
108
101
|
function getUserBuilder(viewer, input) {
|
|
109
102
|
const action = getUserAction(viewer, input);
|
|
110
103
|
return action.builder;
|
|
@@ -115,7 +108,7 @@ function getUserAction(viewer, input) {
|
|
|
115
108
|
for (const key in input) {
|
|
116
109
|
m.set(key, input[key]);
|
|
117
110
|
}
|
|
118
|
-
const action = new builder_1.SimpleAction(viewer,
|
|
111
|
+
const action = new builder_1.SimpleAction(viewer, exports.FakeUserSchema, m);
|
|
119
112
|
action.viewerForEntLoad = (data) => {
|
|
120
113
|
// load the created ent using a VC of the newly created user.
|
|
121
114
|
return new viewer_1.IDViewer(data.id);
|
|
@@ -107,7 +107,7 @@ async function createUserPlusFriendRequests(input, slice) {
|
|
|
107
107
|
return createTestUser(input);
|
|
108
108
|
}));
|
|
109
109
|
expect(friendRequests.length).toBe(userInputs.length);
|
|
110
|
-
await addEdge(user,
|
|
110
|
+
await addEdge(user, _1.FakeUserSchema, _1.EdgeType.UserToFriendRequests, true, ...friendRequests);
|
|
111
111
|
return [user, friendRequests];
|
|
112
112
|
}
|
|
113
113
|
exports.createUserPlusFriendRequests = createUserPlusFriendRequests;
|