@graphitation/supermassive 0.1.3 → 0.4.1

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 (193) hide show
  1. package/CHANGELOG.md +34 -2
  2. package/NOTICE +27 -0
  3. package/README.md +264 -2
  4. package/bin/supermassive.js +7 -0
  5. package/lib/{src/ast → ast}/TypedAST.d.ts +2 -0
  6. package/lib/ast/TypedAST.d.ts.map +1 -0
  7. package/lib/{src/ast → ast}/addTypesToRequestDocument.d.ts +0 -0
  8. package/lib/ast/addTypesToRequestDocument.d.ts.map +1 -0
  9. package/lib/ast/addTypesToRequestDocument.js +8 -5
  10. package/lib/ast/addTypesToRequestDocument.mjs +12 -6
  11. package/lib/benchmarks/index.d.ts.map +1 -1
  12. package/lib/benchmarks/index.js +127 -0
  13. package/lib/benchmarks/index.mjs +111 -0
  14. package/lib/benchmarks/nice-benchmark.d.ts +1 -1
  15. package/lib/benchmarks/nice-benchmark.d.ts.map +1 -1
  16. package/lib/benchmarks/nice-benchmark.js +72 -0
  17. package/lib/benchmarks/nice-benchmark.mjs +52 -0
  18. package/lib/benchmarks/swapi-schema/index.d.ts +1 -0
  19. package/lib/benchmarks/swapi-schema/index.d.ts.map +1 -1
  20. package/lib/benchmarks/swapi-schema/index.js +39 -0
  21. package/lib/benchmarks/swapi-schema/index.mjs +17 -0
  22. package/lib/benchmarks/swapi-schema/models.d.ts.map +1 -1
  23. package/lib/benchmarks/swapi-schema/models.js +29 -0
  24. package/lib/benchmarks/swapi-schema/models.mjs +7 -0
  25. package/lib/benchmarks/swapi-schema/resolvers.d.ts.map +1 -1
  26. package/lib/benchmarks/swapi-schema/resolvers.js +237 -0
  27. package/lib/benchmarks/swapi-schema/resolvers.mjs +230 -0
  28. package/lib/bin/supermassive.d.ts +3 -0
  29. package/lib/bin/supermassive.d.ts.map +1 -0
  30. package/lib/bin/supermassive.js +83 -0
  31. package/lib/bin/supermassive.mjs +62 -0
  32. package/lib/collectFields.d.ts +17 -0
  33. package/lib/collectFields.d.ts.map +1 -0
  34. package/lib/collectFields.js +83 -0
  35. package/lib/collectFields.mjs +61 -0
  36. package/lib/compiledQuery.d.ts +1 -0
  37. package/lib/compiledQuery.d.ts.map +1 -0
  38. package/lib/compiledQuery.js +0 -0
  39. package/lib/compiledQuery.mjs +0 -0
  40. package/lib/executeWithSchema.d.ts +4 -0
  41. package/lib/executeWithSchema.d.ts.map +1 -0
  42. package/lib/{index.test.js → executeWithSchema.js} +45 -46
  43. package/lib/executeWithSchema.mjs +64 -0
  44. package/lib/executeWithoutSchema.d.ts +99 -0
  45. package/lib/executeWithoutSchema.d.ts.map +1 -0
  46. package/lib/executeWithoutSchema.js +376 -0
  47. package/lib/executeWithoutSchema.mjs +363 -0
  48. package/lib/extractImplicitTypesRuntime.d.ts +4 -0
  49. package/lib/extractImplicitTypesRuntime.d.ts.map +1 -0
  50. package/lib/extractImplicitTypesRuntime.js +103 -0
  51. package/lib/extractImplicitTypesRuntime.mjs +91 -0
  52. package/lib/extractImplicitTypesToTypescript.d.ts +4 -0
  53. package/lib/extractImplicitTypesToTypescript.d.ts.map +1 -0
  54. package/lib/extractImplicitTypesToTypescript.js +169 -0
  55. package/lib/extractImplicitTypesToTypescript.mjs +149 -0
  56. package/lib/index.d.ts +8 -0
  57. package/lib/index.d.ts.map +1 -0
  58. package/lib/index.js +12 -29
  59. package/lib/index.mjs +13 -29
  60. package/lib/jsutils/Maybe.d.ts +3 -0
  61. package/lib/jsutils/Maybe.d.ts.map +1 -0
  62. package/lib/jsutils/Maybe.js +3 -0
  63. package/lib/jsutils/Maybe.mjs +0 -0
  64. package/lib/jsutils/ObjMap.d.ts +13 -0
  65. package/lib/jsutils/ObjMap.d.ts.map +1 -0
  66. package/lib/jsutils/ObjMap.js +3 -0
  67. package/lib/jsutils/ObjMap.mjs +0 -0
  68. package/lib/jsutils/Path.d.ts +15 -0
  69. package/lib/jsutils/Path.d.ts.map +1 -0
  70. package/lib/jsutils/Path.js +23 -0
  71. package/lib/jsutils/Path.mjs +17 -0
  72. package/lib/jsutils/PromiseOrValue.d.ts +2 -0
  73. package/lib/jsutils/PromiseOrValue.d.ts.map +1 -0
  74. package/lib/jsutils/PromiseOrValue.js +3 -0
  75. package/lib/jsutils/PromiseOrValue.mjs +0 -0
  76. package/lib/jsutils/devAssert.d.ts +2 -0
  77. package/lib/jsutils/devAssert.d.ts.map +1 -0
  78. package/lib/jsutils/devAssert.js +16 -0
  79. package/lib/jsutils/devAssert.mjs +10 -0
  80. package/lib/jsutils/didYouMean.d.ts +6 -0
  81. package/lib/jsutils/didYouMean.d.ts.map +1 -0
  82. package/lib/jsutils/didYouMean.js +30 -0
  83. package/lib/jsutils/didYouMean.mjs +24 -0
  84. package/lib/jsutils/identityFunc.d.ts +5 -0
  85. package/lib/jsutils/identityFunc.d.ts.map +1 -0
  86. package/lib/jsutils/identityFunc.js +13 -0
  87. package/lib/jsutils/identityFunc.mjs +7 -0
  88. package/lib/jsutils/inspect.d.ts +5 -0
  89. package/lib/jsutils/inspect.d.ts.map +1 -0
  90. package/lib/jsutils/inspect.js +89 -0
  91. package/lib/jsutils/inspect.mjs +83 -0
  92. package/lib/jsutils/instanceOf.d.ts +14 -0
  93. package/lib/jsutils/instanceOf.d.ts.map +1 -0
  94. package/lib/jsutils/instanceOf.js +55 -0
  95. package/lib/jsutils/instanceOf.mjs +33 -0
  96. package/lib/jsutils/invariant.d.ts +2 -0
  97. package/lib/jsutils/invariant.d.ts.map +1 -0
  98. package/lib/jsutils/invariant.js +16 -0
  99. package/lib/jsutils/invariant.mjs +10 -0
  100. package/lib/jsutils/isAsyncIterable.d.ts +6 -0
  101. package/lib/jsutils/isAsyncIterable.d.ts.map +1 -0
  102. package/lib/jsutils/isAsyncIterable.js +13 -0
  103. package/lib/jsutils/isAsyncIterable.mjs +7 -0
  104. package/lib/jsutils/isIterableObject.d.ts +18 -0
  105. package/lib/jsutils/isIterableObject.d.ts.map +1 -0
  106. package/lib/jsutils/isIterableObject.js +13 -0
  107. package/lib/jsutils/isIterableObject.mjs +7 -0
  108. package/lib/jsutils/isObjectLike.d.ts +8 -0
  109. package/lib/jsutils/isObjectLike.d.ts.map +1 -0
  110. package/lib/jsutils/isObjectLike.js +13 -0
  111. package/lib/jsutils/isObjectLike.mjs +7 -0
  112. package/lib/jsutils/isPromise.d.ts +6 -0
  113. package/lib/jsutils/isPromise.d.ts.map +1 -0
  114. package/lib/jsutils/isPromise.js +13 -0
  115. package/lib/jsutils/isPromise.mjs +7 -0
  116. package/lib/jsutils/keyMap.d.ts +26 -0
  117. package/lib/jsutils/keyMap.d.ts.map +1 -0
  118. package/lib/jsutils/keyMap.js +17 -0
  119. package/lib/jsutils/keyMap.mjs +11 -0
  120. package/lib/jsutils/keyValMap.d.ts +20 -0
  121. package/lib/jsutils/keyValMap.d.ts.map +1 -0
  122. package/lib/jsutils/keyValMap.js +17 -0
  123. package/lib/jsutils/keyValMap.mjs +11 -0
  124. package/lib/jsutils/mapValue.d.ts +7 -0
  125. package/lib/jsutils/mapValue.d.ts.map +1 -0
  126. package/lib/jsutils/mapValue.js +17 -0
  127. package/lib/jsutils/mapValue.mjs +11 -0
  128. package/lib/jsutils/memoize3.d.ts +5 -0
  129. package/lib/jsutils/memoize3.d.ts.map +1 -0
  130. package/lib/jsutils/memoize3.js +34 -0
  131. package/lib/jsutils/memoize3.mjs +28 -0
  132. package/lib/jsutils/naturalCompare.d.ts +9 -0
  133. package/lib/jsutils/naturalCompare.d.ts.map +1 -0
  134. package/lib/jsutils/naturalCompare.js +53 -0
  135. package/lib/jsutils/naturalCompare.mjs +47 -0
  136. package/lib/jsutils/printPathArray.d.ts +5 -0
  137. package/lib/jsutils/printPathArray.d.ts.map +1 -0
  138. package/lib/jsutils/printPathArray.js +13 -0
  139. package/lib/jsutils/printPathArray.mjs +7 -0
  140. package/lib/jsutils/promiseForObject.d.ts +10 -0
  141. package/lib/jsutils/promiseForObject.d.ts.map +1 -0
  142. package/lib/jsutils/promiseForObject.js +19 -0
  143. package/lib/jsutils/promiseForObject.mjs +13 -0
  144. package/lib/jsutils/promiseReduce.d.ts +10 -0
  145. package/lib/jsutils/promiseReduce.d.ts.map +1 -0
  146. package/lib/jsutils/promiseReduce.js +34 -0
  147. package/lib/jsutils/promiseReduce.mjs +12 -0
  148. package/lib/jsutils/suggestionList.d.ts +6 -0
  149. package/lib/jsutils/suggestionList.d.ts.map +1 -0
  150. package/lib/jsutils/suggestionList.js +109 -0
  151. package/lib/jsutils/suggestionList.mjs +87 -0
  152. package/lib/jsutils/toObjMap.d.ts +4 -0
  153. package/lib/jsutils/toObjMap.d.ts.map +1 -0
  154. package/lib/jsutils/toObjMap.js +20 -0
  155. package/lib/jsutils/toObjMap.mjs +14 -0
  156. package/lib/transforms/annotateDocumentGraphQLTransform.d.ts +3 -0
  157. package/lib/transforms/annotateDocumentGraphQLTransform.d.ts.map +1 -0
  158. package/lib/transforms/annotateDocumentGraphQLTransform.js +37 -0
  159. package/lib/transforms/annotateDocumentGraphQLTransform.mjs +17 -0
  160. package/lib/transforms/transformerTestUtils.d.ts +79 -0
  161. package/lib/transforms/transformerTestUtils.d.ts.map +1 -0
  162. package/lib/transforms/transformerTestUtils.js +175 -0
  163. package/lib/transforms/transformerTestUtils.mjs +160 -0
  164. package/lib/types.d.ts +74 -0
  165. package/lib/types.d.ts.map +1 -0
  166. package/lib/types.js +3 -0
  167. package/lib/types.mjs +0 -0
  168. package/lib/utilities/typeNameFromAST.d.ts +3 -0
  169. package/lib/utilities/typeNameFromAST.d.ts.map +1 -0
  170. package/lib/utilities/typeNameFromAST.js +34 -0
  171. package/lib/utilities/typeNameFromAST.mjs +12 -0
  172. package/lib/values.d.ts +64 -0
  173. package/lib/values.d.ts.map +1 -0
  174. package/lib/values.js +145 -0
  175. package/lib/values.mjs +138 -0
  176. package/package.json +21 -6
  177. package/.eslintcache +0 -1
  178. package/CHANGELOG.json +0 -65
  179. package/benchmarks/fixtures/query1.graphql +0 -20
  180. package/benchmarks/index.ts +0 -68
  181. package/benchmarks/nice-benchmark.ts +0 -32
  182. package/benchmarks/swapi-schema/index.ts +0 -13
  183. package/benchmarks/swapi-schema/models.ts +0 -4
  184. package/benchmarks/swapi-schema/resolvers.ts +0 -331
  185. package/benchmarks/swapi-schema/schema.graphql +0 -164
  186. package/benchmarks/swapi-schema/starwars.json +0 -5991
  187. package/lib/index.test.mjs +0 -63
  188. package/lib/src/ast/TypedAST.d.ts.map +0 -1
  189. package/lib/src/ast/addTypesToRequestDocument.d.ts.map +0 -1
  190. package/lib/src/index.d.ts +0 -16
  191. package/lib/src/index.d.ts.map +0 -1
  192. package/lib/src/index.test.d.ts +0 -2
  193. package/lib/src/index.test.d.ts.map +0 -1
@@ -0,0 +1,230 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
3
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
4
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {enumerable: true, configurable: true, writable: true, value}) : obj[key] = value;
6
+ var __objSpread = (a, b) => {
7
+ for (var prop in b || (b = {}))
8
+ if (__hasOwnProp.call(b, prop))
9
+ __defNormalProp(a, prop, b[prop]);
10
+ if (__getOwnPropSymbols)
11
+ for (var prop of __getOwnPropSymbols(b)) {
12
+ if (__propIsEnum.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ }
15
+ return a;
16
+ };
17
+
18
+ // src/benchmarks/swapi-schema/resolvers.ts
19
+ var films = (parent, args, {models}) => {
20
+ return models.getData("/films").filter(({id}) => parent.films.includes(id));
21
+ };
22
+ var starships = (parent, {id}, {models}) => {
23
+ return models.getData("/starships").filter(({id: id2}) => parent.starships.includes(id2));
24
+ };
25
+ function people(key) {
26
+ return (parent, args, {models}) => {
27
+ return models.getData("/people").filter(({id}) => parent[key].includes(id));
28
+ };
29
+ }
30
+ var vehicles = (parent, args, {models}) => {
31
+ return models.getData("/vehicles").filter(({id}) => parent.vehicles.includes(id));
32
+ };
33
+ var planets = (parent, args, {models}) => {
34
+ return models.getData("/planets").filter(({id}) => parent.planets.includes(id));
35
+ };
36
+ var species = (parent, args, {models}) => {
37
+ return models.getData("/species").filter(({id}) => parent.species.includes(id));
38
+ };
39
+ var homeworld = (parent, args, {models}) => {
40
+ return models.getData("/planets").find((planet2) => planet2.id === parent.homeworld);
41
+ };
42
+ var person = (parent, {id}, {models}) => {
43
+ return models.getData("/people").find((person2) => person2.id === id);
44
+ };
45
+ var planet = (parent, {id}, {models}) => {
46
+ return models.getData("/planets").find((planet2) => planet2.id === id);
47
+ };
48
+ var film = (parent, {id}, {models}) => {
49
+ return models.getData("/films").find((film2) => film2.id === id);
50
+ };
51
+ var starship = (parent, {id}, {models}) => {
52
+ return models.getData("/starships").find((starship2) => starship2.id === id);
53
+ };
54
+ var transport = (parent, {id}, {models}) => {
55
+ return models.getData("/transport").find((transport2) => transport2.id === id);
56
+ };
57
+ var vehicle = (parent, {id}, {models}) => {
58
+ return models.getData("/vehicles").find((vehicle2) => vehicle2.id === id);
59
+ };
60
+ var searchPeopleByName = (parent, {search}, {models}) => {
61
+ return models.getData("/people").filter((person2) => new RegExp(search, "i").test(person2.name));
62
+ };
63
+ var searchPlanetsByName = (parent, {search}, {models}) => {
64
+ return models.getData("/planets").filter((planet2) => new RegExp(search, "i").test(planet2.name));
65
+ };
66
+ var searchFilmsByTitle = (parent, {search}, {models}) => {
67
+ return models.getData("/films").filter((film2) => new RegExp(search, "i").test(film2.title));
68
+ };
69
+ var searchSpeciesByName = (parent, {search}, {models}) => {
70
+ return models.getData("/species").filter((species2) => new RegExp(search, "i").test(species2.name));
71
+ };
72
+ var searchStarshipsByName = (parent, {search}, {models}) => {
73
+ return models.getData("/starships").filter((starship2) => new RegExp(search, "i").test(starship2.name));
74
+ };
75
+ var searchVehiclesByName = (parent, {search}, {models}) => {
76
+ return models.getData("/vehicles").filter((vehicle2) => new RegExp(search, "i").test(vehicle2.name));
77
+ };
78
+ var searchTransportsByName = (parent, {search}, {models}) => {
79
+ return models.getData("/transport").filter((transport2) => new RegExp(search, "i").test(transport2.name));
80
+ };
81
+ var resolvers = {
82
+ SearchResult: {
83
+ __resolveType(parent) {
84
+ return parent.__typename;
85
+ }
86
+ },
87
+ Query: {
88
+ search(parent, {search}, {models}, info) {
89
+ const result = [
90
+ ...searchFilmsByTitle(parent, {search}, {models}, info).map((r) => (r.__typename = "Film") && r),
91
+ ...searchPeopleByName(parent, {search}, {models}, info).map((r) => (r.__typename = "Person") && r),
92
+ ...searchPlanetsByName(parent, {search}, {models}, info).map((r) => (r.__typename = "Planet") && r),
93
+ ...searchSpeciesByName(parent, {search}, {models}, info).map((r) => (r.__typename = "Species") && r),
94
+ ...searchStarshipsByName(parent, {search}, {models}, info).map((r) => (r.__typename = "Starship") && r),
95
+ ...searchTransportsByName(parent, {search}, {models}, info).map((r) => (r.__typename = "Transport") && r),
96
+ ...searchVehiclesByName(parent, {search}, {models}, info).map((r) => (r.__typename = "Vehicle") && r)
97
+ ];
98
+ return result;
99
+ },
100
+ node(parent, args, context, info) {
101
+ let result;
102
+ switch (args.nodeType) {
103
+ case "Person": {
104
+ result = person(parent, args, context, info);
105
+ break;
106
+ }
107
+ case "Starship": {
108
+ result = starship(parent, args, context, info);
109
+ break;
110
+ }
111
+ case "Transport": {
112
+ result = transport(parent, args, context, info);
113
+ break;
114
+ }
115
+ case "Species": {
116
+ result = species(parent, args, context, info);
117
+ break;
118
+ }
119
+ case "Vehicle": {
120
+ result = vehicle(parent, args, context, info);
121
+ break;
122
+ }
123
+ case "Planet": {
124
+ result = planet(parent, args, context, info);
125
+ break;
126
+ }
127
+ case "Film": {
128
+ result = film(parent, args, context, info);
129
+ break;
130
+ }
131
+ default:
132
+ throw new Error(`Invalid node type ${args.nodeType}`);
133
+ }
134
+ return __objSpread(__objSpread({}, result), {
135
+ __typename: args.nodeType
136
+ });
137
+ },
138
+ person,
139
+ planet,
140
+ film,
141
+ transport,
142
+ starship,
143
+ vehicle,
144
+ searchPeopleByName,
145
+ searchStarshipsByName,
146
+ searchTransportsByName,
147
+ searchSpeciesByName,
148
+ searchVehiclesByName,
149
+ searchPlanetsByName,
150
+ searchFilmsByTitle,
151
+ allStarships(parent, args, {models}) {
152
+ return models.getData("/starships");
153
+ },
154
+ allFilms(parent, args, {models}) {
155
+ return models.getData("/films");
156
+ },
157
+ allPeople(parent, args, {models}) {
158
+ return models.getData("/people");
159
+ },
160
+ allPlanets(parent, args, {models}) {
161
+ return models.getData("/planets");
162
+ },
163
+ allSpecies(parent, args, {models}) {
164
+ return models.getData("/species");
165
+ },
166
+ allTransports(parent, args, {models}) {
167
+ return models.getData("/transport");
168
+ }
169
+ },
170
+ Film: {
171
+ starships,
172
+ vehicles,
173
+ planets,
174
+ characters: people("characters"),
175
+ species
176
+ },
177
+ Starship: {
178
+ MGLT: (starship2) => +starship2.MGLT,
179
+ hyperdrive_rating: (starship2) => +starship2.hyperdrive_rating,
180
+ cargo_capacity: (starship2) => +starship2.cargo_capacity,
181
+ passengers: (starship2) => +starship2.passengers,
182
+ max_atmosphering_speed: (starship2) => +starship2.max_atmosphering_speed,
183
+ length: (starship2) => +starship2.length,
184
+ cost_in_credits: (starship2) => +starship2.cost_in_credits,
185
+ pilots: people("pilots"),
186
+ films
187
+ },
188
+ Person: {
189
+ height: (pilot) => +pilot.height,
190
+ mass: (pilot) => +pilot.mass,
191
+ starships,
192
+ homeworld
193
+ },
194
+ Vehicle: {
195
+ cargo_capacity: (vehicle2) => +vehicle2.cargo_capacity,
196
+ passengers: (vehicle2) => +vehicle2.passengers,
197
+ max_atmosphering_speed: (vehicle2) => +vehicle2.max_atmosphering_speed,
198
+ crew: (vehicle2) => forceNumber(vehicle2.crew),
199
+ length: (vehicle2) => +vehicle2.length,
200
+ cost_in_credits: (vehicle2) => +vehicle2.cost_in_credits,
201
+ pilots: people("pilots")
202
+ },
203
+ Planet: {
204
+ diameter: (planet2) => +planet2.diameter,
205
+ rotation_period: (planet2) => +planet2.rotation_period,
206
+ orbital_period: (planet2) => +planet2.orbital_period,
207
+ population: (planet2) => +planet2.population,
208
+ residents: people("residents"),
209
+ films
210
+ },
211
+ Species: {
212
+ average_lifespan: (species2) => +species2.average_lifespan,
213
+ average_height: (species2) => +species2.average_height,
214
+ homeworld,
215
+ people: people("people")
216
+ },
217
+ Transport: {
218
+ cargo_capacity: (vehicle2) => +vehicle2.cargo_capacity,
219
+ passengers: (vehicle2) => +vehicle2.passengers,
220
+ max_atmosphering_speed: (vehicle2) => +vehicle2.max_atmosphering_speed,
221
+ crew: (vehicle2) => forceNumber(vehicle2.crew),
222
+ length: (vehicle2) => +vehicle2.length,
223
+ cost_in_credits: (vehicle2) => +vehicle2.cost_in_credits
224
+ }
225
+ };
226
+ var forceNumber = (i) => Number(i.split(",").join("").split("-")[0]) || -1;
227
+ var resolvers_default = resolvers;
228
+ export {
229
+ resolvers_default as default
230
+ };
@@ -0,0 +1,3 @@
1
+ import { Command } from "commander";
2
+ export declare function supermassive(): Command;
3
+ //# sourceMappingURL=supermassive.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"supermassive.d.ts","sourceRoot":"","sources":["../../src/bin/supermassive.ts"],"names":[],"mappings":"AAGA,OAAO,EAAW,OAAO,EAAE,MAAM,WAAW,CAAC;AAI7C,wBAAgB,YAAY,IAAI,OAAO,CAYtC"}
@@ -0,0 +1,83 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getProtoOf = Object.getPrototypeOf;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, {get: all[name], enumerable: true});
11
+ };
12
+ var __reExport = (target, module2, desc) => {
13
+ if (module2 && typeof module2 === "object" || typeof module2 === "function") {
14
+ for (let key of __getOwnPropNames(module2))
15
+ if (!__hasOwnProp.call(target, key) && key !== "default")
16
+ __defProp(target, key, {get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable});
17
+ }
18
+ return target;
19
+ };
20
+ var __toModule = (module2) => {
21
+ return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2);
22
+ };
23
+ var __async = (__this, __arguments, generator) => {
24
+ return new Promise((resolve, reject) => {
25
+ var fulfilled = (value) => {
26
+ try {
27
+ step(generator.next(value));
28
+ } catch (e) {
29
+ reject(e);
30
+ }
31
+ };
32
+ var rejected = (value) => {
33
+ try {
34
+ step(generator.throw(value));
35
+ } catch (e) {
36
+ reject(e);
37
+ }
38
+ };
39
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
40
+ step((generator = generator.apply(__this, __arguments)).next());
41
+ });
42
+ };
43
+ __markAsModule(exports);
44
+ __export(exports, {
45
+ supermassive: () => supermassive
46
+ });
47
+ var import_path = __toModule(require("path"));
48
+ var import_promises = __toModule(require("fs/promises"));
49
+ var import_typescript = __toModule(require("typescript"));
50
+ var import_commander = __toModule(require("commander"));
51
+ var import_extractImplicitTypesToTypescript = __toModule(require("../extractImplicitTypesToTypescript"));
52
+ var import_graphql = __toModule(require("graphql"));
53
+ function supermassive() {
54
+ const command = new import_commander.Command();
55
+ command.name("extract-schema").argument("<files...>").description("extract implicit resolvers to a ts file from graphql typedefs").action((files) => __async(this, null, function* () {
56
+ yield typeDefsToImplicitResolversImpl(files);
57
+ }));
58
+ return import_commander.program.name("supermassive").addCommand(command);
59
+ }
60
+ function typeDefsToImplicitResolversImpl(files) {
61
+ return __async(this, null, function* () {
62
+ for (const file of files) {
63
+ let fullPath;
64
+ if (import_path.default.isAbsolute(file)) {
65
+ fullPath = file;
66
+ } else {
67
+ fullPath = import_path.default.join(process.cwd(), file);
68
+ }
69
+ const stat = yield import_promises.default.stat(fullPath);
70
+ if (!stat.isFile) {
71
+ throw new Error(`Invalid file ${file}`);
72
+ }
73
+ const content = yield import_promises.default.readFile(fullPath, {encoding: "utf-8"});
74
+ const document = (0, import_graphql.parse)(content);
75
+ const tsContents = (0, import_extractImplicitTypesToTypescript.extractImplicitTypesToTypescript)(document);
76
+ const tsDir = import_path.default.join(import_path.default.dirname(fullPath), "__generated__");
77
+ yield import_promises.default.mkdir(tsDir, {recursive: true});
78
+ const tsFileName = import_path.default.join(tsDir, import_path.default.basename(fullPath, import_path.default.extname(fullPath)) + ".ts");
79
+ const printer = import_typescript.default.createPrinter();
80
+ yield import_promises.default.writeFile(tsFileName, printer.printNode(import_typescript.default.EmitHint.SourceFile, tsContents, tsContents), {encoding: "utf-8"});
81
+ }
82
+ });
83
+ }
@@ -0,0 +1,62 @@
1
+ var __async = (__this, __arguments, generator) => {
2
+ return new Promise((resolve, reject) => {
3
+ var fulfilled = (value) => {
4
+ try {
5
+ step(generator.next(value));
6
+ } catch (e) {
7
+ reject(e);
8
+ }
9
+ };
10
+ var rejected = (value) => {
11
+ try {
12
+ step(generator.throw(value));
13
+ } catch (e) {
14
+ reject(e);
15
+ }
16
+ };
17
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
+ step((generator = generator.apply(__this, __arguments)).next());
19
+ });
20
+ };
21
+
22
+ // src/bin/supermassive.ts
23
+ import path from "path";
24
+ import fs from "fs/promises";
25
+ import ts from "typescript";
26
+ import {program, Command} from "commander";
27
+ import {extractImplicitTypesToTypescript} from "../extractImplicitTypesToTypescript.mjs";
28
+ import {parse} from "graphql";
29
+ function supermassive() {
30
+ const command = new Command();
31
+ command.name("extract-schema").argument("<files...>").description("extract implicit resolvers to a ts file from graphql typedefs").action((files) => __async(this, null, function* () {
32
+ yield typeDefsToImplicitResolversImpl(files);
33
+ }));
34
+ return program.name("supermassive").addCommand(command);
35
+ }
36
+ function typeDefsToImplicitResolversImpl(files) {
37
+ return __async(this, null, function* () {
38
+ for (const file of files) {
39
+ let fullPath;
40
+ if (path.isAbsolute(file)) {
41
+ fullPath = file;
42
+ } else {
43
+ fullPath = path.join(process.cwd(), file);
44
+ }
45
+ const stat = yield fs.stat(fullPath);
46
+ if (!stat.isFile) {
47
+ throw new Error(`Invalid file ${file}`);
48
+ }
49
+ const content = yield fs.readFile(fullPath, {encoding: "utf-8"});
50
+ const document = parse(content);
51
+ const tsContents = extractImplicitTypesToTypescript(document);
52
+ const tsDir = path.join(path.dirname(fullPath), "__generated__");
53
+ yield fs.mkdir(tsDir, {recursive: true});
54
+ const tsFileName = path.join(tsDir, path.basename(fullPath, path.extname(fullPath)) + ".ts");
55
+ const printer = ts.createPrinter();
56
+ yield fs.writeFile(tsFileName, printer.printNode(ts.EmitHint.SourceFile, tsContents, tsContents), {encoding: "utf-8"});
57
+ }
58
+ });
59
+ }
60
+ export {
61
+ supermassive
62
+ };
@@ -0,0 +1,17 @@
1
+ import { FieldNode, FragmentDefinitionNode, SelectionSetNode } from "./ast/TypedAST";
2
+ import type { ObjMap } from "./jsutils/ObjMap";
3
+ import { Resolvers } from "./types";
4
+ /**
5
+ * Given a selectionSet, adds all of the fields in that selection to
6
+ * the passed in map of fields, and returns it at the end.
7
+ *
8
+ * CollectFields requires the "runtime type" of an object. For a field which
9
+ * returns an Interface or Union type, the "runtime type" will be the actual
10
+ * Object type returned by that field.
11
+ *
12
+ * @internal
13
+ */
14
+ export declare function collectFields(resolvers: Resolvers, fragments: ObjMap<FragmentDefinitionNode>, variableValues: {
15
+ [variable: string]: unknown;
16
+ }, runtimeTypeName: string, selectionSet: SelectionSetNode, fields: Map<string, Array<FieldNode>>, visitedFragmentNames: Set<string>): Map<string, Array<FieldNode>>;
17
+ //# sourceMappingURL=collectFields.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collectFields.d.ts","sourceRoot":"","sources":["../src/collectFields.ts"],"names":[],"mappings":"AACA,OAAO,EACL,SAAS,EACT,sBAAsB,EAGtB,gBAAgB,EACjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEpC;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAC3B,SAAS,EAAE,SAAS,EACpB,SAAS,EAAE,MAAM,CAAC,sBAAsB,CAAC,EACzC,cAAc,EAAE;IAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,EAC/C,eAAe,EAAE,MAAM,EACvB,YAAY,EAAE,gBAAgB,EAC9B,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC,EACrC,oBAAoB,EAAE,GAAG,CAAC,MAAM,CAAC,GAChC,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC,CAgE/B"}
@@ -0,0 +1,83 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getProtoOf = Object.getPrototypeOf;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, {get: all[name], enumerable: true});
11
+ };
12
+ var __reExport = (target, module2, desc) => {
13
+ if (module2 && typeof module2 === "object" || typeof module2 === "function") {
14
+ for (let key of __getOwnPropNames(module2))
15
+ if (!__hasOwnProp.call(target, key) && key !== "default")
16
+ __defProp(target, key, {get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable});
17
+ }
18
+ return target;
19
+ };
20
+ var __toModule = (module2) => {
21
+ return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2);
22
+ };
23
+ __markAsModule(exports);
24
+ __export(exports, {
25
+ collectFields: () => collectFields
26
+ });
27
+ var import_graphql = __toModule(require("graphql"));
28
+ function collectFields(resolvers, fragments, variableValues, runtimeTypeName, selectionSet, fields, visitedFragmentNames) {
29
+ for (const selection of selectionSet.selections) {
30
+ switch (selection.kind) {
31
+ case import_graphql.Kind.FIELD: {
32
+ if (!shouldIncludeNode(variableValues, selection)) {
33
+ continue;
34
+ }
35
+ const name = getFieldEntryKey(selection);
36
+ const fieldList = fields.get(name);
37
+ if (fieldList !== void 0) {
38
+ fieldList.push(selection);
39
+ } else {
40
+ fields.set(name, [selection]);
41
+ }
42
+ break;
43
+ }
44
+ case import_graphql.Kind.INLINE_FRAGMENT: {
45
+ if (!shouldIncludeNode(variableValues, selection) || !doesFragmentConditionMatch(selection, runtimeTypeName)) {
46
+ continue;
47
+ }
48
+ collectFields(resolvers, fragments, variableValues, runtimeTypeName, selection.selectionSet, fields, visitedFragmentNames);
49
+ break;
50
+ }
51
+ case import_graphql.Kind.FRAGMENT_SPREAD: {
52
+ const fragName = selection.name.value;
53
+ if (visitedFragmentNames.has(fragName) || !shouldIncludeNode(variableValues, selection)) {
54
+ continue;
55
+ }
56
+ visitedFragmentNames.add(fragName);
57
+ const fragment = fragments[fragName];
58
+ if (!fragment || !doesFragmentConditionMatch(fragment, runtimeTypeName)) {
59
+ continue;
60
+ }
61
+ collectFields(resolvers, fragments, variableValues, runtimeTypeName, fragment.selectionSet, fields, visitedFragmentNames);
62
+ break;
63
+ }
64
+ }
65
+ }
66
+ return fields;
67
+ }
68
+ function shouldIncludeNode(variableValues, node) {
69
+ return true;
70
+ }
71
+ function doesFragmentConditionMatch(fragment, typeName) {
72
+ const typeConditionNode = fragment.typeCondition;
73
+ if (!typeConditionNode) {
74
+ return true;
75
+ }
76
+ if (typeConditionNode.name.value === typeName) {
77
+ return true;
78
+ }
79
+ return false;
80
+ }
81
+ function getFieldEntryKey(node) {
82
+ return node.alias ? node.alias.value : node.name.value;
83
+ }
@@ -0,0 +1,61 @@
1
+ // src/collectFields.ts
2
+ import {Kind} from "graphql";
3
+ function collectFields(resolvers, fragments, variableValues, runtimeTypeName, selectionSet, fields, visitedFragmentNames) {
4
+ for (const selection of selectionSet.selections) {
5
+ switch (selection.kind) {
6
+ case Kind.FIELD: {
7
+ if (!shouldIncludeNode(variableValues, selection)) {
8
+ continue;
9
+ }
10
+ const name = getFieldEntryKey(selection);
11
+ const fieldList = fields.get(name);
12
+ if (fieldList !== void 0) {
13
+ fieldList.push(selection);
14
+ } else {
15
+ fields.set(name, [selection]);
16
+ }
17
+ break;
18
+ }
19
+ case Kind.INLINE_FRAGMENT: {
20
+ if (!shouldIncludeNode(variableValues, selection) || !doesFragmentConditionMatch(selection, runtimeTypeName)) {
21
+ continue;
22
+ }
23
+ collectFields(resolvers, fragments, variableValues, runtimeTypeName, selection.selectionSet, fields, visitedFragmentNames);
24
+ break;
25
+ }
26
+ case Kind.FRAGMENT_SPREAD: {
27
+ const fragName = selection.name.value;
28
+ if (visitedFragmentNames.has(fragName) || !shouldIncludeNode(variableValues, selection)) {
29
+ continue;
30
+ }
31
+ visitedFragmentNames.add(fragName);
32
+ const fragment = fragments[fragName];
33
+ if (!fragment || !doesFragmentConditionMatch(fragment, runtimeTypeName)) {
34
+ continue;
35
+ }
36
+ collectFields(resolvers, fragments, variableValues, runtimeTypeName, fragment.selectionSet, fields, visitedFragmentNames);
37
+ break;
38
+ }
39
+ }
40
+ }
41
+ return fields;
42
+ }
43
+ function shouldIncludeNode(variableValues, node) {
44
+ return true;
45
+ }
46
+ function doesFragmentConditionMatch(fragment, typeName) {
47
+ const typeConditionNode = fragment.typeCondition;
48
+ if (!typeConditionNode) {
49
+ return true;
50
+ }
51
+ if (typeConditionNode.name.value === typeName) {
52
+ return true;
53
+ }
54
+ return false;
55
+ }
56
+ function getFieldEntryKey(node) {
57
+ return node.alias ? node.alias.value : node.name.value;
58
+ }
59
+ export {
60
+ collectFields
61
+ };
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=compiledQuery.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compiledQuery.d.ts","sourceRoot":"","sources":["../src/compiledQuery.ts"],"names":[],"mappings":""}
File without changes
File without changes
@@ -0,0 +1,4 @@
1
+ import { PromiseOrValue } from "./jsutils/PromiseOrValue";
2
+ import { ExecutionResult, ExecutionWithSchemaArgs } from "./types";
3
+ export declare function executeWithSchema({ typeDefs, resolvers, document: rawDocument, rootValue, contextValue, variableValues, operationName, fieldResolver, typeResolver, }: ExecutionWithSchemaArgs): PromiseOrValue<ExecutionResult>;
4
+ //# sourceMappingURL=executeWithSchema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executeWithSchema.d.ts","sourceRoot":"","sources":["../src/executeWithSchema.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAa,eAAe,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAE9E,wBAAgB,iBAAiB,CAAC,EAChC,QAAQ,EACR,SAAS,EACT,QAAQ,EAAE,WAAW,EACrB,SAAS,EACT,YAAY,EACZ,cAAc,EACd,aAAa,EACb,aAAa,EACb,YAAY,GACb,EAAE,uBAAuB,GAAG,cAAc,CAAC,eAAe,CAAC,CA2B3D"}
@@ -19,6 +19,10 @@ var __objSpread = (a, b) => {
19
19
  return a;
20
20
  };
21
21
  var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
22
+ var __export = (target, all) => {
23
+ for (var name in all)
24
+ __defProp(target, name, {get: all[name], enumerable: true});
25
+ };
22
26
  var __reExport = (target, module2, desc) => {
23
27
  if (module2 && typeof module2 === "object" || typeof module2 === "function") {
24
28
  for (let key of __getOwnPropNames(module2))
@@ -30,50 +34,45 @@ var __reExport = (target, module2, desc) => {
30
34
  var __toModule = (module2) => {
31
35
  return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2);
32
36
  };
33
- var __async = (__this, __arguments, generator) => {
34
- return new Promise((resolve, reject) => {
35
- var fulfilled = (value) => {
36
- try {
37
- step(generator.next(value));
38
- } catch (e) {
39
- reject(e);
40
- }
41
- };
42
- var rejected = (value) => {
43
- try {
44
- step(generator.throw(value));
45
- } catch (e) {
46
- reject(e);
47
- }
48
- };
49
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
50
- step((generator = generator.apply(__this, __arguments)).next());
51
- });
52
- };
53
- var import_graphql = __toModule(require("graphql"));
54
- var import__ = __toModule(require("."));
55
- var import_swapi_schema = __toModule(require("../benchmarks/swapi-schema"));
56
- var import_models = __toModule(require("../benchmarks/swapi-schema/models"));
57
- var import_resolvers = __toModule(require("../benchmarks/swapi-schema/resolvers"));
58
- describe("execute", () => {
59
- it.skip("executes a basic query", () => __async(void 0, null, function* () {
60
- const query = `
61
- {
62
- person(id: 1) {
63
- name
64
- gender
65
- }
66
- }`;
67
- const document = (0, import_graphql.parse)(query);
68
- expect.assertions(1);
69
- const args = {
70
- document,
71
- contextValue: {
72
- models: import_models.default
73
- }
74
- };
75
- const result = yield (0, import__.execute)(__objSpread(__objSpread({}, args), {resolvers: import_resolvers.default}));
76
- const validResult = yield (0, import_graphql.execute)(__objSpread(__objSpread({}, args), {schema: import_swapi_schema.default}));
77
- expect(result).toEqual(validResult);
78
- }));
37
+ __markAsModule(exports);
38
+ __export(exports, {
39
+ executeWithSchema: () => executeWithSchema
79
40
  });
41
+ var import_schema = __toModule(require("@graphql-tools/schema"));
42
+ var import_graphql = __toModule(require("graphql"));
43
+ var import_index = __toModule(require("./index"));
44
+ function executeWithSchema({
45
+ typeDefs,
46
+ resolvers,
47
+ document: rawDocument,
48
+ rootValue,
49
+ contextValue,
50
+ variableValues,
51
+ operationName,
52
+ fieldResolver,
53
+ typeResolver
54
+ }) {
55
+ const schema = (0, import_schema.makeExecutableSchema)({typeDefs, resolvers});
56
+ let extractedResolvers = {};
57
+ const getTypeByName = (name) => {
58
+ const type = import_index.specifiedScalars[name] || extractedResolvers[name];
59
+ if ((0, import_graphql.isInputType)(type)) {
60
+ return type;
61
+ } else {
62
+ throw new Error("Invalid type");
63
+ }
64
+ };
65
+ extractedResolvers = (0, import_index.extractImplicitTypes)(typeDefs, getTypeByName);
66
+ const fullResolvers = __objSpread(__objSpread({}, extractedResolvers), resolvers);
67
+ const document = (0, import_index.addTypesToRequestDocument)(schema, rawDocument);
68
+ return (0, import_index.executeWithoutSchema)({
69
+ document,
70
+ resolvers: fullResolvers,
71
+ rootValue,
72
+ contextValue,
73
+ variableValues,
74
+ operationName,
75
+ fieldResolver,
76
+ typeResolver
77
+ });
78
+ }