@graphitation/supermassive 0.2.0 → 0.3.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.
Files changed (66) hide show
  1. package/CHANGELOG.md +10 -2
  2. package/README.md +179 -5
  3. package/bin/supermassive.js +3 -1
  4. package/lib/ast/addTypesToRequestDocument.mjs +3 -1
  5. package/lib/benchmarks/index.mjs +16 -14
  6. package/lib/benchmarks/nice-benchmark.mjs +6 -3
  7. package/lib/benchmarks/swapi-schema/index.mjs +3 -2
  8. package/lib/benchmarks/swapi-schema/models.mjs +1 -0
  9. package/lib/benchmarks/swapi-schema/resolvers.mjs +23 -24
  10. package/lib/bin/supermassive.d.ts.map +1 -1
  11. package/lib/bin/supermassive.js +0 -0
  12. package/lib/bin/supermassive.mjs +3 -1
  13. package/lib/collectFields.mjs +1 -0
  14. package/lib/executeWithSchema.d.ts.map +1 -1
  15. package/lib/executeWithSchema.js +8 -8
  16. package/lib/executeWithSchema.mjs +6 -4
  17. package/lib/executeWithoutSchema.mjs +15 -17
  18. package/lib/extractImplicitTypesRuntime.mjs +1 -0
  19. package/lib/extractImplicitTypesToTypescript.mjs +2 -1
  20. package/lib/index.d.ts +1 -1
  21. package/lib/index.d.ts.map +1 -1
  22. package/lib/index.js +0 -2
  23. package/lib/index.mjs +7 -8
  24. package/lib/jsutils/Path.mjs +1 -0
  25. package/lib/jsutils/devAssert.mjs +1 -0
  26. package/lib/jsutils/didYouMean.mjs +2 -1
  27. package/lib/jsutils/identityFunc.mjs +1 -0
  28. package/lib/jsutils/inspect.mjs +3 -2
  29. package/lib/jsutils/instanceOf.mjs +3 -2
  30. package/lib/jsutils/invariant.mjs +1 -0
  31. package/lib/jsutils/isAsyncIterable.mjs +1 -0
  32. package/lib/jsutils/isIterableObject.mjs +1 -0
  33. package/lib/jsutils/isObjectLike.mjs +1 -0
  34. package/lib/jsutils/isPromise.mjs +1 -0
  35. package/lib/jsutils/keyMap.mjs +1 -0
  36. package/lib/jsutils/keyValMap.mjs +1 -0
  37. package/lib/jsutils/mapValue.mjs +1 -0
  38. package/lib/jsutils/memoize3.mjs +1 -0
  39. package/lib/jsutils/naturalCompare.mjs +3 -2
  40. package/lib/jsutils/printPathArray.mjs +1 -0
  41. package/lib/jsutils/promiseForObject.mjs +1 -0
  42. package/lib/jsutils/promiseReduce.mjs +2 -1
  43. package/lib/jsutils/suggestionList.mjs +4 -3
  44. package/lib/jsutils/toObjMap.mjs +1 -0
  45. package/lib/transforms/annotateDocumentGraphQLTransform.mjs +3 -2
  46. package/lib/transforms/transformerTestUtils.mjs +14 -8
  47. package/lib/utilities/typeNameFromAST.mjs +1 -0
  48. package/lib/values.mjs +5 -4
  49. package/package.json +13 -3
  50. package/starwars.json +1 -0
  51. package/.eslintcache +0 -1
  52. package/graphitation-supermassive-0.1.3-1.tgz +0 -0
  53. package/graphitation-supermassive-0.1.3-2.tgz +0 -0
  54. package/graphitation-supermassive-0.1.3.tgz +0 -0
  55. package/lib/bin/typeDefsToImplicitResolvers.d.ts +0 -3
  56. package/lib/bin/typeDefsToImplicitResolvers.d.ts.map +0 -1
  57. package/lib/bin/typeDefsToImplicitResolvers.js +0 -82
  58. package/lib/bin/typeDefsToImplicitResolvers.mjs +0 -59
  59. package/lib/execute.d.ts +0 -128
  60. package/lib/execute.d.ts.map +0 -1
  61. package/lib/execute.js +0 -376
  62. package/lib/execute.mjs +0 -365
  63. package/lib/extractImplicitTypes.d.ts +0 -6
  64. package/lib/extractImplicitTypes.d.ts.map +0 -1
  65. package/lib/extractImplicitTypes.js +0 -246
  66. package/lib/extractImplicitTypes.mjs +0 -233
package/CHANGELOG.md CHANGED
@@ -1,12 +1,20 @@
1
1
  # Change Log - @graphitation/supermassive
2
2
 
3
- This log was last generated on Fri, 26 Nov 2021 15:43:24 GMT and should not be manually modified.
3
+ This log was last generated on Tue, 14 Dec 2021 10:06:07 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## 0.3.0
8
+
9
+ Tue, 14 Dec 2021 10:06:07 GMT
10
+
11
+ ### Minor changes
12
+
13
+ - Support ESM in distro packages (mnovikov@microsoft.com)
14
+
7
15
  ## 0.2.0
8
16
 
9
- Fri, 26 Nov 2021 15:43:24 GMT
17
+ Fri, 26 Nov 2021 15:43:37 GMT
10
18
 
11
19
  ### Minor changes
12
20
 
package/README.md CHANGED
@@ -1,15 +1,189 @@
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
6
 
7
- Running GraphQL executor on client can be expensive. Schema is a heavy object, typedefs, queries - it all can add up both in bundle size and performance. Supermassive aims to reduce that cost by removing the need to have a schema to run queries. It removes all runtime validation and accepts resolvers (like makeExecutableSchema resolvers) object. In addition it annotates GraphQL Documents to containt annotated type information. After that it proceeds to execute the queries without requiring actual schema. In future the plan is that GraphQL Documents are also eliminated and a inline functions are generated instead.
7
+ ## What
8
8
 
9
- 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.
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
+ ```
10
182
 
11
183
  ## Usage
12
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
+
13
187
  ### Executor
14
188
 
15
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.
@@ -40,7 +214,7 @@ function executeWithSchema(args: ExecutionWithSchemaArgs): PromiseOrValue<Execut
40
214
 
41
215
  ### Transform
42
216
 
43
- `addTypesToRequestDocument` converts untyped graphql-js AST node into a supermassive typed one.
217
+ `addTypesToRequestDocument` converts untyped graphql-js AST node into a Supermassive typed one.
44
218
 
45
219
  ```js
46
220
  function addTypesToRequestDocument(
@@ -1,5 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  (function () {
4
- require("../lib/bin/supermassive").supermassive().parseAsync(process.argv);
4
+ require("../lib/cjs/bin/supermassive")
5
+ .supermassive()
6
+ .parseAsync(process.argv);
5
7
  })();
@@ -14,6 +14,8 @@ 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,
@@ -23,7 +25,7 @@ import {
23
25
  visit,
24
26
  visitWithTypeInfo
25
27
  } from "graphql";
26
- export * from "./TypedAST";
28
+ export * from "./TypedAST.mjs";
27
29
  function addTypesToRequestDocument(schema, document) {
28
30
  const typeInfo = new TypeInfo(schema);
29
31
  return visit(document, visitWithTypeInfo(typeInfo, {
@@ -18,23 +18,25 @@ var __async = (__this, __arguments, generator) => {
18
18
  step((generator = generator.apply(__this, __arguments)).next());
19
19
  });
20
20
  };
21
+
22
+ // src/benchmarks/index.ts
21
23
  import fs from "fs";
22
24
  import path from "path";
23
- import NiceBenchmark from "./nice-benchmark";
24
- import schema from "./swapi-schema";
25
- import resolvers from "./swapi-schema/resolvers";
26
- import models from "./swapi-schema/models";
25
+ import NiceBenchmark from "./nice-benchmark.mjs";
26
+ import schema from "./swapi-schema.mjs";
27
+ import resolvers from "./swapi-schema/resolvers.mjs";
28
+ import models from "./swapi-schema/models.mjs";
27
29
  import {graphql, execute as graphqlExecute, parse} from "graphql";
28
30
  import {compileQuery, isCompiledQuery} from "graphql-jit";
29
- import {executeWithoutSchema as supermassiveExecute} from "../executeWithoutSchema";
30
- import {addTypesToRequestDocument} from "../ast/addTypesToRequestDocument";
31
- const query = fs.readFileSync(path.join(__dirname, "./fixtures/query1.graphql"), {
31
+ import {executeWithoutSchema as supermassiveExecute} from "../executeWithoutSchema.mjs";
32
+ import {addTypesToRequestDocument} from "../ast/addTypesToRequestDocument.mjs";
33
+ var query = fs.readFileSync(path.join(__dirname, "./fixtures/query1.graphql"), {
32
34
  encoding: "utf-8"
33
35
  });
34
- const parsedQuery = parse(query);
35
- const compiledQuery = compileQuery(schema, parsedQuery);
36
- const typeAnnotatedQuery = addTypesToRequestDocument(schema, parsedQuery);
37
- const queryRunningSuite = new NiceBenchmark("Query Running");
36
+ var parsedQuery = parse(query);
37
+ var compiledQuery = compileQuery(schema, parsedQuery);
38
+ var typeAnnotatedQuery = addTypesToRequestDocument(schema, parsedQuery);
39
+ var queryRunningSuite = new NiceBenchmark("Query Running");
38
40
  queryRunningSuite.add("graphql-js - string queries", () => __async(void 0, null, function* () {
39
41
  const result = yield graphql({
40
42
  schema,
@@ -86,15 +88,15 @@ queryRunningSuite.add("supermassive - runtime schemaless", () => __async(void 0,
86
88
  throw new Error("Stuff ain't executing");
87
89
  }
88
90
  }));
89
- const queryParsingSuite = new NiceBenchmark("Query parsing");
91
+ var queryParsingSuite = new NiceBenchmark("Query parsing");
90
92
  queryParsingSuite.add("graphql-js", () => __async(void 0, null, function* () {
91
93
  parse(query);
92
94
  }));
93
- const queryCompilingSuite = new NiceBenchmark("Query compiling");
95
+ var queryCompilingSuite = new NiceBenchmark("Query compiling");
94
96
  queryCompilingSuite.add("graphql-jit", () => __async(void 0, null, function* () {
95
97
  yield compileQuery(schema, parsedQuery);
96
98
  }));
97
- const queryAnnotationSuite = new NiceBenchmark("Query annotation");
99
+ var queryAnnotationSuite = new NiceBenchmark("Query annotation");
98
100
  queryAnnotationSuite.add("supermassive", () => {
99
101
  addTypesToRequestDocument(schema, parsedQuery);
100
102
  });
@@ -18,8 +18,10 @@ var __async = (__this, __arguments, generator) => {
18
18
  step((generator = generator.apply(__this, __arguments)).next());
19
19
  });
20
20
  };
21
+
22
+ // src/benchmarks/nice-benchmark.ts
21
23
  import {Suite} from "benchmark";
22
- class NiceBenchmark {
24
+ var NiceBenchmark = class {
23
25
  constructor(name) {
24
26
  this.name = name;
25
27
  this.suite = new Suite(name);
@@ -43,7 +45,8 @@ class NiceBenchmark {
43
45
  this.suite.run(options);
44
46
  });
45
47
  }
46
- }
48
+ };
49
+ var nice_benchmark_default = NiceBenchmark;
47
50
  export {
48
- NiceBenchmark as default
51
+ nice_benchmark_default as default
49
52
  };
@@ -1,9 +1,10 @@
1
+ // src/benchmarks/swapi-schema/index.ts
1
2
  import {makeExecutableSchema} from "@graphql-tools/schema";
2
3
  import {parse} from "graphql";
3
4
  import {join} from "path";
4
5
  import {readFileSync} from "fs";
5
- import resolvers from "./resolvers";
6
- const typeDefs = parse(readFileSync(join(__dirname, "./schema.graphql"), {
6
+ import resolvers from "./resolvers.mjs";
7
+ var typeDefs = parse(readFileSync(join(__dirname, "./schema.graphql"), {
7
8
  encoding: "utf-8"
8
9
  }));
9
10
  var swapi_schema_default = makeExecutableSchema({
@@ -1,3 +1,4 @@
1
+ // src/benchmarks/swapi-schema/models.ts
1
2
  import path from "path";
2
3
  import {JsonDB} from "node-json-db";
3
4
  var models_default = new JsonDB(path.join(__dirname, "./starwars"));
@@ -14,10 +14,12 @@ var __objSpread = (a, b) => {
14
14
  }
15
15
  return a;
16
16
  };
17
- const films = (parent, args, {models}) => {
17
+
18
+ // src/benchmarks/swapi-schema/resolvers.ts
19
+ var films = (parent, args, {models}) => {
18
20
  return models.getData("/films").filter(({id}) => parent.films.includes(id));
19
21
  };
20
- const starships = (parent, {id}, {models}) => {
22
+ var starships = (parent, {id}, {models}) => {
21
23
  return models.getData("/starships").filter(({id: id2}) => parent.starships.includes(id2));
22
24
  };
23
25
  function people(key) {
@@ -25,61 +27,58 @@ function people(key) {
25
27
  return models.getData("/people").filter(({id}) => parent[key].includes(id));
26
28
  };
27
29
  }
28
- const vehicles = (parent, args, {models}) => {
30
+ var vehicles = (parent, args, {models}) => {
29
31
  return models.getData("/vehicles").filter(({id}) => parent.vehicles.includes(id));
30
32
  };
31
- const transports = (parent, args, {models}) => {
32
- return models.getData("/transport").filter(({id}) => parent.starships.includes(id));
33
- };
34
- const planets = (parent, args, {models}) => {
33
+ var planets = (parent, args, {models}) => {
35
34
  return models.getData("/planets").filter(({id}) => parent.planets.includes(id));
36
35
  };
37
- const species = (parent, args, {models}) => {
36
+ var species = (parent, args, {models}) => {
38
37
  return models.getData("/species").filter(({id}) => parent.species.includes(id));
39
38
  };
40
- const homeworld = (parent, args, {models}) => {
39
+ var homeworld = (parent, args, {models}) => {
41
40
  return models.getData("/planets").find((planet2) => planet2.id === parent.homeworld);
42
41
  };
43
- const person = (parent, {id}, {models}) => {
42
+ var person = (parent, {id}, {models}) => {
44
43
  return models.getData("/people").find((person2) => person2.id === id);
45
44
  };
46
- const planet = (parent, {id}, {models}) => {
45
+ var planet = (parent, {id}, {models}) => {
47
46
  return models.getData("/planets").find((planet2) => planet2.id === id);
48
47
  };
49
- const film = (parent, {id}, {models}) => {
48
+ var film = (parent, {id}, {models}) => {
50
49
  return models.getData("/films").find((film2) => film2.id === id);
51
50
  };
52
- const starship = (parent, {id}, {models}) => {
51
+ var starship = (parent, {id}, {models}) => {
53
52
  return models.getData("/starships").find((starship2) => starship2.id === id);
54
53
  };
55
- const transport = (parent, {id}, {models}) => {
54
+ var transport = (parent, {id}, {models}) => {
56
55
  return models.getData("/transport").find((transport2) => transport2.id === id);
57
56
  };
58
- const vehicle = (parent, {id}, {models}) => {
57
+ var vehicle = (parent, {id}, {models}) => {
59
58
  return models.getData("/vehicles").find((vehicle2) => vehicle2.id === id);
60
59
  };
61
- const searchPeopleByName = (parent, {search}, {models}) => {
60
+ var searchPeopleByName = (parent, {search}, {models}) => {
62
61
  return models.getData("/people").filter((person2) => new RegExp(search, "i").test(person2.name));
63
62
  };
64
- const searchPlanetsByName = (parent, {search}, {models}) => {
63
+ var searchPlanetsByName = (parent, {search}, {models}) => {
65
64
  return models.getData("/planets").filter((planet2) => new RegExp(search, "i").test(planet2.name));
66
65
  };
67
- const searchFilmsByTitle = (parent, {search}, {models}) => {
66
+ var searchFilmsByTitle = (parent, {search}, {models}) => {
68
67
  return models.getData("/films").filter((film2) => new RegExp(search, "i").test(film2.title));
69
68
  };
70
- const searchSpeciesByName = (parent, {search}, {models}) => {
69
+ var searchSpeciesByName = (parent, {search}, {models}) => {
71
70
  return models.getData("/species").filter((species2) => new RegExp(search, "i").test(species2.name));
72
71
  };
73
- const searchStarshipsByName = (parent, {search}, {models}) => {
72
+ var searchStarshipsByName = (parent, {search}, {models}) => {
74
73
  return models.getData("/starships").filter((starship2) => new RegExp(search, "i").test(starship2.name));
75
74
  };
76
- const searchVehiclesByName = (parent, {search}, {models}) => {
75
+ var searchVehiclesByName = (parent, {search}, {models}) => {
77
76
  return models.getData("/vehicles").filter((vehicle2) => new RegExp(search, "i").test(vehicle2.name));
78
77
  };
79
- const searchTransportsByName = (parent, {search}, {models}) => {
78
+ var searchTransportsByName = (parent, {search}, {models}) => {
80
79
  return models.getData("/transport").filter((transport2) => new RegExp(search, "i").test(transport2.name));
81
80
  };
82
- const resolvers = {
81
+ var resolvers = {
83
82
  SearchResult: {
84
83
  __resolveType(parent) {
85
84
  return parent.__typename;
@@ -224,7 +223,7 @@ const resolvers = {
224
223
  cost_in_credits: (vehicle2) => +vehicle2.cost_in_credits
225
224
  }
226
225
  };
227
- const forceNumber = (i) => Number(i.split(",").join("").split("-")[0]) || -1;
226
+ var forceNumber = (i) => Number(i.split(",").join("").split("-")[0]) || -1;
228
227
  var resolvers_default = resolvers;
229
228
  export {
230
229
  resolvers_default as default
@@ -1 +1 @@
1
- {"version":3,"file":"supermassive.d.ts","sourceRoot":"","sources":["../../src/bin/supermassive.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC,wBAAgB,YAAY,IAAI,OAAO,CAUtC"}
1
+ {"version":3,"file":"supermassive.d.ts","sourceRoot":"","sources":["../../src/bin/supermassive.ts"],"names":[],"mappings":"AAGA,OAAO,EAAW,OAAO,EAAE,MAAM,WAAW,CAAC;AAI7C,wBAAgB,YAAY,IAAI,OAAO,CAYtC"}
File without changes
@@ -18,11 +18,13 @@ var __async = (__this, __arguments, generator) => {
18
18
  step((generator = generator.apply(__this, __arguments)).next());
19
19
  });
20
20
  };
21
+
22
+ // src/bin/supermassive.ts
21
23
  import path from "path";
22
24
  import fs from "fs/promises";
23
25
  import ts from "typescript";
24
26
  import {program, Command} from "commander";
25
- import {extractImplicitTypesToTypescript} from "../extractImplicitTypesToTypescript";
27
+ import {extractImplicitTypesToTypescript} from "../extractImplicitTypesToTypescript.mjs";
26
28
  import {parse} from "graphql";
27
29
  function supermassive() {
28
30
  const command = new Command();
@@ -1,3 +1,4 @@
1
+ // src/collectFields.ts
1
2
  import {Kind} from "graphql";
2
3
  function collectFields(resolvers, fragments, variableValues, runtimeTypeName, selectionSet, fields, visitedFragmentNames) {
3
4
  for (const selection of selectionSet.selections) {
@@ -1 +1 @@
1
- {"version":3,"file":"executeWithSchema.d.ts","sourceRoot":"","sources":["../src/executeWithSchema.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAIL,eAAe,EACf,uBAAuB,EACxB,MAAM,SAAS,CAAC;AAEjB,wBAAgB,iBAAiB,CAAC,EAChC,QAAQ,EACR,SAAS,EACT,QAAQ,EAAE,WAAW,EACrB,SAAS,EACT,YAAY,EACZ,cAAc,EACd,aAAa,EACb,aAAa,EACb,YAAY,GACb,EAAE,uBAAuB,GAAG,cAAc,CAAC,eAAe,CAAC,CA2B3D"}
1
+ {"version":3,"file":"executeWithSchema.d.ts","sourceRoot":"","sources":["../src/executeWithSchema.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAa,eAAe,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAE9E,wBAAgB,iBAAiB,CAAC,EAChC,QAAQ,EACR,SAAS,EACT,QAAQ,EAAE,WAAW,EACrB,SAAS,EACT,YAAY,EACZ,cAAc,EACd,aAAa,EACb,aAAa,EACb,YAAY,GACb,EAAE,uBAAuB,GAAG,cAAc,CAAC,eAAe,CAAC,CA2B3D"}
@@ -40,10 +40,10 @@ __export(exports, {
40
40
  });
41
41
  var import_schema = __toModule(require("@graphql-tools/schema"));
42
42
  var import_graphql = __toModule(require("graphql"));
43
- var import__ = __toModule(require("."));
43
+ var import_index = __toModule(require("./index"));
44
44
  function executeWithSchema({
45
45
  typeDefs,
46
- resolvers: resolvers2,
46
+ resolvers,
47
47
  document: rawDocument,
48
48
  rootValue,
49
49
  contextValue,
@@ -52,20 +52,20 @@ function executeWithSchema({
52
52
  fieldResolver,
53
53
  typeResolver
54
54
  }) {
55
- const schema = (0, import_schema.makeExecutableSchema)({typeDefs, resolvers: resolvers2});
55
+ const schema = (0, import_schema.makeExecutableSchema)({typeDefs, resolvers});
56
56
  let extractedResolvers = {};
57
57
  const getTypeByName = (name) => {
58
- const type = import__.specifiedScalars[name] || extractedResolvers[name];
58
+ const type = import_index.specifiedScalars[name] || extractedResolvers[name];
59
59
  if ((0, import_graphql.isInputType)(type)) {
60
60
  return type;
61
61
  } else {
62
62
  throw new Error("Invalid type");
63
63
  }
64
64
  };
65
- extractedResolvers = (0, import__.extractImplicitTypes)(typeDefs, getTypeByName);
66
- const fullResolvers = __objSpread(__objSpread({}, extractedResolvers), resolvers2);
67
- const document = (0, import__.addTypesToRequestDocument)(schema, rawDocument);
68
- return (0, import__.executeWithoutSchema)({
65
+ extractedResolvers = (0, import_index.extractImplicitTypes)(typeDefs, getTypeByName);
66
+ const fullResolvers = __objSpread(__objSpread({}, extractedResolvers), resolvers);
67
+ const document = (0, import_index.addTypesToRequestDocument)(schema, rawDocument);
68
+ return (0, import_index.executeWithoutSchema)({
69
69
  document,
70
70
  resolvers: fullResolvers,
71
71
  rootValue,
@@ -14,6 +14,8 @@ var __objSpread = (a, b) => {
14
14
  }
15
15
  return a;
16
16
  };
17
+
18
+ // src/executeWithSchema.ts
17
19
  import {makeExecutableSchema} from "@graphql-tools/schema";
18
20
  import {isInputType} from "graphql";
19
21
  import {
@@ -21,10 +23,10 @@ import {
21
23
  executeWithoutSchema,
22
24
  extractImplicitTypes,
23
25
  specifiedScalars
24
- } from ".";
26
+ } from "./index.mjs";
25
27
  function executeWithSchema({
26
28
  typeDefs,
27
- resolvers: resolvers2,
29
+ resolvers,
28
30
  document: rawDocument,
29
31
  rootValue,
30
32
  contextValue,
@@ -33,7 +35,7 @@ function executeWithSchema({
33
35
  fieldResolver,
34
36
  typeResolver
35
37
  }) {
36
- const schema = makeExecutableSchema({typeDefs, resolvers: resolvers2});
38
+ const schema = makeExecutableSchema({typeDefs, resolvers});
37
39
  let extractedResolvers = {};
38
40
  const getTypeByName = (name) => {
39
41
  const type = specifiedScalars[name] || extractedResolvers[name];
@@ -44,7 +46,7 @@ function executeWithSchema({
44
46
  }
45
47
  };
46
48
  extractedResolvers = extractImplicitTypes(typeDefs, getTypeByName);
47
- const fullResolvers = __objSpread(__objSpread({}, extractedResolvers), resolvers2);
49
+ const fullResolvers = __objSpread(__objSpread({}, extractedResolvers), resolvers);
48
50
  const document = addTypesToRequestDocument(schema, rawDocument);
49
51
  return executeWithoutSchema({
50
52
  document,
@@ -1,3 +1,4 @@
1
+ // src/executeWithoutSchema.ts
1
2
  import {
2
3
  GraphQLEnumType,
3
4
  GraphQLError,
@@ -7,22 +8,22 @@ import {
7
8
  Kind,
8
9
  locatedError
9
10
  } from "graphql";
10
- import {collectFields} from "./collectFields";
11
- import {devAssert} from "./jsutils/devAssert";
12
- import {inspect} from "./jsutils/inspect";
13
- import {invariant} from "./jsutils/invariant";
14
- import {isIterableObject} from "./jsutils/isIterableObject";
15
- import {isObjectLike} from "./jsutils/isObjectLike";
16
- import {isPromise} from "./jsutils/isPromise";
17
- import {addPath, pathToArray} from "./jsutils/Path";
18
- import {promiseForObject} from "./jsutils/promiseForObject";
19
- import {promiseReduce} from "./jsutils/promiseReduce";
20
- import {typeNameFromAST} from "./utilities/typeNameFromAST";
11
+ import {collectFields} from "./collectFields.mjs";
12
+ import {devAssert} from "./jsutils/devAssert.mjs";
13
+ import {inspect} from "./jsutils/inspect.mjs";
14
+ import {invariant} from "./jsutils/invariant.mjs";
15
+ import {isIterableObject} from "./jsutils/isIterableObject.mjs";
16
+ import {isObjectLike} from "./jsutils/isObjectLike.mjs";
17
+ import {isPromise} from "./jsutils/isPromise.mjs";
18
+ import {addPath, pathToArray} from "./jsutils/Path.mjs";
19
+ import {promiseForObject} from "./jsutils/promiseForObject.mjs";
20
+ import {promiseReduce} from "./jsutils/promiseReduce.mjs";
21
+ import {typeNameFromAST} from "./utilities/typeNameFromAST.mjs";
21
22
  import {
22
23
  getArgumentValues,
23
24
  getVariableValues,
24
25
  specifiedScalars
25
- } from "./values";
26
+ } from "./values.mjs";
26
27
  function executeWithoutSchema(args) {
27
28
  const {
28
29
  resolvers,
@@ -318,9 +319,6 @@ function completeObjectValue(exeContext, returnTypeName, fieldNodes, info, path,
318
319
  const subFieldNodes = collectSubfields(exeContext, returnTypeName, fieldNodes);
319
320
  return executeFields(exeContext, returnTypeName, result, path, subFieldNodes);
320
321
  }
321
- function invalidReturnTypeError(returnType, result, fieldNodes) {
322
- return new GraphQLError(`Expected value of type "${returnType.name}" but got: ${inspect(result)}.`, fieldNodes);
323
- }
324
322
  function collectSubfields(exeContext, returnTypeName, fieldNodes) {
325
323
  let subFieldNodes = new Map();
326
324
  const visitedFragmentNames = new Set();
@@ -331,12 +329,12 @@ function collectSubfields(exeContext, returnTypeName, fieldNodes) {
331
329
  }
332
330
  return subFieldNodes;
333
331
  }
334
- const defaultTypeResolver = function(value) {
332
+ var defaultTypeResolver = function(value) {
335
333
  if (isObjectLike(value) && typeof value.__typename === "string") {
336
334
  return value.__typename;
337
335
  }
338
336
  };
339
- const defaultFieldResolver = function(source, args, contextValue, info) {
337
+ var defaultFieldResolver = function(source, args, contextValue, info) {
340
338
  if (isObjectLike(source) || typeof source === "function") {
341
339
  const property = source[info.fieldName];
342
340
  if (typeof property === "function") {
@@ -1,3 +1,4 @@
1
+ // src/extractImplicitTypesRuntime.ts
1
2
  import {
2
3
  getDirectiveValues,
3
4
  GraphQLDeprecatedDirective,
@@ -1,8 +1,9 @@
1
+ // src/extractImplicitTypesToTypescript.ts
1
2
  import ts, {factory} from "typescript";
2
3
  import {
3
4
  Kind
4
5
  } from "graphql";
5
- const SPECIFIED_SCALARS = {
6
+ var SPECIFIED_SCALARS = {
6
7
  ID: "GraphQLID",
7
8
  String: "GraphQLString",
8
9
  Int: "GraphQLInt",