@snowtop/ent 0.1.0-alpha97 → 0.1.0-alpha98-5dd3b3b0-9b44-11ed-83bb-45feb44f884b

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/config.d.ts CHANGED
@@ -21,6 +21,7 @@ export interface Config {
21
21
  codegen?: CodegenConfig;
22
22
  logQueryWithError?: boolean;
23
23
  customGraphQLJSONPath?: string;
24
+ dynamicScriptCustomGraphQLJSONPath?: string;
24
25
  globalSchemaPath?: string;
25
26
  }
26
27
  interface CodegenConfig {
@@ -42,6 +42,8 @@ interface CustomFieldImpl {
42
42
  export interface CustomField extends CustomFieldImpl {
43
43
  args: Field[];
44
44
  results: Field[];
45
+ extraImports?: any[];
46
+ functionContents?: string;
45
47
  }
46
48
  export interface CustomMutation extends CustomField {
47
49
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snowtop/ent",
3
- "version": "0.1.0-alpha97",
3
+ "version": "0.1.0-alpha98-5dd3b3b0-9b44-11ed-83bb-45feb44f884b",
4
4
  "description": "snowtop ent framework",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -36,6 +36,7 @@ const graphql_1 = require("../graphql/graphql");
36
36
  const readline = __importStar(require("readline"));
37
37
  const imports_1 = require("../imports");
38
38
  const process_1 = require("process");
39
+ const child_process_1 = require("child_process");
39
40
  // need to use the GQLCapture from the package so that when we call GQLCapture.enable()
40
41
  // we're affecting the local paths as opposed to a different instance
41
42
  // life is hard
@@ -115,6 +116,8 @@ function processTopLevel(l, l2) {
115
116
  args: transformArgs(custom),
116
117
  results: transformResultType(custom),
117
118
  description: custom.description,
119
+ extraImports: custom.extraImports,
120
+ functionContents: custom.functionContents,
118
121
  });
119
122
  }
120
123
  }
@@ -134,6 +137,43 @@ function processCustomFields(fields, gqlCapture, nodeName) {
134
137
  }
135
138
  m.set(nodeName, results);
136
139
  }
140
+ async function captureDynamic(filePath, gqlCapture) {
141
+ if (!filePath) {
142
+ return;
143
+ }
144
+ return await new Promise((resolve, reject) => {
145
+ // TODO tsconfig-paths?
146
+ const r = (0, child_process_1.spawn)("ts-node", [filePath]);
147
+ const datas = [];
148
+ r.stdout.on("data", (data) => {
149
+ datas.push(data.toString());
150
+ });
151
+ r.stderr.on("data", (data) => {
152
+ reject(new Error(data.toString()));
153
+ });
154
+ r.on("close", (code) => {
155
+ if (code !== 0) {
156
+ reject(new Error(`error code ${code} on dynamic path`));
157
+ return;
158
+ }
159
+ let json = json5_1.default.parse(datas.join(""));
160
+ for (const k in json) {
161
+ const v = json[k];
162
+ switch (k) {
163
+ case "queries":
164
+ processTopLevel(v, gqlCapture.getCustomQueries());
165
+ break;
166
+ case "mutations":
167
+ processTopLevel(v, gqlCapture.getCustomMutations());
168
+ break;
169
+ default:
170
+ reject(new Error(`key ${k} is unsupported in dynamic custom graphql. only queries and mutations are supported`));
171
+ }
172
+ }
173
+ resolve(undefined);
174
+ });
175
+ });
176
+ }
137
177
  async function captureCustom(filePath, filesCsv, jsonPath, gqlCapture) {
138
178
  if (jsonPath !== undefined) {
139
179
  let json = json5_1.default.parse(fs.readFileSync(jsonPath, {
@@ -297,9 +337,10 @@ async function main() {
297
337
  gqlCapture = r.GQLCapture;
298
338
  gqlCapture.enable(true);
299
339
  }
300
- const [inputsRead, _, imports] = await Promise.all([
340
+ const [inputsRead, _, __, imports] = await Promise.all([
301
341
  readInputs(),
302
342
  captureCustom(options.path, options.files, options.json_path, gqlCapture),
343
+ captureDynamic(options.dynamic_path, gqlCapture),
303
344
  parseImports(options.path),
304
345
  ]);
305
346
  const { nodes, nodesMap } = inputsRead;