@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
package/CHANGELOG.md CHANGED
@@ -1,12 +1,44 @@
1
1
  # Change Log - @graphitation/supermassive
2
2
 
3
- This log was last generated on Tue, 26 Oct 2021 21:09:16 GMT and should not be manually modified.
3
+ This log was last generated on Thu, 23 Dec 2021 11:32:09 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## 0.4.1
8
+
9
+ Thu, 23 Dec 2021 11:32:09 GMT
10
+
11
+ ### Patches
12
+
13
+ - Add graphql-js notice (mnovikov@microsoft.com)
14
+
15
+ ## 0.4.0
16
+
17
+ Thu, 23 Dec 2021 11:31:14 GMT
18
+
19
+ ### Minor changes
20
+
21
+ - Added proper mjs builds (bump for main release) (mnovikov@microsoft.com)
22
+
23
+ ## 0.3.0
24
+
25
+ Tue, 14 Dec 2021 10:13:54 GMT
26
+
27
+ ### Minor changes
28
+
29
+ - Support ESM in distro packages (mnovikov@microsoft.com)
30
+
31
+ ## 0.2.0
32
+
33
+ Fri, 26 Nov 2021 15:43:37 GMT
34
+
35
+ ### Minor changes
36
+
37
+ - Updated supermassive to be more suitable for usage (mnovikov@microsoft.com)
38
+
7
39
  ## 0.1.3
8
40
 
9
- Tue, 26 Oct 2021 21:09:16 GMT
41
+ Tue, 26 Oct 2021 21:09:29 GMT
10
42
 
11
43
  ### Patches
12
44
 
package/NOTICE ADDED
@@ -0,0 +1,27 @@
1
+ NOTICES
2
+
3
+ This repository incorporates material as listed below or described in the code.
4
+
5
+ graphql-js
6
+
7
+ MIT License
8
+
9
+ Copyright (c) GraphQL Contributors
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ of this software and associated documentation files (the "Software"), to deal
13
+ in the Software without restriction, including without limitation the rights
14
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ copies of the Software, and to permit persons to whom the Software is
16
+ furnished to do so, subject to the following conditions:
17
+
18
+ The above copyright notice and this permission notice shall be included in all
19
+ copies or substantial portions of the Software.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ SOFTWARE.
package/README.md CHANGED
@@ -1,5 +1,267 @@
1
1
  # @graphitation/supermassive
2
2
 
3
- _Pack more performance into smaller space_
3
+ _[Pack more performance into smaller space](https://en.wikipedia.org/wiki/Supermassive_black_hole)_
4
4
 
5
- Supermassive is lightweight schema-less GraphQL executor and query build-time compiler.
5
+ Supermassive is a lightweight schema-less GraphQL executor and query build-time compiler.
6
+
7
+ ## What
8
+
9
+ Supermassive's goals are to provide a solution with the following optimizations for when all GraphQL operations (queries, mutations, subscriptions) needed by the user-experiences are statically known at build-time:
10
+
11
+ - Bundle size of production targets needs to be as small as possible.
12
+ - Performance is favored over runtime validation.
13
+
14
+ Such is the case in our scenarios, where our schema lives entirely in the client application and some of these applications have very little to no GraphQL needs [yet] other than to suffice the needs of a single or few components.
15
+
16
+ ## Why
17
+
18
+ Running a GraphQL executor can be an expensive exercise. The JavaScript community has the good fortune of having the official reference implementation of the GraphQL specification being implemented in JavaScript, namely [graphql-js](http://github.com/graphql/graphql-js). Inevitably this means that most general purpose GraphQL libraries in the JavaScript ecosystem end up wrapping it or otherwise rely on it. However, graphql-js' goal is specifically to be an _all-encompassing_ implementation used for reference needs, _not_ to be an optimized solution for specific use-cases.
19
+
20
+ ## How
21
+
22
+ Consider a GraphQL schema. It is typically a sizeable chunk of data, both in terms of type/field definition metadata as well as associated field-resolvers and _their_ code dependencies. Statically knowing all GraphQL operations allows us to reduce the bundle size to a minimum by [tree-shaking](https://en.wikipedia.org/wiki/Tree_shaking) all the definition metadata not required by any of the given operations. A JavaScript code bundler can in turn ensure only that code which is needed by the remaining field-resolvers is included in the production bundle. This means that the process is entirely dependency driven by needs expressed by the user-experiences, rather than requiring blunt manual configuration.
23
+
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
+
26
+ ## Roadmap
27
+
28
+ ### Phase 1
29
+
30
+ 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
+
32
+ Consider a GraphQL operation like the following:
33
+
34
+ ```graphql
35
+ query CurrentUserNameQuery {
36
+ me {
37
+ name
38
+ }
39
+ }
40
+ ```
41
+
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
+
65
+ ...and the field-resolver map:
66
+
67
+ ```diff
68
+ import { getUser } from "user-service";
69
+ -import { getUserPresence } from "presence-service";
70
+
71
+ const resolvers = {
72
+ Query: {
73
+ me: async (_source, _args, context) => getUser(context.currentUserId),
74
+ },
75
+ User: {
76
+ name: (source) => source.name,
77
+ - presence: async (source) => getUserPresence(source.id),
78
+ },
79
+ };
80
+ ```
81
+
82
+ ### Phase 2
83
+
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.
85
+
86
+ 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
+
88
+ ```ts
89
+ function visitSelectionSet(parentType, selectionSet, parentSource) {
90
+ const result = {};
91
+ for (const selection of selectionSet.selections) {
92
+ switch (selection.kind) {
93
+ case "Field": {
94
+ const type = getType(selection.type.name);
95
+ if (isScalarType(type)) {
96
+ result[selection.name] = parentType.invokeFieldResolver(
97
+ selection.name,
98
+ parentSource
99
+ );
100
+ } else if (isObjectType(type)) {
101
+ const source = parentType.invokeFieldResolver(
102
+ selection.name,
103
+ parentSource
104
+ );
105
+ result[selection.name] = visitSelectionSet(
106
+ type,
107
+ selection.selectionSet,
108
+ source
109
+ );
110
+ } else {
111
+ // ...
112
+ }
113
+ }
114
+ // ...
115
+ }
116
+ }
117
+ return result;
118
+ }
119
+
120
+ function execute(query, rootSource = {}) {
121
+ return visitSelectionSet(getType("Query"), query.selectionSet, rootSource);
122
+ }
123
+
124
+ execute(
125
+ parse(`
126
+ query CurrentUserNameQuery {
127
+ me {
128
+ name
129
+ }
130
+ }
131
+ `)
132
+ );
133
+ ```
134
+
135
+ Whereas a compiled version of the specific operation would look something like the following:
136
+
137
+ ```ts
138
+ function CurrentUserNameQuery(rootSource = {}) {
139
+ const meSource = QueryType.fieldResolvers["me"](rootSource);
140
+ const result = {
141
+ me: {
142
+ name: UserType.fieldResolvers["name"](meSource),
143
+ },
144
+ };
145
+ return result;
146
+ }
147
+
148
+ CurrentUserNameQuery();
149
+ ```
150
+
151
+ ### Phase 3
152
+
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.
154
+
155
+ 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
+
157
+ ```tsx
158
+ function CurrentUser() {
159
+ const data = useQuery({
160
+ document: `
161
+ query CurrentUserNameQuery {
162
+ me {
163
+ name
164
+ }
165
+ }
166
+ `,
167
+ });
168
+ return <div>User: {data.me.name}</div>;
169
+ }
170
+ ```
171
+
172
+ However, now that we can compile the operation to code ahead-of-time, and no longer need the operation AST during execution, we can eliminate the document entirely and compile the component to refer to the compiled version of the document instead:
173
+
174
+ ```tsx
175
+ function CurrentUser() {
176
+ const data = useQuery({
177
+ persistedDocumentId: "CurrentUserNameQuery",
178
+ });
179
+ return <div>User: {data.me.name}</div>;
180
+ }
181
+ ```
182
+
183
+ ## Usage
184
+
185
+ There are 3 main parts of Supermassive - the executor, query annotator and implicit resolver extractor. Executor is the part that actually runs the queries. It takes resolvers object instead of schema and annotated documents instead of normal documents. Query annotator processes query to include type information inside them. It can be ran as part of query extraction stage in Relay Compiler or eg in `@graphitation/graphql-js-tag`. Implicit resolver extractor writes out resolvers for types that are only implicitly defined in GraphQL SDL, like Unions or Input Objects. It generates typescript file with extracted object that can be merged with the rest of the resolvers.
186
+
187
+ ### Executor
188
+
189
+ Two functions are provided - `executeWithSchema` and `executeWithoutSchema`. They attempt to match `graphql-js`'s `execute` function parameters. `executeWithSchema` fully matches it and is meant for development or testing. It does the transform and resolver extraction in runtime. `executeWithoutSchema` relies on those being done during compile/bundling time.
190
+
191
+ ```graphql
192
+ interface CommonExecutionArgs {
193
+ resolvers: Resolvers;
194
+ rootValue?: unknown;
195
+ contextValue?: unknown;
196
+ variableValues?: Maybe<{ [variable: string]: unknown }>;
197
+ operationName?: Maybe<string>;
198
+ fieldResolver?: Maybe<FieldResolver<any, any>>;
199
+ typeResolver?: Maybe<TypeResolver<any, any>>;
200
+ }
201
+ type ExecutionWithoutSchemaArgs = CommonExecutionArgs & {
202
+ document: DocumentNode;
203
+ };
204
+
205
+ type ExecutionWithSchemaArgs = CommonExecutionArgs & {
206
+ document: UntypedDocumentNode;
207
+ typeDefs: UntypedDocumentNode;
208
+ };
209
+
210
+ function executeWithoutSchema(args: ExecutionWithoutSchemaArgs): PromiseOrValue<ExecutionResult>
211
+
212
+ function executeWithSchema(args: ExecutionWithSchemaArgs): PromiseOrValue<ExecutionResult>
213
+ ```
214
+
215
+ ### Transform
216
+
217
+ `addTypesToRequestDocument` converts untyped graphql-js AST node into a Supermassive typed one.
218
+
219
+ ```js
220
+ function addTypesToRequestDocument(
221
+ schema: GraphQLSchema,
222
+ document: TypelessAST.DocumentNode
223
+ ): TypedAST.DocumentNode
224
+ ```
225
+
226
+ With `@graphitation/graphql-js-tag` and `@graphitation/ts-transform-graphql-js-tag` (in webpack config)
227
+
228
+ ```js
229
+ import { buildASTSchema } from 'graphql'
230
+ import { getTransformer } from "@graphitation/ts-transform-graphql-js-tag";
231
+ import { annotateDocumentGraphQLTransform } from "@graphitation/supermassive";
232
+
233
+ // ...
234
+
235
+ {
236
+ test: /\.tsx?$/,
237
+ loader: "ts-loader",
238
+ options: {
239
+ getCustomTransformers: () => ({
240
+ before: [
241
+ getTransformer({
242
+ graphqlTagModuleExport: "graphql",
243
+ transformer: annotateDocumentGraphQLTransform(
244
+ buildASTSchema({
245
+ fs.readFileSync(
246
+ "PATH_TO_SCHEMA_TYPEDEFS.graphql",
247
+ { encoding: "utf-8" }
248
+ ),
249
+ )
250
+ ),
251
+ }),
252
+ ],
253
+ }),
254
+ },
255
+ },
256
+ }
257
+ ```
258
+
259
+ ### Resolver extractor
260
+
261
+ Supermassive provides a bin command to extract implicit resolvers.
262
+
263
+ ```sh
264
+ supermassive extract-schema PATH_TO_TYPEDEFS.graphql
265
+ ```
266
+
267
+ It generates `__generated__/NAME_OF_TYPEDEFS.ts` file, on top of which user provided resolvers can be merged when executing.
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+
3
+ (function () {
4
+ require("../lib/cjs/bin/supermassive")
5
+ .supermassive()
6
+ .parseAsync(process.argv);
7
+ })();
@@ -5,6 +5,7 @@
5
5
  *
6
6
  * Our changes MUST be annotated inline for ease of future merging.
7
7
  */
8
+ import { Maybe } from "../jsutils/Maybe";
8
9
  /**
9
10
  * [SUPERMASSIVE]
10
11
  *
@@ -116,6 +117,7 @@ export interface FieldNode {
116
117
  }
117
118
  export interface ArgumentNode {
118
119
  readonly __type: TypeNode;
120
+ readonly __defaultValue: Maybe<ValueNode>;
119
121
  readonly kind: "Argument";
120
122
  readonly loc?: Location;
121
123
  readonly name: NameNode;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TypedAST.d.ts","sourceRoot":"","sources":["../../src/ast/TypedAST.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEzC;;;;GAIG;AACH,aAAK,QAAQ,GAAG,OAAO,CAAC;AAExB;;GAEG;AACH,oBAAY,OAAO,GACf,QAAQ,GACR,YAAY,GACZ,uBAAuB,GACvB,sBAAsB,GACtB,YAAY,GACZ,gBAAgB,GAChB,SAAS,GACT,YAAY,GACZ,kBAAk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EAEL,aAAa,EASd,MAAM,SAAS,CAAC;AAEjB,OAAO,KAAK,WAAW,MAAM,sBAAsB,CAAC;AACpD,OAAO,KAAK,QAAQ,MAAM,YAAY,CAAC;AACvC,cAAc,YAAY,CAAC;AAE3B,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,aAAa,EACrB,QAAQ,EAAE,WAAW,CAAC,YAAY,GACjC,QAAQ,CAAC,YAAY,CAsCvB"}
@@ -45,11 +45,14 @@ function addTypesToRequestDocument(schema, document) {
45
45
  return (0, import_graphql.visit)(document, (0, import_graphql.visitWithTypeInfo)(typeInfo, {
46
46
  Argument(node) {
47
47
  const argument = typeInfo.getArgument();
48
- const typeNode = generateTypeNode(argument.type);
49
- const newNode = __objSpread(__objSpread({}, node), {
50
- __type: typeNode
51
- });
52
- return newNode;
48
+ if (argument) {
49
+ const typeNode = generateTypeNode(argument.type);
50
+ const newNode = __objSpread(__objSpread({}, node), {
51
+ __type: typeNode,
52
+ __defaultValue: argument.defaultValue ? (0, import_graphql.parseValue)(JSON.stringify(argument.defaultValue)) : void 0
53
+ });
54
+ return newNode;
55
+ }
53
56
  },
54
57
  Field(node) {
55
58
  const type = typeInfo.getType();
@@ -14,25 +14,31 @@ var __objSpread = (a, b) => {
14
14
  }
15
15
  return a;
16
16
  };
17
+
18
+ // src/ast/addTypesToRequestDocument.ts
17
19
  import {
18
20
  isListType,
19
21
  isNamedType,
20
22
  isNonNullType,
23
+ parseValue,
21
24
  TypeInfo,
22
25
  visit,
23
26
  visitWithTypeInfo
24
27
  } from "graphql";
25
- export * from "./TypedAST";
28
+ export * from "./TypedAST.mjs";
26
29
  function addTypesToRequestDocument(schema, document) {
27
30
  const typeInfo = new TypeInfo(schema);
28
31
  return visit(document, visitWithTypeInfo(typeInfo, {
29
32
  Argument(node) {
30
33
  const argument = typeInfo.getArgument();
31
- const typeNode = generateTypeNode(argument.type);
32
- const newNode = __objSpread(__objSpread({}, node), {
33
- __type: typeNode
34
- });
35
- return newNode;
34
+ if (argument) {
35
+ const typeNode = generateTypeNode(argument.type);
36
+ const newNode = __objSpread(__objSpread({}, node), {
37
+ __type: typeNode,
38
+ __defaultValue: argument.defaultValue ? parseValue(JSON.stringify(argument.defaultValue)) : void 0
39
+ });
40
+ return newNode;
41
+ }
36
42
  },
37
43
  Field(node) {
38
44
  const type = typeInfo.getType();
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../benchmarks/index.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/benchmarks/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1,127 @@
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 __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});
13
+ }
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);
18
+ };
19
+ var __async = (__this, __arguments, generator) => {
20
+ return new Promise((resolve, reject) => {
21
+ var fulfilled = (value) => {
22
+ try {
23
+ step(generator.next(value));
24
+ } catch (e) {
25
+ reject(e);
26
+ }
27
+ };
28
+ var rejected = (value) => {
29
+ try {
30
+ step(generator.throw(value));
31
+ } catch (e) {
32
+ reject(e);
33
+ }
34
+ };
35
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
36
+ step((generator = generator.apply(__this, __arguments)).next());
37
+ });
38
+ };
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
+ const query = import_fs.default.readFileSync(import_path.default.join(__dirname, "./fixtures/query1.graphql"), {
50
+ encoding: "utf-8"
51
+ });
52
+ const parsedQuery = (0, import_graphql.parse)(query);
53
+ const compiledQuery = (0, import_graphql_jit.compileQuery)(import_swapi_schema.default, parsedQuery);
54
+ const typeAnnotatedQuery = (0, import_addTypesToRequestDocument.addTypesToRequestDocument)(import_swapi_schema.default, parsedQuery);
55
+ const queryRunningSuite = new import_nice_benchmark.default("Query Running");
56
+ queryRunningSuite.add("graphql-js - string queries", () => __async(void 0, null, function* () {
57
+ const result = yield (0, import_graphql.graphql)({
58
+ schema: import_swapi_schema.default,
59
+ source: query,
60
+ contextValue: {models: import_models.default}
61
+ });
62
+ if (result.errors || !result.data) {
63
+ throw new Error("Stuff ain't executing");
64
+ }
65
+ }));
66
+ queryRunningSuite.add("graphql-js - parsed queries", () => __async(void 0, null, function* () {
67
+ const result = yield (0, import_graphql.execute)({
68
+ schema: import_swapi_schema.default,
69
+ document: parsedQuery,
70
+ contextValue: {models: import_models.default}
71
+ });
72
+ if (result.errors || !result.data) {
73
+ throw new Error("Stuff ain't executing");
74
+ }
75
+ }));
76
+ queryRunningSuite.add("graphql-jit - uncompiled", () => __async(void 0, null, function* () {
77
+ const freshCompiledQuery = (0, import_graphql_jit.compileQuery)(import_swapi_schema.default, parsedQuery);
78
+ if ((0, import_graphql_jit.isCompiledQuery)(freshCompiledQuery)) {
79
+ const result = yield freshCompiledQuery.query({}, {models: import_models.default}, {});
80
+ if (result.errors || !result.data) {
81
+ throw new Error("Stuff ain't executing");
82
+ }
83
+ } else {
84
+ throw new Error("Wrong query");
85
+ }
86
+ }));
87
+ queryRunningSuite.add("graphql-jit - precompiled", () => __async(void 0, null, function* () {
88
+ if ((0, import_graphql_jit.isCompiledQuery)(compiledQuery)) {
89
+ const result = yield compiledQuery.query({}, {models: import_models.default}, {});
90
+ if (result.errors || !result.data) {
91
+ throw new Error("Stuff ain't executing");
92
+ }
93
+ } else {
94
+ throw new Error("Wrong query");
95
+ }
96
+ }));
97
+ queryRunningSuite.add("supermassive - runtime schemaless", () => __async(void 0, null, function* () {
98
+ const result = yield (0, import_executeWithoutSchema.executeWithoutSchema)({
99
+ resolvers: import_resolvers.default,
100
+ document: typeAnnotatedQuery,
101
+ contextValue: {models: import_models.default}
102
+ });
103
+ if (result.errors || !result.data) {
104
+ throw new Error("Stuff ain't executing");
105
+ }
106
+ }));
107
+ const queryParsingSuite = new import_nice_benchmark.default("Query parsing");
108
+ queryParsingSuite.add("graphql-js", () => __async(void 0, null, function* () {
109
+ (0, import_graphql.parse)(query);
110
+ }));
111
+ const queryCompilingSuite = new import_nice_benchmark.default("Query compiling");
112
+ queryCompilingSuite.add("graphql-jit", () => __async(void 0, null, function* () {
113
+ yield (0, import_graphql_jit.compileQuery)(import_swapi_schema.default, parsedQuery);
114
+ }));
115
+ const queryAnnotationSuite = new import_nice_benchmark.default("Query annotation");
116
+ queryAnnotationSuite.add("supermassive", () => {
117
+ (0, import_addTypesToRequestDocument.addTypesToRequestDocument)(import_swapi_schema.default, parsedQuery);
118
+ });
119
+ function main() {
120
+ return __async(this, null, function* () {
121
+ yield queryCompilingSuite.run();
122
+ yield queryParsingSuite.run();
123
+ yield queryAnnotationSuite.run();
124
+ yield queryRunningSuite.run();
125
+ });
126
+ }
127
+ main();