@snowtop/ent 0.1.0-alpha160-test5 → 0.1.0-alpha160-test6

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 (317) hide show
  1. package/dist/package.json +64 -0
  2. package/{scripts → dist/scripts}/custom_compiler.js +0 -0
  3. package/{scripts → dist/scripts}/custom_graphql.js +0 -0
  4. package/package.json +47 -5
  5. package/src/action/action.ts +330 -0
  6. package/src/action/executor.ts +453 -0
  7. package/src/action/experimental_action.ts +277 -0
  8. package/src/action/index.ts +31 -0
  9. package/src/action/operations.ts +967 -0
  10. package/src/action/orchestrator.ts +1527 -0
  11. package/src/action/privacy.ts +37 -0
  12. package/src/action/relative_value.ts +242 -0
  13. package/src/action/transaction.ts +38 -0
  14. package/src/auth/auth.ts +77 -0
  15. package/src/auth/index.ts +8 -0
  16. package/src/core/base.ts +367 -0
  17. package/src/core/clause.ts +1065 -0
  18. package/src/core/config.ts +219 -0
  19. package/src/core/const.ts +5 -0
  20. package/src/core/context.ts +135 -0
  21. package/src/core/convert.ts +106 -0
  22. package/src/core/date.ts +23 -0
  23. package/src/core/db.ts +498 -0
  24. package/src/core/ent.ts +1740 -0
  25. package/src/core/global_schema.ts +49 -0
  26. package/src/core/loaders/assoc_count_loader.ts +99 -0
  27. package/src/core/loaders/assoc_edge_loader.ts +250 -0
  28. package/src/core/loaders/index.ts +12 -0
  29. package/src/core/loaders/loader.ts +66 -0
  30. package/src/core/loaders/object_loader.ts +489 -0
  31. package/src/core/loaders/query_loader.ts +314 -0
  32. package/src/core/loaders/raw_count_loader.ts +175 -0
  33. package/src/core/logger.ts +49 -0
  34. package/src/core/privacy.ts +660 -0
  35. package/src/core/query/assoc_query.ts +240 -0
  36. package/src/core/query/custom_clause_query.ts +174 -0
  37. package/src/core/query/custom_query.ts +302 -0
  38. package/src/core/query/index.ts +9 -0
  39. package/src/core/query/query.ts +674 -0
  40. package/src/core/query_impl.ts +32 -0
  41. package/src/core/viewer.ts +52 -0
  42. package/src/ent.code-workspace +73 -0
  43. package/src/graphql/builtins/connection.ts +25 -0
  44. package/src/graphql/builtins/edge.ts +16 -0
  45. package/src/graphql/builtins/node.ts +12 -0
  46. package/src/graphql/graphql.ts +891 -0
  47. package/src/graphql/graphql_field_helpers.ts +221 -0
  48. package/src/graphql/index.ts +42 -0
  49. package/src/graphql/mutations/union.ts +39 -0
  50. package/src/graphql/node_resolver.ts +122 -0
  51. package/src/graphql/query/connection_type.ts +113 -0
  52. package/src/graphql/query/edge_connection.ts +171 -0
  53. package/src/graphql/query/page_info.ts +34 -0
  54. package/src/graphql/query/shared_edge_connection.ts +287 -0
  55. package/src/graphql/scalars/orderby_direction.ts +13 -0
  56. package/src/graphql/scalars/time.ts +38 -0
  57. package/src/imports/dataz/example1/_auth.ts +51 -0
  58. package/src/imports/dataz/example1/_viewer.ts +35 -0
  59. package/src/imports/index.ts +213 -0
  60. package/src/index.ts +145 -0
  61. package/src/parse_schema/parse.ts +585 -0
  62. package/src/schema/base_schema.ts +224 -0
  63. package/src/schema/field.ts +1087 -0
  64. package/src/schema/index.ts +53 -0
  65. package/src/schema/json_field.ts +94 -0
  66. package/src/schema/schema.ts +1028 -0
  67. package/src/schema/struct_field.ts +234 -0
  68. package/src/schema/union_field.ts +105 -0
  69. package/src/scripts/custom_compiler.ts +331 -0
  70. package/src/scripts/custom_graphql.ts +550 -0
  71. package/src/scripts/migrate_v0.1.ts +41 -0
  72. package/src/scripts/move_types.ts +131 -0
  73. package/src/scripts/read_schema.ts +67 -0
  74. package/src/setupPackage.js +42 -0
  75. package/src/testutils/action/complex_schemas.ts +517 -0
  76. package/src/testutils/builder.ts +422 -0
  77. package/src/testutils/context/test_context.ts +25 -0
  78. package/src/testutils/db/fixture.ts +32 -0
  79. package/src/testutils/db/temp_db.ts +941 -0
  80. package/src/testutils/db/value.ts +294 -0
  81. package/src/testutils/db_mock.ts +351 -0
  82. package/src/testutils/db_time_zone.ts +40 -0
  83. package/src/testutils/ent-graphql-tests/index.ts +653 -0
  84. package/src/testutils/fake_comms.ts +50 -0
  85. package/src/testutils/fake_data/const.ts +64 -0
  86. package/src/testutils/fake_data/events_query.ts +145 -0
  87. package/src/testutils/fake_data/fake_contact.ts +150 -0
  88. package/src/testutils/fake_data/fake_event.ts +150 -0
  89. package/src/testutils/fake_data/fake_tag.ts +139 -0
  90. package/src/testutils/fake_data/fake_user.ts +232 -0
  91. package/src/testutils/fake_data/index.ts +1 -0
  92. package/src/testutils/fake_data/internal.ts +8 -0
  93. package/src/testutils/fake_data/tag_query.ts +56 -0
  94. package/src/testutils/fake_data/test_helpers.ts +388 -0
  95. package/src/testutils/fake_data/user_query.ts +524 -0
  96. package/src/testutils/fake_log.ts +52 -0
  97. package/src/testutils/mock_date.ts +10 -0
  98. package/src/testutils/mock_log.ts +39 -0
  99. package/src/testutils/parse_sql.ts +685 -0
  100. package/src/testutils/test_edge_global_schema.ts +49 -0
  101. package/src/testutils/write.ts +70 -0
  102. package/src/tsc/ast.ts +351 -0
  103. package/src/tsc/compilerOptions.ts +85 -0
  104. package/src/tsc/move_generated.ts +191 -0
  105. package/src/tsc/transform.ts +226 -0
  106. package/src/tsc/transform_action.ts +224 -0
  107. package/src/tsc/transform_ent.ts +66 -0
  108. package/src/tsc/transform_schema.ts +546 -0
  109. package/tsconfig.json +20 -0
  110. package/core/query/shared_assoc_test.d.ts +0 -2
  111. package/core/query/shared_assoc_test.js +0 -804
  112. package/core/query/shared_test.d.ts +0 -21
  113. package/core/query/shared_test.js +0 -736
  114. package/graphql/query/shared_assoc_test.d.ts +0 -1
  115. package/graphql/query/shared_assoc_test.js +0 -203
  116. /package/{action → dist/action}/action.d.ts +0 -0
  117. /package/{action → dist/action}/action.js +0 -0
  118. /package/{action → dist/action}/executor.d.ts +0 -0
  119. /package/{action → dist/action}/executor.js +0 -0
  120. /package/{action → dist/action}/experimental_action.d.ts +0 -0
  121. /package/{action → dist/action}/experimental_action.js +0 -0
  122. /package/{action → dist/action}/index.d.ts +0 -0
  123. /package/{action → dist/action}/index.js +0 -0
  124. /package/{action → dist/action}/operations.d.ts +0 -0
  125. /package/{action → dist/action}/operations.js +0 -0
  126. /package/{action → dist/action}/orchestrator.d.ts +0 -0
  127. /package/{action → dist/action}/orchestrator.js +0 -0
  128. /package/{action → dist/action}/privacy.d.ts +0 -0
  129. /package/{action → dist/action}/privacy.js +0 -0
  130. /package/{action → dist/action}/relative_value.d.ts +0 -0
  131. /package/{action → dist/action}/relative_value.js +0 -0
  132. /package/{action → dist/action}/transaction.d.ts +0 -0
  133. /package/{action → dist/action}/transaction.js +0 -0
  134. /package/{auth → dist/auth}/auth.d.ts +0 -0
  135. /package/{auth → dist/auth}/auth.js +0 -0
  136. /package/{auth → dist/auth}/index.d.ts +0 -0
  137. /package/{auth → dist/auth}/index.js +0 -0
  138. /package/{core → dist/core}/base.d.ts +0 -0
  139. /package/{core → dist/core}/base.js +0 -0
  140. /package/{core → dist/core}/clause.d.ts +0 -0
  141. /package/{core → dist/core}/clause.js +0 -0
  142. /package/{core → dist/core}/config.d.ts +0 -0
  143. /package/{core → dist/core}/config.js +0 -0
  144. /package/{core → dist/core}/const.d.ts +0 -0
  145. /package/{core → dist/core}/const.js +0 -0
  146. /package/{core → dist/core}/context.d.ts +0 -0
  147. /package/{core → dist/core}/context.js +0 -0
  148. /package/{core → dist/core}/convert.d.ts +0 -0
  149. /package/{core → dist/core}/convert.js +0 -0
  150. /package/{core → dist/core}/date.d.ts +0 -0
  151. /package/{core → dist/core}/date.js +0 -0
  152. /package/{core → dist/core}/db.d.ts +0 -0
  153. /package/{core → dist/core}/db.js +0 -0
  154. /package/{core → dist/core}/ent.d.ts +0 -0
  155. /package/{core → dist/core}/ent.js +0 -0
  156. /package/{core → dist/core}/global_schema.d.ts +0 -0
  157. /package/{core → dist/core}/global_schema.js +0 -0
  158. /package/{core → dist/core}/loaders/assoc_count_loader.d.ts +0 -0
  159. /package/{core → dist/core}/loaders/assoc_count_loader.js +0 -0
  160. /package/{core → dist/core}/loaders/assoc_edge_loader.d.ts +0 -0
  161. /package/{core → dist/core}/loaders/assoc_edge_loader.js +0 -0
  162. /package/{core → dist/core}/loaders/index.d.ts +0 -0
  163. /package/{core → dist/core}/loaders/index.js +0 -0
  164. /package/{core → dist/core}/loaders/loader.d.ts +0 -0
  165. /package/{core → dist/core}/loaders/loader.js +0 -0
  166. /package/{core → dist/core}/loaders/object_loader.d.ts +0 -0
  167. /package/{core → dist/core}/loaders/object_loader.js +0 -0
  168. /package/{core → dist/core}/loaders/query_loader.d.ts +0 -0
  169. /package/{core → dist/core}/loaders/query_loader.js +0 -0
  170. /package/{core → dist/core}/loaders/raw_count_loader.d.ts +0 -0
  171. /package/{core → dist/core}/loaders/raw_count_loader.js +0 -0
  172. /package/{core → dist/core}/logger.d.ts +0 -0
  173. /package/{core → dist/core}/logger.js +0 -0
  174. /package/{core → dist/core}/privacy.d.ts +0 -0
  175. /package/{core → dist/core}/privacy.js +0 -0
  176. /package/{core → dist/core}/query/assoc_query.d.ts +0 -0
  177. /package/{core → dist/core}/query/assoc_query.js +0 -0
  178. /package/{core → dist/core}/query/custom_clause_query.d.ts +0 -0
  179. /package/{core → dist/core}/query/custom_clause_query.js +0 -0
  180. /package/{core → dist/core}/query/custom_query.d.ts +0 -0
  181. /package/{core → dist/core}/query/custom_query.js +0 -0
  182. /package/{core → dist/core}/query/index.d.ts +0 -0
  183. /package/{core → dist/core}/query/index.js +0 -0
  184. /package/{core → dist/core}/query/query.d.ts +0 -0
  185. /package/{core → dist/core}/query/query.js +0 -0
  186. /package/{core → dist/core}/query_impl.d.ts +0 -0
  187. /package/{core → dist/core}/query_impl.js +0 -0
  188. /package/{core → dist/core}/viewer.d.ts +0 -0
  189. /package/{core → dist/core}/viewer.js +0 -0
  190. /package/{graphql → dist/graphql}/builtins/connection.d.ts +0 -0
  191. /package/{graphql → dist/graphql}/builtins/connection.js +0 -0
  192. /package/{graphql → dist/graphql}/builtins/edge.d.ts +0 -0
  193. /package/{graphql → dist/graphql}/builtins/edge.js +0 -0
  194. /package/{graphql → dist/graphql}/builtins/node.d.ts +0 -0
  195. /package/{graphql → dist/graphql}/builtins/node.js +0 -0
  196. /package/{graphql → dist/graphql}/graphql.d.ts +0 -0
  197. /package/{graphql → dist/graphql}/graphql.js +0 -0
  198. /package/{graphql → dist/graphql}/graphql_field_helpers.d.ts +0 -0
  199. /package/{graphql → dist/graphql}/graphql_field_helpers.js +0 -0
  200. /package/{graphql → dist/graphql}/index.d.ts +0 -0
  201. /package/{graphql → dist/graphql}/index.js +0 -0
  202. /package/{graphql → dist/graphql}/mutations/union.d.ts +0 -0
  203. /package/{graphql → dist/graphql}/mutations/union.js +0 -0
  204. /package/{graphql → dist/graphql}/node_resolver.d.ts +0 -0
  205. /package/{graphql → dist/graphql}/node_resolver.js +0 -0
  206. /package/{graphql → dist/graphql}/query/connection_type.d.ts +0 -0
  207. /package/{graphql → dist/graphql}/query/connection_type.js +0 -0
  208. /package/{graphql → dist/graphql}/query/edge_connection.d.ts +0 -0
  209. /package/{graphql → dist/graphql}/query/edge_connection.js +0 -0
  210. /package/{graphql → dist/graphql}/query/page_info.d.ts +0 -0
  211. /package/{graphql → dist/graphql}/query/page_info.js +0 -0
  212. /package/{graphql → dist/graphql}/query/shared_edge_connection.d.ts +0 -0
  213. /package/{graphql → dist/graphql}/query/shared_edge_connection.js +0 -0
  214. /package/{graphql → dist/graphql}/scalars/orderby_direction.d.ts +0 -0
  215. /package/{graphql → dist/graphql}/scalars/orderby_direction.js +0 -0
  216. /package/{graphql → dist/graphql}/scalars/time.d.ts +0 -0
  217. /package/{graphql → dist/graphql}/scalars/time.js +0 -0
  218. /package/{imports → dist/imports}/dataz/example1/_auth.d.ts +0 -0
  219. /package/{imports → dist/imports}/dataz/example1/_auth.js +0 -0
  220. /package/{imports → dist/imports}/dataz/example1/_viewer.d.ts +0 -0
  221. /package/{imports → dist/imports}/dataz/example1/_viewer.js +0 -0
  222. /package/{imports → dist/imports}/index.d.ts +0 -0
  223. /package/{imports → dist/imports}/index.js +0 -0
  224. /package/{index.d.ts → dist/index.d.ts} +0 -0
  225. /package/{index.js → dist/index.js} +0 -0
  226. /package/{parse_schema → dist/parse_schema}/parse.d.ts +0 -0
  227. /package/{parse_schema → dist/parse_schema}/parse.js +0 -0
  228. /package/{schema → dist/schema}/base_schema.d.ts +0 -0
  229. /package/{schema → dist/schema}/base_schema.js +0 -0
  230. /package/{schema → dist/schema}/field.d.ts +0 -0
  231. /package/{schema → dist/schema}/field.js +0 -0
  232. /package/{schema → dist/schema}/index.d.ts +0 -0
  233. /package/{schema → dist/schema}/index.js +0 -0
  234. /package/{schema → dist/schema}/json_field.d.ts +0 -0
  235. /package/{schema → dist/schema}/json_field.js +0 -0
  236. /package/{schema → dist/schema}/schema.d.ts +0 -0
  237. /package/{schema → dist/schema}/schema.js +0 -0
  238. /package/{schema → dist/schema}/struct_field.d.ts +0 -0
  239. /package/{schema → dist/schema}/struct_field.js +0 -0
  240. /package/{schema → dist/schema}/union_field.d.ts +0 -0
  241. /package/{schema → dist/schema}/union_field.js +0 -0
  242. /package/{scripts → dist/scripts}/custom_compiler.d.ts +0 -0
  243. /package/{scripts → dist/scripts}/custom_graphql.d.ts +0 -0
  244. /package/{scripts → dist/scripts}/migrate_v0.1.d.ts +0 -0
  245. /package/{scripts → dist/scripts}/migrate_v0.1.js +0 -0
  246. /package/{scripts → dist/scripts}/move_types.d.ts +0 -0
  247. /package/{scripts → dist/scripts}/move_types.js +0 -0
  248. /package/{scripts → dist/scripts}/read_schema.d.ts +0 -0
  249. /package/{scripts → dist/scripts}/read_schema.js +0 -0
  250. /package/{testutils → dist/testutils}/action/complex_schemas.d.ts +0 -0
  251. /package/{testutils → dist/testutils}/action/complex_schemas.js +0 -0
  252. /package/{testutils → dist/testutils}/builder.d.ts +0 -0
  253. /package/{testutils → dist/testutils}/builder.js +0 -0
  254. /package/{testutils → dist/testutils}/context/test_context.d.ts +0 -0
  255. /package/{testutils → dist/testutils}/context/test_context.js +0 -0
  256. /package/{testutils → dist/testutils}/db/fixture.d.ts +0 -0
  257. /package/{testutils → dist/testutils}/db/fixture.js +0 -0
  258. /package/{testutils → dist/testutils}/db/temp_db.d.ts +0 -0
  259. /package/{testutils → dist/testutils}/db/temp_db.js +0 -0
  260. /package/{testutils → dist/testutils}/db/value.d.ts +0 -0
  261. /package/{testutils → dist/testutils}/db/value.js +0 -0
  262. /package/{testutils → dist/testutils}/db_mock.d.ts +0 -0
  263. /package/{testutils → dist/testutils}/db_mock.js +0 -0
  264. /package/{testutils → dist/testutils}/db_time_zone.d.ts +0 -0
  265. /package/{testutils → dist/testutils}/db_time_zone.js +0 -0
  266. /package/{testutils → dist/testutils}/ent-graphql-tests/index.d.ts +0 -0
  267. /package/{testutils → dist/testutils}/ent-graphql-tests/index.js +0 -0
  268. /package/{testutils → dist/testutils}/fake_comms.d.ts +0 -0
  269. /package/{testutils → dist/testutils}/fake_comms.js +0 -0
  270. /package/{testutils → dist/testutils}/fake_data/const.d.ts +0 -0
  271. /package/{testutils → dist/testutils}/fake_data/const.js +0 -0
  272. /package/{testutils → dist/testutils}/fake_data/events_query.d.ts +0 -0
  273. /package/{testutils → dist/testutils}/fake_data/events_query.js +0 -0
  274. /package/{testutils → dist/testutils}/fake_data/fake_contact.d.ts +0 -0
  275. /package/{testutils → dist/testutils}/fake_data/fake_contact.js +0 -0
  276. /package/{testutils → dist/testutils}/fake_data/fake_event.d.ts +0 -0
  277. /package/{testutils → dist/testutils}/fake_data/fake_event.js +0 -0
  278. /package/{testutils → dist/testutils}/fake_data/fake_tag.d.ts +0 -0
  279. /package/{testutils → dist/testutils}/fake_data/fake_tag.js +0 -0
  280. /package/{testutils → dist/testutils}/fake_data/fake_user.d.ts +0 -0
  281. /package/{testutils → dist/testutils}/fake_data/fake_user.js +0 -0
  282. /package/{testutils → dist/testutils}/fake_data/index.d.ts +0 -0
  283. /package/{testutils → dist/testutils}/fake_data/index.js +0 -0
  284. /package/{testutils → dist/testutils}/fake_data/internal.d.ts +0 -0
  285. /package/{testutils → dist/testutils}/fake_data/internal.js +0 -0
  286. /package/{testutils → dist/testutils}/fake_data/tag_query.d.ts +0 -0
  287. /package/{testutils → dist/testutils}/fake_data/tag_query.js +0 -0
  288. /package/{testutils → dist/testutils}/fake_data/test_helpers.d.ts +0 -0
  289. /package/{testutils → dist/testutils}/fake_data/test_helpers.js +0 -0
  290. /package/{testutils → dist/testutils}/fake_data/user_query.d.ts +0 -0
  291. /package/{testutils → dist/testutils}/fake_data/user_query.js +0 -0
  292. /package/{testutils → dist/testutils}/fake_log.d.ts +0 -0
  293. /package/{testutils → dist/testutils}/fake_log.js +0 -0
  294. /package/{testutils → dist/testutils}/mock_date.d.ts +0 -0
  295. /package/{testutils → dist/testutils}/mock_date.js +0 -0
  296. /package/{testutils → dist/testutils}/mock_log.d.ts +0 -0
  297. /package/{testutils → dist/testutils}/mock_log.js +0 -0
  298. /package/{testutils → dist/testutils}/parse_sql.d.ts +0 -0
  299. /package/{testutils → dist/testutils}/parse_sql.js +0 -0
  300. /package/{testutils → dist/testutils}/test_edge_global_schema.d.ts +0 -0
  301. /package/{testutils → dist/testutils}/test_edge_global_schema.js +0 -0
  302. /package/{testutils → dist/testutils}/write.d.ts +0 -0
  303. /package/{testutils → dist/testutils}/write.js +0 -0
  304. /package/{tsc → dist/tsc}/ast.d.ts +0 -0
  305. /package/{tsc → dist/tsc}/ast.js +0 -0
  306. /package/{tsc → dist/tsc}/compilerOptions.d.ts +0 -0
  307. /package/{tsc → dist/tsc}/compilerOptions.js +0 -0
  308. /package/{tsc → dist/tsc}/move_generated.d.ts +0 -0
  309. /package/{tsc → dist/tsc}/move_generated.js +0 -0
  310. /package/{tsc → dist/tsc}/transform.d.ts +0 -0
  311. /package/{tsc → dist/tsc}/transform.js +0 -0
  312. /package/{tsc → dist/tsc}/transform_action.d.ts +0 -0
  313. /package/{tsc → dist/tsc}/transform_action.js +0 -0
  314. /package/{tsc → dist/tsc}/transform_ent.d.ts +0 -0
  315. /package/{tsc → dist/tsc}/transform_ent.js +0 -0
  316. /package/{tsc → dist/tsc}/transform_schema.d.ts +0 -0
  317. /package/{tsc → dist/tsc}/transform_schema.js +0 -0
@@ -0,0 +1,891 @@
1
+ import { GraphQLScalarType } from "graphql";
2
+ import { Data } from "../core/base";
3
+ import type { FieldMap } from "../schema";
4
+ import {
5
+ processFields,
6
+ ProcessedField as ParsedProcessedField,
7
+ } from "../parse_schema/parse";
8
+ import { ImportPath } from "../schema/schema";
9
+
10
+ interface ClassType<T = any> {
11
+ new (...args: any[]): T;
12
+ }
13
+
14
+ declare type StringToStringMap = {
15
+ [key: string]: string;
16
+ };
17
+
18
+ interface CustomFieldInput {
19
+ graphQLName?: string;
20
+ name?: string;
21
+ functionName?: string;
22
+ args?: Field[];
23
+ results?: Field[];
24
+ fieldType: CustomFieldTypeInput;
25
+ description?: string;
26
+ }
27
+
28
+ interface CustomTopLevelInput {
29
+ class?: string; // for inline fields, it's empty
30
+ graphQLName?: string;
31
+ name?: string;
32
+ functionName?: string;
33
+ edgeName?: string;
34
+ args?: Field[];
35
+ results?: Field[];
36
+ extraImports?: ImportPath[];
37
+ functionContents?: string;
38
+ fieldType: CustomFieldTypeInput;
39
+ description?: string;
40
+ list?: boolean;
41
+ connection?: boolean;
42
+ resultType?: string;
43
+ }
44
+
45
+ type CustomFieldInputMap = {
46
+ [key: string]: CustomFieldInput[];
47
+ };
48
+
49
+ type CustomTypeInputMap = {
50
+ [key: string]: CustomTypeInput;
51
+ };
52
+
53
+ interface CustomObjectInput {
54
+ name: string;
55
+ graphQLName?: string;
56
+ fields?: CustomFieldInput[];
57
+ }
58
+
59
+ export interface CustomGraphQLInput {
60
+ fields?: CustomFieldInputMap;
61
+ inputs?: CustomObjectInput[];
62
+ objects?: CustomObjectInput[];
63
+ args?: CustomObjectInput[];
64
+ queries?: CustomTopLevelInput[];
65
+ mutations?: CustomTopLevelInput[];
66
+ customTypes?: CustomTypeInputMap;
67
+ }
68
+
69
+ export interface CustomTypeInput {
70
+ type: string;
71
+ importPath: string;
72
+ tsType?: string;
73
+ tsImportPath?: string;
74
+ enumMap?: StringToStringMap;
75
+ // create a struct type here...
76
+ structFields?: FieldMap;
77
+
78
+ // if enumMap or structField
79
+ // are we creating an inputType or output type
80
+ // determines where file is located and for the struct type, determines if GraphQLInputObjectType or GraphQLObjectType
81
+ inputType?: boolean;
82
+ [x: string]: any;
83
+ }
84
+
85
+ export type CustomType = Omit<CustomTypeInput, "structFields"> & {
86
+ structFields?: ParsedProcessedField[];
87
+ };
88
+
89
+ // scalars or classes
90
+ // string for GraphQL name in situation where we can't load the object
91
+ // e.g. User, Contact etc
92
+ // CustomType for types that are not in "graphql" and we need to know where to load it from...
93
+ type Type = GraphQLScalarType | ClassType | string | CustomTypeInput;
94
+
95
+ // node in a connection
96
+ export type GraphQLConnection<T> = { node: T };
97
+
98
+ interface gqlFieldOptionsBase {
99
+ name?: string;
100
+ nullable?: boolean | NullableListOptions;
101
+ description?: string;
102
+ type?: Type | Array<Type> | GraphQLConnection<Type>; // types or lists of types
103
+ }
104
+
105
+ interface gqlFieldArg extends Omit<gqlFieldOptionsBase, "name"> {
106
+ isContextArg?: boolean;
107
+ name: string;
108
+ }
109
+
110
+ export interface gqlFieldOptions extends gqlFieldOptionsBase {
111
+ class: string;
112
+
113
+ args?: gqlFieldArg[];
114
+ async?: boolean;
115
+
116
+ // required for @gqlField
117
+ type: NonNullable<gqlFieldOptionsBase["type"]>;
118
+ }
119
+
120
+ export interface gqlObjectOptions {
121
+ name?: string;
122
+ description?: string;
123
+ }
124
+
125
+ export interface gqlObjectWithInterfaceOptions extends gqlObjectOptions {
126
+ interfaces?: string[];
127
+ }
128
+
129
+ export interface gqlObjectWithUnionOptions extends gqlObjectOptions {
130
+ unionTypes: string[];
131
+ }
132
+
133
+ type gqlMutationOptions = Omit<gqlFieldOptions, "nullable" | "type"> & {
134
+ type?: gqlFieldOptionsBase["type"];
135
+ };
136
+
137
+ // nullable allowed in query. why was it previously not allowed??
138
+ type gqlQueryOptions = gqlFieldOptions;
139
+
140
+ export enum CustomFieldType {
141
+ Accessor = "ACCESSOR",
142
+ Field = "FIELD",
143
+ Function = "FUNCTION",
144
+ AsyncFunction = "ASYNC_FUNCTION",
145
+ }
146
+
147
+ export type CustomFieldTypeInput =
148
+ | "ACCESSOR"
149
+ | "FIELD"
150
+ | "FUNCTION"
151
+ | "ASYNC_FUNCTION";
152
+
153
+ interface CustomFieldImpl {
154
+ nodeName: string;
155
+ gqlName: string;
156
+ functionName: string; // accessorName (not necessarily a function)
157
+ // need enum type for accessor/function/etc so we can build generated code
158
+ importPath?: string;
159
+ fieldType: CustomFieldType;
160
+ description?: string;
161
+ }
162
+
163
+ export interface CustomField extends CustomFieldImpl {
164
+ args: Field[];
165
+ results: Field[];
166
+ extraImports?: ImportPath[]; // defined on server
167
+ functionContents?: string; // used in dynamic
168
+ // used by graphql connections e.g. if you a field `foo_connection`, you can specify the edge name here as `foo` so the generated
169
+ // connection is RootToFooConnectionType instead of RootToFooConnectionConnectionType
170
+ // mostly API bloat though but all of this can be changed eventually.
171
+ edgeName?: string;
172
+ }
173
+
174
+ export interface CustomMutation extends CustomField {}
175
+ export interface CustomQuery extends CustomField {}
176
+
177
+ export interface ProcessedCustomField extends CustomFieldImpl {
178
+ args: ProcessedField[];
179
+ results: ProcessedField[];
180
+ }
181
+
182
+ export type ProcessCustomFieldMap = {
183
+ [key: string]: ProcessedCustomField[];
184
+ };
185
+
186
+ export interface CustomObject {
187
+ nodeName: string;
188
+ className: string; // TODO both of these 2 the same right now
189
+ description?: string;
190
+ interfaces?: string[];
191
+ unionTypes?: string[];
192
+ }
193
+
194
+ type NullableListOptions = "contents" | "contentsAndList";
195
+
196
+ interface FieldImpl {
197
+ type: string; // TODO
198
+ tsType?: string; // TODO make this required...
199
+ importPath?: string;
200
+ needsResolving?: boolean; // unknown type that we need to resolve eventually
201
+ list?: boolean;
202
+ connection?: boolean;
203
+ name: string;
204
+ }
205
+
206
+ export interface Field extends FieldImpl {
207
+ // if a list and nullable
208
+ // list itself is nullable
209
+ // if a list and items are nullable, list is not nullable but list contains nullable items
210
+ // if a list and both are nullable, both contents and list itself nullable
211
+ nullable?: boolean | NullableListOptions;
212
+ isContextArg?: boolean;
213
+ }
214
+
215
+ export interface ProcessedField extends FieldImpl {
216
+ nullable?: NullableResult;
217
+ isContextArg?: boolean;
218
+ }
219
+
220
+ enum NullableResult {
221
+ CONTENTS = "contents",
222
+ CONTENTS_AND_LIST = "contentsAndList",
223
+ ITEM = "true", // nullable = true
224
+ }
225
+
226
+ export const knownAllowedNames: Map<string, string> = new Map([
227
+ ["Date", "Date"],
228
+ ["Boolean", "boolean"],
229
+ ["Number", "number"],
230
+ ["String", "string"],
231
+ // TODO not right to have this and Number
232
+ ["Int", "number"],
233
+ ["Float", "number"],
234
+ ["ID", "ID"],
235
+ ["JSON", "any"],
236
+ ["Node", "Ent"],
237
+ ]);
238
+
239
+ export const knownDisAllowedNames: Map<string, boolean> = new Map([
240
+ ["Function", true],
241
+ ["Object", true],
242
+ ["Array", true],
243
+ ["Promise", true],
244
+ ]);
245
+
246
+ export const knownInterfaces: Map<string, boolean> = new Map([
247
+ ["Node", true],
248
+ ["Edge", true],
249
+ ["Connection", true],
250
+ ]);
251
+
252
+ const isArray = (type: Type | Array<Type>): type is Array<Type> => {
253
+ if (typeof type === "function") {
254
+ return false;
255
+ }
256
+ return (type as Array<Type>).push !== undefined;
257
+ };
258
+
259
+ const isConnection = (
260
+ type: Type | Array<Type> | GraphQLConnection<Type>,
261
+ ): type is GraphQLConnection<Type> => {
262
+ if (typeof type !== "object") {
263
+ return false;
264
+ }
265
+ return (type as GraphQLConnection<Type>).node !== undefined;
266
+ };
267
+
268
+ const isString = (type: Type | Array<Type>): type is string => {
269
+ if ((type as string).lastIndexOf !== undefined) {
270
+ return true;
271
+ }
272
+ return false;
273
+ };
274
+
275
+ export const isCustomType = (type: Type): type is CustomTypeInput => {
276
+ return (type as CustomTypeInput).importPath !== undefined;
277
+ };
278
+
279
+ const isGraphQLScalarType = (type: Type): type is GraphQLScalarType => {
280
+ return (type as GraphQLScalarType).serialize !== undefined;
281
+ };
282
+
283
+ export const addCustomType = async (
284
+ type: CustomTypeInput,
285
+ gqlCapture: typeof GQLCapture,
286
+ ) => {
287
+ // TODO these should return ReadOnly objects...
288
+ const customTypes = gqlCapture.getCustomTypes();
289
+ const customType = customTypes.get(type.type);
290
+
291
+ if (customType && customType === type) {
292
+ return;
293
+ }
294
+
295
+ const addType = async (type: CustomTypeInput) => {
296
+ // @ts-expect-error
297
+ const typ2: CustomType = { ...type };
298
+ if (type.structFields) {
299
+ typ2.structFields = await processFields(type.structFields);
300
+ }
301
+ customTypes.set(type.type, typ2);
302
+ };
303
+
304
+ if (type.enumMap || type.structFields) {
305
+ await addType(type);
306
+ }
307
+ try {
308
+ const r = require(type.importPath);
309
+ const ct = r[type.type];
310
+ // this gets us the information needed for scalars
311
+ if (ct && isGraphQLScalarType(ct)) {
312
+ type.scalarInfo = {
313
+ description: ct.description,
314
+ name: ct.name,
315
+ };
316
+ if (ct.specifiedByURL) {
317
+ type.scalarInfo.specifiedByUrl = ct.specifiedByURL;
318
+ }
319
+ }
320
+ } catch (e) {
321
+ if (type.secondaryImportPath) {
322
+ addCustomType(
323
+ {
324
+ ...type,
325
+ importPath: type.secondaryImportPath,
326
+ },
327
+ gqlCapture,
328
+ );
329
+ }
330
+ return;
331
+ }
332
+
333
+ if (customType) {
334
+ if (JSON.stringify(customType) !== JSON.stringify(type)) {
335
+ throw new Error(`cannot add multiple custom types of name ${type.type}`);
336
+ }
337
+ return;
338
+ }
339
+ await addType(type);
340
+ };
341
+
342
+ interface typeInfo {
343
+ list?: boolean | undefined;
344
+ scalarType?: boolean;
345
+ connection?: boolean | undefined;
346
+ type: string;
347
+ }
348
+
349
+ const getType = (
350
+ typ: Type | Array<Type> | GraphQLConnection<Type>,
351
+ result: typeInfo,
352
+ ): undefined => {
353
+ if (isConnection(typ)) {
354
+ result.connection = true;
355
+ return getType(typ.node, result);
356
+ }
357
+
358
+ if (isArray(typ)) {
359
+ result.list = true;
360
+ return getType(typ[0], result);
361
+ }
362
+
363
+ if (isString(typ)) {
364
+ if (typ.lastIndexOf("]") !== -1) {
365
+ result.list = true;
366
+ result.type = typ.substr(1, typ.length - 2);
367
+ } else {
368
+ result.type = typ;
369
+ }
370
+ return;
371
+ }
372
+ if (isCustomType(typ)) {
373
+ result.type = typ.type;
374
+ // TODO???
375
+ addCustomType(typ, GQLCapture);
376
+ return;
377
+ }
378
+ // GraphQLScalarType or ClassType
379
+ result.scalarType = isGraphQLScalarType(typ);
380
+ result.type = typ.name;
381
+ return;
382
+ };
383
+
384
+ export class GQLCapture {
385
+ private static enabled = false;
386
+
387
+ static enable(enabled: boolean) {
388
+ this.enabled = enabled;
389
+ }
390
+
391
+ static isEnabled(): boolean {
392
+ return this.enabled;
393
+ }
394
+
395
+ // map from class name to fields
396
+ private static customFields: Map<string, CustomField[]> = new Map();
397
+ private static customQueries: CustomQuery[] = [];
398
+ private static customMutations: CustomMutation[] = [];
399
+ private static customArgs: Map<string, CustomObject> = new Map();
400
+ private static customInputObjects: Map<string, CustomObject> = new Map();
401
+ private static customObjects: Map<string, CustomObject> = new Map();
402
+ private static customInterfaces: Map<string, CustomObject> = new Map();
403
+ private static customUnions: Map<string, CustomObject> = new Map();
404
+ private static customTypes: Map<string, CustomType> = new Map();
405
+
406
+ static clear(): void {
407
+ this.customFields.clear();
408
+ this.customQueries = [];
409
+ this.customMutations = [];
410
+ this.customArgs.clear();
411
+ this.customInputObjects.clear();
412
+ this.customObjects.clear();
413
+ this.customInterfaces.clear();
414
+ this.customUnions.clear();
415
+ this.customTypes.clear();
416
+ }
417
+
418
+ static getCustomFields(): Map<string, CustomField[]> {
419
+ return this.customFields;
420
+ }
421
+
422
+ static getCustomMutations(): CustomMutation[] {
423
+ return this.customMutations;
424
+ }
425
+
426
+ static getCustomQueries(): CustomQuery[] {
427
+ return this.customQueries;
428
+ }
429
+
430
+ static getCustomArgs(): Map<string, CustomObject> {
431
+ return this.customArgs;
432
+ }
433
+
434
+ static getCustomInputObjects(): Map<string, CustomObject> {
435
+ return this.customInputObjects;
436
+ }
437
+
438
+ static getCustomObjects(): Map<string, CustomObject> {
439
+ return this.customObjects;
440
+ }
441
+
442
+ static getCustomInterfaces(): Map<string, CustomObject> {
443
+ return this.customInterfaces;
444
+ }
445
+
446
+ static getCustomUnions(): Map<string, CustomObject> {
447
+ return this.customUnions;
448
+ }
449
+
450
+ static getCustomTypes(): Map<string, CustomType> {
451
+ return this.customTypes;
452
+ }
453
+
454
+ private static getNullableArg(fd: Field): ProcessedField {
455
+ let res: ProcessedField = fd as ProcessedField;
456
+ if (fd.nullable === undefined) {
457
+ return res;
458
+ }
459
+ if (fd.nullable === "contents") {
460
+ res.nullable = NullableResult.CONTENTS;
461
+ } else if (fd.nullable === "contentsAndList") {
462
+ res.nullable = NullableResult.CONTENTS_AND_LIST;
463
+ } else {
464
+ res.nullable = NullableResult.ITEM;
465
+ }
466
+ return res;
467
+ }
468
+
469
+ static getProcessedCustomFields(): ProcessCustomFieldMap {
470
+ let result: Data = {};
471
+ for (const [key, value] of this.customFields) {
472
+ result[key] = this.getProcessedCustomFieldsImpl(value);
473
+ }
474
+ return result;
475
+ }
476
+
477
+ static getProcessedCustomMutations(): ProcessedCustomField[] {
478
+ return this.getProcessedCustomFieldsImpl(this.customMutations);
479
+ }
480
+
481
+ static getProcessedCustomQueries(): ProcessedCustomField[] {
482
+ return this.getProcessedCustomFieldsImpl(this.customQueries);
483
+ }
484
+
485
+ private static getProcessedCustomFieldsImpl(
486
+ customFields: CustomField[],
487
+ ): ProcessedCustomField[] {
488
+ return customFields.map((field) => {
489
+ let res: ProcessedCustomField = field as ProcessedCustomField;
490
+ res.args = field.args.map((arg) => {
491
+ return this.getNullableArg(arg);
492
+ });
493
+ res.results = field.results.map((result) => {
494
+ return this.getNullableArg(result);
495
+ });
496
+ return res;
497
+ });
498
+ }
499
+
500
+ private static getField(field: gqlFieldOptionsBase | gqlFieldArg): Field {
501
+ let list: boolean | undefined;
502
+ let scalarType = false;
503
+ let connection: boolean | undefined;
504
+ let type = "";
505
+
506
+ if (field?.type) {
507
+ let r: typeInfo = { type: "" };
508
+ getType(field.type, r);
509
+ list = r.list;
510
+ scalarType = r.scalarType || false;
511
+ connection = r.connection;
512
+ type = r.type;
513
+ }
514
+
515
+ if (!type) {
516
+ throw new Error(`type is required for accessor/function/property`);
517
+ }
518
+ if (knownDisAllowedNames.has(type)) {
519
+ throw new Error(
520
+ `${type} isn't a valid type for accessor/function/property`,
521
+ );
522
+ }
523
+
524
+ let result: Field = {
525
+ name: field?.name || "",
526
+ type: type,
527
+ tsType: knownAllowedNames.get(type) || this.customTypes.get(type)?.tsType,
528
+ nullable: field?.nullable,
529
+ list: list,
530
+ connection: connection,
531
+ // @ts-ignore
532
+ isContextArg: field?.isContextArg,
533
+ };
534
+
535
+ // unknown type. we need to flag that this field needs to eventually be resolved
536
+ if (!knownAllowedNames.has(type)) {
537
+ if (scalarType) {
538
+ throw new Error(
539
+ `custom scalar type ${type} is not supported this way. use CustomType syntax. see \`gqlFileUpload\` as an example`,
540
+ );
541
+ }
542
+ result.needsResolving = true;
543
+ }
544
+ return result;
545
+ }
546
+
547
+ static gqlField(options: gqlFieldOptions): any {
548
+ return function (
549
+ _target: any,
550
+ ctx:
551
+ | ClassMethodDecoratorContext
552
+ | ClassFieldDecoratorContext
553
+ | ClassGetterDecoratorContext,
554
+ ) {
555
+ if (
556
+ !GQLCapture.isEnabled() ||
557
+ (ctx.kind !== "method" &&
558
+ ctx.kind !== "field" &&
559
+ ctx.kind !== "getter") ||
560
+ ctx.static ||
561
+ ctx.private
562
+ ) {
563
+ return;
564
+ }
565
+
566
+ let customField = GQLCapture.getCustomField(ctx, options);
567
+ if (!customField) {
568
+ return;
569
+ }
570
+ const connections = customField.results.filter(
571
+ (result) => result.connection,
572
+ );
573
+ if (connections.length > 1) {
574
+ throw new Error(`if using a connection, need to only return one item`);
575
+ }
576
+ if (connections.length === 1) {
577
+ const conn = connections[0];
578
+ if (conn.list) {
579
+ throw new Error("GraphQLConnection result cannot be a list");
580
+ }
581
+ if (conn.nullable) {
582
+ throw new Error("GraphQLConnection result cannot be nullable");
583
+ }
584
+ if (conn.isContextArg) {
585
+ throw new Error("GraphQLConnection result cannot be contextArg");
586
+ }
587
+
588
+ if (customField.fieldType === CustomFieldType.AsyncFunction) {
589
+ throw new Error(
590
+ `async function not currently supported for GraphQLConnection`,
591
+ );
592
+ }
593
+ }
594
+ let list = GQLCapture.customFields.get(customField.nodeName);
595
+ if (list === undefined) {
596
+ list = [];
597
+ }
598
+ list.push(customField);
599
+ GQLCapture.customFields.set(customField.nodeName, list);
600
+ };
601
+ }
602
+
603
+ private static getCustomField(
604
+ ctx:
605
+ | ClassMethodDecoratorContext
606
+ | ClassFieldDecoratorContext
607
+ | ClassGetterDecoratorContext,
608
+ options: gqlFieldOptions | gqlMutationOptions | gqlQueryOptions,
609
+ allowNoReturnType?: boolean,
610
+ ): CustomField {
611
+ let fieldType: CustomFieldType;
612
+
613
+ let args: Field[] = [];
614
+ let results: Field[] = [];
615
+
616
+ switch (ctx.kind) {
617
+ case "method":
618
+ fieldType = CustomFieldType.Function;
619
+ if (options.async) {
620
+ fieldType = CustomFieldType.AsyncFunction;
621
+ }
622
+ break;
623
+
624
+ case "field":
625
+ fieldType = CustomFieldType.Field;
626
+ break;
627
+
628
+ case "getter":
629
+ fieldType = CustomFieldType.Accessor;
630
+ break;
631
+ }
632
+
633
+ if (!allowNoReturnType && !options.type) {
634
+ throw new Error(`type is required for ${fieldType}`);
635
+ }
636
+ if (options.type) {
637
+ // override name property passed down so we return '' as name
638
+ results.push(GQLCapture.getField({ ...options, name: "" }));
639
+ }
640
+
641
+ if (options.args?.length) {
642
+ options.args.forEach((arg) => {
643
+ args.push(GQLCapture.getField(arg));
644
+ });
645
+ }
646
+
647
+ return {
648
+ nodeName: options.class,
649
+ gqlName: options?.name || ctx.name.toString(),
650
+ functionName: ctx.name.toString(),
651
+ args: args,
652
+ results: results,
653
+ fieldType: fieldType!,
654
+ description: options?.description,
655
+ };
656
+ }
657
+
658
+ static gqlContextType(): gqlFieldArg {
659
+ return {
660
+ name: "context",
661
+ isContextArg: true,
662
+ type: "Context",
663
+ };
664
+ }
665
+
666
+ static gqlArgType(options?: gqlObjectOptions): any {
667
+ return function (target: any, ctx: ClassDecoratorContext): void {
668
+ return GQLCapture.customGQLObject(ctx, GQLCapture.customArgs, options);
669
+ };
670
+ }
671
+
672
+ static gqlInputObjectType(options?: gqlObjectOptions): any {
673
+ return function (target: any, ctx: ClassDecoratorContext): void {
674
+ return GQLCapture.customGQLObject(
675
+ ctx,
676
+ GQLCapture.customInputObjects,
677
+ options,
678
+ );
679
+ };
680
+ }
681
+
682
+ static gqlObjectType(options?: gqlObjectWithInterfaceOptions): any {
683
+ return function (target: any, ctx: ClassDecoratorContext): void {
684
+ return GQLCapture.customGQLObject(ctx, GQLCapture.customObjects, options);
685
+ };
686
+ }
687
+
688
+ static gqlUnionType(options: gqlObjectWithUnionOptions): any {
689
+ return function (target: any, ctx: ClassDecoratorContext): void {
690
+ return GQLCapture.customGQLObject(ctx, GQLCapture.customUnions, options);
691
+ };
692
+ }
693
+
694
+ static gqlInterfaceType(options?: gqlObjectOptions): any {
695
+ return function (target: any, ctx: ClassDecoratorContext): void {
696
+ return GQLCapture.customGQLObject(
697
+ ctx,
698
+ GQLCapture.customInterfaces,
699
+ options,
700
+ );
701
+ };
702
+ }
703
+
704
+ private static customGQLObject(
705
+ ctx: ClassDecoratorContext,
706
+ map: Map<string, CustomObject>,
707
+ options?: gqlObjectWithInterfaceOptions | gqlObjectWithUnionOptions,
708
+ ) {
709
+ if (!GQLCapture.isEnabled() || ctx.kind !== "class" || !ctx.name) {
710
+ return;
711
+ }
712
+
713
+ let className = ctx.name.toString();
714
+ let nodeName = options?.name || className;
715
+
716
+ map.set(className, {
717
+ className,
718
+ nodeName,
719
+ description: options?.description,
720
+ // @ts-ignore
721
+ interfaces: options?.interfaces,
722
+ // @ts-ignore
723
+ unionTypes: options?.unionTypes,
724
+ });
725
+ }
726
+
727
+ // we want to specify args if any, name, response if any
728
+ static gqlQuery(options: gqlQueryOptions): any {
729
+ return function (target: Function, ctx: ClassMethodDecoratorContext): void {
730
+ if (!GQLCapture.isEnabled()) {
731
+ return;
732
+ }
733
+
734
+ GQLCapture.customQueries.push(GQLCapture.getCustomField(ctx, options));
735
+ };
736
+ }
737
+
738
+ static gqlMutation(options: gqlMutationOptions): any {
739
+ return function (target: Function, ctx: ClassMethodDecoratorContext): void {
740
+ if (!GQLCapture.isEnabled()) {
741
+ return;
742
+ }
743
+
744
+ GQLCapture.customMutations.push(
745
+ GQLCapture.getCustomField(ctx, options, true),
746
+ );
747
+ };
748
+ }
749
+
750
+ static gqlConnection(type: Type): any {
751
+ return {
752
+ node: type,
753
+ };
754
+ }
755
+
756
+ static resolve(objects: string[]): void {
757
+ let baseObjects = new Map<string, boolean>();
758
+ objects.forEach((object) => baseObjects.set(object, true));
759
+
760
+ this.customObjects.forEach((obj, key) => {
761
+ baseObjects.set(key, true);
762
+
763
+ obj.interfaces?.forEach((interfaceName) => {
764
+ const inter = this.customInterfaces.get(interfaceName);
765
+ if (inter) {
766
+ const fields = this.customFields.get(inter.nodeName);
767
+ if (fields) {
768
+ // check for duplicate fields
769
+ // if field is already defined no need to add it
770
+ let objFields = this.customFields.get(obj.nodeName);
771
+ if (!objFields) {
772
+ objFields = [];
773
+ }
774
+ let map = new Map();
775
+ for (const f of objFields) {
776
+ map.set(f.gqlName, f);
777
+ }
778
+ for (const field of fields) {
779
+ const newField = {
780
+ ...field,
781
+ nodeName: obj.nodeName,
782
+ };
783
+ if (map.has(field.gqlName)) {
784
+ const existing = map.get(field.gqlName)!;
785
+ if (JSON.stringify(existing) !== JSON.stringify(newField)) {
786
+ throw new Error(
787
+ `object ${obj.nodeName} has duplicate field ${field.gqlName} with different definition`,
788
+ );
789
+ }
790
+ continue;
791
+ }
792
+ objFields.push(newField);
793
+ }
794
+ this.customFields.set(obj.nodeName, objFields);
795
+ }
796
+ } else if (!knownInterfaces.has(interfaceName)) {
797
+ throw new Error(
798
+ `object ${key} references unknown interface ${interfaceName}`,
799
+ );
800
+ }
801
+ });
802
+ });
803
+
804
+ let baseArgs = new Map<string, boolean>();
805
+ this.customArgs.forEach((_val, key) => baseArgs.set(key, true));
806
+ this.customInputObjects.forEach((_val, key) => baseArgs.set(key, true));
807
+ baseArgs.set("Context", true);
808
+ this.customTypes.forEach((_val, key) => baseArgs.set(key, true));
809
+
810
+ this.customUnions.forEach((val, key) => {
811
+ if (this.customFields.has(key)) {
812
+ throw new Error(`union ${key} has custom fields which is not allowed`);
813
+ }
814
+
815
+ val.unionTypes?.forEach((typ) => {
816
+ if (!baseObjects.has(typ)) {
817
+ throw new Error(
818
+ `union ${key} references ${typ} which isn't a graphql object`,
819
+ );
820
+ }
821
+ });
822
+ });
823
+
824
+ // TODO this should be aware of knownCustomTypes
825
+ const resolveFields = (fields: CustomField[]) => {
826
+ fields.forEach((field) => {
827
+ // we have a check earlier that *should* make this path impossible
828
+ field.args.forEach((arg) => {
829
+ if (arg.needsResolving) {
830
+ if (baseArgs.has(arg.type)) {
831
+ arg.needsResolving = false;
832
+ } else {
833
+ throw new Error(
834
+ `arg ${arg.name} of field ${field.functionName} needs resolving. should not be possible`,
835
+ );
836
+ }
837
+ }
838
+ });
839
+ // fields are not because we can return existing ents and we want to run the capturing
840
+ // in parallel with the codegen gathering step so we resolve at the end to make
841
+ // sure there's no dangling objects
842
+ // TODO when we have other objects, we may need to change the logic here
843
+ // but i don't think it applies
844
+ field.results.forEach((result) => {
845
+ if (result.needsResolving) {
846
+ if (
847
+ baseObjects.has(result.type) ||
848
+ this.customUnions.has(result.type) ||
849
+ this.customInterfaces.has(result.type)
850
+ ) {
851
+ result.needsResolving = false;
852
+ } else {
853
+ throw new Error(
854
+ `field ${field.functionName} references ${result.type} which isn't a graphql object`,
855
+ );
856
+ }
857
+ }
858
+ });
859
+ });
860
+ };
861
+ GQLCapture.customFields.forEach((customFields) =>
862
+ resolveFields(customFields),
863
+ );
864
+ resolveFields(GQLCapture.customQueries);
865
+ resolveFields(GQLCapture.customMutations);
866
+ }
867
+ }
868
+
869
+ // why is this a static class lol?
870
+ // TODO make all these just plain functions
871
+ export const gqlField = GQLCapture.gqlField;
872
+
873
+ export const gqlArgType = GQLCapture.gqlArgType;
874
+ export const gqlInputObjectType = GQLCapture.gqlInputObjectType;
875
+ export const gqlObjectType = GQLCapture.gqlObjectType;
876
+ export const gqlInterfaceType = GQLCapture.gqlInterfaceType;
877
+ export const gqlUnionType = GQLCapture.gqlUnionType;
878
+ export const gqlQuery = GQLCapture.gqlQuery;
879
+ export const gqlMutation = GQLCapture.gqlMutation;
880
+ export const gqlContextType = GQLCapture.gqlContextType;
881
+ export const gqlConnection = GQLCapture.gqlConnection;
882
+
883
+ // this requires the developer to npm-install "graphql-upload on their own"
884
+ const gqlFileUpload: CustomTypeInput = {
885
+ type: "GraphQLUpload",
886
+ importPath: "graphql-upload",
887
+ tsType: "FileUpload",
888
+ tsImportPath: "graphql-upload",
889
+ };
890
+
891
+ export { gqlFileUpload };