@graphitation/supermassive 0.8.1 → 0.8.4

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 (93) hide show
  1. package/CHANGELOG.md +25 -1
  2. package/README.md +24 -29
  3. package/lib/ast/TypedAST.js +14 -2
  4. package/lib/ast/addTypesToRequestDocument.js +23 -23
  5. package/lib/ast/addTypesToRequestDocument.mjs +8 -5
  6. package/lib/benchmarks/index.js +33 -36
  7. package/lib/benchmarks/index.mjs +101 -92
  8. package/lib/benchmarks/nice-benchmark.js +14 -18
  9. package/lib/benchmarks/nice-benchmark.mjs +2 -3
  10. package/lib/benchmarks/swapi-schema/index.js +19 -20
  11. package/lib/benchmarks/swapi-schema/index.mjs +4 -4
  12. package/lib/benchmarks/swapi-schema/models.js +16 -17
  13. package/lib/benchmarks/swapi-schema/models.mjs +1 -1
  14. package/lib/benchmarks/swapi-schema/resolvers.js +65 -66
  15. package/lib/benchmarks/swapi-schema/resolvers.mjs +51 -48
  16. package/lib/bin/supermassive.d.ts +1 -0
  17. package/lib/bin/supermassive.d.ts.map +1 -1
  18. package/lib/bin/supermassive.js +25 -25
  19. package/lib/bin/supermassive.mjs +8 -7
  20. package/lib/collectFields.js +23 -27
  21. package/lib/collectFields.mjs +10 -10
  22. package/lib/definition.js +15 -19
  23. package/lib/definition.mjs +2 -2
  24. package/lib/directives.js +21 -25
  25. package/lib/directives.mjs +7 -7
  26. package/lib/executeWithSchema.js +15 -19
  27. package/lib/executeWithSchema.mjs +1 -1
  28. package/lib/executeWithoutSchema.js +37 -41
  29. package/lib/executeWithoutSchema.mjs +22 -22
  30. package/lib/extractImplicitTypesRuntime.js +17 -21
  31. package/lib/extractImplicitTypesRuntime.mjs +3 -3
  32. package/lib/extractImplicitTypesToTypescript.js +16 -17
  33. package/lib/extractImplicitTypesToTypescript.mjs +1 -1
  34. package/lib/index.d.ts +2 -1
  35. package/lib/index.d.ts.map +1 -1
  36. package/lib/index.js +24 -26
  37. package/lib/index.mjs +11 -9
  38. package/lib/jsutils/Maybe.js +14 -2
  39. package/lib/jsutils/ObjMap.js +14 -2
  40. package/lib/jsutils/Path.js +17 -5
  41. package/lib/jsutils/Path.mjs +1 -1
  42. package/lib/jsutils/PromiseOrValue.js +14 -2
  43. package/lib/jsutils/devAssert.js +16 -4
  44. package/lib/jsutils/didYouMean.js +16 -4
  45. package/lib/jsutils/identityFunc.js +16 -4
  46. package/lib/jsutils/inspect.js +16 -4
  47. package/lib/jsutils/instanceOf.js +14 -18
  48. package/lib/jsutils/instanceOf.mjs +1 -1
  49. package/lib/jsutils/invariant.js +16 -4
  50. package/lib/jsutils/isAsyncIterable.js +16 -4
  51. package/lib/jsutils/isIterableObject.js +16 -4
  52. package/lib/jsutils/isObjectLike.js +16 -4
  53. package/lib/jsutils/isPromise.js +16 -4
  54. package/lib/jsutils/keyMap.js +17 -5
  55. package/lib/jsutils/keyMap.mjs +1 -1
  56. package/lib/jsutils/keyValMap.js +17 -5
  57. package/lib/jsutils/keyValMap.mjs +1 -1
  58. package/lib/jsutils/mapValue.js +17 -5
  59. package/lib/jsutils/mapValue.mjs +1 -1
  60. package/lib/jsutils/memoize3.js +19 -7
  61. package/lib/jsutils/memoize3.mjs +3 -3
  62. package/lib/jsutils/naturalCompare.js +16 -4
  63. package/lib/jsutils/printPathArray.js +16 -4
  64. package/lib/jsutils/promiseForObject.js +17 -5
  65. package/lib/jsutils/promiseForObject.mjs +1 -1
  66. package/lib/jsutils/promiseReduce.js +14 -18
  67. package/lib/jsutils/promiseReduce.mjs +1 -1
  68. package/lib/jsutils/suggestionList.js +15 -19
  69. package/lib/jsutils/suggestionList.mjs +2 -2
  70. package/lib/jsutils/toObjMap.js +17 -5
  71. package/lib/jsutils/toObjMap.mjs +1 -1
  72. package/lib/subscribeWithSchema.js +15 -19
  73. package/lib/subscribeWithSchema.mjs +1 -1
  74. package/lib/subscribeWithoutSchema.js +26 -30
  75. package/lib/subscribeWithoutSchema.mjs +11 -11
  76. package/lib/transforms/annotateDocumentGraphQLTransform.js +15 -19
  77. package/lib/transforms/annotateDocumentGraphQLTransform.mjs +1 -1
  78. package/lib/transforms/transformerTestUtils.js +24 -25
  79. package/lib/transforms/transformerTestUtils.mjs +12 -16
  80. package/lib/types.js +14 -2
  81. package/lib/utilities/mapAsyncIterator.js +18 -6
  82. package/lib/utilities/mapAsyncIterator.mjs +2 -2
  83. package/lib/utilities/mergeResolvers.js +20 -9
  84. package/lib/utilities/mergeResolvers.mjs +5 -5
  85. package/lib/utilities/typeNameFromAST.js +14 -18
  86. package/lib/utilities/typeNameFromAST.mjs +1 -1
  87. package/lib/values.js +19 -23
  88. package/lib/values.mjs +5 -5
  89. package/package.json +5 -4
  90. package/.eslintcache +0 -1
  91. package/CHANGELOG.json +0 -380
  92. package/lib/benchmarks/swapi-schema/__generated__/schema.d.ts +0 -3
  93. package/lib/benchmarks/swapi-schema/__generated__/schema.d.ts.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,9 +1,33 @@
1
1
  # Change Log - @graphitation/supermassive
2
2
 
3
- This log was last generated on Thu, 10 Feb 2022 13:09:46 GMT and should not be manually modified.
3
+ This log was last generated on Thu, 23 Jun 2022 14:40:40 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## 0.8.4
8
+
9
+ Thu, 23 Jun 2022 14:40:40 GMT
10
+
11
+ ### Patches
12
+
13
+ - Schem extraction function exported (jakubvejr@microsoft.com)
14
+
15
+ ## 0.8.3
16
+
17
+ Tue, 03 May 2022 17:45:10 GMT
18
+
19
+ ### Patches
20
+
21
+ - Expose TypeScript type FunctionFieldResolver (vladimir.razuvaev@gmail.com)
22
+
23
+ ## 0.8.2
24
+
25
+ Fri, 01 Apr 2022 16:00:03 GMT
26
+
27
+ ### Patches
28
+
29
+ - Pin TS dependency (eloy.de.enige@gmail.com)
30
+
7
31
  ## 0.8.0
8
32
 
9
33
  Thu, 10 Feb 2022 13:09:46 GMT
package/README.md CHANGED
@@ -23,12 +23,29 @@ Consider a GraphQL schema. It is typically a sizeable chunk of data, both in ter
23
23
 
24
24
  Similarly, the GraphQL operations themselves, described using e.g. [GraphQL SDL](https://graphql.org/learn/schema/) or [`graphql-js` AST](https://github.com/graphql/graphql-js/blob/main/src/language/ast.ts), can incur quite some overhead as operations and number of operations grow. Eliminating these from the bundles can save size as well as runtime processing.
25
25
 
26
- ## Roadmap
26
+ ## Implementation details and plans
27
27
 
28
- ### Phase 1
28
+ ### Current
29
+
30
+ Currently, supermassive expects inlined types in normal GraphQL documents that are sent to it. It doesn't require having a schema, only the query document and resolver functions. We achieve this by running a pre-processing step on queries using the schema, in a same stage where `graphql` tags would normally be extracted and pre-parsed. Schema is often a very big part of the bundle and memory volume, so this drastically improves that and removes the need of creating a schema in runtime, which can also be very costly.
29
31
 
30
32
  In this initial phase, we will achieve the goal of tree-shaking the schema definitions. We do this by inlining required metadata into the documents that describe the operations, after which they can be executed with the need of the entire schema. This means overall bundle size will be decreased when only a subset of the schema is actually used, which pays off significantly when a host application introduces its first component(s) leveraging GraphQL.
31
33
 
34
+ ### Possible future 1 - Relay IR
35
+
36
+ Current implementation has some bundle size / memory cost because GraphQL AST format isn't super optimized and adding types to it makes it even worse. However there is an already type annotated AST format that is more compact - Relay IR. As Relay anyway needs IR to do it's store operations, this wouldn't incur additional bundle cost to include them. Relay IR Printer would need to be modified to include more type information, but Relay IR is otherwise already typed and has all type information we
37
+ need.
38
+
39
+ Relay IR is more efficient because it allows aliasing common elements of the document, like types or selections, thus reducing the total document size.
40
+
41
+ ### Possible future 2 - pre-normalized executor
42
+
43
+ In a scenario where executor is running close to the client (sometimes even in same process or at least in same browser), it might be worth exploring removing some of the requirements imposed by the usual GraphQL transport - for example serialization. Not only GraphQL executors do the JSON serialization, but also they return the data that is optimized for transport and that matches the query tree. This means clients need to perform often expensive normazilation. As traffic and message size might be less important in same process / same browser scenarios, it might be worthwhile exploring return pre-normalized data from supermassive. This offers massive speedups for some clients like Apollo ([see benchmarks](https://github.com/vladar/graphql-normalized)).
44
+
45
+ ### Possible future 3 - Tree-shaking based on documents
46
+
47
+ Current implementation is more efficient in terms of bundles than one requiring full schema, but resolvers are also not always needed. By going through fields being selected in the documents, resolvers can be split or tree-shook to only load ones that are required for certain frontend bundle.
48
+
32
49
  Consider a GraphQL operation like the following:
33
50
 
34
51
  ```graphql
@@ -39,30 +56,8 @@ query CurrentUserNameQuery {
39
56
  }
40
57
  ```
41
58
 
42
- This would lead to the following [conceptual] tree-shaking after compilation of the schema:
43
-
44
- ```diff
45
- type Query {
46
- me: User!
47
- }
48
-
49
- type User {
50
- name: String!
51
- - presence: Presence!
52
- }
53
-
54
- -type Presence {
55
- - availability: PresenceAvailability!
56
- -}
57
- -
58
- -enum PresenceAvailability {
59
- - AVAILABLE
60
- - BUSY
61
- - OFFLINE
62
- -}
63
- ```
64
59
 
65
- ...and the field-resolver map:
60
+ This would lead to the following [conceptual] tree-shaking after compilation of the field-resolver map:
66
61
 
67
62
  ```diff
68
63
  import { getUser } from "user-service";
@@ -79,9 +74,9 @@ This would lead to the following [conceptual] tree-shaking after compilation of
79
74
  };
80
75
  ```
81
76
 
82
- ### Phase 2
77
+ ### Possible future 4 - GraphQL-to-JS
83
78
 
84
- In this phase, we will expand on the previous phase by ahead-of-time compiling the resolution of the operations, their field-resolvers, and invocation thereof into JavaScript code. This essentially does away with any need for AST of the operation during execution. This means execution will be faster as no more generic lookups and checks need to be performed.
79
+ We can expand on the previous phase by ahead-of-time compiling the resolution of the operations, their field-resolvers, and invocation thereof into JavaScript code. This essentially does away with any need for AST of the operation during execution. This means execution will be faster as no more generic lookups and checks need to be performed.
85
80
 
86
81
  Consider the GraphQL operation shown in the previous phase, typical generic execution (as [described in the specification](https://spec.graphql.org/June2018/#sec-Execution)) would look something like the following recursive pseudo-code:
87
82
 
@@ -148,9 +143,9 @@ function CurrentUserNameQuery(rootSource = {}) {
148
143
  CurrentUserNameQuery();
149
144
  ```
150
145
 
151
- ### Phase 3
146
+ ### Possible future 5 - persisted queries
152
147
 
153
- In this final phase, we will make it possible to replace the operations at runtime using a simple identifier, thus allowing GraphQL clients to execute their operations using these identifiers that they obtain through a concept known as ["persisted queries"](https://relay.dev/docs/guides/persisted-queries/). This means that GraphQL clients that do not require graphql-js AST _themselves_ to operate, such as Relay, will be able to greatly reduce the size of the User-Experience bundles by entirely eliminating the document in favour of a short identifier.
148
+ we can make it possible to replace the operations at runtime using a simple identifier, thus allowing GraphQL clients to execute their operations using these identifiers that they obtain through a concept known as ["persisted queries"](https://relay.dev/docs/guides/persisted-queries/). This means that GraphQL clients that do not require graphql-js AST _themselves_ to operate, such as Relay, will be able to greatly reduce the size of the User-Experience bundles by entirely eliminating the document in favour of a short identifier.
154
149
 
155
150
  Again, considering the above GraphQL operation, a React component needing that data would include the GraphQL document in its bundle and look something like the following:
156
151
 
@@ -1,3 +1,15 @@
1
1
  var __defProp = Object.defineProperty;
2
- var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
3
- __markAsModule(exports);
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
+ var TypedAST_exports = {};
15
+ module.exports = __toCommonJS(TypedAST_exports);
@@ -1,13 +1,13 @@
1
- var __create = Object.create;
2
1
  var __defProp = Object.defineProperty;
3
- var __getProtoOf = Object.getPrototypeOf;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
2
+ var __defProps = Object.defineProperties;
6
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
6
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
8
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
9
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {enumerable: true, configurable: true, writable: true, value}) : obj[key] = value;
10
- var __objSpread = (a, b) => {
9
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10
+ var __spreadValues = (a, b) => {
11
11
  for (var prop in b || (b = {}))
12
12
  if (__hasOwnProp.call(b, prop))
13
13
  __defNormalProp(a, prop, b[prop]);
@@ -18,28 +18,28 @@ var __objSpread = (a, b) => {
18
18
  }
19
19
  return a;
20
20
  };
21
- var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
21
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
22
22
  var __export = (target, all) => {
23
23
  for (var name in all)
24
- __defProp(target, name, {get: all[name], enumerable: true});
24
+ __defProp(target, name, { get: all[name], enumerable: true });
25
25
  };
26
- var __reExport = (target, module2, desc) => {
27
- if (module2 && typeof module2 === "object" || typeof module2 === "function") {
28
- for (let key of __getOwnPropNames(module2))
29
- if (!__hasOwnProp.call(target, key) && key !== "default")
30
- __defProp(target, key, {get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable});
26
+ var __copyProps = (to, from, except, desc) => {
27
+ if (from && typeof from === "object" || typeof from === "function") {
28
+ for (let key of __getOwnPropNames(from))
29
+ if (!__hasOwnProp.call(to, key) && key !== except)
30
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
31
31
  }
32
- return target;
33
- };
34
- var __toModule = (module2) => {
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
+ return to;
36
33
  };
37
- __markAsModule(exports);
38
- __export(exports, {
34
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
35
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
36
+ var addTypesToRequestDocument_exports = {};
37
+ __export(addTypesToRequestDocument_exports, {
39
38
  addTypesToRequestDocument: () => addTypesToRequestDocument
40
39
  });
41
- var import_graphql = __toModule(require("graphql"));
42
- __reExport(exports, __toModule(require("./TypedAST")));
40
+ module.exports = __toCommonJS(addTypesToRequestDocument_exports);
41
+ var import_graphql = require("graphql");
42
+ __reExport(addTypesToRequestDocument_exports, require("./TypedAST"), module.exports);
43
43
  function addTypesToRequestDocument(schema, document) {
44
44
  const typeInfo = new import_graphql.TypeInfo(schema);
45
45
  return (0, import_graphql.visit)(document, (0, import_graphql.visitWithTypeInfo)(typeInfo, {
@@ -47,7 +47,7 @@ function addTypesToRequestDocument(schema, document) {
47
47
  const argument = typeInfo.getArgument();
48
48
  if (argument) {
49
49
  const typeNode = generateTypeNode(argument.type);
50
- const newNode = __objSpread(__objSpread({}, node), {
50
+ const newNode = __spreadProps(__spreadValues({}, node), {
51
51
  __type: typeNode,
52
52
  __defaultValue: argument.defaultValue ? (0, import_graphql.parseValue)(JSON.stringify(argument.defaultValue)) : void 0
53
53
  });
@@ -58,7 +58,7 @@ function addTypesToRequestDocument(schema, document) {
58
58
  const type = typeInfo.getType();
59
59
  if (type) {
60
60
  const typeNode = generateTypeNode(type);
61
- const newNode = __objSpread(__objSpread({}, node), {
61
+ const newNode = __spreadProps(__spreadValues({}, node), {
62
62
  __type: typeNode
63
63
  });
64
64
  return newNode;
@@ -1,9 +1,11 @@
1
1
  var __defProp = Object.defineProperty;
2
- var __hasOwnProp = Object.prototype.hasOwnProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
3
4
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
4
6
  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
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
7
9
  for (var prop in b || (b = {}))
8
10
  if (__hasOwnProp.call(b, prop))
9
11
  __defNormalProp(a, prop, b[prop]);
@@ -14,6 +16,7 @@ var __objSpread = (a, b) => {
14
16
  }
15
17
  return a;
16
18
  };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
17
20
 
18
21
  // src/ast/addTypesToRequestDocument.ts
19
22
  import {
@@ -33,7 +36,7 @@ function addTypesToRequestDocument(schema, document) {
33
36
  const argument = typeInfo.getArgument();
34
37
  if (argument) {
35
38
  const typeNode = generateTypeNode(argument.type);
36
- const newNode = __objSpread(__objSpread({}, node), {
39
+ const newNode = __spreadProps(__spreadValues({}, node), {
37
40
  __type: typeNode,
38
41
  __defaultValue: argument.defaultValue ? parseValue(JSON.stringify(argument.defaultValue)) : void 0
39
42
  });
@@ -44,7 +47,7 @@ function addTypesToRequestDocument(schema, document) {
44
47
  const type = typeInfo.getType();
45
48
  if (type) {
46
49
  const typeNode = generateTypeNode(type);
47
- const newNode = __objSpread(__objSpread({}, node), {
50
+ const newNode = __spreadProps(__spreadValues({}, node), {
48
51
  __type: typeNode
49
52
  });
50
53
  return newNode;
@@ -1,21 +1,18 @@
1
1
  var __create = Object.create;
2
2
  var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
3
5
  var __getProtoOf = Object.getPrototypeOf;
4
6
  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 __reExport = (target, module2, desc) => {
9
- if (module2 && typeof module2 === "object" || typeof module2 === "function") {
10
- for (let key of __getOwnPropNames(module2))
11
- if (!__hasOwnProp.call(target, key) && key !== "default")
12
- __defProp(target, key, {get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable});
7
+ var __copyProps = (to, from, except, desc) => {
8
+ if (from && typeof from === "object" || typeof from === "function") {
9
+ for (let key of __getOwnPropNames(from))
10
+ if (!__hasOwnProp.call(to, key) && key !== except)
11
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
12
  }
14
- return target;
15
- };
16
- var __toModule = (module2) => {
17
- 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);
13
+ return to;
18
14
  };
15
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
19
16
  var __async = (__this, __arguments, generator) => {
20
17
  return new Promise((resolve, reject) => {
21
18
  var fulfilled = (value) => {
@@ -36,18 +33,18 @@ var __async = (__this, __arguments, generator) => {
36
33
  step((generator = generator.apply(__this, __arguments)).next());
37
34
  });
38
35
  };
39
- var import_fs = __toModule(require("fs"));
40
- var import_path = __toModule(require("path"));
41
- var import_nice_benchmark = __toModule(require("./nice-benchmark"));
42
- var import_swapi_schema = __toModule(require("./swapi-schema"));
43
- var import_resolvers = __toModule(require("./swapi-schema/resolvers"));
44
- var import_models = __toModule(require("./swapi-schema/models"));
45
- var import_graphql = __toModule(require("graphql"));
46
- var import_graphql_jit = __toModule(require("graphql-jit"));
47
- var import_executeWithoutSchema = __toModule(require("../executeWithoutSchema"));
48
- var import_addTypesToRequestDocument = __toModule(require("../ast/addTypesToRequestDocument"));
49
- var import_extractImplicitTypesRuntime = __toModule(require("../extractImplicitTypesRuntime"));
50
- var import_values = __toModule(require("../values"));
36
+ var import_fs = __toESM(require("fs"));
37
+ var import_path = __toESM(require("path"));
38
+ var import_nice_benchmark = __toESM(require("./nice-benchmark"));
39
+ var import_swapi_schema = __toESM(require("./swapi-schema"));
40
+ var import_resolvers = __toESM(require("./swapi-schema/resolvers"));
41
+ var import_models = __toESM(require("./swapi-schema/models"));
42
+ var import_graphql = require("graphql");
43
+ var import_graphql_jit = require("graphql-jit");
44
+ var import_executeWithoutSchema = require("../executeWithoutSchema");
45
+ var import_addTypesToRequestDocument = require("../ast/addTypesToRequestDocument");
46
+ var import_extractImplicitTypesRuntime = require("../extractImplicitTypesRuntime");
47
+ var import_values = require("../values");
51
48
  const query = import_fs.default.readFileSync(import_path.default.join(__dirname, "./fixtures/query1.graphql"), {
52
49
  encoding: "utf-8"
53
50
  });
@@ -55,30 +52,30 @@ const parsedQuery = (0, import_graphql.parse)(query);
55
52
  const compiledQuery = (0, import_graphql_jit.compileQuery)(import_swapi_schema.default, parsedQuery);
56
53
  const typeAnnotatedQuery = (0, import_addTypesToRequestDocument.addTypesToRequestDocument)(import_swapi_schema.default, parsedQuery);
57
54
  const queryRunningSuite = new import_nice_benchmark.default("Query Running");
58
- queryRunningSuite.add("graphql-js - string queries", () => __async(void 0, null, function* () {
55
+ queryRunningSuite.add("graphql-js - string queries", () => __async(exports, null, function* () {
59
56
  const result = yield (0, import_graphql.graphql)({
60
57
  schema: import_swapi_schema.default,
61
58
  source: query,
62
- contextValue: {models: import_models.default}
59
+ contextValue: { models: import_models.default }
63
60
  });
64
61
  if (result.errors || !result.data) {
65
62
  throw new Error("Stuff ain't executing");
66
63
  }
67
64
  }));
68
- queryRunningSuite.add("graphql-js - parsed queries", () => __async(void 0, null, function* () {
65
+ queryRunningSuite.add("graphql-js - parsed queries", () => __async(exports, null, function* () {
69
66
  const result = yield (0, import_graphql.execute)({
70
67
  schema: import_swapi_schema.default,
71
68
  document: parsedQuery,
72
- contextValue: {models: import_models.default}
69
+ contextValue: { models: import_models.default }
73
70
  });
74
71
  if (result.errors || !result.data) {
75
72
  throw new Error("Stuff ain't executing");
76
73
  }
77
74
  }));
78
- queryRunningSuite.add("graphql-jit - uncompiled", () => __async(void 0, null, function* () {
75
+ queryRunningSuite.add("graphql-jit - uncompiled", () => __async(exports, null, function* () {
79
76
  const freshCompiledQuery = (0, import_graphql_jit.compileQuery)(import_swapi_schema.default, parsedQuery);
80
77
  if ((0, import_graphql_jit.isCompiledQuery)(freshCompiledQuery)) {
81
- const result = yield freshCompiledQuery.query({}, {models: import_models.default}, {});
78
+ const result = yield freshCompiledQuery.query({}, { models: import_models.default }, {});
82
79
  if (result.errors || !result.data) {
83
80
  throw new Error("Stuff ain't executing");
84
81
  }
@@ -86,9 +83,9 @@ queryRunningSuite.add("graphql-jit - uncompiled", () => __async(void 0, null, fu
86
83
  throw new Error("Wrong query");
87
84
  }
88
85
  }));
89
- queryRunningSuite.add("graphql-jit - precompiled", () => __async(void 0, null, function* () {
86
+ queryRunningSuite.add("graphql-jit - precompiled", () => __async(exports, null, function* () {
90
87
  if ((0, import_graphql_jit.isCompiledQuery)(compiledQuery)) {
91
- const result = yield compiledQuery.query({}, {models: import_models.default}, {});
88
+ const result = yield compiledQuery.query({}, { models: import_models.default }, {});
92
89
  if (result.errors || !result.data) {
93
90
  throw new Error("Stuff ain't executing");
94
91
  }
@@ -96,7 +93,7 @@ queryRunningSuite.add("graphql-jit - precompiled", () => __async(void 0, null, f
96
93
  throw new Error("Wrong query");
97
94
  }
98
95
  }));
99
- queryRunningSuite.add("supermassive - runtime schemaless", () => __async(void 0, null, function* () {
96
+ queryRunningSuite.add("supermassive - runtime schemaless", () => __async(exports, null, function* () {
100
97
  let extractedResolvers = {};
101
98
  const getTypeByName = (name) => {
102
99
  const type = import_values.specifiedScalars[name] || extractedResolvers[name];
@@ -111,18 +108,18 @@ queryRunningSuite.add("supermassive - runtime schemaless", () => __async(void 0,
111
108
  resolvers: import_resolvers.default,
112
109
  schemaResolvers: extractedResolvers,
113
110
  document: typeAnnotatedQuery,
114
- contextValue: {models: import_models.default}
111
+ contextValue: { models: import_models.default }
115
112
  });
116
113
  if (result.errors || !result.data) {
117
114
  throw new Error("Stuff ain't executing");
118
115
  }
119
116
  }));
120
117
  const queryParsingSuite = new import_nice_benchmark.default("Query parsing");
121
- queryParsingSuite.add("graphql-js", () => __async(void 0, null, function* () {
118
+ queryParsingSuite.add("graphql-js", () => __async(exports, null, function* () {
122
119
  (0, import_graphql.parse)(query);
123
120
  }));
124
121
  const queryCompilingSuite = new import_nice_benchmark.default("Query compiling");
125
- queryCompilingSuite.add("graphql-jit", () => __async(void 0, null, function* () {
122
+ queryCompilingSuite.add("graphql-jit", () => __async(exports, null, function* () {
126
123
  yield (0, import_graphql_jit.compileQuery)(import_swapi_schema.default, parsedQuery);
127
124
  }));
128
125
  const queryAnnotationSuite = new import_nice_benchmark.default("Query annotation");
@@ -1,3 +1,7 @@
1
+ var __getOwnPropNames = Object.getOwnPropertyNames;
2
+ var __commonJS = (cb, mod) => function __require() {
3
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
4
+ };
1
5
  var __async = (__this, __arguments, generator) => {
2
6
  return new Promise((resolve, reject) => {
3
7
  var fulfilled = (value) => {
@@ -32,98 +36,103 @@ import {
32
36
  parse,
33
37
  isInputType
34
38
  } from "graphql";
35
- import {compileQuery, isCompiledQuery} from "graphql-jit";
36
- import {executeWithoutSchema as supermassiveExecute} from "../executeWithoutSchema.mjs";
37
- import {addTypesToRequestDocument} from "../ast/addTypesToRequestDocument.mjs";
38
- import {extractImplicitTypes} from "../extractImplicitTypesRuntime.mjs";
39
- import {specifiedScalars} from "../values.mjs";
40
- var query = fs.readFileSync(path.join(__dirname, "./fixtures/query1.graphql"), {
41
- encoding: "utf-8"
42
- });
43
- var parsedQuery = parse(query);
44
- var compiledQuery = compileQuery(schema, parsedQuery);
45
- var typeAnnotatedQuery = addTypesToRequestDocument(schema, parsedQuery);
46
- var queryRunningSuite = new NiceBenchmark("Query Running");
47
- queryRunningSuite.add("graphql-js - string queries", () => __async(void 0, null, function* () {
48
- const result = yield graphql({
49
- schema,
50
- source: query,
51
- contextValue: {models}
52
- });
53
- if (result.errors || !result.data) {
54
- throw new Error("Stuff ain't executing");
55
- }
56
- }));
57
- queryRunningSuite.add("graphql-js - parsed queries", () => __async(void 0, null, function* () {
58
- const result = yield graphqlExecute({
59
- schema,
60
- document: parsedQuery,
61
- contextValue: {models}
62
- });
63
- if (result.errors || !result.data) {
64
- throw new Error("Stuff ain't executing");
65
- }
66
- }));
67
- queryRunningSuite.add("graphql-jit - uncompiled", () => __async(void 0, null, function* () {
68
- const freshCompiledQuery = compileQuery(schema, parsedQuery);
69
- if (isCompiledQuery(freshCompiledQuery)) {
70
- const result = yield freshCompiledQuery.query({}, {models}, {});
71
- if (result.errors || !result.data) {
72
- throw new Error("Stuff ain't executing");
73
- }
74
- } else {
75
- throw new Error("Wrong query");
76
- }
77
- }));
78
- queryRunningSuite.add("graphql-jit - precompiled", () => __async(void 0, null, function* () {
79
- if (isCompiledQuery(compiledQuery)) {
80
- const result = yield compiledQuery.query({}, {models}, {});
81
- if (result.errors || !result.data) {
82
- throw new Error("Stuff ain't executing");
83
- }
84
- } else {
85
- throw new Error("Wrong query");
86
- }
87
- }));
88
- queryRunningSuite.add("supermassive - runtime schemaless", () => __async(void 0, null, function* () {
89
- let extractedResolvers = {};
90
- const getTypeByName = (name) => {
91
- const type = specifiedScalars[name] || extractedResolvers[name];
92
- if (isInputType(type)) {
93
- return type;
94
- } else {
95
- throw new Error("Invalid type");
39
+ import { compileQuery, isCompiledQuery } from "graphql-jit";
40
+ import { executeWithoutSchema as supermassiveExecute } from "../executeWithoutSchema.mjs";
41
+ import { addTypesToRequestDocument } from "../ast/addTypesToRequestDocument.mjs";
42
+ import { extractImplicitTypes } from "../extractImplicitTypesRuntime.mjs";
43
+ import { specifiedScalars } from "../values.mjs";
44
+ var require_benchmarks = __commonJS({
45
+ "src/benchmarks/index.ts"(exports) {
46
+ var query = fs.readFileSync(path.join(__dirname, "./fixtures/query1.graphql"), {
47
+ encoding: "utf-8"
48
+ });
49
+ var parsedQuery = parse(query);
50
+ var compiledQuery = compileQuery(schema, parsedQuery);
51
+ var typeAnnotatedQuery = addTypesToRequestDocument(schema, parsedQuery);
52
+ var queryRunningSuite = new NiceBenchmark("Query Running");
53
+ queryRunningSuite.add("graphql-js - string queries", () => __async(exports, null, function* () {
54
+ const result = yield graphql({
55
+ schema,
56
+ source: query,
57
+ contextValue: { models }
58
+ });
59
+ if (result.errors || !result.data) {
60
+ throw new Error("Stuff ain't executing");
61
+ }
62
+ }));
63
+ queryRunningSuite.add("graphql-js - parsed queries", () => __async(exports, null, function* () {
64
+ const result = yield graphqlExecute({
65
+ schema,
66
+ document: parsedQuery,
67
+ contextValue: { models }
68
+ });
69
+ if (result.errors || !result.data) {
70
+ throw new Error("Stuff ain't executing");
71
+ }
72
+ }));
73
+ queryRunningSuite.add("graphql-jit - uncompiled", () => __async(exports, null, function* () {
74
+ const freshCompiledQuery = compileQuery(schema, parsedQuery);
75
+ if (isCompiledQuery(freshCompiledQuery)) {
76
+ const result = yield freshCompiledQuery.query({}, { models }, {});
77
+ if (result.errors || !result.data) {
78
+ throw new Error("Stuff ain't executing");
79
+ }
80
+ } else {
81
+ throw new Error("Wrong query");
82
+ }
83
+ }));
84
+ queryRunningSuite.add("graphql-jit - precompiled", () => __async(exports, null, function* () {
85
+ if (isCompiledQuery(compiledQuery)) {
86
+ const result = yield compiledQuery.query({}, { models }, {});
87
+ if (result.errors || !result.data) {
88
+ throw new Error("Stuff ain't executing");
89
+ }
90
+ } else {
91
+ throw new Error("Wrong query");
92
+ }
93
+ }));
94
+ queryRunningSuite.add("supermassive - runtime schemaless", () => __async(exports, null, function* () {
95
+ let extractedResolvers = {};
96
+ const getTypeByName = (name) => {
97
+ const type = specifiedScalars[name] || extractedResolvers[name];
98
+ if (isInputType(type)) {
99
+ return type;
100
+ } else {
101
+ throw new Error("Invalid type");
102
+ }
103
+ };
104
+ extractedResolvers = extractImplicitTypes(parsedQuery, getTypeByName);
105
+ const result = yield supermassiveExecute({
106
+ resolvers,
107
+ schemaResolvers: extractedResolvers,
108
+ document: typeAnnotatedQuery,
109
+ contextValue: { models }
110
+ });
111
+ if (result.errors || !result.data) {
112
+ throw new Error("Stuff ain't executing");
113
+ }
114
+ }));
115
+ var queryParsingSuite = new NiceBenchmark("Query parsing");
116
+ queryParsingSuite.add("graphql-js", () => __async(exports, null, function* () {
117
+ parse(query);
118
+ }));
119
+ var queryCompilingSuite = new NiceBenchmark("Query compiling");
120
+ queryCompilingSuite.add("graphql-jit", () => __async(exports, null, function* () {
121
+ yield compileQuery(schema, parsedQuery);
122
+ }));
123
+ var queryAnnotationSuite = new NiceBenchmark("Query annotation");
124
+ queryAnnotationSuite.add("supermassive", () => {
125
+ addTypesToRequestDocument(schema, parsedQuery);
126
+ });
127
+ function main() {
128
+ return __async(this, null, function* () {
129
+ yield queryCompilingSuite.run();
130
+ yield queryParsingSuite.run();
131
+ yield queryAnnotationSuite.run();
132
+ yield queryRunningSuite.run();
133
+ });
96
134
  }
97
- };
98
- extractedResolvers = extractImplicitTypes(parsedQuery, getTypeByName);
99
- const result = yield supermassiveExecute({
100
- resolvers,
101
- schemaResolvers: extractedResolvers,
102
- document: typeAnnotatedQuery,
103
- contextValue: {models}
104
- });
105
- if (result.errors || !result.data) {
106
- throw new Error("Stuff ain't executing");
135
+ main();
107
136
  }
108
- }));
109
- var queryParsingSuite = new NiceBenchmark("Query parsing");
110
- queryParsingSuite.add("graphql-js", () => __async(void 0, null, function* () {
111
- parse(query);
112
- }));
113
- var queryCompilingSuite = new NiceBenchmark("Query compiling");
114
- queryCompilingSuite.add("graphql-jit", () => __async(void 0, null, function* () {
115
- yield compileQuery(schema, parsedQuery);
116
- }));
117
- var queryAnnotationSuite = new NiceBenchmark("Query annotation");
118
- queryAnnotationSuite.add("supermassive", () => {
119
- addTypesToRequestDocument(schema, parsedQuery);
120
137
  });
121
- function main() {
122
- return __async(this, null, function* () {
123
- yield queryCompilingSuite.run();
124
- yield queryParsingSuite.run();
125
- yield queryAnnotationSuite.run();
126
- yield queryRunningSuite.run();
127
- });
128
- }
129
- main();
138
+ export default require_benchmarks();