@snowtop/ent 0.2.0-alpha.7 → 0.2.0-alpha.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/core/base.d.ts +1 -0
- package/core/query/custom_clause_query.d.ts +7 -4
- package/core/query/custom_clause_query.js +21 -2
- package/core/query_impl.js +18 -1
- package/graphql/query/edge_connection.js +17 -2
- package/graphql/query/shared_edge_connection.js +3 -1
- package/package.json +1 -1
- package/schema/schema.d.ts +1 -0
package/core/base.d.ts
CHANGED
|
@@ -86,6 +86,7 @@ interface JoinOptions<T2 extends Data = Data, K2 = keyof T2> {
|
|
|
86
86
|
tableName: string;
|
|
87
87
|
alias?: string;
|
|
88
88
|
clause: clause.Clause<T2, K2>;
|
|
89
|
+
type?: "inner" | "outer" | "left" | "right";
|
|
89
90
|
}
|
|
90
91
|
export interface QueryDataOptions<T extends Data = Data, K = keyof T> {
|
|
91
92
|
distinct?: boolean;
|
|
@@ -2,8 +2,9 @@ import { Data, EdgeQueryableDataOptions, Ent, ID, LoadEntOptions, QueryDataOptio
|
|
|
2
2
|
import { Clause } from "../clause";
|
|
3
3
|
import { OrderBy } from "../query_impl";
|
|
4
4
|
import { BaseEdgeQuery, IDInfo } from "./query";
|
|
5
|
-
export interface CustomClauseQueryOptions<TDest extends Ent<TViewer>, TViewer extends Viewer = Viewer> {
|
|
5
|
+
export interface CustomClauseQueryOptions<TDest extends Ent<TViewer>, TViewer extends Viewer = Viewer, TSource extends Ent<TViewer> | undefined = undefined> {
|
|
6
6
|
loadEntOptions: LoadEntOptions<TDest, TViewer>;
|
|
7
|
+
source?: TSource;
|
|
7
8
|
clause: Clause;
|
|
8
9
|
name: string;
|
|
9
10
|
primarySortColIsUnique?: boolean;
|
|
@@ -14,12 +15,14 @@ export interface CustomClauseQueryOptions<TDest extends Ent<TViewer>, TViewer ex
|
|
|
14
15
|
disableTransformations?: boolean;
|
|
15
16
|
joinBETA?: QueryDataOptions["join"];
|
|
16
17
|
}
|
|
17
|
-
export declare class CustomClauseQuery<TDest extends Ent<TViewer>, TViewer extends Viewer = Viewer> extends BaseEdgeQuery<any, TDest, Data> {
|
|
18
|
+
export declare class CustomClauseQuery<TDest extends Ent<TViewer>, TViewer extends Viewer = Viewer, TSource extends Ent<TViewer> | undefined = undefined> extends BaseEdgeQuery<any, TDest, Data> {
|
|
18
19
|
viewer: TViewer;
|
|
19
20
|
private options;
|
|
20
21
|
private clause;
|
|
22
|
+
private source?;
|
|
21
23
|
constructor(viewer: TViewer, options: CustomClauseQueryOptions<TDest, TViewer>);
|
|
22
|
-
|
|
24
|
+
__maybeSetSource(src: TSource): void;
|
|
25
|
+
sourceEnt(_id: ID): Promise<NonNullable<TSource> | null>;
|
|
23
26
|
getTableName(): string;
|
|
24
27
|
queryRawCount(): Promise<number>;
|
|
25
28
|
queryAllRawCount(): Promise<Map<ID, number>>;
|
|
@@ -27,5 +30,5 @@ export declare class CustomClauseQuery<TDest extends Ent<TViewer>, TViewer exten
|
|
|
27
30
|
protected loadRawData(_infos: IDInfo[], options: EdgeQueryableDataOptions): Promise<void>;
|
|
28
31
|
dataToID(edge: Data): ID;
|
|
29
32
|
protected loadEntsFromEdges(id: ID, rows: Data[]): Promise<TDest[]>;
|
|
30
|
-
__getOptions(): CustomClauseQueryOptions<TDest, TViewer>;
|
|
33
|
+
__getOptions(): CustomClauseQueryOptions<TDest, TViewer, undefined>;
|
|
31
34
|
}
|
|
@@ -52,9 +52,23 @@ class CustomClauseQuery extends query_1.BaseEdgeQuery {
|
|
|
52
52
|
this.viewer = viewer;
|
|
53
53
|
this.options = options;
|
|
54
54
|
this.clause = getClause(options);
|
|
55
|
+
this.source = options.source;
|
|
56
|
+
}
|
|
57
|
+
__maybeSetSource(src) {
|
|
58
|
+
if (this.source && this.source !== src) {
|
|
59
|
+
console.warn("source already set to something else");
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
this.source = src;
|
|
63
|
+
}
|
|
55
64
|
}
|
|
56
65
|
async sourceEnt(_id) {
|
|
57
|
-
|
|
66
|
+
// The sourceEnt is used for privacy checks and if we have the source we already know
|
|
67
|
+
// the privacy checks have been done or will be done
|
|
68
|
+
// This is being set for completeness but we don't really care about this.
|
|
69
|
+
// See https://github.com/lolopinto/ent/blob/15af0165f83458acc1d1c9f934f4534dca6154ff/ts/src/core/query/query.ts#L729-L739 for how sourceEnt is
|
|
70
|
+
// used in the codebase
|
|
71
|
+
return this.source ?? null;
|
|
58
72
|
}
|
|
59
73
|
getTableName() {
|
|
60
74
|
return this.options.loadEntOptions.tableName;
|
|
@@ -112,7 +126,12 @@ class CustomClauseQuery extends query_1.BaseEdgeQuery {
|
|
|
112
126
|
// if doing a join, select distinct rows
|
|
113
127
|
distinct: this.options.joinBETA !== undefined,
|
|
114
128
|
});
|
|
115
|
-
this.
|
|
129
|
+
if (this.source) {
|
|
130
|
+
this.edges.set(this.source.id, rows);
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
this.edges.set(1, rows);
|
|
134
|
+
}
|
|
116
135
|
}
|
|
117
136
|
dataToID(edge) {
|
|
118
137
|
return edge.id;
|
package/core/query_impl.js
CHANGED
|
@@ -36,7 +36,24 @@ function getJoinInfo(join, clauseIdx = 1) {
|
|
|
36
36
|
? `${join.tableName} ${join.alias}`
|
|
37
37
|
: join.tableName;
|
|
38
38
|
valuesUsed += join.clause.values().length;
|
|
39
|
-
|
|
39
|
+
let joinType;
|
|
40
|
+
switch (join.type) {
|
|
41
|
+
case "left":
|
|
42
|
+
joinType = "LEFT JOIN";
|
|
43
|
+
break;
|
|
44
|
+
case "right":
|
|
45
|
+
joinType = "RIGHT JOIN";
|
|
46
|
+
break;
|
|
47
|
+
case "outer":
|
|
48
|
+
joinType = "FULL OUTER JOIN";
|
|
49
|
+
break;
|
|
50
|
+
case "inner":
|
|
51
|
+
joinType = "INNER JOIN";
|
|
52
|
+
break;
|
|
53
|
+
default:
|
|
54
|
+
joinType = "JOIN";
|
|
55
|
+
}
|
|
56
|
+
return `${joinType} ${joinTable} ON ${join.clause.clause(clauseIdx)}`;
|
|
40
57
|
})
|
|
41
58
|
.join(" ");
|
|
42
59
|
return {
|
|
@@ -1,23 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.GraphQLEdgeConnection = void 0;
|
|
4
|
+
const query_1 = require("../../core/query");
|
|
4
5
|
// TODO probably need to template Ent. maybe 2 ents?
|
|
5
6
|
class GraphQLEdgeConnection {
|
|
6
7
|
constructor(viewer, arg2, arg3, args) {
|
|
7
8
|
this.results = [];
|
|
8
9
|
this.viewer = viewer;
|
|
10
|
+
async function resolveQuery(query, source) {
|
|
11
|
+
const resolved = await query;
|
|
12
|
+
// To have pagination correctly work with CustomClauseQuery in GraphQL contexts, we need to
|
|
13
|
+
// pass the source to the query so that we can set the page info correctly
|
|
14
|
+
// See https://github.com/lolopinto/ent/issues/1836 for full details of how this breaks down
|
|
15
|
+
if (resolved instanceof query_1.CustomClauseQuery && source !== undefined) {
|
|
16
|
+
resolved.__maybeSetSource(source);
|
|
17
|
+
}
|
|
18
|
+
return resolved;
|
|
19
|
+
}
|
|
20
|
+
let query;
|
|
21
|
+
let source;
|
|
9
22
|
if (typeof arg2 === "function") {
|
|
10
|
-
|
|
23
|
+
query = arg2(this.viewer);
|
|
11
24
|
}
|
|
12
25
|
else {
|
|
13
26
|
this.source = arg2;
|
|
27
|
+
source = arg2;
|
|
14
28
|
}
|
|
15
29
|
if (typeof arg3 === "function") {
|
|
16
|
-
|
|
30
|
+
query = arg3(this.viewer, this.source);
|
|
17
31
|
}
|
|
18
32
|
else {
|
|
19
33
|
this.args = arg3;
|
|
20
34
|
}
|
|
35
|
+
this.query = Promise.resolve(resolveQuery(query, source));
|
|
21
36
|
if (args !== undefined) {
|
|
22
37
|
this.args = args;
|
|
23
38
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.commonTests = void 0;
|
|
4
|
+
const query_1 = require("../../core/query");
|
|
4
5
|
const ent_1 = require("../../core/ent");
|
|
5
6
|
const viewer_1 = require("../../core/viewer");
|
|
6
7
|
const index_1 = require("../../testutils/fake_data/index");
|
|
@@ -60,7 +61,8 @@ const commonTests = (opts) => {
|
|
|
60
61
|
q instanceof index_1.UserToContactsFkeyQueryDeprecated ||
|
|
61
62
|
q instanceof index_1.UserToContactsFkeyQueryAsc ||
|
|
62
63
|
q instanceof index_1.UserToContactsFkeyQueryDeletedAt ||
|
|
63
|
-
q instanceof index_1.UserToContactsFkeyQueryDeletedAtAsc
|
|
64
|
+
q instanceof index_1.UserToContactsFkeyQueryDeletedAtAsc ||
|
|
65
|
+
q instanceof query_1.CustomClauseQuery);
|
|
64
66
|
}
|
|
65
67
|
function getCursorFrom(q, contacts, idx) {
|
|
66
68
|
let opts;
|
package/package.json
CHANGED
package/schema/schema.d.ts
CHANGED