@snowtop/ent 0.1.0-alpha99 → 0.1.0

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 (115) hide show
  1. package/action/action.d.ts +8 -1
  2. package/action/executor.d.ts +16 -3
  3. package/action/executor.js +83 -27
  4. package/action/index.d.ts +2 -1
  5. package/action/operations.d.ts +126 -0
  6. package/action/operations.js +686 -0
  7. package/action/orchestrator.d.ts +22 -8
  8. package/action/orchestrator.js +278 -67
  9. package/core/base.d.ts +34 -24
  10. package/core/clause.d.ts +62 -79
  11. package/core/clause.js +77 -5
  12. package/core/config.d.ts +5 -1
  13. package/core/config.js +3 -0
  14. package/core/const.d.ts +3 -0
  15. package/core/const.js +6 -0
  16. package/core/context.d.ts +4 -3
  17. package/core/context.js +2 -1
  18. package/core/db.d.ts +1 -0
  19. package/core/db.js +7 -7
  20. package/core/ent.d.ts +53 -105
  21. package/core/ent.js +104 -599
  22. package/core/global_schema.d.ts +7 -0
  23. package/core/global_schema.js +51 -0
  24. package/core/loaders/assoc_count_loader.d.ts +4 -2
  25. package/core/loaders/assoc_count_loader.js +10 -2
  26. package/core/loaders/assoc_edge_loader.d.ts +2 -3
  27. package/core/loaders/assoc_edge_loader.js +16 -7
  28. package/core/loaders/index.d.ts +0 -1
  29. package/core/loaders/index.js +1 -3
  30. package/core/loaders/loader.d.ts +3 -3
  31. package/core/loaders/loader.js +3 -20
  32. package/core/loaders/object_loader.d.ts +30 -10
  33. package/core/loaders/object_loader.js +179 -40
  34. package/core/loaders/query_loader.d.ts +4 -4
  35. package/core/loaders/query_loader.js +14 -19
  36. package/core/loaders/raw_count_loader.d.ts +1 -0
  37. package/core/loaders/raw_count_loader.js +3 -2
  38. package/core/privacy.d.ts +19 -10
  39. package/core/privacy.js +47 -26
  40. package/core/query/assoc_query.js +1 -1
  41. package/core/query/custom_clause_query.d.ts +6 -3
  42. package/core/query/custom_clause_query.js +36 -9
  43. package/core/query/custom_query.d.ts +3 -1
  44. package/core/query/custom_query.js +29 -6
  45. package/core/query/query.d.ts +12 -2
  46. package/core/query/query.js +67 -38
  47. package/core/query/shared_assoc_test.js +151 -10
  48. package/core/query/shared_test.d.ts +2 -2
  49. package/core/query/shared_test.js +90 -30
  50. package/core/query_impl.d.ts +8 -0
  51. package/core/query_impl.js +28 -0
  52. package/core/viewer.d.ts +2 -0
  53. package/core/viewer.js +2 -0
  54. package/graphql/graphql.d.ts +103 -19
  55. package/graphql/graphql.js +169 -134
  56. package/graphql/graphql_field_helpers.d.ts +9 -3
  57. package/graphql/graphql_field_helpers.js +22 -2
  58. package/graphql/index.d.ts +2 -1
  59. package/graphql/index.js +5 -2
  60. package/graphql/scalars/orderby_direction.d.ts +2 -0
  61. package/graphql/scalars/orderby_direction.js +15 -0
  62. package/imports/dataz/example1/_auth.js +128 -47
  63. package/imports/dataz/example1/_viewer.js +87 -39
  64. package/imports/index.d.ts +1 -1
  65. package/imports/index.js +2 -2
  66. package/index.d.ts +12 -1
  67. package/index.js +18 -6
  68. package/package.json +20 -17
  69. package/parse_schema/parse.d.ts +10 -4
  70. package/parse_schema/parse.js +70 -24
  71. package/schema/base_schema.d.ts +8 -0
  72. package/schema/base_schema.js +11 -0
  73. package/schema/field.d.ts +6 -3
  74. package/schema/field.js +72 -17
  75. package/schema/index.d.ts +1 -1
  76. package/schema/index.js +2 -1
  77. package/schema/json_field.d.ts +3 -3
  78. package/schema/json_field.js +4 -1
  79. package/schema/schema.d.ts +42 -5
  80. package/schema/schema.js +35 -41
  81. package/schema/struct_field.d.ts +8 -6
  82. package/schema/struct_field.js +67 -8
  83. package/schema/union_field.d.ts +1 -1
  84. package/scripts/custom_compiler.js +4 -4
  85. package/scripts/custom_graphql.js +105 -75
  86. package/scripts/move_types.js +4 -1
  87. package/scripts/read_schema.js +2 -2
  88. package/testutils/action/complex_schemas.d.ts +1 -1
  89. package/testutils/action/complex_schemas.js +10 -3
  90. package/testutils/builder.d.ts +3 -0
  91. package/testutils/builder.js +6 -0
  92. package/testutils/db/temp_db.d.ts +9 -1
  93. package/testutils/db/temp_db.js +82 -14
  94. package/testutils/db_mock.js +1 -3
  95. package/testutils/ent-graphql-tests/index.d.ts +1 -1
  96. package/testutils/ent-graphql-tests/index.js +30 -19
  97. package/testutils/fake_comms.js +1 -1
  98. package/testutils/fake_data/fake_contact.d.ts +1 -1
  99. package/testutils/fake_data/fake_tag.d.ts +1 -1
  100. package/testutils/fake_data/fake_user.d.ts +3 -3
  101. package/testutils/fake_data/fake_user.js +15 -4
  102. package/testutils/fake_data/tag_query.js +8 -3
  103. package/testutils/fake_data/test_helpers.d.ts +3 -2
  104. package/testutils/fake_data/test_helpers.js +4 -4
  105. package/testutils/fake_data/user_query.d.ts +5 -2
  106. package/testutils/fake_data/user_query.js +19 -2
  107. package/testutils/fake_log.js +1 -1
  108. package/tsc/ast.js +2 -1
  109. package/tsc/move_generated.js +2 -2
  110. package/tsc/transform.d.ts +2 -2
  111. package/tsc/transform.js +4 -3
  112. package/tsc/transform_ent.js +2 -1
  113. package/tsc/transform_schema.js +4 -3
  114. package/core/loaders/index_loader.d.ts +0 -14
  115. package/core/loaders/index_loader.js +0 -27
@@ -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,13 +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 customTypes = GQLCapture.getCustomTypes();
68
+ const customTypes = gqlCapture.getCustomTypes();
67
69
  const customType = customTypes.get(type.type);
68
70
  if (customType && customType === type) {
69
71
  return;
70
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
+ }
71
84
  try {
72
85
  const r = require(type.importPath);
73
86
  const ct = r[type.type];
@@ -87,7 +100,7 @@ const addCustomType = (type) => {
87
100
  (0, exports.addCustomType)({
88
101
  ...type,
89
102
  importPath: type.secondaryImportPath,
90
- });
103
+ }, gqlCapture);
91
104
  }
92
105
  return;
93
106
  }
@@ -97,7 +110,7 @@ const addCustomType = (type) => {
97
110
  }
98
111
  return;
99
112
  }
100
- customTypes.set(type.type, type);
113
+ await addType(type);
101
114
  };
102
115
  exports.addCustomType = addCustomType;
103
116
  const getType = (typ, result) => {
@@ -121,7 +134,8 @@ const getType = (typ, result) => {
121
134
  }
122
135
  if ((0, exports.isCustomType)(typ)) {
123
136
  result.type = typ.type;
124
- (0, exports.addCustomType)(typ);
137
+ // TODO???
138
+ (0, exports.addCustomType)(typ, GQLCapture);
125
139
  return;
126
140
  }
127
141
  // GraphQLScalarType or ClassType
@@ -143,8 +157,9 @@ class GQLCapture {
143
157
  this.customArgs.clear();
144
158
  this.customInputObjects.clear();
145
159
  this.customObjects.clear();
160
+ this.customInterfaces.clear();
161
+ this.customUnions.clear();
146
162
  this.customTypes.clear();
147
- this.argMap.clear();
148
163
  }
149
164
  static getCustomFields() {
150
165
  return this.customFields;
@@ -164,6 +179,12 @@ class GQLCapture {
164
179
  static getCustomObjects() {
165
180
  return this.customObjects;
166
181
  }
182
+ static getCustomInterfaces() {
183
+ return this.customInterfaces;
184
+ }
185
+ static getCustomUnions() {
186
+ return this.customUnions;
187
+ }
167
188
  static getCustomTypes() {
168
189
  return this.customTypes;
169
190
  }
@@ -208,33 +229,34 @@ class GQLCapture {
208
229
  return res;
209
230
  });
210
231
  }
211
- static getResultFromMetadata(metadata, options) {
212
- let type = metadata.name;
213
- if ((type === "Number" || type === "Object") && !options?.type) {
214
- throw new Error(`type is required when accessor/function/property returns a ${type}`);
215
- }
232
+ static getField(field) {
216
233
  let list;
217
234
  let scalarType = false;
218
235
  let connection;
219
- if (options?.type) {
236
+ let type = "";
237
+ if (field?.type) {
220
238
  let r = { type: "" };
221
- getType(options.type, r);
239
+ getType(field.type, r);
222
240
  list = r.list;
223
241
  scalarType = r.scalarType || false;
224
242
  connection = r.connection;
225
243
  type = r.type;
226
244
  }
245
+ if (!type) {
246
+ throw new Error(`type is required for accessor/function/property`);
247
+ }
227
248
  if (exports.knownDisAllowedNames.has(type)) {
228
249
  throw new Error(`${type} isn't a valid type for accessor/function/property`);
229
250
  }
230
251
  let result = {
231
- name: metadata.paramName || "",
232
- type,
252
+ name: field?.name || "",
253
+ type: type,
233
254
  tsType: exports.knownAllowedNames.get(type) || this.customTypes.get(type)?.tsType,
234
- nullable: options?.nullable,
255
+ nullable: field?.nullable,
235
256
  list: list,
236
257
  connection: connection,
237
- isContextArg: metadata.isContextArg,
258
+ // @ts-ignore
259
+ isContextArg: field?.isContextArg,
238
260
  };
239
261
  // unknown type. we need to flag that this field needs to eventually be resolved
240
262
  if (!exports.knownAllowedNames.has(type)) {
@@ -246,11 +268,16 @@ class GQLCapture {
246
268
  return result;
247
269
  }
248
270
  static gqlField(options) {
249
- return function (target, propertyKey, descriptor) {
250
- 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) {
251
278
  return;
252
279
  }
253
- let customField = GQLCapture.getCustomField(target, propertyKey, descriptor, options);
280
+ let customField = GQLCapture.getCustomField(ctx, options);
254
281
  if (!customField) {
255
282
  return;
256
283
  }
@@ -281,152 +308,109 @@ class GQLCapture {
281
308
  GQLCapture.customFields.set(customField.nodeName, list);
282
309
  };
283
310
  }
284
- static getCustomField(target, propertyKey, descriptor, options) {
311
+ static getCustomField(ctx, options, allowNoReturnType) {
285
312
  let fieldType;
286
- let nodeName = target.constructor.name;
287
313
  let args = [];
288
314
  let results = [];
289
- let typeMetadata = Reflect.getMetadata("design:type", target, propertyKey);
290
- let returnTypeMetadata = Reflect.getMetadata("design:returntype", target, propertyKey);
291
- if (returnTypeMetadata) {
292
- // function...
293
- if (returnTypeMetadata.name === "Promise") {
294
- fieldType = CustomFieldType.AsyncFunction;
295
- }
296
- else {
297
- fieldType = CustomFieldType.Function;
298
- }
299
- results.push(GQLCapture.getResultFromMetadata(returnTypeMetadata, options));
300
- }
301
- else if (typeMetadata) {
302
- if (descriptor && descriptor.get) {
303
- fieldType = CustomFieldType.Accessor;
304
- }
305
- else if (descriptor && descriptor.value) {
306
- // could be implicit async
315
+ switch (ctx.kind) {
316
+ case "method":
307
317
  fieldType = CustomFieldType.Function;
308
- }
309
- else {
318
+ if (options.async) {
319
+ fieldType = CustomFieldType.AsyncFunction;
320
+ }
321
+ break;
322
+ case "field":
310
323
  fieldType = CustomFieldType.Field;
311
- }
312
- if (!(options?.allowFunctionType &&
313
- fieldType === CustomFieldType.Function &&
314
- typeMetadata.name === "Function")) {
315
- results.push(GQLCapture.getResultFromMetadata(typeMetadata, options));
316
- }
324
+ break;
325
+ case "getter":
326
+ fieldType = CustomFieldType.Accessor;
327
+ break;
317
328
  }
318
- let params = Reflect.getMetadata("design:paramtypes", target, propertyKey);
319
- if (params && params.length > 0) {
320
- let parsedArgs = GQLCapture.argMap.get(nodeName)?.get(propertyKey) || [];
321
- if (params.length !== parsedArgs.length) {
322
- throw new Error(`args were not captured correctly, ${params.length}, ${parsedArgs.length}`);
323
- }
324
- parsedArgs.forEach((arg) => {
325
- let param = params[arg.index];
326
- let paramName = arg.name;
327
- let field = GQLCapture.getResultFromMetadata({
328
- name: param.name,
329
- paramName,
330
- isContextArg: arg.isContextArg,
331
- }, arg.options);
332
- // TODO this may not be the right order...
333
- 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));
334
339
  });
335
- // TODO this is deterministically (so far) coming in reverse order so reverse (for now)
336
- args = args.reverse();
337
340
  }
338
341
  return {
339
- nodeName: nodeName,
340
- gqlName: options?.name || propertyKey,
341
- functionName: propertyKey,
342
+ nodeName: options.class,
343
+ gqlName: options?.name || ctx.name.toString(),
344
+ functionName: ctx.name.toString(),
342
345
  args: args,
343
346
  results: results,
344
347
  fieldType: fieldType,
345
348
  description: options?.description,
346
349
  };
347
350
  }
348
- static argImpl(name, isContextArg, options) {
349
- return function (target, propertyKey, index) {
350
- if (!GQLCapture.isEnabled()) {
351
- return;
352
- }
353
- let nodeName = target.constructor.name;
354
- let m = GQLCapture.argMap.get(nodeName);
355
- if (!m) {
356
- m = new Map();
357
- GQLCapture.argMap.set(nodeName, m);
358
- }
359
- let propertyMap = m.get(propertyKey);
360
- if (!propertyMap) {
361
- propertyMap = [];
362
- m.set(propertyKey, propertyMap);
363
- }
364
- propertyMap.push({
365
- name: name,
366
- index: index,
367
- options: options,
368
- isContextArg,
369
- });
370
- // console.log("arg", name, target, propertyKey, index);
371
- };
372
- }
373
- // TODO custom args because for example name doesn't make sense here.
374
- static gqlArg(name, options) {
375
- return GQLCapture.argImpl(name, undefined, options);
376
- }
377
351
  static gqlContextType() {
378
- // hardcoded?
379
- return GQLCapture.argImpl("context", true, { type: "Context" });
352
+ return {
353
+ name: "context",
354
+ isContextArg: true,
355
+ type: "Context",
356
+ };
380
357
  }
381
358
  static gqlArgType(options) {
382
- return function (target, _propertyKey, _descriptor) {
383
- return GQLCapture.customGQLObject(target, GQLCapture.customArgs, options);
359
+ return function (target, ctx) {
360
+ return GQLCapture.customGQLObject(ctx, GQLCapture.customArgs, options);
384
361
  };
385
362
  }
386
363
  static gqlInputObjectType(options) {
387
- return function (target, _propertyKey, _descriptor) {
388
- return GQLCapture.customGQLObject(target, GQLCapture.customInputObjects, options);
364
+ return function (target, ctx) {
365
+ return GQLCapture.customGQLObject(ctx, GQLCapture.customInputObjects, options);
389
366
  };
390
367
  }
391
368
  static gqlObjectType(options) {
392
- return function (target, _propertyKey, _descriptor) {
393
- 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);
394
376
  };
395
377
  }
396
- static customGQLObject(target, map, options) {
397
- if (!GQLCapture.isEnabled()) {
378
+ static gqlInterfaceType(options) {
379
+ return function (target, ctx) {
380
+ return GQLCapture.customGQLObject(ctx, GQLCapture.customInterfaces, options);
381
+ };
382
+ }
383
+ static customGQLObject(ctx, map, options) {
384
+ if (!GQLCapture.isEnabled() || ctx.kind !== "class" || !ctx.name) {
398
385
  return;
399
386
  }
400
- let className = target.name;
387
+ let className = ctx.name.toString();
401
388
  let nodeName = options?.name || className;
402
389
  map.set(className, {
403
390
  className,
404
391
  nodeName,
405
392
  description: options?.description,
393
+ // @ts-ignore
394
+ interfaces: options?.interfaces,
395
+ // @ts-ignore
396
+ unionTypes: options?.unionTypes,
406
397
  });
407
398
  }
408
- // TODO query and mutation
409
399
  // we want to specify args if any, name, response if any
410
400
  static gqlQuery(options) {
411
- return function (target, propertyKey, descriptor) {
401
+ return function (target, ctx) {
412
402
  if (!GQLCapture.isEnabled()) {
413
403
  return;
414
404
  }
415
- GQLCapture.customQueries.push(GQLCapture.getCustomField(target, propertyKey, descriptor, options));
405
+ GQLCapture.customQueries.push(GQLCapture.getCustomField(ctx, options));
416
406
  };
417
407
  }
418
- // we want to specify inputs (required), name, response
419
- // input is via gqlArg
420
- // should it be gqlInputArg?
421
408
  static gqlMutation(options) {
422
- return function (target, propertyKey, descriptor) {
409
+ return function (target, ctx) {
423
410
  if (!GQLCapture.isEnabled()) {
424
411
  return;
425
412
  }
426
- GQLCapture.customMutations.push(GQLCapture.getCustomField(target, propertyKey, descriptor, {
427
- ...options,
428
- allowFunctionType: true,
429
- }));
413
+ GQLCapture.customMutations.push(GQLCapture.getCustomField(ctx, options, true));
430
414
  };
431
415
  }
432
416
  static gqlConnection(type) {
@@ -436,13 +420,61 @@ class GQLCapture {
436
420
  }
437
421
  static resolve(objects) {
438
422
  let baseObjects = new Map();
439
- objects.map((object) => baseObjects.set(object, true));
440
- 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
+ });
441
463
  let baseArgs = new Map();
442
464
  this.customArgs.forEach((_val, key) => baseArgs.set(key, true));
443
465
  this.customInputObjects.forEach((_val, key) => baseArgs.set(key, true));
444
466
  baseArgs.set("Context", true);
445
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
+ });
446
478
  // TODO this should be aware of knownCustomTypes
447
479
  const resolveFields = (fields) => {
448
480
  fields.forEach((field) => {
@@ -464,7 +496,9 @@ class GQLCapture {
464
496
  // but i don't think it applies
465
497
  field.results.forEach((result) => {
466
498
  if (result.needsResolving) {
467
- if (baseObjects.has(result.type)) {
499
+ if (baseObjects.has(result.type) ||
500
+ this.customUnions.has(result.type) ||
501
+ this.customInterfaces.has(result.type)) {
468
502
  result.needsResolving = false;
469
503
  }
470
504
  else {
@@ -479,7 +513,6 @@ class GQLCapture {
479
513
  resolveFields(GQLCapture.customMutations);
480
514
  }
481
515
  }
482
- exports.GQLCapture = GQLCapture;
483
516
  GQLCapture.enabled = false;
484
517
  // map from class name to fields
485
518
  GQLCapture.customFields = new Map();
@@ -488,16 +521,18 @@ GQLCapture.customMutations = [];
488
521
  GQLCapture.customArgs = new Map();
489
522
  GQLCapture.customInputObjects = new Map();
490
523
  GQLCapture.customObjects = new Map();
524
+ GQLCapture.customInterfaces = new Map();
525
+ GQLCapture.customUnions = new Map();
491
526
  GQLCapture.customTypes = new Map();
492
- // User -> add -> [{name, options}, {}, {}]
493
- GQLCapture.argMap = new Map();
527
+ exports.GQLCapture = GQLCapture;
494
528
  // why is this a static class lol?
495
529
  // TODO make all these just plain functions
496
530
  exports.gqlField = GQLCapture.gqlField;
497
- exports.gqlArg = GQLCapture.gqlArg;
498
531
  exports.gqlArgType = GQLCapture.gqlArgType;
499
532
  exports.gqlInputObjectType = GQLCapture.gqlInputObjectType;
500
533
  exports.gqlObjectType = GQLCapture.gqlObjectType;
534
+ exports.gqlInterfaceType = GQLCapture.gqlInterfaceType;
535
+ exports.gqlUnionType = GQLCapture.gqlUnionType;
501
536
  exports.gqlQuery = GQLCapture.gqlQuery;
502
537
  exports.gqlMutation = GQLCapture.gqlMutation;
503
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";
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.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");
@@ -0,0 +1,2 @@
1
+ import { GraphQLEnumType } from "graphql";
2
+ export declare const GraphQLOrderByDirection: GraphQLEnumType;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GraphQLOrderByDirection = void 0;
4
+ const graphql_1 = require("graphql");
5
+ exports.GraphQLOrderByDirection = new graphql_1.GraphQLEnumType({
6
+ name: "OrderByDirection",
7
+ values: {
8
+ ASC: {
9
+ value: "ASC",
10
+ },
11
+ DESC: {
12
+ value: "DESC",
13
+ },
14
+ },
15
+ });