@snowtop/ent 0.1.0-alpha110 → 0.1.0-alpha111

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snowtop/ent",
3
- "version": "0.1.0-alpha110",
3
+ "version": "0.1.0-alpha111",
4
4
  "description": "snowtop ent framework",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -11,7 +11,7 @@ export declare class JSONField extends BaseField implements Field {
11
11
  private options?;
12
12
  type: Type;
13
13
  constructor(jsonb: boolean, options?: allJSONOptions | undefined);
14
- format(val: any): string;
14
+ format(val: any, nested?: boolean): any;
15
15
  valid(val: any): boolean;
16
16
  }
17
17
  export declare function JSONType(options?: JSONOptions): JSONField;
@@ -22,7 +22,10 @@ class JSONField extends field_1.BaseField {
22
22
  };
23
23
  }
24
24
  }
25
- format(val) {
25
+ format(val, nested) {
26
+ if (nested) {
27
+ return val;
28
+ }
26
29
  return JSON.stringify(val);
27
30
  }
28
31
  valid(val) {
@@ -203,6 +203,7 @@ export interface FieldOptions {
203
203
  foreignKey?: ForeignKey;
204
204
  fieldEdge?: FieldEdge;
205
205
  primaryKey?: boolean;
206
+ immutable?: boolean;
206
207
  disableUserEditable?: boolean;
207
208
  disableUserGraphQLEditable?: boolean;
208
209
  defaultValueOnCreate?(builder: Builder<Ent>, input: Data): any;
@@ -162,8 +162,9 @@ function makeGraphQLRequest(config, query, fieldArgs) {
162
162
  }
163
163
  function buildTreeFromQueryPaths(schema, fieldType, ...options) {
164
164
  let fields;
165
- if (fieldType instanceof graphql_1.GraphQLObjectType) {
166
- fields = fieldType.getFields();
165
+ const [typ] = getInnerType(fieldType, false);
166
+ if (typ instanceof graphql_1.GraphQLObjectType) {
167
+ fields = typ.getFields();
167
168
  }
168
169
  let topLevelTree = {};
169
170
  options.forEach((option) => {
@@ -201,10 +202,11 @@ function buildTreeFromQueryPaths(schema, fieldType, ...options) {
201
202
  }
202
203
  // TODO this needs to be aware of paths etc so this part works for complicated
203
204
  // cases but inlineFragmentRoot is a workaround for now.
204
- function handleSubtree(obj, tree) {
205
+ function handleSubtree(obj, tree, parts) {
206
+ let parts2 = [...parts];
205
207
  if (Array.isArray(obj)) {
206
208
  for (const obj2 of obj) {
207
- handleSubtree(obj2, tree);
209
+ handleSubtree(obj2, tree, parts2);
208
210
  }
209
211
  return;
210
212
  }
@@ -213,28 +215,36 @@ function buildTreeFromQueryPaths(schema, fieldType, ...options) {
213
215
  tree[key] = {};
214
216
  }
215
217
  if (typeof obj[key] === "object") {
216
- if (!isScalarField(key)) {
217
- handleSubtree(obj[key], tree[key]);
218
+ let parts2 = [...parts, key];
219
+ if (!scalarFieldAtLeaf(parts2)) {
220
+ handleSubtree(obj[key], tree[key], parts2);
218
221
  }
219
222
  }
220
223
  }
221
224
  }
222
- // TODO this needs to work for super complicated objects and have fields update as nesting applies...
223
- function isScalarField(f) {
224
- const subField = fields?.[f];
225
- if (!subField) {
225
+ function scalarFieldAtLeaf(pathFromRoot) {
226
+ let root = fields;
227
+ if (!root) {
226
228
  return false;
227
229
  }
228
- if (!(0, graphql_1.isWrappingType)(subField.type)) {
230
+ let subField;
231
+ for (const p of pathFromRoot) {
232
+ subField = root?.[p];
233
+ if (subField) {
234
+ [subField] = getInnerType(subField.type, false);
235
+ if (subField instanceof graphql_1.GraphQLObjectType) {
236
+ root = subField.getFields();
237
+ }
238
+ }
239
+ }
240
+ if (!subField) {
229
241
  return false;
230
242
  }
231
- // only spread out if an object
232
- const [typ, _] = getInnerType(subField.type, true);
233
- return (0, graphql_1.isScalarType)(typ) || (0, graphql_1.isEnumType)(typ);
243
+ return (0, graphql_1.isScalarType)(subField) || (0, graphql_1.isEnumType)(subField);
234
244
  }
235
245
  if (i === parts.length - 1 && typeof option[1] === "object") {
236
- if (!isScalarField(part)) {
237
- handleSubtree(option[1], tree);
246
+ if (!scalarFieldAtLeaf(parts)) {
247
+ handleSubtree(option[1], tree, parts);
238
248
  }
239
249
  }
240
250
  }