@snowtop/ent 0.0.36 → 0.0.39-alpha10
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 +24 -3
- package/core/clause.js +244 -5
- package/core/config.d.ts +13 -0
- package/core/config.js +12 -0
- package/core/ent.d.ts +2 -2
- package/core/ent.js +15 -6
- package/core/loaders/assoc_edge_loader.js +0 -1
- package/core/loaders/index_loader.js +1 -0
- 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/index.d.ts +15 -0
- package/index.js +15 -0
- 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 +42 -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
|
@@ -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,
|