@snowtop/ent 0.2.0-alpha.3 → 0.2.0-alpha.5

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.
@@ -621,17 +621,23 @@ class Orchestrator {
621
621
  }
622
622
  if (transformed.data) {
623
623
  updateInput = true;
624
- for (const k in transformed.data) {
625
- let field = schemaFields.get(k);
626
- if (!field) {
627
- throw new Error(`tried to transform field with unknown field ${k}`);
624
+ for (const [k, field] of schemaFields) {
625
+ const inputKey = this.getInputKey(k);
626
+ const storageKey = this.getStorageKey(k);
627
+ let val = transformed.data[inputKey];
628
+ if (val === undefined) {
629
+ val = transformed.data[storageKey];
630
+ }
631
+ if (val === undefined) {
632
+ continue;
628
633
  }
629
- let val = transformed.data[k];
630
634
  if (field.format) {
631
- val = field.format(transformed.data[k]);
635
+ val = field.format(transformed.data[k], true);
632
636
  }
633
637
  data[this.getStorageKey(k)] = val;
634
- this.defaultFieldsByTSName[this.getInputKey(k)] = val;
638
+ if (!field.immutable) {
639
+ this.defaultFieldsByTSName[this.getInputKey(k)] = val;
640
+ }
635
641
  // hmm do we need this?
636
642
  // TODO how to do this for local tests?
637
643
  // this.defaultFieldsByFieldName[k] = val;
@@ -517,6 +517,9 @@ class GQLCapture {
517
517
  field.results.forEach((result) => {
518
518
  if (result.needsResolving) {
519
519
  if (baseObjects.has(result.type) ||
520
+ // allow custom input objects to be returned
521
+ // depend on GraphQL type complaining if we try and reference an input from a non-input object
522
+ this.customInputObjects.has(result.type) ||
520
523
  this.customUnions.has(result.type) ||
521
524
  this.customInterfaces.has(result.type) ||
522
525
  this.customTypes.has(result.type)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snowtop/ent",
3
- "version": "0.2.0-alpha.3",
3
+ "version": "0.2.0-alpha.5",
4
4
  "description": "snowtop ent framework",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -1,5 +1,6 @@
1
1
  import { Field, Schema } from "../../schema";
2
2
  export declare function randomEmail(domain?: string): string;
3
+ export declare function randomPhoneNumber(): string;
3
4
  interface Info {
4
5
  schema: Schema;
5
6
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getDefaultValue = exports.randomEmail = void 0;
3
+ exports.getDefaultValue = exports.randomPhoneNumber = exports.randomEmail = void 0;
4
4
  const uuid_1 = require("uuid");
5
5
  const schema_1 = require("../../schema");
6
6
  const schema_2 = require("../../schema");
@@ -15,6 +15,7 @@ exports.randomEmail = randomEmail;
15
15
  function randomPhoneNumber() {
16
16
  return `+1${Math.random().toString(10).substring(2, 11)}`;
17
17
  }
18
+ exports.randomPhoneNumber = randomPhoneNumber;
18
19
  function coinFlip() {
19
20
  return Math.floor(Math.random() * 10) >= 5;
20
21
  }