@snowtop/ent 0.1.0-alpha123 → 0.1.0-alpha125

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/ent.d.ts CHANGED
@@ -4,6 +4,7 @@ import { Executor } from "../action/action";
4
4
  import * as clause from "./clause";
5
5
  import { Builder } from "../action";
6
6
  import DataLoader from "dataloader";
7
+ import { GlobalSchema } from "../schema/";
7
8
  export declare function getEntKey<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, id: ID, options: LoadEntOptions<TEnt, TViewer>): string;
8
9
  export declare function loadEnt<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, id: ID, options: LoadEntOptions<TEnt, TViewer>): Promise<TEnt | null>;
9
10
  export declare function loadEntViaKey<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, key: any, options: LoadEntOptions<TEnt, TViewer>): Promise<TEnt | null>;
@@ -113,6 +114,9 @@ export declare class EditNodeOperation<T extends Ent> implements DataOperation {
113
114
  returnedRow(): Data | null;
114
115
  createdEnt(viewer: Viewer): T | null;
115
116
  }
117
+ export declare function setGlobalSchema(val: GlobalSchema): void;
118
+ export declare function clearGlobalSchema(): void;
119
+ export declare function __hasGlobalSchema(): boolean;
116
120
  export declare class EdgeOperation implements DataOperation {
117
121
  private builder;
118
122
  edgeInput: AssocEdgeInput;
package/core/ent.js CHANGED
@@ -26,16 +26,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.loadNodesByEdge = exports.loadEdgeForID2 = exports.loadRawEdgeCountX = exports.loadUniqueNode = exports.loadUniqueEdge = exports.loadCustomEdges = exports.getEdgeClauseAndFields = exports.loadEdges = exports.DefaultLimit = exports.loadEdgeDatas = exports.loadEdgeData = exports.assocEdgeLoader = exports.AssocEdgeData = exports.getCursor = exports.AssocEdge = exports.DeleteNodeOperation = exports.deleteRowsSync = exports.deleteRows = exports.editRowSync = exports.editRow = exports.buildUpdateQuery = exports.createRowSync = exports.createRow = exports.buildInsertQuery = exports.EdgeOperation = exports.EditNodeOperation = exports.RawQueryOperation = exports.buildGroupQuery = exports.buildQuery = exports.loadRows = exports.performRawQuery = exports.___setLogQueryErrorWithError = exports.loadRow = exports.loadRowX = exports.logQuery = exports.loadDerivedEntX = exports.loadDerivedEnt = exports.loadCustomCount = exports.loadCustomData = exports.loadCustomEnts = exports.loadEntsFromClause = exports.loadEntsList = exports.loadEnts = exports.loadEntXFromClause = exports.loadEntFromClause = exports.loadEntXViaKey = exports.loadEntX = exports.loadEntViaKey = exports.loadEnt = exports.getEntKey = void 0;
30
- exports.getEdgeTypeInGroup = exports.applyPrivacyPolicyForRows = exports.applyPrivacyPolicyForRow = void 0;
29
+ exports.loadUniqueNode = exports.loadUniqueEdge = exports.loadCustomEdges = exports.getEdgeClauseAndFields = exports.loadEdges = exports.DefaultLimit = exports.loadEdgeDatas = exports.loadEdgeData = exports.assocEdgeLoader = exports.AssocEdgeData = exports.getCursor = exports.AssocEdge = exports.DeleteNodeOperation = exports.deleteRowsSync = exports.deleteRows = exports.editRowSync = exports.editRow = exports.buildUpdateQuery = exports.createRowSync = exports.createRow = exports.buildInsertQuery = exports.EdgeOperation = exports.__hasGlobalSchema = exports.clearGlobalSchema = exports.setGlobalSchema = exports.EditNodeOperation = exports.RawQueryOperation = exports.buildGroupQuery = exports.buildQuery = exports.loadRows = exports.performRawQuery = exports.___setLogQueryErrorWithError = exports.loadRow = exports.loadRowX = exports.logQuery = exports.loadDerivedEntX = exports.loadDerivedEnt = exports.loadCustomCount = exports.loadCustomData = exports.loadCustomEnts = exports.loadEntsFromClause = exports.loadEntsList = exports.loadEnts = exports.loadEntXFromClause = exports.loadEntFromClause = exports.loadEntXViaKey = exports.loadEntX = exports.loadEntViaKey = exports.loadEnt = exports.getEntKey = void 0;
30
+ exports.getEdgeTypeInGroup = exports.applyPrivacyPolicyForRows = exports.applyPrivacyPolicyForRow = exports.loadNodesByEdge = exports.loadEdgeForID2 = exports.loadRawEdgeCountX = void 0;
31
31
  const db_1 = __importStar(require("./db"));
32
32
  const privacy_1 = require("./privacy");
33
33
  const clause = __importStar(require("./clause"));
34
34
  const action_1 = require("../action");
35
35
  const logger_1 = require("./logger");
36
36
  const dataloader_1 = __importDefault(require("dataloader"));
37
- const schema_1 = require("../schema/schema");
38
- const global_schema_1 = require("./global_schema");
37
+ const schema_1 = require("../schema/");
39
38
  // TODO kill this and createDataLoader
40
39
  class cacheMap {
41
40
  constructor(options) {
@@ -610,7 +609,7 @@ async function performRawQuery(query, values, logValues) {
610
609
  catch (e) {
611
610
  if (_logQueryWithError) {
612
611
  const msg = e.message;
613
- throw new Error(`error \`${msg}\` running query: \`${query}\` with values: \`${logValues}\``);
612
+ throw new Error(`error \`${msg}\` running query: \`${query}\``);
614
613
  }
615
614
  throw e;
616
615
  }
@@ -817,6 +816,20 @@ class EditNodeOperation {
817
816
  }
818
817
  }
819
818
  exports.EditNodeOperation = EditNodeOperation;
819
+ let globalSchema;
820
+ function setGlobalSchema(val) {
821
+ globalSchema = val;
822
+ }
823
+ exports.setGlobalSchema = setGlobalSchema;
824
+ function clearGlobalSchema() {
825
+ globalSchema = undefined;
826
+ }
827
+ exports.clearGlobalSchema = clearGlobalSchema;
828
+ // used by tests. no guarantee will always exist
829
+ function __hasGlobalSchema() {
830
+ return globalSchema !== undefined;
831
+ }
832
+ exports.__hasGlobalSchema = __hasGlobalSchema;
820
833
  class EdgeOperation {
821
834
  constructor(builder, edgeInput, options) {
822
835
  this.builder = builder;
@@ -859,9 +872,8 @@ class EdgeOperation {
859
872
  let op = schema_1.SQLStatementOperation.Delete;
860
873
  let updateData = null;
861
874
  // TODO respect disableTransformations
862
- const transformedEdgeWrite = (0, global_schema_1.__getGlobalSchema)()?.transformEdgeWrite;
863
- if (transformedEdgeWrite) {
864
- transformed = transformedEdgeWrite({
875
+ if (globalSchema?.transformEdgeWrite) {
876
+ transformed = globalSchema.transformEdgeWrite({
865
877
  op: schema_1.SQLStatementOperation.Delete,
866
878
  edge,
867
879
  });
@@ -939,10 +951,9 @@ class EdgeOperation {
939
951
  fields["time"] = new Date().toISOString();
940
952
  }
941
953
  const onConflictFields = ["data"];
942
- const extraEdgeFields = (0, global_schema_1.__getGlobalSchema)()?.extraEdgeFields;
943
- if (extraEdgeFields) {
944
- for (const name in extraEdgeFields) {
945
- const f = extraEdgeFields[name];
954
+ if (globalSchema?.extraEdgeFields) {
955
+ for (const name in globalSchema.extraEdgeFields) {
956
+ const f = globalSchema.extraEdgeFields[name];
946
957
  if (f.defaultValueOnCreate) {
947
958
  const storageKey = (0, schema_1.getStorageKey)(f, name);
948
959
  fields[storageKey] = f.defaultValueOnCreate(this.builder, {});
@@ -954,9 +965,8 @@ class EdgeOperation {
954
965
  }
955
966
  // TODO respect disableTransformations
956
967
  let transformed = null;
957
- const transformEdgeWrite = (0, global_schema_1.__getGlobalSchema)()?.transformEdgeWrite;
958
- if (transformEdgeWrite) {
959
- transformed = transformEdgeWrite({
968
+ if (globalSchema?.transformEdgeWrite) {
969
+ transformed = globalSchema.transformEdgeWrite({
960
970
  op: schema_1.SQLStatementOperation.Insert,
961
971
  edge,
962
972
  });
@@ -1473,9 +1483,8 @@ async function loadEdges(options) {
1473
1483
  exports.loadEdges = loadEdges;
1474
1484
  function getEdgeClauseAndFields(cls, options) {
1475
1485
  let fields = edgeFields;
1476
- const transformEdgeRead = (0, global_schema_1.__getGlobalSchema)()?.transformEdgeRead;
1477
- if (transformEdgeRead) {
1478
- const transformClause = transformEdgeRead();
1486
+ if (globalSchema?.transformEdgeRead) {
1487
+ const transformClause = globalSchema.transformEdgeRead();
1479
1488
  if (!options.disableTransformations) {
1480
1489
  cls = clause.And(cls, transformClause);
1481
1490
  }
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.commonTests = void 0;
4
4
  const ent_1 = require("../ent");
5
- const global_schema_1 = require("../global_schema");
6
5
  const viewer_1 = require("../viewer");
7
6
  const index_1 = require("../../testutils/fake_data/index");
8
7
  const test_helpers_1 = require("../../testutils/fake_data/test_helpers");
@@ -290,7 +289,7 @@ const commonTests = (opts) => {
290
289
  return { verify, getCursor };
291
290
  }
292
291
  if (opts.globalSchema) {
293
- (0, global_schema_1.setGlobalSchema)(test_edge_global_schema_1.testEdgeGlobalSchema);
292
+ (0, ent_1.setGlobalSchema)(test_edge_global_schema_1.testEdgeGlobalSchema);
294
293
  }
295
294
  let tdb;
296
295
  if (opts.sqlite) {
@@ -1,4 +1,3 @@
1
- import "reflect-metadata";
2
1
  import { GraphQLScalarType } from "graphql";
3
2
  interface ClassType<T = any> {
4
3
  new (...args: any[]): T;
@@ -19,17 +18,29 @@ type Type = GraphQLScalarType | ClassType | string | CustomType;
19
18
  export type GraphQLConnection<T> = {
20
19
  node: T;
21
20
  };
22
- export interface gqlFieldOptions {
21
+ interface gqlFieldOptionsBase {
23
22
  name?: string;
24
23
  nullable?: boolean | NullableListOptions;
25
24
  description?: string;
26
25
  type?: Type | Array<Type> | GraphQLConnection<Type>;
27
26
  }
27
+ interface gqlFieldArg extends gqlFieldOptionsBase {
28
+ isContextArg?: boolean;
29
+ }
30
+ export interface gqlFieldOptions extends gqlFieldOptionsBase {
31
+ nodeName: string;
32
+ args?: gqlFieldArg[];
33
+ async?: boolean;
34
+ type: NonNullable<gqlFieldOptionsBase["type"]>;
35
+ }
28
36
  export interface gqlObjectOptions {
29
37
  name?: string;
30
38
  description?: string;
31
39
  }
32
- type gqlTopLevelOptions = Exclude<gqlFieldOptions, "nullable">;
40
+ type gqlMutationOptions = Omit<gqlFieldOptions, "nullable" | "type"> & {
41
+ type?: gqlFieldOptionsBase["type"];
42
+ };
43
+ type gqlQueryOptions = Omit<gqlFieldOptions, "nullable">;
33
44
  export declare enum CustomFieldType {
34
45
  Accessor = "ACCESSOR",
35
46
  Field = "FIELD",
@@ -118,24 +129,20 @@ export declare class GQLCapture {
118
129
  static getProcessedCustomMutations(): ProcessedCustomField[];
119
130
  static getProcessedCustomQueries(): ProcessedCustomField[];
120
131
  private static getProcessedCustomFieldsImpl;
121
- private static getResultFromMetadata;
122
- static gqlField(options?: gqlFieldOptions): any;
132
+ private static getField;
133
+ static gqlField(options: gqlFieldOptions): any;
123
134
  private static getCustomField;
124
- private static argMap;
125
- private static argImpl;
126
- static gqlArg(name: string, options?: gqlFieldOptions): any;
127
- static gqlContextType(): any;
135
+ static gqlContextType(): gqlFieldArg;
128
136
  static gqlArgType(options?: gqlObjectOptions): any;
129
137
  static gqlInputObjectType(options?: gqlObjectOptions): any;
130
138
  static gqlObjectType(options?: gqlObjectOptions): any;
131
139
  private static customGQLObject;
132
- static gqlQuery(options?: gqlTopLevelOptions): any;
133
- static gqlMutation(options?: gqlTopLevelOptions): any;
140
+ static gqlQuery(options: gqlQueryOptions): any;
141
+ static gqlMutation(options: gqlMutationOptions): any;
134
142
  static gqlConnection(type: Type): any;
135
143
  static resolve(objects: string[]): void;
136
144
  }
137
145
  export declare const gqlField: typeof GQLCapture.gqlField;
138
- export declare const gqlArg: typeof GQLCapture.gqlArg;
139
146
  export declare const gqlArgType: typeof GQLCapture.gqlArgType;
140
147
  export declare const gqlInputObjectType: typeof GQLCapture.gqlInputObjectType;
141
148
  export declare const gqlObjectType: typeof GQLCapture.gqlObjectType;
@@ -1,12 +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.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.gqlObjectType = exports.gqlInputObjectType = exports.gqlArgType = exports.gqlField = exports.GQLCapture = exports.addCustomType = exports.isCustomType = exports.knownDisAllowedNames = exports.knownAllowedNames = exports.CustomFieldType = void 0;
10
4
  var CustomFieldType;
11
5
  (function (CustomFieldType) {
12
6
  CustomFieldType["Accessor"] = "ACCESSOR";
@@ -149,7 +143,6 @@ class GQLCapture {
149
143
  this.customInputObjects.clear();
150
144
  this.customObjects.clear();
151
145
  this.customTypes.clear();
152
- this.argMap.clear();
153
146
  }
154
147
  static getCustomFields() {
155
148
  return this.customFields;
@@ -213,33 +206,34 @@ class GQLCapture {
213
206
  return res;
214
207
  });
215
208
  }
216
- static getResultFromMetadata(metadata, options) {
217
- let type = metadata.name;
218
- if ((type === "Number" || type === "Object") && !options?.type) {
219
- throw new Error(`type is required when accessor/function/property returns a ${type}`);
220
- }
209
+ static getField(field) {
221
210
  let list;
222
211
  let scalarType = false;
223
212
  let connection;
224
- if (options?.type) {
213
+ let type = "";
214
+ if (field?.type) {
225
215
  let r = { type: "" };
226
- getType(options.type, r);
216
+ getType(field.type, r);
227
217
  list = r.list;
228
218
  scalarType = r.scalarType || false;
229
219
  connection = r.connection;
230
220
  type = r.type;
231
221
  }
222
+ if (!type) {
223
+ throw new Error(`type is required for accessor/function/property`);
224
+ }
232
225
  if (exports.knownDisAllowedNames.has(type)) {
233
226
  throw new Error(`${type} isn't a valid type for accessor/function/property`);
234
227
  }
235
228
  let result = {
236
- name: metadata.paramName || "",
237
- type,
229
+ name: field?.name || "",
230
+ type: type,
238
231
  tsType: exports.knownAllowedNames.get(type) || this.customTypes.get(type)?.tsType,
239
- nullable: options?.nullable,
232
+ nullable: field?.nullable,
240
233
  list: list,
241
234
  connection: connection,
242
- isContextArg: metadata.isContextArg,
235
+ // @ts-ignore
236
+ isContextArg: field?.isContextArg,
243
237
  };
244
238
  // unknown type. we need to flag that this field needs to eventually be resolved
245
239
  if (!exports.knownAllowedNames.has(type)) {
@@ -251,11 +245,16 @@ class GQLCapture {
251
245
  return result;
252
246
  }
253
247
  static gqlField(options) {
254
- return function (target, propertyKey, descriptor) {
255
- if (!GQLCapture.isEnabled()) {
248
+ return function (_target, ctx) {
249
+ if (!GQLCapture.isEnabled() ||
250
+ (ctx.kind !== "method" &&
251
+ ctx.kind !== "field" &&
252
+ ctx.kind !== "getter") ||
253
+ ctx.static ||
254
+ ctx.private) {
256
255
  return;
257
256
  }
258
- let customField = GQLCapture.getCustomField(target, propertyKey, descriptor, options);
257
+ let customField = GQLCapture.getCustomField(ctx, options);
259
258
  if (!customField) {
260
259
  return;
261
260
  }
@@ -286,123 +285,73 @@ class GQLCapture {
286
285
  GQLCapture.customFields.set(customField.nodeName, list);
287
286
  };
288
287
  }
289
- static getCustomField(target, propertyKey, descriptor, options) {
288
+ static getCustomField(ctx, options, allowNoReturnType) {
290
289
  let fieldType;
291
- let nodeName = target.constructor.name;
292
290
  let args = [];
293
291
  let results = [];
294
- let typeMetadata = Reflect.getMetadata("design:type", target, propertyKey);
295
- let returnTypeMetadata = Reflect.getMetadata("design:returntype", target, propertyKey);
296
- if (returnTypeMetadata) {
297
- // function...
298
- if (returnTypeMetadata.name === "Promise") {
299
- fieldType = CustomFieldType.AsyncFunction;
300
- }
301
- else {
292
+ switch (ctx.kind) {
293
+ case "method":
302
294
  fieldType = CustomFieldType.Function;
303
- }
304
- results.push(GQLCapture.getResultFromMetadata(returnTypeMetadata, options));
305
- }
306
- else if (typeMetadata) {
307
- if (descriptor && descriptor.get) {
308
- fieldType = CustomFieldType.Accessor;
309
- }
310
- else if (descriptor && descriptor.value) {
311
- // could be implicit async
312
- fieldType = CustomFieldType.Function;
313
- }
314
- else {
295
+ if (options.async) {
296
+ fieldType = CustomFieldType.AsyncFunction;
297
+ }
298
+ break;
299
+ case "field":
315
300
  fieldType = CustomFieldType.Field;
316
- }
317
- if (!(options?.allowFunctionType &&
318
- fieldType === CustomFieldType.Function &&
319
- typeMetadata.name === "Function")) {
320
- results.push(GQLCapture.getResultFromMetadata(typeMetadata, options));
321
- }
301
+ break;
302
+ case "getter":
303
+ fieldType = CustomFieldType.Accessor;
304
+ break;
322
305
  }
323
- let params = Reflect.getMetadata("design:paramtypes", target, propertyKey);
324
- if (params && params.length > 0) {
325
- let parsedArgs = GQLCapture.argMap.get(nodeName)?.get(propertyKey) || [];
326
- if (params.length !== parsedArgs.length) {
327
- throw new Error(`args were not captured correctly, ${params.length}, ${parsedArgs.length}`);
328
- }
329
- parsedArgs.forEach((arg) => {
330
- let param = params[arg.index];
331
- let paramName = arg.name;
332
- let field = GQLCapture.getResultFromMetadata({
333
- name: param.name,
334
- paramName,
335
- isContextArg: arg.isContextArg,
336
- }, arg.options);
337
- // TODO this may not be the right order...
338
- args.push(field);
306
+ if (!allowNoReturnType && !options.type) {
307
+ throw new Error(`type is required for ${fieldType}`);
308
+ }
309
+ if (options.type) {
310
+ // override name property passed down so we return '' as name
311
+ results.push(GQLCapture.getField({ ...options, name: "" }));
312
+ }
313
+ if (options.args?.length) {
314
+ options.args.forEach((arg) => {
315
+ args.push(GQLCapture.getField(arg));
339
316
  });
340
- // TODO this is deterministically (so far) coming in reverse order so reverse (for now)
341
- args = args.reverse();
342
317
  }
343
318
  return {
344
- nodeName: nodeName,
345
- gqlName: options?.name || propertyKey,
346
- functionName: propertyKey,
319
+ nodeName: options.nodeName,
320
+ gqlName: options?.name || ctx.name.toString(),
321
+ functionName: ctx.name.toString(),
347
322
  args: args,
348
323
  results: results,
349
324
  fieldType: fieldType,
350
325
  description: options?.description,
351
326
  };
352
327
  }
353
- static argImpl(name, isContextArg, options) {
354
- return function (target, propertyKey, index) {
355
- if (!GQLCapture.isEnabled()) {
356
- return;
357
- }
358
- let nodeName = target.constructor.name;
359
- let m = GQLCapture.argMap.get(nodeName);
360
- if (!m) {
361
- m = new Map();
362
- GQLCapture.argMap.set(nodeName, m);
363
- }
364
- let propertyMap = m.get(propertyKey);
365
- if (!propertyMap) {
366
- propertyMap = [];
367
- m.set(propertyKey, propertyMap);
368
- }
369
- propertyMap.push({
370
- name: name,
371
- index: index,
372
- options: options,
373
- isContextArg,
374
- });
375
- // console.log("arg", name, target, propertyKey, index);
376
- };
377
- }
378
- // TODO custom args because for example name doesn't make sense here.
379
- static gqlArg(name, options) {
380
- return GQLCapture.argImpl(name, undefined, options);
381
- }
382
328
  static gqlContextType() {
383
- // hardcoded?
384
- return GQLCapture.argImpl("context", true, { type: "Context" });
329
+ return {
330
+ name: "context",
331
+ isContextArg: true,
332
+ type: "Context",
333
+ };
385
334
  }
386
335
  static gqlArgType(options) {
387
- return function (target, _propertyKey, _descriptor) {
388
- return GQLCapture.customGQLObject(target, GQLCapture.customArgs, options);
336
+ return function (target, ctx) {
337
+ return GQLCapture.customGQLObject(ctx, GQLCapture.customArgs, options);
389
338
  };
390
339
  }
391
340
  static gqlInputObjectType(options) {
392
- return function (target, _propertyKey, _descriptor) {
393
- return GQLCapture.customGQLObject(target, GQLCapture.customInputObjects, options);
341
+ return function (target, ctx) {
342
+ return GQLCapture.customGQLObject(ctx, GQLCapture.customInputObjects, options);
394
343
  };
395
344
  }
396
345
  static gqlObjectType(options) {
397
- return function (target, _propertyKey, _descriptor) {
398
- return GQLCapture.customGQLObject(target, GQLCapture.customObjects, options);
346
+ return function (target, ctx) {
347
+ return GQLCapture.customGQLObject(ctx, GQLCapture.customObjects, options);
399
348
  };
400
349
  }
401
- static customGQLObject(target, map, options) {
402
- if (!GQLCapture.isEnabled()) {
350
+ static customGQLObject(ctx, map, options) {
351
+ if (!GQLCapture.isEnabled() || ctx.kind !== "class" || !ctx.name) {
403
352
  return;
404
353
  }
405
- let className = target.name;
354
+ let className = ctx.name.toString();
406
355
  let nodeName = options?.name || className;
407
356
  map.set(className, {
408
357
  className,
@@ -410,28 +359,21 @@ class GQLCapture {
410
359
  description: options?.description,
411
360
  });
412
361
  }
413
- // TODO query and mutation
414
362
  // we want to specify args if any, name, response if any
415
363
  static gqlQuery(options) {
416
- return function (target, propertyKey, descriptor) {
364
+ return function (target, ctx) {
417
365
  if (!GQLCapture.isEnabled()) {
418
366
  return;
419
367
  }
420
- GQLCapture.customQueries.push(GQLCapture.getCustomField(target, propertyKey, descriptor, options));
368
+ GQLCapture.customQueries.push(GQLCapture.getCustomField(ctx, options));
421
369
  };
422
370
  }
423
- // we want to specify inputs (required), name, response
424
- // input is via gqlArg
425
- // should it be gqlInputArg?
426
371
  static gqlMutation(options) {
427
- return function (target, propertyKey, descriptor) {
372
+ return function (target, ctx) {
428
373
  if (!GQLCapture.isEnabled()) {
429
374
  return;
430
375
  }
431
- GQLCapture.customMutations.push(GQLCapture.getCustomField(target, propertyKey, descriptor, {
432
- ...options,
433
- allowFunctionType: true,
434
- }));
376
+ GQLCapture.customMutations.push(GQLCapture.getCustomField(ctx, options, true));
435
377
  };
436
378
  }
437
379
  static gqlConnection(type) {
@@ -484,7 +426,6 @@ class GQLCapture {
484
426
  resolveFields(GQLCapture.customMutations);
485
427
  }
486
428
  }
487
- exports.GQLCapture = GQLCapture;
488
429
  GQLCapture.enabled = false;
489
430
  // map from class name to fields
490
431
  GQLCapture.customFields = new Map();
@@ -494,12 +435,10 @@ GQLCapture.customArgs = new Map();
494
435
  GQLCapture.customInputObjects = new Map();
495
436
  GQLCapture.customObjects = new Map();
496
437
  GQLCapture.customTypes = new Map();
497
- // User -> add -> [{name, options}, {}, {}]
498
- GQLCapture.argMap = new Map();
438
+ exports.GQLCapture = GQLCapture;
499
439
  // why is this a static class lol?
500
440
  // TODO make all these just plain functions
501
441
  exports.gqlField = GQLCapture.gqlField;
502
- exports.gqlArg = GQLCapture.gqlArg;
503
442
  exports.gqlArgType = GQLCapture.gqlArgType;
504
443
  exports.gqlInputObjectType = GQLCapture.gqlInputObjectType;
505
444
  exports.gqlObjectType = GQLCapture.gqlObjectType;
@@ -1,4 +1,4 @@
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, } from "./graphql";
2
2
  export { GraphQLTime } from "./scalars/time";
3
3
  export { GraphQLOrderByDirection } from "./scalars/orderby_direction";
4
4
  export { GraphQLPageInfo } from "./query/page_info";
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.GraphQLOrderByDirection = 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.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; } });