@snowtop/ent 0.1.0-alpha16 → 0.1.0-alpha160-test2

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.
Files changed (176) hide show
  1. package/action/action.d.ts +25 -14
  2. package/action/action.js +22 -7
  3. package/action/executor.d.ts +16 -3
  4. package/action/executor.js +89 -28
  5. package/action/experimental_action.d.ts +25 -16
  6. package/action/experimental_action.js +34 -14
  7. package/action/index.d.ts +4 -1
  8. package/action/index.js +7 -1
  9. package/action/operations.d.ts +126 -0
  10. package/action/operations.js +686 -0
  11. package/action/orchestrator.d.ts +43 -12
  12. package/action/orchestrator.js +461 -101
  13. package/action/relative_value.d.ts +47 -0
  14. package/action/relative_value.js +125 -0
  15. package/action/transaction.d.ts +10 -0
  16. package/action/transaction.js +23 -0
  17. package/auth/auth.d.ts +1 -1
  18. package/core/base.d.ts +56 -23
  19. package/core/base.js +7 -1
  20. package/core/clause.d.ts +103 -39
  21. package/core/clause.js +430 -66
  22. package/core/config.d.ts +13 -3
  23. package/core/config.js +10 -1
  24. package/core/const.d.ts +3 -0
  25. package/core/const.js +6 -0
  26. package/core/context.d.ts +6 -3
  27. package/core/context.js +22 -3
  28. package/core/convert.d.ts +1 -1
  29. package/core/date.js +1 -5
  30. package/core/db.d.ts +12 -8
  31. package/core/db.js +21 -9
  32. package/core/ent.d.ts +99 -95
  33. package/core/ent.js +550 -602
  34. package/core/global_schema.d.ts +7 -0
  35. package/core/global_schema.js +51 -0
  36. package/core/loaders/assoc_count_loader.d.ts +5 -2
  37. package/core/loaders/assoc_count_loader.js +19 -3
  38. package/core/loaders/assoc_edge_loader.d.ts +2 -3
  39. package/core/loaders/assoc_edge_loader.js +23 -17
  40. package/core/loaders/index.d.ts +1 -2
  41. package/core/loaders/index.js +1 -5
  42. package/core/loaders/loader.d.ts +3 -3
  43. package/core/loaders/loader.js +4 -21
  44. package/core/loaders/object_loader.d.ts +30 -9
  45. package/core/loaders/object_loader.js +226 -79
  46. package/core/loaders/query_loader.d.ts +7 -13
  47. package/core/loaders/query_loader.js +60 -24
  48. package/core/loaders/raw_count_loader.d.ts +1 -0
  49. package/core/loaders/raw_count_loader.js +8 -3
  50. package/core/logger.d.ts +1 -1
  51. package/core/logger.js +1 -0
  52. package/core/privacy.d.ts +26 -16
  53. package/core/privacy.js +68 -51
  54. package/core/query/assoc_query.d.ts +3 -2
  55. package/core/query/assoc_query.js +10 -2
  56. package/core/query/custom_clause_query.d.ts +29 -0
  57. package/core/query/custom_clause_query.js +105 -0
  58. package/core/query/custom_query.d.ts +19 -2
  59. package/core/query/custom_query.js +111 -13
  60. package/core/query/index.d.ts +1 -0
  61. package/core/query/index.js +3 -1
  62. package/core/query/query.d.ts +18 -4
  63. package/core/query/query.js +135 -58
  64. package/core/query/shared_assoc_test.d.ts +2 -1
  65. package/core/query/shared_assoc_test.js +186 -55
  66. package/core/query/shared_test.d.ts +9 -2
  67. package/core/query/shared_test.js +529 -236
  68. package/core/query_impl.d.ts +8 -0
  69. package/core/query_impl.js +28 -0
  70. package/core/viewer.d.ts +2 -0
  71. package/core/viewer.js +3 -1
  72. package/graphql/graphql.d.ts +108 -22
  73. package/graphql/graphql.js +183 -137
  74. package/graphql/graphql_field_helpers.d.ts +9 -3
  75. package/graphql/graphql_field_helpers.js +22 -2
  76. package/graphql/index.d.ts +2 -2
  77. package/graphql/index.js +5 -5
  78. package/graphql/query/connection_type.d.ts +9 -9
  79. package/graphql/query/shared_assoc_test.js +1 -1
  80. package/graphql/query/shared_edge_connection.js +1 -19
  81. package/graphql/scalars/orderby_direction.d.ts +2 -0
  82. package/graphql/scalars/orderby_direction.js +15 -0
  83. package/imports/dataz/example1/_auth.js +128 -47
  84. package/imports/dataz/example1/_viewer.js +87 -39
  85. package/imports/index.d.ts +7 -2
  86. package/imports/index.js +20 -5
  87. package/index.d.ts +23 -5
  88. package/index.js +35 -10
  89. package/package.json +20 -19
  90. package/parse_schema/parse.d.ts +33 -9
  91. package/parse_schema/parse.js +182 -33
  92. package/schema/base_schema.d.ts +13 -3
  93. package/schema/base_schema.js +13 -0
  94. package/schema/field.d.ts +78 -21
  95. package/schema/field.js +232 -72
  96. package/schema/index.d.ts +2 -2
  97. package/schema/index.js +7 -2
  98. package/schema/json_field.d.ts +16 -4
  99. package/schema/json_field.js +32 -2
  100. package/schema/schema.d.ts +109 -20
  101. package/schema/schema.js +42 -53
  102. package/schema/struct_field.d.ts +15 -3
  103. package/schema/struct_field.js +117 -22
  104. package/schema/union_field.d.ts +1 -1
  105. package/scripts/custom_compiler.js +12 -8
  106. package/scripts/custom_graphql.js +167 -64
  107. package/scripts/migrate_v0.1.js +36 -0
  108. package/scripts/move_types.js +120 -0
  109. package/scripts/read_schema.js +22 -7
  110. package/testutils/action/complex_schemas.d.ts +69 -0
  111. package/testutils/action/complex_schemas.js +405 -0
  112. package/testutils/builder.d.ts +37 -41
  113. package/testutils/builder.js +66 -46
  114. package/testutils/db/fixture.d.ts +10 -0
  115. package/testutils/db/fixture.js +26 -0
  116. package/testutils/db/{test_db.d.ts → temp_db.d.ts} +32 -8
  117. package/testutils/db/{test_db.js → temp_db.js} +251 -48
  118. package/testutils/db/value.d.ts +7 -0
  119. package/testutils/db/value.js +251 -0
  120. package/testutils/db_mock.d.ts +16 -4
  121. package/testutils/db_mock.js +52 -9
  122. package/testutils/db_time_zone.d.ts +4 -0
  123. package/testutils/db_time_zone.js +41 -0
  124. package/testutils/ent-graphql-tests/index.d.ts +7 -1
  125. package/testutils/ent-graphql-tests/index.js +56 -26
  126. package/testutils/fake_comms.js +1 -1
  127. package/testutils/fake_data/const.d.ts +2 -1
  128. package/testutils/fake_data/const.js +3 -0
  129. package/testutils/fake_data/fake_contact.d.ts +7 -3
  130. package/testutils/fake_data/fake_contact.js +13 -7
  131. package/testutils/fake_data/fake_event.d.ts +4 -1
  132. package/testutils/fake_data/fake_event.js +7 -6
  133. package/testutils/fake_data/fake_tag.d.ts +36 -0
  134. package/testutils/fake_data/fake_tag.js +89 -0
  135. package/testutils/fake_data/fake_user.d.ts +8 -5
  136. package/testutils/fake_data/fake_user.js +31 -19
  137. package/testutils/fake_data/index.js +5 -1
  138. package/testutils/fake_data/internal.d.ts +2 -0
  139. package/testutils/fake_data/internal.js +7 -1
  140. package/testutils/fake_data/tag_query.d.ts +13 -0
  141. package/testutils/fake_data/tag_query.js +48 -0
  142. package/testutils/fake_data/test_helpers.d.ts +14 -6
  143. package/testutils/fake_data/test_helpers.js +31 -15
  144. package/testutils/fake_data/user_query.d.ts +16 -6
  145. package/testutils/fake_data/user_query.js +72 -23
  146. package/testutils/fake_log.js +1 -1
  147. package/testutils/parse_sql.d.ts +6 -0
  148. package/testutils/parse_sql.js +16 -2
  149. package/testutils/test_edge_global_schema.d.ts +15 -0
  150. package/testutils/test_edge_global_schema.js +62 -0
  151. package/testutils/write.d.ts +2 -2
  152. package/testutils/write.js +33 -7
  153. package/tsc/ast.d.ts +15 -3
  154. package/tsc/ast.js +114 -23
  155. package/tsc/compilerOptions.js +5 -1
  156. package/tsc/move_generated.d.ts +1 -0
  157. package/tsc/move_generated.js +164 -0
  158. package/tsc/transform.d.ts +22 -0
  159. package/tsc/transform.js +182 -0
  160. package/tsc/transform_action.d.ts +22 -0
  161. package/tsc/transform_action.js +183 -0
  162. package/tsc/transform_ent.d.ts +17 -0
  163. package/tsc/transform_ent.js +60 -0
  164. package/tsc/transform_schema.d.ts +27 -0
  165. package/{scripts → tsc}/transform_schema.js +146 -117
  166. package/core/loaders/index_loader.d.ts +0 -14
  167. package/core/loaders/index_loader.js +0 -27
  168. package/graphql/enums.d.ts +0 -3
  169. package/graphql/enums.js +0 -25
  170. package/scripts/move_generated.js +0 -141
  171. package/scripts/transform_actions.js +0 -266
  172. package/scripts/transform_code.d.ts +0 -1
  173. package/scripts/transform_code.js +0 -111
  174. package/scripts/transform_schema.d.ts +0 -1
  175. /package/scripts/{move_generated.d.ts → migrate_v0.1.d.ts} +0 -0
  176. /package/scripts/{transform_actions.d.ts → move_types.d.ts} +0 -0
@@ -1,12 +1,7 @@
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.isCustomType = exports.knownDisAllowedNames = exports.knownAllowedNames = exports.CustomFieldType = void 0;
4
- require("reflect-metadata");
5
- // export interface gqlTopLevelOptions
6
- // name?: string;
7
- // type?: Type | Array<Type>;
8
- // description?: string;
9
- // }
3
+ exports.gqlFileUpload = exports.gqlConnection = exports.gqlContextType = exports.gqlMutation = exports.gqlQuery = exports.gqlUnionType = exports.gqlInterfaceType = exports.gqlObjectType = exports.gqlInputObjectType = exports.gqlArgType = exports.gqlField = exports.GQLCapture = exports.addCustomType = exports.isCustomType = exports.knownInterfaces = exports.knownDisAllowedNames = exports.knownAllowedNames = exports.CustomFieldType = void 0;
4
+ const parse_1 = require("../parse_schema/parse");
10
5
  var CustomFieldType;
11
6
  (function (CustomFieldType) {
12
7
  CustomFieldType["Accessor"] = "ACCESSOR";
@@ -29,6 +24,8 @@ exports.knownAllowedNames = new Map([
29
24
  ["Int", "number"],
30
25
  ["Float", "number"],
31
26
  ["ID", "ID"],
27
+ ["JSON", "any"],
28
+ ["Node", "Ent"],
32
29
  ]);
33
30
  exports.knownDisAllowedNames = new Map([
34
31
  ["Function", true],
@@ -36,6 +33,11 @@ exports.knownDisAllowedNames = new Map([
36
33
  ["Array", true],
37
34
  ["Promise", true],
38
35
  ]);
36
+ exports.knownInterfaces = new Map([
37
+ ["Node", true],
38
+ ["Edge", true],
39
+ ["Connection", true],
40
+ ]);
39
41
  const isArray = (type) => {
40
42
  if (typeof type === "function") {
41
43
  return false;
@@ -61,15 +63,24 @@ exports.isCustomType = isCustomType;
61
63
  const isGraphQLScalarType = (type) => {
62
64
  return type.serialize !== undefined;
63
65
  };
64
- const addCustomType = (type) => {
66
+ const addCustomType = async (type, gqlCapture) => {
65
67
  // TODO these should return ReadOnly objects...
66
- const customType = GQLCapture.getCustomTypes().get(type.type);
67
- if (customType && customType !== type) {
68
- throw new Error(`cannot add multiple custom types of name ${type.type}`);
69
- }
70
- if (customType) {
68
+ const customTypes = gqlCapture.getCustomTypes();
69
+ const customType = customTypes.get(type.type);
70
+ if (customType && customType === type) {
71
71
  return;
72
72
  }
73
+ const addType = async (type) => {
74
+ // @ts-expect-error
75
+ const typ2 = { ...type };
76
+ if (type.structFields) {
77
+ typ2.structFields = await (0, parse_1.processFields)(type.structFields);
78
+ }
79
+ customTypes.set(type.type, typ2);
80
+ };
81
+ if (type.enumMap || type.structFields) {
82
+ await addType(type);
83
+ }
73
84
  try {
74
85
  const r = require(type.importPath);
75
86
  const ct = r[type.type];
@@ -85,9 +96,21 @@ const addCustomType = (type) => {
85
96
  }
86
97
  }
87
98
  catch (e) {
99
+ if (type.secondaryImportPath) {
100
+ (0, exports.addCustomType)({
101
+ ...type,
102
+ importPath: type.secondaryImportPath,
103
+ }, gqlCapture);
104
+ }
88
105
  return;
89
106
  }
90
- GQLCapture.getCustomTypes().set(type.type, type);
107
+ if (customType) {
108
+ if (JSON.stringify(customType) !== JSON.stringify(type)) {
109
+ throw new Error(`cannot add multiple custom types of name ${type.type}`);
110
+ }
111
+ return;
112
+ }
113
+ await addType(type);
91
114
  };
92
115
  exports.addCustomType = addCustomType;
93
116
  const getType = (typ, result) => {
@@ -111,7 +134,8 @@ const getType = (typ, result) => {
111
134
  }
112
135
  if ((0, exports.isCustomType)(typ)) {
113
136
  result.type = typ.type;
114
- (0, exports.addCustomType)(typ);
137
+ // TODO???
138
+ (0, exports.addCustomType)(typ, GQLCapture);
115
139
  return;
116
140
  }
117
141
  // GraphQLScalarType or ClassType
@@ -133,8 +157,9 @@ class GQLCapture {
133
157
  this.customArgs.clear();
134
158
  this.customInputObjects.clear();
135
159
  this.customObjects.clear();
160
+ this.customInterfaces.clear();
161
+ this.customUnions.clear();
136
162
  this.customTypes.clear();
137
- this.argMap.clear();
138
163
  }
139
164
  static getCustomFields() {
140
165
  return this.customFields;
@@ -154,6 +179,12 @@ class GQLCapture {
154
179
  static getCustomObjects() {
155
180
  return this.customObjects;
156
181
  }
182
+ static getCustomInterfaces() {
183
+ return this.customInterfaces;
184
+ }
185
+ static getCustomUnions() {
186
+ return this.customUnions;
187
+ }
157
188
  static getCustomTypes() {
158
189
  return this.customTypes;
159
190
  }
@@ -198,33 +229,34 @@ class GQLCapture {
198
229
  return res;
199
230
  });
200
231
  }
201
- static getResultFromMetadata(metadata, options) {
202
- let type = metadata.name;
203
- if ((type === "Number" || type === "Object") && !options?.type) {
204
- throw new Error(`type is required when accessor/function/property returns a ${type}`);
205
- }
232
+ static getField(field) {
206
233
  let list;
207
234
  let scalarType = false;
208
235
  let connection;
209
- if (options?.type) {
236
+ let type = "";
237
+ if (field?.type) {
210
238
  let r = { type: "" };
211
- getType(options.type, r);
239
+ getType(field.type, r);
212
240
  list = r.list;
213
241
  scalarType = r.scalarType || false;
214
242
  connection = r.connection;
215
243
  type = r.type;
216
244
  }
245
+ if (!type) {
246
+ throw new Error(`type is required for accessor/function/property`);
247
+ }
217
248
  if (exports.knownDisAllowedNames.has(type)) {
218
249
  throw new Error(`${type} isn't a valid type for accessor/function/property`);
219
250
  }
220
251
  let result = {
221
- name: metadata.paramName || "",
222
- type,
252
+ name: field?.name || "",
253
+ type: type,
223
254
  tsType: exports.knownAllowedNames.get(type) || this.customTypes.get(type)?.tsType,
224
- nullable: options?.nullable,
255
+ nullable: field?.nullable,
225
256
  list: list,
226
257
  connection: connection,
227
- isContextArg: metadata.isContextArg,
258
+ // @ts-ignore
259
+ isContextArg: field?.isContextArg,
228
260
  };
229
261
  // unknown type. we need to flag that this field needs to eventually be resolved
230
262
  if (!exports.knownAllowedNames.has(type)) {
@@ -236,11 +268,16 @@ class GQLCapture {
236
268
  return result;
237
269
  }
238
270
  static gqlField(options) {
239
- return function (target, propertyKey, descriptor) {
240
- if (!GQLCapture.isEnabled()) {
271
+ return function (_target, ctx) {
272
+ if (!GQLCapture.isEnabled() ||
273
+ (ctx.kind !== "method" &&
274
+ ctx.kind !== "field" &&
275
+ ctx.kind !== "getter") ||
276
+ ctx.static ||
277
+ ctx.private) {
241
278
  return;
242
279
  }
243
- let customField = GQLCapture.getCustomField(target, propertyKey, descriptor, options);
280
+ let customField = GQLCapture.getCustomField(ctx, options);
244
281
  if (!customField) {
245
282
  return;
246
283
  }
@@ -271,152 +308,109 @@ class GQLCapture {
271
308
  GQLCapture.customFields.set(customField.nodeName, list);
272
309
  };
273
310
  }
274
- static getCustomField(target, propertyKey, descriptor, options) {
311
+ static getCustomField(ctx, options, allowNoReturnType) {
275
312
  let fieldType;
276
- let nodeName = target.constructor.name;
277
313
  let args = [];
278
314
  let results = [];
279
- let typeMetadata = Reflect.getMetadata("design:type", target, propertyKey);
280
- let returnTypeMetadata = Reflect.getMetadata("design:returntype", target, propertyKey);
281
- if (returnTypeMetadata) {
282
- // function...
283
- if (returnTypeMetadata.name === "Promise") {
284
- fieldType = CustomFieldType.AsyncFunction;
285
- }
286
- else {
315
+ switch (ctx.kind) {
316
+ case "method":
287
317
  fieldType = CustomFieldType.Function;
288
- }
289
- results.push(GQLCapture.getResultFromMetadata(returnTypeMetadata, options));
290
- }
291
- else if (typeMetadata) {
292
- if (descriptor && descriptor.get) {
293
- fieldType = CustomFieldType.Accessor;
294
- }
295
- else if (descriptor && descriptor.value) {
296
- // could be implicit async
297
- fieldType = CustomFieldType.Function;
298
- }
299
- else {
318
+ if (options.async) {
319
+ fieldType = CustomFieldType.AsyncFunction;
320
+ }
321
+ break;
322
+ case "field":
300
323
  fieldType = CustomFieldType.Field;
301
- }
302
- if (!(options?.allowFunctionType &&
303
- fieldType === CustomFieldType.Function &&
304
- typeMetadata.name === "Function")) {
305
- results.push(GQLCapture.getResultFromMetadata(typeMetadata, options));
306
- }
324
+ break;
325
+ case "getter":
326
+ fieldType = CustomFieldType.Accessor;
327
+ break;
307
328
  }
308
- let params = Reflect.getMetadata("design:paramtypes", target, propertyKey);
309
- if (params && params.length > 0) {
310
- let parsedArgs = GQLCapture.argMap.get(nodeName)?.get(propertyKey) || [];
311
- if (params.length !== parsedArgs.length) {
312
- throw new Error(`args were not captured correctly, ${params.length}, ${parsedArgs.length}`);
313
- }
314
- parsedArgs.forEach((arg) => {
315
- let param = params[arg.index];
316
- let paramName = arg.name;
317
- let field = GQLCapture.getResultFromMetadata({
318
- name: param.name,
319
- paramName,
320
- isContextArg: arg.isContextArg,
321
- }, arg.options);
322
- // TODO this may not be the right order...
323
- args.push(field);
329
+ if (!allowNoReturnType && !options.type) {
330
+ throw new Error(`type is required for ${fieldType}`);
331
+ }
332
+ if (options.type) {
333
+ // override name property passed down so we return '' as name
334
+ results.push(GQLCapture.getField({ ...options, name: "" }));
335
+ }
336
+ if (options.args?.length) {
337
+ options.args.forEach((arg) => {
338
+ args.push(GQLCapture.getField(arg));
324
339
  });
325
- // TODO this is deterministically (so far) coming in reverse order so reverse (for now)
326
- args = args.reverse();
327
340
  }
328
341
  return {
329
- nodeName: nodeName,
330
- gqlName: options?.name || propertyKey,
331
- functionName: propertyKey,
342
+ nodeName: options.class,
343
+ gqlName: options?.name || ctx.name.toString(),
344
+ functionName: ctx.name.toString(),
332
345
  args: args,
333
346
  results: results,
334
347
  fieldType: fieldType,
335
348
  description: options?.description,
336
349
  };
337
350
  }
338
- static argImpl(name, isContextArg, options) {
339
- return function (target, propertyKey, index) {
340
- if (!GQLCapture.isEnabled()) {
341
- return;
342
- }
343
- let nodeName = target.constructor.name;
344
- let m = GQLCapture.argMap.get(nodeName);
345
- if (!m) {
346
- m = new Map();
347
- GQLCapture.argMap.set(nodeName, m);
348
- }
349
- let propertyMap = m.get(propertyKey);
350
- if (!propertyMap) {
351
- propertyMap = [];
352
- m.set(propertyKey, propertyMap);
353
- }
354
- propertyMap.push({
355
- name: name,
356
- index: index,
357
- options: options,
358
- isContextArg,
359
- });
360
- // console.log("arg", name, target, propertyKey, index);
361
- };
362
- }
363
- // TODO custom args because for example name doesn't make sense here.
364
- static gqlArg(name, options) {
365
- return GQLCapture.argImpl(name, undefined, options);
366
- }
367
351
  static gqlContextType() {
368
- // hardcoded?
369
- return GQLCapture.argImpl("context", true, { type: "Context" });
352
+ return {
353
+ name: "context",
354
+ isContextArg: true,
355
+ type: "Context",
356
+ };
370
357
  }
371
358
  static gqlArgType(options) {
372
- return function (target, _propertyKey, _descriptor) {
373
- return GQLCapture.customGQLObject(target, GQLCapture.customArgs, options);
359
+ return function (target, ctx) {
360
+ return GQLCapture.customGQLObject(ctx, GQLCapture.customArgs, options);
374
361
  };
375
362
  }
376
363
  static gqlInputObjectType(options) {
377
- return function (target, _propertyKey, _descriptor) {
378
- return GQLCapture.customGQLObject(target, GQLCapture.customInputObjects, options);
364
+ return function (target, ctx) {
365
+ return GQLCapture.customGQLObject(ctx, GQLCapture.customInputObjects, options);
379
366
  };
380
367
  }
381
368
  static gqlObjectType(options) {
382
- return function (target, _propertyKey, _descriptor) {
383
- return GQLCapture.customGQLObject(target, GQLCapture.customObjects, options);
369
+ return function (target, ctx) {
370
+ return GQLCapture.customGQLObject(ctx, GQLCapture.customObjects, options);
371
+ };
372
+ }
373
+ static gqlUnionType(options) {
374
+ return function (target, ctx) {
375
+ return GQLCapture.customGQLObject(ctx, GQLCapture.customUnions, options);
376
+ };
377
+ }
378
+ static gqlInterfaceType(options) {
379
+ return function (target, ctx) {
380
+ return GQLCapture.customGQLObject(ctx, GQLCapture.customInterfaces, options);
384
381
  };
385
382
  }
386
- static customGQLObject(target, map, options) {
387
- if (!GQLCapture.isEnabled()) {
383
+ static customGQLObject(ctx, map, options) {
384
+ if (!GQLCapture.isEnabled() || ctx.kind !== "class" || !ctx.name) {
388
385
  return;
389
386
  }
390
- let className = target.name;
387
+ let className = ctx.name.toString();
391
388
  let nodeName = options?.name || className;
392
389
  map.set(className, {
393
390
  className,
394
391
  nodeName,
395
392
  description: options?.description,
393
+ // @ts-ignore
394
+ interfaces: options?.interfaces,
395
+ // @ts-ignore
396
+ unionTypes: options?.unionTypes,
396
397
  });
397
398
  }
398
- // TODO query and mutation
399
399
  // we want to specify args if any, name, response if any
400
400
  static gqlQuery(options) {
401
- return function (target, propertyKey, descriptor) {
401
+ return function (target, ctx) {
402
402
  if (!GQLCapture.isEnabled()) {
403
403
  return;
404
404
  }
405
- GQLCapture.customQueries.push(GQLCapture.getCustomField(target, propertyKey, descriptor, options));
405
+ GQLCapture.customQueries.push(GQLCapture.getCustomField(ctx, options));
406
406
  };
407
407
  }
408
- // we want to specify inputs (required), name, response
409
- // input is via gqlArg
410
- // should it be gqlInputArg?
411
408
  static gqlMutation(options) {
412
- return function (target, propertyKey, descriptor) {
409
+ return function (target, ctx) {
413
410
  if (!GQLCapture.isEnabled()) {
414
411
  return;
415
412
  }
416
- GQLCapture.customMutations.push(GQLCapture.getCustomField(target, propertyKey, descriptor, {
417
- ...options,
418
- allowFunctionType: true,
419
- }));
413
+ GQLCapture.customMutations.push(GQLCapture.getCustomField(ctx, options, true));
420
414
  };
421
415
  }
422
416
  static gqlConnection(type) {
@@ -426,13 +420,62 @@ class GQLCapture {
426
420
  }
427
421
  static resolve(objects) {
428
422
  let baseObjects = new Map();
429
- objects.map((object) => baseObjects.set(object, true));
430
- this.customObjects.forEach((_val, key) => baseObjects.set(key, true));
423
+ objects.forEach((object) => baseObjects.set(object, true));
424
+ this.customObjects.forEach((obj, key) => {
425
+ baseObjects.set(key, true);
426
+ obj.interfaces?.forEach((interfaceName) => {
427
+ const inter = this.customInterfaces.get(interfaceName);
428
+ if (inter) {
429
+ const fields = this.customFields.get(inter.nodeName);
430
+ if (fields) {
431
+ // check for duplicate fields
432
+ // if field is already defined no need to add it
433
+ let objFields = this.customFields.get(obj.nodeName);
434
+ if (!objFields) {
435
+ objFields = [];
436
+ }
437
+ let map = new Map();
438
+ for (const f of objFields) {
439
+ map.set(f.gqlName, f);
440
+ }
441
+ for (const field of fields) {
442
+ const newField = {
443
+ ...field,
444
+ nodeName: obj.nodeName,
445
+ };
446
+ if (map.has(field.gqlName)) {
447
+ const existing = map.get(field.gqlName);
448
+ if (JSON.stringify(existing) !== JSON.stringify(newField)) {
449
+ throw new Error(`object ${obj.nodeName} has duplicate field ${field.gqlName} with different definition`);
450
+ }
451
+ continue;
452
+ }
453
+ objFields.push(newField);
454
+ }
455
+ this.customFields.set(obj.nodeName, objFields);
456
+ }
457
+ }
458
+ else if (!exports.knownInterfaces.has(interfaceName)) {
459
+ throw new Error(`object ${key} references unknown interface ${interfaceName}`);
460
+ }
461
+ });
462
+ });
431
463
  let baseArgs = new Map();
432
464
  this.customArgs.forEach((_val, key) => baseArgs.set(key, true));
433
465
  this.customInputObjects.forEach((_val, key) => baseArgs.set(key, true));
434
466
  baseArgs.set("Context", true);
435
467
  this.customTypes.forEach((_val, key) => baseArgs.set(key, true));
468
+ this.customUnions.forEach((val, key) => {
469
+ if (this.customFields.has(key)) {
470
+ throw new Error(`union ${key} has custom fields which is not allowed`);
471
+ }
472
+ val.unionTypes?.forEach((typ) => {
473
+ if (!baseObjects.has(typ)) {
474
+ throw new Error(`union ${key} references ${typ} which isn't a graphql object`);
475
+ }
476
+ });
477
+ });
478
+ // TODO this should be aware of knownCustomTypes
436
479
  const resolveFields = (fields) => {
437
480
  fields.forEach((field) => {
438
481
  // we have a check earlier that *should* make this path impossible
@@ -453,7 +496,9 @@ class GQLCapture {
453
496
  // but i don't think it applies
454
497
  field.results.forEach((result) => {
455
498
  if (result.needsResolving) {
456
- if (baseObjects.has(result.type)) {
499
+ if (baseObjects.has(result.type) ||
500
+ this.customUnions.has(result.type) ||
501
+ this.customInterfaces.has(result.type)) {
457
502
  result.needsResolving = false;
458
503
  }
459
504
  else {
@@ -468,7 +513,6 @@ class GQLCapture {
468
513
  resolveFields(GQLCapture.customMutations);
469
514
  }
470
515
  }
471
- exports.GQLCapture = GQLCapture;
472
516
  GQLCapture.enabled = false;
473
517
  // map from class name to fields
474
518
  GQLCapture.customFields = new Map();
@@ -477,16 +521,18 @@ GQLCapture.customMutations = [];
477
521
  GQLCapture.customArgs = new Map();
478
522
  GQLCapture.customInputObjects = new Map();
479
523
  GQLCapture.customObjects = new Map();
524
+ GQLCapture.customInterfaces = new Map();
525
+ GQLCapture.customUnions = new Map();
480
526
  GQLCapture.customTypes = new Map();
481
- // User -> add -> [{name, options}, {}, {}]
482
- GQLCapture.argMap = new Map();
527
+ exports.GQLCapture = GQLCapture;
483
528
  // why is this a static class lol?
484
529
  // TODO make all these just plain functions
485
530
  exports.gqlField = GQLCapture.gqlField;
486
- exports.gqlArg = GQLCapture.gqlArg;
487
531
  exports.gqlArgType = GQLCapture.gqlArgType;
488
532
  exports.gqlInputObjectType = GQLCapture.gqlInputObjectType;
489
533
  exports.gqlObjectType = GQLCapture.gqlObjectType;
534
+ exports.gqlInterfaceType = GQLCapture.gqlInterfaceType;
535
+ exports.gqlUnionType = GQLCapture.gqlUnionType;
490
536
  exports.gqlQuery = GQLCapture.gqlQuery;
491
537
  exports.gqlMutation = GQLCapture.gqlMutation;
492
538
  exports.gqlContextType = GQLCapture.gqlContextType;
@@ -1,4 +1,4 @@
1
- import { CustomField, Field, CustomObject, CustomMutation, CustomQuery, CustomType } from "./graphql";
1
+ import { CustomField, Field, CustomObject, CustomMutation, CustomQuery, CustomTypeInput } from "./graphql";
2
2
  export declare function validateOneCustomField(expected: CustomField): void;
3
3
  export declare function validateCustomFields(expected: CustomField[]): void;
4
4
  export declare function validateCustomMutations(expected: CustomMutation[]): void;
@@ -8,12 +8,16 @@ export declare function validateNoCustomFields(): void;
8
8
  export declare function validateCustomArgs(expected: CustomObject[]): void;
9
9
  export declare function validateCustomInputObjects(expected: CustomObject[]): void;
10
10
  export declare function validateCustomObjects(expected: CustomObject[]): void;
11
+ export declare function validateCustomInterfaces(expected: CustomObject[]): void;
12
+ export declare function validateCustomUnions(expected: CustomObject[]): void;
11
13
  export declare function validateNoCustomArgs(): void;
12
14
  export declare function validateNoCustomQueries(): void;
13
15
  export declare function validateNoCustomMutations(): void;
14
16
  export declare function validateNoCustomInputObjects(): void;
15
17
  export declare function validateNoCustomObjects(): void;
16
18
  export declare function validateNoCustomTypes(): void;
19
+ export declare function validateNoCustomInterfaces(): void;
20
+ export declare function validateNoCustomUnions(): void;
17
21
  export declare enum CustomObjectTypes {
18
22
  Field = 1,
19
23
  Arg = 2,
@@ -21,7 +25,9 @@ export declare enum CustomObjectTypes {
21
25
  InputObject = 8,
22
26
  Query = 16,
23
27
  Mutation = 32,
24
- CustomTypes = 64
28
+ CustomTypes = 64,
29
+ Interface = 128,
30
+ Union = 256
25
31
  }
26
32
  export declare function validateNoCustom(...exceptions: number[]): void;
27
- export declare function validateCustomTypes(expected: CustomType[]): void;
33
+ export declare function validateCustomTypes(expected: CustomTypeInput[]): void;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateCustomTypes = exports.validateNoCustom = exports.CustomObjectTypes = exports.validateNoCustomTypes = exports.validateNoCustomObjects = exports.validateNoCustomInputObjects = exports.validateNoCustomMutations = exports.validateNoCustomQueries = exports.validateNoCustomArgs = exports.validateCustomObjects = exports.validateCustomInputObjects = exports.validateCustomArgs = exports.validateNoCustomFields = exports.validateFields = exports.validateCustomQueries = exports.validateCustomMutations = exports.validateCustomFields = exports.validateOneCustomField = void 0;
3
+ exports.validateCustomTypes = exports.validateNoCustom = exports.CustomObjectTypes = exports.validateNoCustomUnions = exports.validateNoCustomInterfaces = exports.validateNoCustomTypes = exports.validateNoCustomObjects = exports.validateNoCustomInputObjects = exports.validateNoCustomMutations = exports.validateNoCustomQueries = exports.validateNoCustomArgs = exports.validateCustomUnions = exports.validateCustomInterfaces = exports.validateCustomObjects = exports.validateCustomInputObjects = exports.validateCustomArgs = exports.validateNoCustomFields = exports.validateFields = exports.validateCustomQueries = exports.validateCustomMutations = exports.validateCustomFields = exports.validateOneCustomField = void 0;
4
4
  const graphql_1 = require("./graphql");
5
5
  function validateOneCustomField(expected) {
6
6
  let customFields = graphql_1.GQLCapture.getCustomFields();
@@ -101,6 +101,14 @@ function validateCustomObjects(expected) {
101
101
  validateCustom(expected, graphql_1.GQLCapture.getCustomObjects());
102
102
  }
103
103
  exports.validateCustomObjects = validateCustomObjects;
104
+ function validateCustomInterfaces(expected) {
105
+ validateCustom(expected, graphql_1.GQLCapture.getCustomInterfaces());
106
+ }
107
+ exports.validateCustomInterfaces = validateCustomInterfaces;
108
+ function validateCustomUnions(expected) {
109
+ validateCustom(expected, graphql_1.GQLCapture.getCustomUnions());
110
+ }
111
+ exports.validateCustomUnions = validateCustomUnions;
104
112
  function validateNoCustomArgs() {
105
113
  expect(graphql_1.GQLCapture.getCustomArgs().size).toBe(0);
106
114
  }
@@ -125,6 +133,14 @@ function validateNoCustomTypes() {
125
133
  expect(graphql_1.GQLCapture.getCustomTypes().size).toBe(0);
126
134
  }
127
135
  exports.validateNoCustomTypes = validateNoCustomTypes;
136
+ function validateNoCustomInterfaces() {
137
+ expect(graphql_1.GQLCapture.getCustomInterfaces().size).toBe(0);
138
+ }
139
+ exports.validateNoCustomInterfaces = validateNoCustomInterfaces;
140
+ function validateNoCustomUnions() {
141
+ expect(graphql_1.GQLCapture.getCustomUnions().size).toBe(0);
142
+ }
143
+ exports.validateNoCustomUnions = validateNoCustomUnions;
128
144
  var CustomObjectTypes;
129
145
  (function (CustomObjectTypes) {
130
146
  CustomObjectTypes[CustomObjectTypes["Field"] = 1] = "Field";
@@ -134,8 +150,10 @@ var CustomObjectTypes;
134
150
  CustomObjectTypes[CustomObjectTypes["Query"] = 16] = "Query";
135
151
  CustomObjectTypes[CustomObjectTypes["Mutation"] = 32] = "Mutation";
136
152
  CustomObjectTypes[CustomObjectTypes["CustomTypes"] = 64] = "CustomTypes";
153
+ CustomObjectTypes[CustomObjectTypes["Interface"] = 128] = "Interface";
154
+ CustomObjectTypes[CustomObjectTypes["Union"] = 256] = "Union";
137
155
  })(CustomObjectTypes = exports.CustomObjectTypes || (exports.CustomObjectTypes = {}));
138
- // TODO what's a good name for this instead
156
+ // what's a good name for this instead?
139
157
  function validateNoCustom(...exceptions) {
140
158
  let bit = 0;
141
159
  exceptions.forEach((exp) => (bit = bit | exp));
@@ -151,6 +169,8 @@ function validateNoCustom(...exceptions) {
151
169
  validate(CustomObjectTypes.Mutation, validateNoCustomMutations);
152
170
  validate(CustomObjectTypes.InputObject, validateNoCustomInputObjects);
153
171
  validate(CustomObjectTypes.CustomTypes, validateNoCustomTypes);
172
+ validate(CustomObjectTypes.Interface, validateNoCustomInterfaces);
173
+ validate(CustomObjectTypes.Union, validateNoCustomUnions);
154
174
  }
155
175
  exports.validateNoCustom = validateNoCustom;
156
176
  function validateCustomTypes(expected) {
@@ -1,5 +1,6 @@
1
- export { gqlFieldOptions, gqlObjectOptions, gqlField, gqlArg, gqlArgType, gqlInputObjectType, gqlObjectType, gqlQuery, gqlMutation, gqlContextType, gqlConnection, GraphQLConnection, GQLCapture, gqlFileUpload, CustomType, } from "./graphql";
1
+ export { gqlFieldOptions, gqlObjectOptions, gqlField, gqlArgType, gqlInputObjectType, gqlObjectType, gqlQuery, gqlMutation, gqlContextType, gqlConnection, GraphQLConnection, GQLCapture, gqlFileUpload, CustomType, gqlInterfaceType, gqlUnionType, } from "./graphql";
2
2
  export { GraphQLTime } from "./scalars/time";
3
+ export { GraphQLOrderByDirection } from "./scalars/orderby_direction";
3
4
  export { GraphQLPageInfo } from "./query/page_info";
4
5
  export { GraphQLEdge, GraphQLEdgeConnection } from "./query/edge_connection";
5
6
  export { GraphQLEdgeType, GraphQLConnectionType, } from "./query/connection_type";
@@ -7,5 +8,4 @@ export { GraphQLNodeInterface } from "./builtins/node";
7
8
  export { GraphQLConnectionInterface } from "./builtins/connection";
8
9
  export { GraphQLEdgeInterface } from "./builtins/edge";
9
10
  export { NodeResolver, EntNodeResolver, registerResolver, clearResolvers, resolveID, nodeIDEncoder, mustDecodeIDFromGQLID, mustDecodeNullableIDFromGQLID, encodeGQLID, } from "./node_resolver";
10
- export { convertFromGQLEnum, convertToGQLEnum } from "./enums";
11
11
  export { transformUnionTypes } from "./mutations/union";
package/graphql/index.js CHANGED
@@ -1,9 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.transformUnionTypes = exports.convertToGQLEnum = exports.convertFromGQLEnum = exports.encodeGQLID = exports.mustDecodeNullableIDFromGQLID = exports.mustDecodeIDFromGQLID = exports.nodeIDEncoder = exports.resolveID = exports.clearResolvers = exports.registerResolver = exports.EntNodeResolver = exports.GraphQLEdgeInterface = exports.GraphQLConnectionInterface = exports.GraphQLNodeInterface = exports.GraphQLConnectionType = exports.GraphQLEdgeType = exports.GraphQLEdgeConnection = exports.GraphQLPageInfo = exports.GraphQLTime = exports.gqlFileUpload = exports.GQLCapture = exports.gqlConnection = exports.gqlContextType = exports.gqlMutation = exports.gqlQuery = exports.gqlObjectType = exports.gqlInputObjectType = exports.gqlArgType = exports.gqlArg = exports.gqlField = void 0;
3
+ exports.transformUnionTypes = exports.encodeGQLID = exports.mustDecodeNullableIDFromGQLID = exports.mustDecodeIDFromGQLID = exports.nodeIDEncoder = exports.resolveID = exports.clearResolvers = exports.registerResolver = exports.EntNodeResolver = exports.GraphQLEdgeInterface = exports.GraphQLConnectionInterface = exports.GraphQLNodeInterface = exports.GraphQLConnectionType = exports.GraphQLEdgeType = exports.GraphQLEdgeConnection = exports.GraphQLPageInfo = exports.GraphQLOrderByDirection = exports.GraphQLTime = exports.gqlUnionType = exports.gqlInterfaceType = exports.gqlFileUpload = exports.GQLCapture = exports.gqlConnection = exports.gqlContextType = exports.gqlMutation = exports.gqlQuery = exports.gqlObjectType = exports.gqlInputObjectType = exports.gqlArgType = exports.gqlField = void 0;
4
4
  var graphql_1 = require("./graphql");
5
5
  Object.defineProperty(exports, "gqlField", { enumerable: true, get: function () { return graphql_1.gqlField; } });
6
- Object.defineProperty(exports, "gqlArg", { enumerable: true, get: function () { return graphql_1.gqlArg; } });
7
6
  Object.defineProperty(exports, "gqlArgType", { enumerable: true, get: function () { return graphql_1.gqlArgType; } });
8
7
  Object.defineProperty(exports, "gqlInputObjectType", { enumerable: true, get: function () { return graphql_1.gqlInputObjectType; } });
9
8
  Object.defineProperty(exports, "gqlObjectType", { enumerable: true, get: function () { return graphql_1.gqlObjectType; } });
@@ -13,8 +12,12 @@ Object.defineProperty(exports, "gqlContextType", { enumerable: true, get: functi
13
12
  Object.defineProperty(exports, "gqlConnection", { enumerable: true, get: function () { return graphql_1.gqlConnection; } });
14
13
  Object.defineProperty(exports, "GQLCapture", { enumerable: true, get: function () { return graphql_1.GQLCapture; } });
15
14
  Object.defineProperty(exports, "gqlFileUpload", { enumerable: true, get: function () { return graphql_1.gqlFileUpload; } });
15
+ Object.defineProperty(exports, "gqlInterfaceType", { enumerable: true, get: function () { return graphql_1.gqlInterfaceType; } });
16
+ Object.defineProperty(exports, "gqlUnionType", { enumerable: true, get: function () { return graphql_1.gqlUnionType; } });
16
17
  var time_1 = require("./scalars/time");
17
18
  Object.defineProperty(exports, "GraphQLTime", { enumerable: true, get: function () { return time_1.GraphQLTime; } });
19
+ var orderby_direction_1 = require("./scalars/orderby_direction");
20
+ Object.defineProperty(exports, "GraphQLOrderByDirection", { enumerable: true, get: function () { return orderby_direction_1.GraphQLOrderByDirection; } });
18
21
  var page_info_1 = require("./query/page_info");
19
22
  Object.defineProperty(exports, "GraphQLPageInfo", { enumerable: true, get: function () { return page_info_1.GraphQLPageInfo; } });
20
23
  var edge_connection_1 = require("./query/edge_connection");
@@ -37,8 +40,5 @@ Object.defineProperty(exports, "nodeIDEncoder", { enumerable: true, get: functio
37
40
  Object.defineProperty(exports, "mustDecodeIDFromGQLID", { enumerable: true, get: function () { return node_resolver_1.mustDecodeIDFromGQLID; } });
38
41
  Object.defineProperty(exports, "mustDecodeNullableIDFromGQLID", { enumerable: true, get: function () { return node_resolver_1.mustDecodeNullableIDFromGQLID; } });
39
42
  Object.defineProperty(exports, "encodeGQLID", { enumerable: true, get: function () { return node_resolver_1.encodeGQLID; } });
40
- var enums_1 = require("./enums");
41
- Object.defineProperty(exports, "convertFromGQLEnum", { enumerable: true, get: function () { return enums_1.convertFromGQLEnum; } });
42
- Object.defineProperty(exports, "convertToGQLEnum", { enumerable: true, get: function () { return enums_1.convertToGQLEnum; } });
43
43
  var union_1 = require("./mutations/union");
44
44
  Object.defineProperty(exports, "transformUnionTypes", { enumerable: true, get: function () { return union_1.transformUnionTypes; } });