@graphitation/supermassive 0.8.3 → 1.0.0
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.
- package/CHANGELOG.md +26 -2
- package/README.md +24 -29
- package/lib/ast/TypedAST.js +14 -2
- package/lib/ast/addTypesToRequestDocument.js +23 -23
- package/lib/ast/addTypesToRequestDocument.mjs +8 -5
- package/lib/benchmarks/index.js +33 -36
- package/lib/benchmarks/index.mjs +101 -92
- package/lib/benchmarks/nice-benchmark.js +14 -18
- package/lib/benchmarks/nice-benchmark.mjs +2 -3
- package/lib/benchmarks/swapi-schema/index.js +19 -20
- package/lib/benchmarks/swapi-schema/index.mjs +4 -4
- package/lib/benchmarks/swapi-schema/models.js +16 -17
- package/lib/benchmarks/swapi-schema/models.mjs +1 -1
- package/lib/benchmarks/swapi-schema/resolvers.js +65 -66
- package/lib/benchmarks/swapi-schema/resolvers.mjs +51 -48
- package/lib/bin/supermassive.js +23 -24
- package/lib/bin/supermassive.mjs +6 -6
- package/lib/collectFields.js +23 -27
- package/lib/collectFields.mjs +10 -10
- package/lib/definition.js +15 -19
- package/lib/definition.mjs +2 -2
- package/lib/directives.js +21 -25
- package/lib/directives.mjs +7 -7
- package/lib/executeWithSchema.js +15 -19
- package/lib/executeWithSchema.mjs +1 -1
- package/lib/executeWithoutSchema.js +37 -41
- package/lib/executeWithoutSchema.mjs +22 -22
- package/lib/extractImplicitTypesRuntime.js +17 -21
- package/lib/extractImplicitTypesRuntime.mjs +3 -3
- package/lib/extractImplicitTypesToTypescript.js +16 -17
- package/lib/extractImplicitTypesToTypescript.mjs +1 -1
- package/lib/extractors/index.d.ts +2 -0
- package/lib/extractors/index.d.ts.map +1 -0
- package/lib/extractors/index.js +23 -0
- package/lib/extractors/index.mjs +5 -0
- package/lib/index.js +21 -25
- package/lib/index.mjs +8 -8
- package/lib/jsutils/Maybe.js +14 -2
- package/lib/jsutils/ObjMap.js +14 -2
- package/lib/jsutils/Path.js +17 -5
- package/lib/jsutils/Path.mjs +1 -1
- package/lib/jsutils/PromiseOrValue.js +14 -2
- package/lib/jsutils/devAssert.js +16 -4
- package/lib/jsutils/didYouMean.js +16 -4
- package/lib/jsutils/identityFunc.js +16 -4
- package/lib/jsutils/inspect.js +16 -4
- package/lib/jsutils/instanceOf.js +14 -18
- package/lib/jsutils/instanceOf.mjs +1 -1
- package/lib/jsutils/invariant.js +16 -4
- package/lib/jsutils/isAsyncIterable.js +16 -4
- package/lib/jsutils/isIterableObject.js +16 -4
- package/lib/jsutils/isObjectLike.js +16 -4
- package/lib/jsutils/isPromise.js +16 -4
- package/lib/jsutils/keyMap.js +17 -5
- package/lib/jsutils/keyMap.mjs +1 -1
- package/lib/jsutils/keyValMap.js +17 -5
- package/lib/jsutils/keyValMap.mjs +1 -1
- package/lib/jsutils/mapValue.js +17 -5
- package/lib/jsutils/mapValue.mjs +1 -1
- package/lib/jsutils/memoize3.js +19 -7
- package/lib/jsutils/memoize3.mjs +3 -3
- package/lib/jsutils/naturalCompare.js +16 -4
- package/lib/jsutils/printPathArray.js +16 -4
- package/lib/jsutils/promiseForObject.js +17 -5
- package/lib/jsutils/promiseForObject.mjs +1 -1
- package/lib/jsutils/promiseReduce.js +14 -18
- package/lib/jsutils/promiseReduce.mjs +1 -1
- package/lib/jsutils/suggestionList.js +15 -19
- package/lib/jsutils/suggestionList.mjs +2 -2
- package/lib/jsutils/toObjMap.js +17 -5
- package/lib/jsutils/toObjMap.mjs +1 -1
- package/lib/subscribeWithSchema.js +15 -19
- package/lib/subscribeWithSchema.mjs +1 -1
- package/lib/subscribeWithoutSchema.js +26 -30
- package/lib/subscribeWithoutSchema.mjs +11 -11
- package/lib/transforms/annotateDocumentGraphQLTransform.js +15 -19
- package/lib/transforms/annotateDocumentGraphQLTransform.mjs +1 -1
- package/lib/transforms/transformerTestUtils.js +24 -25
- package/lib/transforms/transformerTestUtils.mjs +12 -16
- package/lib/types.js +14 -2
- package/lib/utilities/mapAsyncIterator.js +18 -6
- package/lib/utilities/mapAsyncIterator.mjs +2 -2
- package/lib/utilities/mergeResolvers.js +20 -9
- package/lib/utilities/mergeResolvers.mjs +5 -5
- package/lib/utilities/typeNameFromAST.js +14 -18
- package/lib/utilities/typeNameFromAST.mjs +1 -1
- package/lib/values.js +19 -23
- package/lib/values.mjs +5 -5
- package/package.json +13 -8
- package/.eslintcache +0 -1
- package/lib/benchmarks/swapi-schema/__generated__/schema.d.ts +0 -3
- package/lib/benchmarks/swapi-schema/__generated__/schema.d.ts.map +0 -1
- package/lib/benchmarks/swapi-schema/__generated__/schema.js +0 -41
- package/lib/benchmarks/swapi-schema/__generated__/schema.mjs +0 -19
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,36 @@
|
|
|
1
1
|
# Change Log - @graphitation/supermassive
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Wed, 20 Jul 2022 16:31:49 GMT and should not be manually modified.
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
+
## 1.0.0
|
|
8
|
+
|
|
9
|
+
Wed, 20 Jul 2022 16:31:49 GMT
|
|
10
|
+
|
|
11
|
+
### Major changes
|
|
12
|
+
|
|
13
|
+
- extractImplicitTypesToTypescript exported separately from supermassive (jakubvejr@microsoft.com)
|
|
14
|
+
|
|
15
|
+
## 0.8.5
|
|
16
|
+
|
|
17
|
+
Fri, 24 Jun 2022 11:59:47 GMT
|
|
18
|
+
|
|
19
|
+
### Patches
|
|
20
|
+
|
|
21
|
+
- Hotfix: re-export extractImplicitTypesToTypescript (jakubvejr@microsoft.com)
|
|
22
|
+
|
|
23
|
+
## 0.8.4
|
|
24
|
+
|
|
25
|
+
Thu, 23 Jun 2022 14:40:50 GMT
|
|
26
|
+
|
|
27
|
+
### Patches
|
|
28
|
+
|
|
29
|
+
- Schem extraction function exported (jakubvejr@microsoft.com)
|
|
30
|
+
|
|
7
31
|
## 0.8.3
|
|
8
32
|
|
|
9
|
-
Tue, 03 May 2022 17:45:
|
|
33
|
+
Tue, 03 May 2022 17:45:10 GMT
|
|
10
34
|
|
|
11
35
|
### Patches
|
|
12
36
|
|
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
|
-
##
|
|
26
|
+
## Implementation details and plans
|
|
27
27
|
|
|
28
|
-
###
|
|
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
|
-
|
|
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
|
-
###
|
|
77
|
+
### Possible future 4 - GraphQL-to-JS
|
|
83
78
|
|
|
84
|
-
|
|
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
|
-
###
|
|
146
|
+
### Possible future 5 - persisted queries
|
|
152
147
|
|
|
153
|
-
|
|
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
|
|
package/lib/ast/TypedAST.js
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
-
var
|
|
3
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
27
|
-
if (
|
|
28
|
-
for (let key of __getOwnPropNames(
|
|
29
|
-
if (!__hasOwnProp.call(
|
|
30
|
-
__defProp(
|
|
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
|
|
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
|
-
|
|
38
|
-
|
|
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
|
-
|
|
42
|
-
|
|
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 =
|
|
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 =
|
|
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
|
|
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
|
|
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 =
|
|
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 =
|
|
50
|
+
const newNode = __spreadProps(__spreadValues({}, node), {
|
|
48
51
|
__type: typeNode
|
|
49
52
|
});
|
|
50
53
|
return newNode;
|
package/lib/benchmarks/index.js
CHANGED
|
@@ -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
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
|
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 =
|
|
40
|
-
var import_path =
|
|
41
|
-
var import_nice_benchmark =
|
|
42
|
-
var import_swapi_schema =
|
|
43
|
-
var import_resolvers =
|
|
44
|
-
var import_models =
|
|
45
|
-
var import_graphql =
|
|
46
|
-
var import_graphql_jit =
|
|
47
|
-
var import_executeWithoutSchema =
|
|
48
|
-
var import_addTypesToRequestDocument =
|
|
49
|
-
var import_extractImplicitTypesRuntime =
|
|
50
|
-
var import_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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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");
|
package/lib/benchmarks/index.mjs
CHANGED
|
@@ -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
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
var
|
|
46
|
-
var
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
-
|
|
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();
|