@snowtop/ent 0.0.36 → 0.0.39-alpha4
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/orchestrator.d.ts +6 -0
- package/action/orchestrator.js +98 -20
- package/core/base.d.ts +1 -0
- package/core/clause.d.ts +5 -3
- package/core/clause.js +67 -4
- package/core/config.d.ts +11 -0
- package/core/config.js +12 -0
- package/core/ent.d.ts +2 -2
- package/core/ent.js +61 -6
- package/core/loaders/assoc_edge_loader.js +0 -1
- package/core/loaders/object_loader.d.ts +1 -0
- package/core/loaders/object_loader.js +22 -4
- package/graphql/graphql.d.ts +3 -2
- package/graphql/graphql.js +22 -21
- package/graphql/node_resolver.d.ts +0 -1
- package/package.json +2 -2
- package/parse_schema/parse.d.ts +7 -1
- package/parse_schema/parse.js +40 -1
- package/schema/index.d.ts +1 -1
- package/schema/index.js +3 -1
- package/schema/schema.d.ts +28 -1
- package/schema/schema.js +49 -5
- package/scripts/custom_graphql.js +122 -15
- package/testutils/builder.js +5 -0
- package/testutils/ent-graphql-tests/index.d.ts +2 -0
- package/testutils/ent-graphql-tests/index.js +7 -5
package/graphql/graphql.d.ts
CHANGED
|
@@ -82,6 +82,9 @@ declare enum NullableResult {
|
|
|
82
82
|
CONTENTS_AND_LIST = "contentsAndList",
|
|
83
83
|
ITEM = "true"
|
|
84
84
|
}
|
|
85
|
+
export declare const knownAllowedNames: Map<string, string>;
|
|
86
|
+
export declare const knownDisAllowedNames: Map<string, boolean>;
|
|
87
|
+
export declare const isCustomType: (type: Type) => type is CustomType;
|
|
85
88
|
export declare const addCustomType: (type: CustomType) => void;
|
|
86
89
|
export declare class GQLCapture {
|
|
87
90
|
private static enabled;
|
|
@@ -107,8 +110,6 @@ export declare class GQLCapture {
|
|
|
107
110
|
static getProcessedCustomMutations(): ProcessedCustomField[];
|
|
108
111
|
static getProcessedCustomQueries(): ProcessedCustomField[];
|
|
109
112
|
private static getProcessedCustomFieldsImpl;
|
|
110
|
-
private static knownAllowedNames;
|
|
111
|
-
private static knownDisAllowedNames;
|
|
112
113
|
private static getResultFromMetadata;
|
|
113
114
|
static gqlField(options?: gqlFieldOptions): any;
|
|
114
115
|
private static getCustomField;
|
package/graphql/graphql.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.gqlFileUpload = exports.gqlConnection = exports.gqlContextType = exports.gqlMutation = exports.gqlQuery = exports.gqlObjectType = exports.gqlInputObjectType = exports.gqlArgType = exports.gqlArg = exports.gqlField = exports.GQLCapture = exports.addCustomType = exports.CustomFieldType = void 0;
|
|
3
|
+
exports.gqlFileUpload = exports.gqlConnection = exports.gqlContextType = exports.gqlMutation = exports.gqlQuery = exports.gqlObjectType = exports.gqlInputObjectType = exports.gqlArgType = exports.gqlArg = exports.gqlField = exports.GQLCapture = exports.addCustomType = exports.isCustomType = exports.knownDisAllowedNames = exports.knownAllowedNames = exports.CustomFieldType = void 0;
|
|
4
4
|
require("reflect-metadata");
|
|
5
5
|
// export interface gqlTopLevelOptions
|
|
6
6
|
// name?: string;
|
|
@@ -20,6 +20,22 @@ var NullableResult;
|
|
|
20
20
|
NullableResult["CONTENTS_AND_LIST"] = "contentsAndList";
|
|
21
21
|
NullableResult["ITEM"] = "true";
|
|
22
22
|
})(NullableResult || (NullableResult = {}));
|
|
23
|
+
exports.knownAllowedNames = new Map([
|
|
24
|
+
["Date", "Date"],
|
|
25
|
+
["Boolean", "boolean"],
|
|
26
|
+
["Number", "number"],
|
|
27
|
+
["String", "string"],
|
|
28
|
+
// TODO not right to have this and Number
|
|
29
|
+
["Int", "number"],
|
|
30
|
+
["Float", "number"],
|
|
31
|
+
["ID", "ID"],
|
|
32
|
+
]);
|
|
33
|
+
exports.knownDisAllowedNames = new Map([
|
|
34
|
+
["Function", true],
|
|
35
|
+
["Object", true],
|
|
36
|
+
["Array", true],
|
|
37
|
+
["Promise", true],
|
|
38
|
+
]);
|
|
23
39
|
const isArray = (type) => {
|
|
24
40
|
if (typeof type === "function") {
|
|
25
41
|
return false;
|
|
@@ -41,6 +57,7 @@ const isString = (type) => {
|
|
|
41
57
|
const isCustomType = (type) => {
|
|
42
58
|
return type.importPath !== undefined;
|
|
43
59
|
};
|
|
60
|
+
exports.isCustomType = isCustomType;
|
|
44
61
|
const isGraphQLScalarType = (type) => {
|
|
45
62
|
return type.serialize !== undefined;
|
|
46
63
|
};
|
|
@@ -92,7 +109,7 @@ const getType = (typ, result) => {
|
|
|
92
109
|
}
|
|
93
110
|
return;
|
|
94
111
|
}
|
|
95
|
-
if (isCustomType(typ)) {
|
|
112
|
+
if ((0, exports.isCustomType)(typ)) {
|
|
96
113
|
result.type = typ.type;
|
|
97
114
|
(0, exports.addCustomType)(typ);
|
|
98
115
|
return;
|
|
@@ -197,20 +214,20 @@ class GQLCapture {
|
|
|
197
214
|
connection = r.connection;
|
|
198
215
|
type = r.type;
|
|
199
216
|
}
|
|
200
|
-
if (
|
|
217
|
+
if (exports.knownDisAllowedNames.has(type)) {
|
|
201
218
|
throw new Error(`${type} isn't a valid type for accessor/function/property`);
|
|
202
219
|
}
|
|
203
220
|
let result = {
|
|
204
221
|
name: metadata.paramName || "",
|
|
205
222
|
type,
|
|
206
|
-
tsType:
|
|
223
|
+
tsType: exports.knownAllowedNames.get(type) || this.customTypes.get(type)?.tsType,
|
|
207
224
|
nullable: options?.nullable,
|
|
208
225
|
list: list,
|
|
209
226
|
connection: connection,
|
|
210
227
|
isContextArg: metadata.isContextArg,
|
|
211
228
|
};
|
|
212
229
|
// unknown type. we need to flag that this field needs to eventually be resolved
|
|
213
|
-
if (!
|
|
230
|
+
if (!exports.knownAllowedNames.has(type)) {
|
|
214
231
|
if (scalarType) {
|
|
215
232
|
throw new Error(`custom scalar type ${type} is not supported this way. use CustomType syntax. see \`gqlFileUpload\` as an example`);
|
|
216
233
|
}
|
|
@@ -461,22 +478,6 @@ GQLCapture.customArgs = new Map();
|
|
|
461
478
|
GQLCapture.customInputObjects = new Map();
|
|
462
479
|
GQLCapture.customObjects = new Map();
|
|
463
480
|
GQLCapture.customTypes = new Map();
|
|
464
|
-
GQLCapture.knownAllowedNames = new Map([
|
|
465
|
-
["Date", "Date"],
|
|
466
|
-
["Boolean", "boolean"],
|
|
467
|
-
["Number", "number"],
|
|
468
|
-
["String", "string"],
|
|
469
|
-
// TODO not right to have this and Number
|
|
470
|
-
["Int", "number"],
|
|
471
|
-
["Float", "number"],
|
|
472
|
-
["ID", "ID"],
|
|
473
|
-
]);
|
|
474
|
-
GQLCapture.knownDisAllowedNames = new Map([
|
|
475
|
-
["Function", true],
|
|
476
|
-
["Object", true],
|
|
477
|
-
["Array", true],
|
|
478
|
-
["Promise", true],
|
|
479
|
-
]);
|
|
480
481
|
// User -> add -> [{name, options}, {}, {}]
|
|
481
482
|
GQLCapture.argMap = new Map();
|
|
482
483
|
// why is this a static class lol?
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@snowtop/ent",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.39-alpha4",
|
|
4
4
|
"description": "snowtop ent framework",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"json5": "^2.1.3",
|
|
18
18
|
"luxon": "^1.25.0",
|
|
19
19
|
"memoizee": "^0.4.15",
|
|
20
|
-
"minimist": "^1.2.
|
|
20
|
+
"minimist": "^1.2.6",
|
|
21
21
|
"pascal-case": "^3.1.2",
|
|
22
22
|
"pg": "^8.0.3",
|
|
23
23
|
"prettier": "^2.3.2",
|
package/parse_schema/parse.d.ts
CHANGED
|
@@ -12,7 +12,13 @@ declare type ProcessedAssocEdge = Omit<AssocEdge, "actionOnlyFields" | "edgeActi
|
|
|
12
12
|
patternName?: string;
|
|
13
13
|
edgeActions?: OutputAction[];
|
|
14
14
|
};
|
|
15
|
-
|
|
15
|
+
interface TransformFlags {
|
|
16
|
+
transformsSelect?: boolean;
|
|
17
|
+
transformsDelete?: boolean;
|
|
18
|
+
transformsInsert?: boolean;
|
|
19
|
+
transformsUpdate?: boolean;
|
|
20
|
+
}
|
|
21
|
+
declare type ProcessedSchema = Omit<Schema, "edges" | "actions" | "edgeGroups" | "fields"> & TransformFlags & {
|
|
16
22
|
actions: OutputAction[];
|
|
17
23
|
assocEdges: ProcessedAssocEdge[];
|
|
18
24
|
assocEdgeGroups: ProcessedAssocEdgeGroup[];
|
package/parse_schema/parse.js
CHANGED
|
@@ -31,10 +31,29 @@ function processFields(src, patternName) {
|
|
|
31
31
|
if (patternName) {
|
|
32
32
|
f.patternName = patternName;
|
|
33
33
|
}
|
|
34
|
+
transformType(field.type);
|
|
34
35
|
ret.push(f);
|
|
35
36
|
}
|
|
36
37
|
return ret;
|
|
37
38
|
}
|
|
39
|
+
function transformImportType(typ) {
|
|
40
|
+
if (!typ.importType) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
typ.importType = {
|
|
44
|
+
...typ.importType,
|
|
45
|
+
// these 2 needed for forwards compatibility with new go schema
|
|
46
|
+
importPath: typ.importType.path,
|
|
47
|
+
import: typ.importType.type,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function transformType(typ) {
|
|
51
|
+
if (!typ) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
transformImportType(typ);
|
|
55
|
+
transformType(typ.listElemType);
|
|
56
|
+
}
|
|
38
57
|
function processEdges(src, patternName) {
|
|
39
58
|
const ret = [];
|
|
40
59
|
for (const edge of src) {
|
|
@@ -59,6 +78,9 @@ function processEdgeGroups(processedSchema, edgeGroups) {
|
|
|
59
78
|
}
|
|
60
79
|
}
|
|
61
80
|
function processPattern(patterns, pattern, processedSchema) {
|
|
81
|
+
let ret = {
|
|
82
|
+
...pattern,
|
|
83
|
+
};
|
|
62
84
|
const name = pattern.name;
|
|
63
85
|
const fields = processFields(pattern.fields, pattern.name);
|
|
64
86
|
processedSchema.fields.push(...fields);
|
|
@@ -66,6 +88,10 @@ function processPattern(patterns, pattern, processedSchema) {
|
|
|
66
88
|
const edges = processEdges(pattern.edges, pattern.name);
|
|
67
89
|
processedSchema.assocEdges.push(...edges);
|
|
68
90
|
}
|
|
91
|
+
// flag transformsSelect
|
|
92
|
+
if (pattern.transformRead) {
|
|
93
|
+
ret.transformsSelect = true;
|
|
94
|
+
}
|
|
69
95
|
if (patterns[name] === undefined) {
|
|
70
96
|
// intentionally processing separately and not passing pattern.name
|
|
71
97
|
const edges = processEdges(pattern.edges || []);
|
|
@@ -79,6 +105,7 @@ function processPattern(patterns, pattern, processedSchema) {
|
|
|
79
105
|
// TODO ideally we want to make sure that different patterns don't have the same name
|
|
80
106
|
// can't do a deepEqual check because function calls and therefore different instances in fields
|
|
81
107
|
}
|
|
108
|
+
return ret;
|
|
82
109
|
}
|
|
83
110
|
var NullableResult;
|
|
84
111
|
(function (NullableResult) {
|
|
@@ -141,7 +168,19 @@ function parseSchema(potentialSchemas) {
|
|
|
141
168
|
// ¯\_(ツ)_/¯
|
|
142
169
|
if (schema.patterns) {
|
|
143
170
|
for (const pattern of schema.patterns) {
|
|
144
|
-
processPattern(patterns, pattern, processedSchema);
|
|
171
|
+
const ret = processPattern(patterns, pattern, processedSchema);
|
|
172
|
+
if (ret.transformsSelect) {
|
|
173
|
+
if (processedSchema.transformsSelect) {
|
|
174
|
+
throw new Error(`can only have one pattern which transforms default querying behavior`);
|
|
175
|
+
}
|
|
176
|
+
processedSchema.transformsSelect = true;
|
|
177
|
+
}
|
|
178
|
+
if (ret.transformsDelete) {
|
|
179
|
+
if (processedSchema.transformsDelete) {
|
|
180
|
+
throw new Error(`can only have one pattern which transforms default deletion behavior`);
|
|
181
|
+
}
|
|
182
|
+
processedSchema.transformsDelete = true;
|
|
183
|
+
}
|
|
145
184
|
}
|
|
146
185
|
}
|
|
147
186
|
const fields = processFields(schema.fields);
|
package/schema/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Schema from "./schema";
|
|
2
2
|
export { Schema };
|
|
3
|
-
export { Field, AssocEdge, AssocEdgeGroup, InverseAssocEdge, Edge, Pattern, DBType, Type, FieldOptions, SchemaConstructor, SchemaInputType, getFields, ActionOperation, Action, EdgeAction, NoFields, Constraint, Index, ConstraintType, ForeignKeyInfo, requiredField, optionalField, } from "./schema";
|
|
3
|
+
export { Field, AssocEdge, AssocEdgeGroup, InverseAssocEdge, Edge, Pattern, DBType, Type, FieldOptions, SchemaConstructor, SchemaInputType, getFields, ActionOperation, Action, EdgeAction, NoFields, Constraint, Index, ConstraintType, ForeignKeyInfo, requiredField, optionalField, UpdateOperation, TransformedUpdateOperation, SQLStatementOperation, getTransformedReadClause, } from "./schema";
|
|
4
4
|
export { Timestamps, Node, BaseEntSchema, BaseEntSchemaWithTZ, } from "./base_schema";
|
|
5
5
|
export * from "./field";
|
|
6
6
|
export * from "./json_field";
|
package/schema/index.js
CHANGED
|
@@ -10,7 +10,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
10
10
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.BaseEntSchemaWithTZ = exports.BaseEntSchema = exports.Node = exports.Timestamps = exports.optionalField = exports.requiredField = exports.ConstraintType = exports.NoFields = exports.ActionOperation = exports.getFields = exports.DBType = void 0;
|
|
13
|
+
exports.BaseEntSchemaWithTZ = exports.BaseEntSchema = exports.Node = exports.Timestamps = exports.getTransformedReadClause = exports.SQLStatementOperation = exports.optionalField = exports.requiredField = exports.ConstraintType = exports.NoFields = exports.ActionOperation = exports.getFields = exports.DBType = void 0;
|
|
14
14
|
var schema_1 = require("./schema");
|
|
15
15
|
Object.defineProperty(exports, "DBType", { enumerable: true, get: function () { return schema_1.DBType; } });
|
|
16
16
|
Object.defineProperty(exports, "getFields", { enumerable: true, get: function () { return schema_1.getFields; } });
|
|
@@ -19,6 +19,8 @@ Object.defineProperty(exports, "NoFields", { enumerable: true, get: function ()
|
|
|
19
19
|
Object.defineProperty(exports, "ConstraintType", { enumerable: true, get: function () { return schema_1.ConstraintType; } });
|
|
20
20
|
Object.defineProperty(exports, "requiredField", { enumerable: true, get: function () { return schema_1.requiredField; } });
|
|
21
21
|
Object.defineProperty(exports, "optionalField", { enumerable: true, get: function () { return schema_1.optionalField; } });
|
|
22
|
+
Object.defineProperty(exports, "SQLStatementOperation", { enumerable: true, get: function () { return schema_1.SQLStatementOperation; } });
|
|
23
|
+
Object.defineProperty(exports, "getTransformedReadClause", { enumerable: true, get: function () { return schema_1.getTransformedReadClause; } });
|
|
22
24
|
var base_schema_1 = require("./base_schema");
|
|
23
25
|
Object.defineProperty(exports, "Timestamps", { enumerable: true, get: function () { return base_schema_1.Timestamps; } });
|
|
24
26
|
Object.defineProperty(exports, "Node", { enumerable: true, get: function () { return base_schema_1.Node; } });
|
package/schema/schema.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Data, Ent, LoaderInfo } from "../core/base";
|
|
1
|
+
import { Data, Ent, LoaderInfo, Viewer } from "../core/base";
|
|
2
2
|
import { Builder } from "../action/action";
|
|
3
|
+
import { Clause } from "../core/clause";
|
|
3
4
|
export default interface Schema {
|
|
4
5
|
fields: Field[];
|
|
5
6
|
tableName?: string;
|
|
@@ -59,6 +60,27 @@ export interface Pattern {
|
|
|
59
60
|
name: string;
|
|
60
61
|
fields: Field[];
|
|
61
62
|
edges?: Edge[];
|
|
63
|
+
transformRead?: () => Clause;
|
|
64
|
+
transformWrite?: <T extends Ent>(stmt: UpdateOperation<T>) => TransformedUpdateOperation<T> | undefined;
|
|
65
|
+
transformsDelete?: boolean;
|
|
66
|
+
transformsInsert?: boolean;
|
|
67
|
+
transformsUpdate?: boolean;
|
|
68
|
+
}
|
|
69
|
+
export declare enum SQLStatementOperation {
|
|
70
|
+
Insert = "insert",
|
|
71
|
+
Update = "update",
|
|
72
|
+
Delete = "delete"
|
|
73
|
+
}
|
|
74
|
+
export interface UpdateOperation<T extends Ent> {
|
|
75
|
+
op: SQLStatementOperation;
|
|
76
|
+
existingEnt?: T;
|
|
77
|
+
viewer: Viewer;
|
|
78
|
+
data?: Map<string, any>;
|
|
79
|
+
}
|
|
80
|
+
export interface TransformedUpdateOperation<T extends Ent> {
|
|
81
|
+
op: SQLStatementOperation;
|
|
82
|
+
data?: Data;
|
|
83
|
+
existingEnt?: T;
|
|
62
84
|
}
|
|
63
85
|
export declare enum DBType {
|
|
64
86
|
UUID = "UUID",
|
|
@@ -82,6 +104,7 @@ export declare enum DBType {
|
|
|
82
104
|
export interface ImportType {
|
|
83
105
|
path: string;
|
|
84
106
|
type: string;
|
|
107
|
+
[x: string]: any;
|
|
85
108
|
}
|
|
86
109
|
declare type EnumMap = {
|
|
87
110
|
[key: string]: string;
|
|
@@ -131,6 +154,7 @@ export interface FieldOptions {
|
|
|
131
154
|
fieldEdge?: FieldEdge;
|
|
132
155
|
primaryKey?: boolean;
|
|
133
156
|
disableUserEditable?: boolean;
|
|
157
|
+
disableUserGraphQLEditable?: boolean;
|
|
134
158
|
defaultValueOnCreate?(builder: Builder<Ent>, input: Data): any;
|
|
135
159
|
defaultToViewerOnCreate?: boolean;
|
|
136
160
|
defaultValueOnEdit?(builder: Builder<Ent>, input: Data): any;
|
|
@@ -153,7 +177,10 @@ export interface SchemaConstructor {
|
|
|
153
177
|
new (): Schema;
|
|
154
178
|
}
|
|
155
179
|
export declare type SchemaInputType = Schema | SchemaConstructor;
|
|
180
|
+
export declare function getSchema(value: SchemaInputType): Schema;
|
|
156
181
|
export declare function getFields(value: SchemaInputType): Map<string, Field>;
|
|
182
|
+
export declare function getTransformedReadClause(value: SchemaInputType): Clause | undefined;
|
|
183
|
+
export declare function getTransformedUpdateOp<T extends Ent>(value: SchemaInputType, stmt: UpdateOperation<T>): TransformedUpdateOperation<T> | undefined;
|
|
157
184
|
export declare enum ActionOperation {
|
|
158
185
|
Create = 1,
|
|
159
186
|
Edit = 2,
|
package/schema/schema.js
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ConstraintType = exports.optionalField = exports.requiredField = exports.NoFields = exports.ActionOperation = exports.getFields = exports.DBType = void 0;
|
|
3
|
+
exports.ConstraintType = exports.optionalField = exports.requiredField = exports.NoFields = exports.ActionOperation = exports.getTransformedUpdateOp = exports.getTransformedReadClause = exports.getFields = exports.getSchema = exports.DBType = exports.SQLStatementOperation = void 0;
|
|
4
|
+
// we also want this transformation to exist on a per-action basis
|
|
5
|
+
// if it exists on an action, we don't do the global schema transformation
|
|
6
|
+
var SQLStatementOperation;
|
|
7
|
+
(function (SQLStatementOperation) {
|
|
8
|
+
// transform insert e.g. to an update based on whatever logic
|
|
9
|
+
SQLStatementOperation["Insert"] = "insert";
|
|
10
|
+
// // transform select e.g. deleted_at. can't change from select to different query type
|
|
11
|
+
// // but can change the query
|
|
12
|
+
// Select = "select",
|
|
13
|
+
// e.g. change updated value
|
|
14
|
+
SQLStatementOperation["Update"] = "update";
|
|
15
|
+
// delete -> update theoretically e.g. deleted_at
|
|
16
|
+
SQLStatementOperation["Delete"] = "delete";
|
|
17
|
+
})(SQLStatementOperation = exports.SQLStatementOperation || (exports.SQLStatementOperation = {}));
|
|
4
18
|
// we want --strictNullChecks flag so nullable is used to type graphql, ts, db
|
|
5
19
|
// should eventually generate (boolean | null) etc
|
|
6
20
|
// supported db types
|
|
@@ -28,14 +42,17 @@ var DBType;
|
|
|
28
42
|
function isSchema(value) {
|
|
29
43
|
return value.fields !== undefined;
|
|
30
44
|
}
|
|
31
|
-
function
|
|
32
|
-
let schema;
|
|
45
|
+
function getSchema(value) {
|
|
33
46
|
if (isSchema(value)) {
|
|
34
|
-
|
|
47
|
+
return value;
|
|
35
48
|
}
|
|
36
49
|
else {
|
|
37
|
-
|
|
50
|
+
return new value();
|
|
38
51
|
}
|
|
52
|
+
}
|
|
53
|
+
exports.getSchema = getSchema;
|
|
54
|
+
function getFields(value) {
|
|
55
|
+
const schema = getSchema(value);
|
|
39
56
|
function addFields(fields) {
|
|
40
57
|
for (const field of fields) {
|
|
41
58
|
const derivedFields = field.derivedFields;
|
|
@@ -55,6 +72,33 @@ function getFields(value) {
|
|
|
55
72
|
return m;
|
|
56
73
|
}
|
|
57
74
|
exports.getFields = getFields;
|
|
75
|
+
function getTransformedReadClause(value) {
|
|
76
|
+
const schema = getSchema(value);
|
|
77
|
+
if (!schema.patterns) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
for (const p of schema.patterns) {
|
|
81
|
+
// e.g. discarded_at, deleted_at, etc
|
|
82
|
+
if (p.transformRead) {
|
|
83
|
+
// return clause.Eq('deleted_at', null);
|
|
84
|
+
return p.transformRead();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
exports.getTransformedReadClause = getTransformedReadClause;
|
|
90
|
+
function getTransformedUpdateOp(value, stmt) {
|
|
91
|
+
const schema = getSchema(value);
|
|
92
|
+
if (!schema.patterns) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
for (const p of schema.patterns) {
|
|
96
|
+
if (p.transformWrite) {
|
|
97
|
+
return p.transformWrite(stmt);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.getTransformedUpdateOp = getTransformedUpdateOp;
|
|
58
102
|
// this maps to ActionOperation in ent/action.go
|
|
59
103
|
var ActionOperation;
|
|
60
104
|
(function (ActionOperation) {
|
|
@@ -24,6 +24,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
const glob_1 = __importDefault(require("glob"));
|
|
27
|
+
const json5_1 = __importDefault(require("json5"));
|
|
27
28
|
const minimist_1 = __importDefault(require("minimist"));
|
|
28
29
|
const graphql_1 = require("../graphql/graphql");
|
|
29
30
|
const readline = __importStar(require("readline"));
|
|
@@ -53,7 +54,103 @@ async function readInputs() {
|
|
|
53
54
|
});
|
|
54
55
|
});
|
|
55
56
|
}
|
|
56
|
-
|
|
57
|
+
function processCustomObjects(l, gqlCapture, input) {
|
|
58
|
+
let m;
|
|
59
|
+
if (input) {
|
|
60
|
+
m = gqlCapture.getCustomInputObjects();
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
m = gqlCapture.getCustomObjects();
|
|
64
|
+
}
|
|
65
|
+
for (const input of l) {
|
|
66
|
+
m.set(input.name, {
|
|
67
|
+
nodeName: input.graphQLName || input.name,
|
|
68
|
+
className: input.name,
|
|
69
|
+
});
|
|
70
|
+
if (input.fields) {
|
|
71
|
+
processCustomFields(input.fields, gqlCapture, input.name);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function transformArgs(f) {
|
|
76
|
+
return (f.args || []).map((v) => {
|
|
77
|
+
const ret = {
|
|
78
|
+
...v,
|
|
79
|
+
};
|
|
80
|
+
// duplicated from getType in graphql.ts
|
|
81
|
+
if ((0, graphql_1.isCustomType)(ret.type)) {
|
|
82
|
+
ret.type = v.type.type;
|
|
83
|
+
(0, graphql_1.addCustomType)(v.type);
|
|
84
|
+
}
|
|
85
|
+
// scalar types not supported for now
|
|
86
|
+
ret.tsType = graphql_1.knownAllowedNames.get(v.type);
|
|
87
|
+
return ret;
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
function transformResultType(f) {
|
|
91
|
+
return f.resultType
|
|
92
|
+
? [
|
|
93
|
+
{
|
|
94
|
+
name: "",
|
|
95
|
+
type: f.resultType,
|
|
96
|
+
tsType: graphql_1.knownAllowedNames.get(f.resultType),
|
|
97
|
+
list: f.list,
|
|
98
|
+
nullable: f.nullable,
|
|
99
|
+
},
|
|
100
|
+
]
|
|
101
|
+
: [];
|
|
102
|
+
}
|
|
103
|
+
function processTopLevel(l, l2) {
|
|
104
|
+
for (const custom of l) {
|
|
105
|
+
l2.push({
|
|
106
|
+
nodeName: custom.class,
|
|
107
|
+
functionName: custom.functionName || custom.name,
|
|
108
|
+
gqlName: custom.graphQLName || custom.name,
|
|
109
|
+
fieldType: custom.fieldType,
|
|
110
|
+
args: transformArgs(custom),
|
|
111
|
+
results: transformResultType(custom),
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function processCustomFields(fields, gqlCapture, nodeName) {
|
|
116
|
+
const m = gqlCapture.getCustomFields();
|
|
117
|
+
let results = [];
|
|
118
|
+
for (const f of fields) {
|
|
119
|
+
results.push({
|
|
120
|
+
nodeName: nodeName,
|
|
121
|
+
gqlName: f.graphQLName || f.name,
|
|
122
|
+
functionName: f.functionName || f.name,
|
|
123
|
+
fieldType: f.fieldType,
|
|
124
|
+
args: transformArgs(f),
|
|
125
|
+
results: transformResultType(f),
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
m.set(nodeName, results);
|
|
129
|
+
}
|
|
130
|
+
async function captureCustom(filePath, filesCsv, jsonPath, gqlCapture) {
|
|
131
|
+
if (jsonPath !== undefined) {
|
|
132
|
+
let json = json5_1.default.parse(fs.readFileSync(jsonPath, {
|
|
133
|
+
encoding: "utf8",
|
|
134
|
+
}));
|
|
135
|
+
if (json.fields) {
|
|
136
|
+
for (const k in json.fields) {
|
|
137
|
+
processCustomFields(json.fields[k], gqlCapture, k);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
if (json.inputs) {
|
|
141
|
+
processCustomObjects(json.inputs, gqlCapture, true);
|
|
142
|
+
}
|
|
143
|
+
if (json.objects) {
|
|
144
|
+
processCustomObjects(json.objects, gqlCapture);
|
|
145
|
+
}
|
|
146
|
+
if (json.queries) {
|
|
147
|
+
processTopLevel(json.queries, gqlCapture.getCustomQueries());
|
|
148
|
+
}
|
|
149
|
+
if (json.mutations) {
|
|
150
|
+
processTopLevel(json.mutations, gqlCapture.getCustomMutations());
|
|
151
|
+
}
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
57
154
|
if (filesCsv !== undefined) {
|
|
58
155
|
let files = filesCsv.split(",");
|
|
59
156
|
for (let i = 0; i < files.length; i++) {
|
|
@@ -153,15 +250,25 @@ async function main() {
|
|
|
153
250
|
if (!gqlPath) {
|
|
154
251
|
throw new Error("could not find graphql path");
|
|
155
252
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
253
|
+
// use different variable so that we use the correct GQLCapture as needed
|
|
254
|
+
// for local dev, get the one from the file system. otherwise, get the one
|
|
255
|
+
// from node_modules
|
|
256
|
+
let gqlCapture;
|
|
257
|
+
if (process.env.LOCAL_SCRIPT_PATH) {
|
|
258
|
+
const r = require("../graphql/graphql");
|
|
259
|
+
gqlCapture = r.GQLCapture;
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
262
|
+
const r = require(gqlPath);
|
|
263
|
+
if (!r.GQLCapture) {
|
|
264
|
+
throw new Error("could not find GQLCapture in module");
|
|
265
|
+
}
|
|
266
|
+
gqlCapture = r.GQLCapture;
|
|
267
|
+
gqlCapture.enable(true);
|
|
159
268
|
}
|
|
160
|
-
const GQLCapture = r.GQLCapture;
|
|
161
|
-
GQLCapture.enable(true);
|
|
162
269
|
const [inputsRead, _, imports] = await Promise.all([
|
|
163
270
|
readInputs(),
|
|
164
|
-
captureCustom(options.path, options.files),
|
|
271
|
+
captureCustom(options.path, options.files, options.json_path, gqlCapture),
|
|
165
272
|
parseImports(options.path),
|
|
166
273
|
]);
|
|
167
274
|
const { nodes, nodesMap } = inputsRead;
|
|
@@ -172,14 +279,14 @@ async function main() {
|
|
|
172
279
|
}
|
|
173
280
|
return result;
|
|
174
281
|
}
|
|
175
|
-
|
|
176
|
-
let args = fromMap(
|
|
177
|
-
let inputs = fromMap(
|
|
178
|
-
let fields =
|
|
179
|
-
let queries =
|
|
180
|
-
let mutations =
|
|
181
|
-
let objects = fromMap(
|
|
182
|
-
let customTypes = fromMap(
|
|
282
|
+
gqlCapture.resolve(nodes);
|
|
283
|
+
let args = fromMap(gqlCapture.getCustomArgs());
|
|
284
|
+
let inputs = fromMap(gqlCapture.getCustomInputObjects());
|
|
285
|
+
let fields = gqlCapture.getProcessedCustomFields();
|
|
286
|
+
let queries = gqlCapture.getProcessedCustomQueries();
|
|
287
|
+
let mutations = gqlCapture.getProcessedCustomMutations();
|
|
288
|
+
let objects = fromMap(gqlCapture.getCustomObjects());
|
|
289
|
+
let customTypes = fromMap(gqlCapture.getCustomTypes());
|
|
183
290
|
let classes = {};
|
|
184
291
|
let allFiles = {};
|
|
185
292
|
const buildClasses2 = (args) => {
|
package/testutils/builder.js
CHANGED
|
@@ -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;
|
|
@@ -56,7 +56,7 @@ function server(config) {
|
|
|
56
56
|
};
|
|
57
57
|
return doWork();
|
|
58
58
|
}));
|
|
59
|
-
app.use("/graphql", ...handlers);
|
|
59
|
+
app.use(config.graphQLPath || "/graphql", ...handlers);
|
|
60
60
|
return app;
|
|
61
61
|
}
|
|
62
62
|
function getInnerType(typ, list) {
|
|
@@ -72,14 +72,14 @@ function makeGraphQLRequest(config, query, fieldArgs) {
|
|
|
72
72
|
let test;
|
|
73
73
|
if (config.test) {
|
|
74
74
|
if (typeof config.test === "function") {
|
|
75
|
-
test = config.test(server(config));
|
|
75
|
+
test = config.test(config.server ? config.server : server(config));
|
|
76
76
|
}
|
|
77
77
|
else {
|
|
78
78
|
test = config.test;
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
else {
|
|
82
|
-
test = (0, supertest_1.default)(server(config));
|
|
82
|
+
test = (0, supertest_1.default)(config.server ? config.server : server(config));
|
|
83
83
|
}
|
|
84
84
|
let files = new Map();
|
|
85
85
|
// handle files
|
|
@@ -104,7 +104,9 @@ function makeGraphQLRequest(config, query, fieldArgs) {
|
|
|
104
104
|
}
|
|
105
105
|
});
|
|
106
106
|
if (files.size) {
|
|
107
|
-
let ret = test
|
|
107
|
+
let ret = test
|
|
108
|
+
.post(config.graphQLPath || "/graphql")
|
|
109
|
+
.set(config.headers || {});
|
|
108
110
|
ret.field("operations", JSON.stringify({
|
|
109
111
|
query: query,
|
|
110
112
|
variables: config.args,
|
|
@@ -130,7 +132,7 @@ function makeGraphQLRequest(config, query, fieldArgs) {
|
|
|
130
132
|
return [
|
|
131
133
|
test,
|
|
132
134
|
test
|
|
133
|
-
.post("/graphql")
|
|
135
|
+
.post(config.graphQLPath || "/graphql")
|
|
134
136
|
.set(config.headers || {})
|
|
135
137
|
.send({
|
|
136
138
|
query: query,
|