@snowtop/ent 0.1.6 → 0.1.8

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.
@@ -1,4 +1,4 @@
1
- import { GraphQLScalarType } from "graphql";
1
+ import { GraphQLEnumType, GraphQLScalarType } from "graphql";
2
2
  import type { FieldMap } from "../schema";
3
3
  import { ProcessedField as ParsedProcessedField } from "../parse_schema/parse";
4
4
  import { ImportPath } from "../schema/schema";
@@ -66,7 +66,7 @@ export interface CustomTypeInput {
66
66
  export type CustomType = Omit<CustomTypeInput, "structFields"> & {
67
67
  structFields?: ParsedProcessedField[];
68
68
  };
69
- type Type = GraphQLScalarType | ClassType | string | CustomTypeInput;
69
+ type Type = GraphQLScalarType | GraphQLEnumType | ClassType | string | CustomTypeInput;
70
70
  export type GraphQLConnection<T> = {
71
71
  node: T;
72
72
  };
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
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 graphql_1 = require("graphql");
4
5
  const parse_1 = require("../parse_schema/parse");
5
6
  var CustomFieldType;
6
7
  (function (CustomFieldType) {
@@ -61,7 +62,10 @@ const isCustomType = (type) => {
61
62
  };
62
63
  exports.isCustomType = isCustomType;
63
64
  const isGraphQLScalarType = (type) => {
64
- return type.serialize !== undefined;
65
+ return (0, graphql_1.isScalarType)(type);
66
+ };
67
+ const isGraphQLEnumType = (type) => {
68
+ return (0, graphql_1.isEnumType)(type);
65
69
  };
66
70
  const addCustomType = async (type, gqlCapture) => {
67
71
  // TODO these should return ReadOnly objects...
@@ -81,28 +85,30 @@ const addCustomType = async (type, gqlCapture) => {
81
85
  if (type.enumMap || type.structFields) {
82
86
  await addType(type);
83
87
  }
84
- try {
85
- const r = require(type.importPath);
86
- const ct = r[type.type];
87
- // this gets us the information needed for scalars
88
- if (ct && isGraphQLScalarType(ct)) {
89
- type.scalarInfo = {
90
- description: ct.description,
91
- name: ct.name,
92
- };
93
- if (ct.specifiedByURL) {
94
- type.scalarInfo.specifiedByUrl = ct.specifiedByURL;
88
+ if (type.importPath) {
89
+ try {
90
+ const r = require(type.importPath);
91
+ const ct = r[type.type];
92
+ // this gets us the information needed for scalars
93
+ if (ct && isGraphQLScalarType(ct)) {
94
+ type.scalarInfo = {
95
+ description: ct.description,
96
+ name: ct.name,
97
+ };
98
+ if (ct.specifiedByURL) {
99
+ type.scalarInfo.specifiedByUrl = ct.specifiedByURL;
100
+ }
95
101
  }
96
102
  }
97
- }
98
- catch (e) {
99
- if (type.secondaryImportPath) {
100
- (0, exports.addCustomType)({
101
- ...type,
102
- importPath: type.secondaryImportPath,
103
- }, gqlCapture);
103
+ catch (e) {
104
+ if (type.secondaryImportPath) {
105
+ await (0, exports.addCustomType)({
106
+ ...type,
107
+ importPath: type.secondaryImportPath,
108
+ }, gqlCapture);
109
+ }
110
+ return;
104
111
  }
105
- return;
106
112
  }
107
113
  if (customType) {
108
114
  if (JSON.stringify(customType) !== JSON.stringify(type)) {
@@ -138,8 +144,9 @@ const getType = (typ, result) => {
138
144
  (0, exports.addCustomType)(typ, GQLCapture);
139
145
  return;
140
146
  }
141
- // GraphQLScalarType or ClassType
147
+ // GraphQLScalarType or GraphQLEnumType or ClassType
142
148
  result.scalarType = isGraphQLScalarType(typ);
149
+ result.enumType = isGraphQLEnumType(typ);
143
150
  result.type = typ.name;
144
151
  return;
145
152
  };
@@ -238,11 +245,13 @@ class GQLCapture {
238
245
  let scalarType = false;
239
246
  let connection;
240
247
  let type = "";
248
+ let enumType = false;
241
249
  if (field?.type) {
242
250
  let r = { type: "" };
243
251
  getType(field.type, r);
244
252
  list = r.list;
245
253
  scalarType = r.scalarType || false;
254
+ enumType = r.enumType || false;
246
255
  connection = r.connection;
247
256
  type = r.type;
248
257
  }
@@ -264,9 +273,14 @@ class GQLCapture {
264
273
  };
265
274
  // unknown type. we need to flag that this field needs to eventually be resolved
266
275
  if (!exports.knownAllowedNames.has(type)) {
276
+ // we do this so that we know how to import them later
277
+ // would be nice not to need that. seems like we should be able to do it by checking the imports for the page
267
278
  if (scalarType) {
268
279
  throw new Error(`custom scalar type ${type} is not supported this way. use CustomType syntax. see \`gqlFileUpload\` as an example`);
269
280
  }
281
+ if (enumType) {
282
+ throw new Error(`custom enum type ${type} is not supported this way. use CustomType syntax. see \`gqlFileUpload\` as an example`);
283
+ }
270
284
  result.needsResolving = true;
271
285
  }
272
286
  return result;
@@ -482,13 +496,12 @@ class GQLCapture {
482
496
  }
483
497
  });
484
498
  });
485
- // TODO this should be aware of knownCustomTypes
486
499
  const resolveFields = (fields) => {
487
500
  fields.forEach((field) => {
488
501
  // we have a check earlier that *should* make this path impossible
489
502
  field.args.forEach((arg) => {
490
503
  if (arg.needsResolving) {
491
- if (baseArgs.has(arg.type)) {
504
+ if (baseArgs.has(arg.type) || this.customTypes.has(arg.type)) {
492
505
  arg.needsResolving = false;
493
506
  }
494
507
  else {
@@ -505,7 +518,8 @@ class GQLCapture {
505
518
  if (result.needsResolving) {
506
519
  if (baseObjects.has(result.type) ||
507
520
  this.customUnions.has(result.type) ||
508
- this.customInterfaces.has(result.type)) {
521
+ this.customInterfaces.has(result.type) ||
522
+ this.customTypes.has(result.type)) {
509
523
  result.needsResolving = false;
510
524
  }
511
525
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snowtop/ent",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "snowtop ent framework",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",