@graphitation/supermassive 0.1.3 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (193) hide show
  1. package/CHANGELOG.md +34 -2
  2. package/NOTICE +27 -0
  3. package/README.md +264 -2
  4. package/bin/supermassive.js +7 -0
  5. package/lib/{src/ast → ast}/TypedAST.d.ts +2 -0
  6. package/lib/ast/TypedAST.d.ts.map +1 -0
  7. package/lib/{src/ast → ast}/addTypesToRequestDocument.d.ts +0 -0
  8. package/lib/ast/addTypesToRequestDocument.d.ts.map +1 -0
  9. package/lib/ast/addTypesToRequestDocument.js +8 -5
  10. package/lib/ast/addTypesToRequestDocument.mjs +12 -6
  11. package/lib/benchmarks/index.d.ts.map +1 -1
  12. package/lib/benchmarks/index.js +127 -0
  13. package/lib/benchmarks/index.mjs +111 -0
  14. package/lib/benchmarks/nice-benchmark.d.ts +1 -1
  15. package/lib/benchmarks/nice-benchmark.d.ts.map +1 -1
  16. package/lib/benchmarks/nice-benchmark.js +72 -0
  17. package/lib/benchmarks/nice-benchmark.mjs +52 -0
  18. package/lib/benchmarks/swapi-schema/index.d.ts +1 -0
  19. package/lib/benchmarks/swapi-schema/index.d.ts.map +1 -1
  20. package/lib/benchmarks/swapi-schema/index.js +39 -0
  21. package/lib/benchmarks/swapi-schema/index.mjs +17 -0
  22. package/lib/benchmarks/swapi-schema/models.d.ts.map +1 -1
  23. package/lib/benchmarks/swapi-schema/models.js +29 -0
  24. package/lib/benchmarks/swapi-schema/models.mjs +7 -0
  25. package/lib/benchmarks/swapi-schema/resolvers.d.ts.map +1 -1
  26. package/lib/benchmarks/swapi-schema/resolvers.js +237 -0
  27. package/lib/benchmarks/swapi-schema/resolvers.mjs +230 -0
  28. package/lib/bin/supermassive.d.ts +3 -0
  29. package/lib/bin/supermassive.d.ts.map +1 -0
  30. package/lib/bin/supermassive.js +83 -0
  31. package/lib/bin/supermassive.mjs +62 -0
  32. package/lib/collectFields.d.ts +17 -0
  33. package/lib/collectFields.d.ts.map +1 -0
  34. package/lib/collectFields.js +83 -0
  35. package/lib/collectFields.mjs +61 -0
  36. package/lib/compiledQuery.d.ts +1 -0
  37. package/lib/compiledQuery.d.ts.map +1 -0
  38. package/lib/compiledQuery.js +0 -0
  39. package/lib/compiledQuery.mjs +0 -0
  40. package/lib/executeWithSchema.d.ts +4 -0
  41. package/lib/executeWithSchema.d.ts.map +1 -0
  42. package/lib/{index.test.js → executeWithSchema.js} +45 -46
  43. package/lib/executeWithSchema.mjs +64 -0
  44. package/lib/executeWithoutSchema.d.ts +99 -0
  45. package/lib/executeWithoutSchema.d.ts.map +1 -0
  46. package/lib/executeWithoutSchema.js +376 -0
  47. package/lib/executeWithoutSchema.mjs +363 -0
  48. package/lib/extractImplicitTypesRuntime.d.ts +4 -0
  49. package/lib/extractImplicitTypesRuntime.d.ts.map +1 -0
  50. package/lib/extractImplicitTypesRuntime.js +103 -0
  51. package/lib/extractImplicitTypesRuntime.mjs +91 -0
  52. package/lib/extractImplicitTypesToTypescript.d.ts +4 -0
  53. package/lib/extractImplicitTypesToTypescript.d.ts.map +1 -0
  54. package/lib/extractImplicitTypesToTypescript.js +169 -0
  55. package/lib/extractImplicitTypesToTypescript.mjs +149 -0
  56. package/lib/index.d.ts +8 -0
  57. package/lib/index.d.ts.map +1 -0
  58. package/lib/index.js +12 -29
  59. package/lib/index.mjs +13 -29
  60. package/lib/jsutils/Maybe.d.ts +3 -0
  61. package/lib/jsutils/Maybe.d.ts.map +1 -0
  62. package/lib/jsutils/Maybe.js +3 -0
  63. package/lib/jsutils/Maybe.mjs +0 -0
  64. package/lib/jsutils/ObjMap.d.ts +13 -0
  65. package/lib/jsutils/ObjMap.d.ts.map +1 -0
  66. package/lib/jsutils/ObjMap.js +3 -0
  67. package/lib/jsutils/ObjMap.mjs +0 -0
  68. package/lib/jsutils/Path.d.ts +15 -0
  69. package/lib/jsutils/Path.d.ts.map +1 -0
  70. package/lib/jsutils/Path.js +23 -0
  71. package/lib/jsutils/Path.mjs +17 -0
  72. package/lib/jsutils/PromiseOrValue.d.ts +2 -0
  73. package/lib/jsutils/PromiseOrValue.d.ts.map +1 -0
  74. package/lib/jsutils/PromiseOrValue.js +3 -0
  75. package/lib/jsutils/PromiseOrValue.mjs +0 -0
  76. package/lib/jsutils/devAssert.d.ts +2 -0
  77. package/lib/jsutils/devAssert.d.ts.map +1 -0
  78. package/lib/jsutils/devAssert.js +16 -0
  79. package/lib/jsutils/devAssert.mjs +10 -0
  80. package/lib/jsutils/didYouMean.d.ts +6 -0
  81. package/lib/jsutils/didYouMean.d.ts.map +1 -0
  82. package/lib/jsutils/didYouMean.js +30 -0
  83. package/lib/jsutils/didYouMean.mjs +24 -0
  84. package/lib/jsutils/identityFunc.d.ts +5 -0
  85. package/lib/jsutils/identityFunc.d.ts.map +1 -0
  86. package/lib/jsutils/identityFunc.js +13 -0
  87. package/lib/jsutils/identityFunc.mjs +7 -0
  88. package/lib/jsutils/inspect.d.ts +5 -0
  89. package/lib/jsutils/inspect.d.ts.map +1 -0
  90. package/lib/jsutils/inspect.js +89 -0
  91. package/lib/jsutils/inspect.mjs +83 -0
  92. package/lib/jsutils/instanceOf.d.ts +14 -0
  93. package/lib/jsutils/instanceOf.d.ts.map +1 -0
  94. package/lib/jsutils/instanceOf.js +55 -0
  95. package/lib/jsutils/instanceOf.mjs +33 -0
  96. package/lib/jsutils/invariant.d.ts +2 -0
  97. package/lib/jsutils/invariant.d.ts.map +1 -0
  98. package/lib/jsutils/invariant.js +16 -0
  99. package/lib/jsutils/invariant.mjs +10 -0
  100. package/lib/jsutils/isAsyncIterable.d.ts +6 -0
  101. package/lib/jsutils/isAsyncIterable.d.ts.map +1 -0
  102. package/lib/jsutils/isAsyncIterable.js +13 -0
  103. package/lib/jsutils/isAsyncIterable.mjs +7 -0
  104. package/lib/jsutils/isIterableObject.d.ts +18 -0
  105. package/lib/jsutils/isIterableObject.d.ts.map +1 -0
  106. package/lib/jsutils/isIterableObject.js +13 -0
  107. package/lib/jsutils/isIterableObject.mjs +7 -0
  108. package/lib/jsutils/isObjectLike.d.ts +8 -0
  109. package/lib/jsutils/isObjectLike.d.ts.map +1 -0
  110. package/lib/jsutils/isObjectLike.js +13 -0
  111. package/lib/jsutils/isObjectLike.mjs +7 -0
  112. package/lib/jsutils/isPromise.d.ts +6 -0
  113. package/lib/jsutils/isPromise.d.ts.map +1 -0
  114. package/lib/jsutils/isPromise.js +13 -0
  115. package/lib/jsutils/isPromise.mjs +7 -0
  116. package/lib/jsutils/keyMap.d.ts +26 -0
  117. package/lib/jsutils/keyMap.d.ts.map +1 -0
  118. package/lib/jsutils/keyMap.js +17 -0
  119. package/lib/jsutils/keyMap.mjs +11 -0
  120. package/lib/jsutils/keyValMap.d.ts +20 -0
  121. package/lib/jsutils/keyValMap.d.ts.map +1 -0
  122. package/lib/jsutils/keyValMap.js +17 -0
  123. package/lib/jsutils/keyValMap.mjs +11 -0
  124. package/lib/jsutils/mapValue.d.ts +7 -0
  125. package/lib/jsutils/mapValue.d.ts.map +1 -0
  126. package/lib/jsutils/mapValue.js +17 -0
  127. package/lib/jsutils/mapValue.mjs +11 -0
  128. package/lib/jsutils/memoize3.d.ts +5 -0
  129. package/lib/jsutils/memoize3.d.ts.map +1 -0
  130. package/lib/jsutils/memoize3.js +34 -0
  131. package/lib/jsutils/memoize3.mjs +28 -0
  132. package/lib/jsutils/naturalCompare.d.ts +9 -0
  133. package/lib/jsutils/naturalCompare.d.ts.map +1 -0
  134. package/lib/jsutils/naturalCompare.js +53 -0
  135. package/lib/jsutils/naturalCompare.mjs +47 -0
  136. package/lib/jsutils/printPathArray.d.ts +5 -0
  137. package/lib/jsutils/printPathArray.d.ts.map +1 -0
  138. package/lib/jsutils/printPathArray.js +13 -0
  139. package/lib/jsutils/printPathArray.mjs +7 -0
  140. package/lib/jsutils/promiseForObject.d.ts +10 -0
  141. package/lib/jsutils/promiseForObject.d.ts.map +1 -0
  142. package/lib/jsutils/promiseForObject.js +19 -0
  143. package/lib/jsutils/promiseForObject.mjs +13 -0
  144. package/lib/jsutils/promiseReduce.d.ts +10 -0
  145. package/lib/jsutils/promiseReduce.d.ts.map +1 -0
  146. package/lib/jsutils/promiseReduce.js +34 -0
  147. package/lib/jsutils/promiseReduce.mjs +12 -0
  148. package/lib/jsutils/suggestionList.d.ts +6 -0
  149. package/lib/jsutils/suggestionList.d.ts.map +1 -0
  150. package/lib/jsutils/suggestionList.js +109 -0
  151. package/lib/jsutils/suggestionList.mjs +87 -0
  152. package/lib/jsutils/toObjMap.d.ts +4 -0
  153. package/lib/jsutils/toObjMap.d.ts.map +1 -0
  154. package/lib/jsutils/toObjMap.js +20 -0
  155. package/lib/jsutils/toObjMap.mjs +14 -0
  156. package/lib/transforms/annotateDocumentGraphQLTransform.d.ts +3 -0
  157. package/lib/transforms/annotateDocumentGraphQLTransform.d.ts.map +1 -0
  158. package/lib/transforms/annotateDocumentGraphQLTransform.js +37 -0
  159. package/lib/transforms/annotateDocumentGraphQLTransform.mjs +17 -0
  160. package/lib/transforms/transformerTestUtils.d.ts +79 -0
  161. package/lib/transforms/transformerTestUtils.d.ts.map +1 -0
  162. package/lib/transforms/transformerTestUtils.js +175 -0
  163. package/lib/transforms/transformerTestUtils.mjs +160 -0
  164. package/lib/types.d.ts +74 -0
  165. package/lib/types.d.ts.map +1 -0
  166. package/lib/types.js +3 -0
  167. package/lib/types.mjs +0 -0
  168. package/lib/utilities/typeNameFromAST.d.ts +3 -0
  169. package/lib/utilities/typeNameFromAST.d.ts.map +1 -0
  170. package/lib/utilities/typeNameFromAST.js +34 -0
  171. package/lib/utilities/typeNameFromAST.mjs +12 -0
  172. package/lib/values.d.ts +64 -0
  173. package/lib/values.d.ts.map +1 -0
  174. package/lib/values.js +145 -0
  175. package/lib/values.mjs +138 -0
  176. package/package.json +21 -6
  177. package/.eslintcache +0 -1
  178. package/CHANGELOG.json +0 -65
  179. package/benchmarks/fixtures/query1.graphql +0 -20
  180. package/benchmarks/index.ts +0 -68
  181. package/benchmarks/nice-benchmark.ts +0 -32
  182. package/benchmarks/swapi-schema/index.ts +0 -13
  183. package/benchmarks/swapi-schema/models.ts +0 -4
  184. package/benchmarks/swapi-schema/resolvers.ts +0 -331
  185. package/benchmarks/swapi-schema/schema.graphql +0 -164
  186. package/benchmarks/swapi-schema/starwars.json +0 -5991
  187. package/lib/index.test.mjs +0 -63
  188. package/lib/src/ast/TypedAST.d.ts.map +0 -1
  189. package/lib/src/ast/addTypesToRequestDocument.d.ts.map +0 -1
  190. package/lib/src/index.d.ts +0 -16
  191. package/lib/src/index.d.ts.map +0 -1
  192. package/lib/src/index.test.d.ts +0 -2
  193. package/lib/src/index.test.d.ts.map +0 -1
@@ -0,0 +1,169 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getProtoOf = Object.getPrototypeOf;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, {get: all[name], enumerable: true});
11
+ };
12
+ var __reExport = (target, module2, desc) => {
13
+ if (module2 && typeof module2 === "object" || typeof module2 === "function") {
14
+ for (let key of __getOwnPropNames(module2))
15
+ if (!__hasOwnProp.call(target, key) && key !== "default")
16
+ __defProp(target, key, {get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable});
17
+ }
18
+ return target;
19
+ };
20
+ var __toModule = (module2) => {
21
+ return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2);
22
+ };
23
+ __markAsModule(exports);
24
+ __export(exports, {
25
+ extractImplicitTypesToTypescript: () => extractImplicitTypesToTypescript
26
+ });
27
+ var import_typescript = __toModule(require("typescript"));
28
+ var import_graphql = __toModule(require("graphql"));
29
+ const SPECIFIED_SCALARS = {
30
+ ID: "GraphQLID",
31
+ String: "GraphQLString",
32
+ Int: "GraphQLInt",
33
+ Float: "GraphQLFloat",
34
+ Boolean: "GraphQLBoolean"
35
+ };
36
+ function extractImplicitTypesToTypescript(document) {
37
+ const definitions = [];
38
+ const imports = [
39
+ "GraphQLList",
40
+ "GraphQLNonNull",
41
+ "GraphQLID",
42
+ "GraphQLString",
43
+ "GraphQLInt",
44
+ "GraphQLFloat",
45
+ "GraphQLBoolean"
46
+ ];
47
+ const identifiers = [];
48
+ for (let astNode of document.definitions) {
49
+ if (astNode.kind === import_graphql.Kind.SCALAR_TYPE_DEFINITION) {
50
+ definitions.push(createScalarType(astNode));
51
+ addToSetArray(imports, "GraphQLScalarType");
52
+ addToSetArray(identifiers, astNode.name.value);
53
+ } else if (astNode.kind === import_graphql.Kind.INPUT_OBJECT_TYPE_DEFINITION) {
54
+ definitions.push(createInputObjectType(astNode));
55
+ addToSetArray(imports, "GraphQLInputObjectType");
56
+ addToSetArray(identifiers, astNode.name.value);
57
+ } else if (astNode.kind === import_graphql.Kind.ENUM_TYPE_DEFINITION) {
58
+ definitions.push(createEnumType(astNode));
59
+ addToSetArray(imports, "GraphQLEnumType");
60
+ addToSetArray(identifiers, astNode.name.value);
61
+ } else if (astNode.kind === import_graphql.Kind.UNION_TYPE_DEFINITION || astNode.kind === import_graphql.Kind.INTERFACE_TYPE_DEFINITION) {
62
+ definitions.push(createAbstractType(astNode));
63
+ addToSetArray(identifiers, astNode.name.value);
64
+ } else if (astNode.kind === import_graphql.Kind.OBJECT_TYPE_DEFINITION) {
65
+ definitions.push(createObjectType(astNode));
66
+ addToSetArray(identifiers, astNode.name.value);
67
+ }
68
+ }
69
+ const importDefinition = import_typescript.factory.createImportDeclaration(void 0, void 0, import_typescript.factory.createImportClause(false, void 0, import_typescript.factory.createNamedImports(imports.map((imp) => import_typescript.factory.createImportSpecifier(void 0, import_typescript.factory.createIdentifier(imp))))), import_typescript.factory.createStringLiteral("graphql"));
70
+ const exportDefinition = import_typescript.factory.createVariableStatement([import_typescript.factory.createModifier(import_typescript.default.SyntaxKind.ExportKeyword)], import_typescript.factory.createVariableDeclarationList([
71
+ import_typescript.factory.createVariableDeclaration(import_typescript.factory.createIdentifier("resolvers"), void 0, void 0, import_typescript.factory.createObjectLiteralExpression(identifiers.map((def) => import_typescript.factory.createShorthandPropertyAssignment(import_typescript.factory.createIdentifier(def), void 0))))
72
+ ], import_typescript.default.NodeFlags.Const));
73
+ return import_typescript.factory.createSourceFile([importDefinition, ...definitions, exportDefinition], import_typescript.factory.createToken(import_typescript.default.SyntaxKind.EndOfFileToken), 0);
74
+ }
75
+ function createDeclaration(name, decl) {
76
+ return import_typescript.factory.createVariableStatement(void 0, import_typescript.factory.createVariableDeclarationList([
77
+ import_typescript.factory.createVariableDeclaration(import_typescript.factory.createIdentifier(name), void 0, void 0, decl)
78
+ ], import_typescript.default.NodeFlags.Const));
79
+ }
80
+ function createScalarType(astNode) {
81
+ var _a;
82
+ return createDeclaration(astNode.name.value, import_typescript.factory.createNewExpression(import_typescript.factory.createIdentifier("GraphQLScalarType"), void 0, [
83
+ import_typescript.factory.createObjectLiteralExpression([
84
+ import_typescript.factory.createPropertyAssignment(import_typescript.factory.createIdentifier("name"), import_typescript.factory.createStringLiteral(astNode.name.value)),
85
+ import_typescript.factory.createPropertyAssignment(import_typescript.factory.createIdentifier("description"), import_typescript.factory.createStringLiteral(((_a = astNode.description) == null ? void 0 : _a.value) || ""))
86
+ ], true)
87
+ ]));
88
+ }
89
+ function createInputObjectType(astNode) {
90
+ var _a;
91
+ return createDeclaration(astNode.name.value, import_typescript.factory.createNewExpression(import_typescript.factory.createIdentifier("GraphQLInputObjectType"), void 0, [
92
+ import_typescript.factory.createObjectLiteralExpression([
93
+ import_typescript.factory.createPropertyAssignment(import_typescript.factory.createIdentifier("name"), import_typescript.factory.createStringLiteral(astNode.name.value)),
94
+ import_typescript.factory.createPropertyAssignment(import_typescript.factory.createIdentifier("description"), import_typescript.factory.createStringLiteral(((_a = astNode.description) == null ? void 0 : _a.value) || "")),
95
+ import_typescript.factory.createPropertyAssignment(import_typescript.factory.createIdentifier("fields"), import_typescript.factory.createArrowFunction(void 0, void 0, [], void 0, import_typescript.factory.createToken(import_typescript.default.SyntaxKind.EqualsGreaterThanToken), import_typescript.factory.createParenthesizedExpression(import_typescript.factory.createObjectLiteralExpression(createInputFields(astNode.fields || []), true))))
96
+ ], true)
97
+ ]));
98
+ }
99
+ function createInputFields(astNodes) {
100
+ return astNodes.map((astNode) => {
101
+ var _a;
102
+ const fields = [
103
+ import_typescript.factory.createPropertyAssignment(import_typescript.factory.createIdentifier("type"), createType(astNode.type)),
104
+ import_typescript.factory.createPropertyAssignment(import_typescript.factory.createIdentifier("description"), import_typescript.factory.createStringLiteral(((_a = astNode.description) == null ? void 0 : _a.value) || ""))
105
+ ];
106
+ if (astNode.defaultValue) {
107
+ fields.push(import_typescript.factory.createPropertyAssignment(import_typescript.factory.createIdentifier("defaultValue"), createValue(astNode.defaultValue)));
108
+ }
109
+ return import_typescript.factory.createPropertyAssignment(import_typescript.factory.createIdentifier(astNode.name.value), import_typescript.factory.createObjectLiteralExpression(fields, true));
110
+ });
111
+ }
112
+ function createEnumType(astNode) {
113
+ var _a;
114
+ return createDeclaration(astNode.name.value, import_typescript.factory.createNewExpression(import_typescript.factory.createIdentifier("GraphQLEnumType"), void 0, [
115
+ import_typescript.factory.createObjectLiteralExpression([
116
+ import_typescript.factory.createPropertyAssignment(import_typescript.factory.createIdentifier("name"), import_typescript.factory.createStringLiteral(astNode.name.value)),
117
+ import_typescript.factory.createPropertyAssignment(import_typescript.factory.createIdentifier("description"), import_typescript.factory.createStringLiteral(((_a = astNode.description) == null ? void 0 : _a.value) || "")),
118
+ import_typescript.factory.createPropertyAssignment(import_typescript.factory.createIdentifier("values"), import_typescript.factory.createObjectLiteralExpression((astNode.values || []).map((valueNode) => {
119
+ var _a2;
120
+ return import_typescript.factory.createPropertyAssignment(import_typescript.factory.createIdentifier(valueNode.name.value), import_typescript.factory.createObjectLiteralExpression([
121
+ import_typescript.factory.createPropertyAssignment(import_typescript.factory.createIdentifier("description"), import_typescript.factory.createStringLiteral(((_a2 = valueNode.description) == null ? void 0 : _a2.value) || ""))
122
+ ]));
123
+ })))
124
+ ])
125
+ ]));
126
+ }
127
+ function createAbstractType(astNode) {
128
+ return createDeclaration(astNode.name.value, import_typescript.factory.createObjectLiteralExpression([
129
+ import_typescript.factory.createPropertyAssignment(import_typescript.factory.createIdentifier("__resolveType"), import_typescript.factory.createIdentifier("undefined"))
130
+ ]));
131
+ }
132
+ function createObjectType(astNode) {
133
+ return createDeclaration(astNode.name.value, import_typescript.factory.createObjectLiteralExpression());
134
+ }
135
+ function createType(astNode) {
136
+ if (astNode.kind === import_graphql.Kind.LIST_TYPE) {
137
+ return import_typescript.factory.createNewExpression(import_typescript.factory.createIdentifier("GraphQLList"), void 0, [createType(astNode.type)]);
138
+ } else if (astNode.kind === import_graphql.Kind.NON_NULL_TYPE) {
139
+ return import_typescript.factory.createNewExpression(import_typescript.factory.createIdentifier("GraphQLNonNull"), void 0, [createType(astNode.type)]);
140
+ } else {
141
+ if (SPECIFIED_SCALARS[astNode.name.value]) {
142
+ return import_typescript.factory.createIdentifier(SPECIFIED_SCALARS[astNode.name.value]);
143
+ } else {
144
+ return import_typescript.factory.createIdentifier(astNode.name.value);
145
+ }
146
+ }
147
+ }
148
+ function createValue(astNode) {
149
+ if (astNode.kind === import_graphql.Kind.INT || astNode.kind === import_graphql.Kind.FLOAT) {
150
+ return import_typescript.factory.createNumericLiteral(astNode.value);
151
+ } else if (astNode.kind === import_graphql.Kind.BOOLEAN) {
152
+ return astNode.value ? import_typescript.factory.createTrue() : import_typescript.factory.createFalse();
153
+ } else if (astNode.kind === import_graphql.Kind.STRING || astNode.kind === import_graphql.Kind.ENUM) {
154
+ return import_typescript.factory.createStringLiteral(astNode.value);
155
+ } else if (astNode.kind === import_graphql.Kind.NULL) {
156
+ return import_typescript.factory.createNull();
157
+ } else if (astNode.kind === import_graphql.Kind.LIST) {
158
+ return import_typescript.factory.createArrayLiteralExpression(astNode.values.map((valueNode) => createValue(valueNode)));
159
+ } else if (astNode.kind === import_graphql.Kind.OBJECT) {
160
+ return import_typescript.factory.createObjectLiteralExpression(astNode.fields.map((fieldNode) => import_typescript.factory.createPropertyAssignment(fieldNode.name.value, createValue(fieldNode.value))));
161
+ } else {
162
+ throw new Error("Invalid value");
163
+ }
164
+ }
165
+ function addToSetArray(array, item) {
166
+ if (array.indexOf(item) === -1) {
167
+ array.push(item);
168
+ }
169
+ }
@@ -0,0 +1,149 @@
1
+ // src/extractImplicitTypesToTypescript.ts
2
+ import ts, {factory} from "typescript";
3
+ import {
4
+ Kind
5
+ } from "graphql";
6
+ var SPECIFIED_SCALARS = {
7
+ ID: "GraphQLID",
8
+ String: "GraphQLString",
9
+ Int: "GraphQLInt",
10
+ Float: "GraphQLFloat",
11
+ Boolean: "GraphQLBoolean"
12
+ };
13
+ function extractImplicitTypesToTypescript(document) {
14
+ const definitions = [];
15
+ const imports = [
16
+ "GraphQLList",
17
+ "GraphQLNonNull",
18
+ "GraphQLID",
19
+ "GraphQLString",
20
+ "GraphQLInt",
21
+ "GraphQLFloat",
22
+ "GraphQLBoolean"
23
+ ];
24
+ const identifiers = [];
25
+ for (let astNode of document.definitions) {
26
+ if (astNode.kind === Kind.SCALAR_TYPE_DEFINITION) {
27
+ definitions.push(createScalarType(astNode));
28
+ addToSetArray(imports, "GraphQLScalarType");
29
+ addToSetArray(identifiers, astNode.name.value);
30
+ } else if (astNode.kind === Kind.INPUT_OBJECT_TYPE_DEFINITION) {
31
+ definitions.push(createInputObjectType(astNode));
32
+ addToSetArray(imports, "GraphQLInputObjectType");
33
+ addToSetArray(identifiers, astNode.name.value);
34
+ } else if (astNode.kind === Kind.ENUM_TYPE_DEFINITION) {
35
+ definitions.push(createEnumType(astNode));
36
+ addToSetArray(imports, "GraphQLEnumType");
37
+ addToSetArray(identifiers, astNode.name.value);
38
+ } else if (astNode.kind === Kind.UNION_TYPE_DEFINITION || astNode.kind === Kind.INTERFACE_TYPE_DEFINITION) {
39
+ definitions.push(createAbstractType(astNode));
40
+ addToSetArray(identifiers, astNode.name.value);
41
+ } else if (astNode.kind === Kind.OBJECT_TYPE_DEFINITION) {
42
+ definitions.push(createObjectType(astNode));
43
+ addToSetArray(identifiers, astNode.name.value);
44
+ }
45
+ }
46
+ const importDefinition = factory.createImportDeclaration(void 0, void 0, factory.createImportClause(false, void 0, factory.createNamedImports(imports.map((imp) => factory.createImportSpecifier(void 0, factory.createIdentifier(imp))))), factory.createStringLiteral("graphql"));
47
+ const exportDefinition = factory.createVariableStatement([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createVariableDeclarationList([
48
+ factory.createVariableDeclaration(factory.createIdentifier("resolvers"), void 0, void 0, factory.createObjectLiteralExpression(identifiers.map((def) => factory.createShorthandPropertyAssignment(factory.createIdentifier(def), void 0))))
49
+ ], ts.NodeFlags.Const));
50
+ return factory.createSourceFile([importDefinition, ...definitions, exportDefinition], factory.createToken(ts.SyntaxKind.EndOfFileToken), 0);
51
+ }
52
+ function createDeclaration(name, decl) {
53
+ return factory.createVariableStatement(void 0, factory.createVariableDeclarationList([
54
+ factory.createVariableDeclaration(factory.createIdentifier(name), void 0, void 0, decl)
55
+ ], ts.NodeFlags.Const));
56
+ }
57
+ function createScalarType(astNode) {
58
+ var _a;
59
+ return createDeclaration(astNode.name.value, factory.createNewExpression(factory.createIdentifier("GraphQLScalarType"), void 0, [
60
+ factory.createObjectLiteralExpression([
61
+ factory.createPropertyAssignment(factory.createIdentifier("name"), factory.createStringLiteral(astNode.name.value)),
62
+ factory.createPropertyAssignment(factory.createIdentifier("description"), factory.createStringLiteral(((_a = astNode.description) == null ? void 0 : _a.value) || ""))
63
+ ], true)
64
+ ]));
65
+ }
66
+ function createInputObjectType(astNode) {
67
+ var _a;
68
+ return createDeclaration(astNode.name.value, factory.createNewExpression(factory.createIdentifier("GraphQLInputObjectType"), void 0, [
69
+ factory.createObjectLiteralExpression([
70
+ factory.createPropertyAssignment(factory.createIdentifier("name"), factory.createStringLiteral(astNode.name.value)),
71
+ factory.createPropertyAssignment(factory.createIdentifier("description"), factory.createStringLiteral(((_a = astNode.description) == null ? void 0 : _a.value) || "")),
72
+ factory.createPropertyAssignment(factory.createIdentifier("fields"), factory.createArrowFunction(void 0, void 0, [], void 0, factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), factory.createParenthesizedExpression(factory.createObjectLiteralExpression(createInputFields(astNode.fields || []), true))))
73
+ ], true)
74
+ ]));
75
+ }
76
+ function createInputFields(astNodes) {
77
+ return astNodes.map((astNode) => {
78
+ var _a;
79
+ const fields = [
80
+ factory.createPropertyAssignment(factory.createIdentifier("type"), createType(astNode.type)),
81
+ factory.createPropertyAssignment(factory.createIdentifier("description"), factory.createStringLiteral(((_a = astNode.description) == null ? void 0 : _a.value) || ""))
82
+ ];
83
+ if (astNode.defaultValue) {
84
+ fields.push(factory.createPropertyAssignment(factory.createIdentifier("defaultValue"), createValue(astNode.defaultValue)));
85
+ }
86
+ return factory.createPropertyAssignment(factory.createIdentifier(astNode.name.value), factory.createObjectLiteralExpression(fields, true));
87
+ });
88
+ }
89
+ function createEnumType(astNode) {
90
+ var _a;
91
+ return createDeclaration(astNode.name.value, factory.createNewExpression(factory.createIdentifier("GraphQLEnumType"), void 0, [
92
+ factory.createObjectLiteralExpression([
93
+ factory.createPropertyAssignment(factory.createIdentifier("name"), factory.createStringLiteral(astNode.name.value)),
94
+ factory.createPropertyAssignment(factory.createIdentifier("description"), factory.createStringLiteral(((_a = astNode.description) == null ? void 0 : _a.value) || "")),
95
+ factory.createPropertyAssignment(factory.createIdentifier("values"), factory.createObjectLiteralExpression((astNode.values || []).map((valueNode) => {
96
+ var _a2;
97
+ return factory.createPropertyAssignment(factory.createIdentifier(valueNode.name.value), factory.createObjectLiteralExpression([
98
+ factory.createPropertyAssignment(factory.createIdentifier("description"), factory.createStringLiteral(((_a2 = valueNode.description) == null ? void 0 : _a2.value) || ""))
99
+ ]));
100
+ })))
101
+ ])
102
+ ]));
103
+ }
104
+ function createAbstractType(astNode) {
105
+ return createDeclaration(astNode.name.value, factory.createObjectLiteralExpression([
106
+ factory.createPropertyAssignment(factory.createIdentifier("__resolveType"), factory.createIdentifier("undefined"))
107
+ ]));
108
+ }
109
+ function createObjectType(astNode) {
110
+ return createDeclaration(astNode.name.value, factory.createObjectLiteralExpression());
111
+ }
112
+ function createType(astNode) {
113
+ if (astNode.kind === Kind.LIST_TYPE) {
114
+ return factory.createNewExpression(factory.createIdentifier("GraphQLList"), void 0, [createType(astNode.type)]);
115
+ } else if (astNode.kind === Kind.NON_NULL_TYPE) {
116
+ return factory.createNewExpression(factory.createIdentifier("GraphQLNonNull"), void 0, [createType(astNode.type)]);
117
+ } else {
118
+ if (SPECIFIED_SCALARS[astNode.name.value]) {
119
+ return factory.createIdentifier(SPECIFIED_SCALARS[astNode.name.value]);
120
+ } else {
121
+ return factory.createIdentifier(astNode.name.value);
122
+ }
123
+ }
124
+ }
125
+ function createValue(astNode) {
126
+ if (astNode.kind === Kind.INT || astNode.kind === Kind.FLOAT) {
127
+ return factory.createNumericLiteral(astNode.value);
128
+ } else if (astNode.kind === Kind.BOOLEAN) {
129
+ return astNode.value ? factory.createTrue() : factory.createFalse();
130
+ } else if (astNode.kind === Kind.STRING || astNode.kind === Kind.ENUM) {
131
+ return factory.createStringLiteral(astNode.value);
132
+ } else if (astNode.kind === Kind.NULL) {
133
+ return factory.createNull();
134
+ } else if (astNode.kind === Kind.LIST) {
135
+ return factory.createArrayLiteralExpression(astNode.values.map((valueNode) => createValue(valueNode)));
136
+ } else if (astNode.kind === Kind.OBJECT) {
137
+ return factory.createObjectLiteralExpression(astNode.fields.map((fieldNode) => factory.createPropertyAssignment(fieldNode.name.value, createValue(fieldNode.value))));
138
+ } else {
139
+ throw new Error("Invalid value");
140
+ }
141
+ }
142
+ function addToSetArray(array, item) {
143
+ if (array.indexOf(item) === -1) {
144
+ array.push(item);
145
+ }
146
+ }
147
+ export {
148
+ extractImplicitTypesToTypescript
149
+ };
package/lib/index.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ export { executeWithoutSchema } from "./executeWithoutSchema";
2
+ export { executeWithSchema } from "./executeWithSchema";
3
+ export type { Resolvers } from "./types";
4
+ export { addTypesToRequestDocument } from "./ast/addTypesToRequestDocument";
5
+ export { extractImplicitTypes } from "./extractImplicitTypesRuntime";
6
+ export { specifiedScalars } from "./values";
7
+ export { annotateDocumentGraphQLTransform } from "./transforms/annotateDocumentGraphQLTransform";
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD,YAAY,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzC,OAAO,EAAE,yBAAyB,EAAE,MAAM,iCAAiC,CAAC;AAE5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAErE,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE5C,OAAO,EAAE,gCAAgC,EAAE,MAAM,+CAA+C,CAAC"}
package/lib/index.js CHANGED
@@ -20,35 +20,18 @@ var __reExport = (target, module2, desc) => {
20
20
  var __toModule = (module2) => {
21
21
  return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2);
22
22
  };
23
- var __async = (__this, __arguments, generator) => {
24
- return new Promise((resolve, reject) => {
25
- var fulfilled = (value) => {
26
- try {
27
- step(generator.next(value));
28
- } catch (e) {
29
- reject(e);
30
- }
31
- };
32
- var rejected = (value) => {
33
- try {
34
- step(generator.throw(value));
35
- } catch (e) {
36
- reject(e);
37
- }
38
- };
39
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
40
- step((generator = generator.apply(__this, __arguments)).next());
41
- });
42
- };
43
23
  __markAsModule(exports);
44
24
  __export(exports, {
45
- execute: () => execute
25
+ addTypesToRequestDocument: () => import_addTypesToRequestDocument.addTypesToRequestDocument,
26
+ annotateDocumentGraphQLTransform: () => import_annotateDocumentGraphQLTransform.annotateDocumentGraphQLTransform,
27
+ executeWithSchema: () => import_executeWithSchema.executeWithSchema,
28
+ executeWithoutSchema: () => import_executeWithoutSchema.executeWithoutSchema,
29
+ extractImplicitTypes: () => import_extractImplicitTypesRuntime.extractImplicitTypes,
30
+ specifiedScalars: () => import_values.specifiedScalars
46
31
  });
47
- var import_graphql = __toModule(require("graphql"));
48
- function execute(args) {
49
- return __async(this, null, function* () {
50
- return {
51
- errors: [new import_graphql.GraphQLError("Not implemented")]
52
- };
53
- });
54
- }
32
+ var import_executeWithoutSchema = __toModule(require("./executeWithoutSchema"));
33
+ var import_executeWithSchema = __toModule(require("./executeWithSchema"));
34
+ var import_addTypesToRequestDocument = __toModule(require("./ast/addTypesToRequestDocument"));
35
+ var import_extractImplicitTypesRuntime = __toModule(require("./extractImplicitTypesRuntime"));
36
+ var import_values = __toModule(require("./values"));
37
+ var import_annotateDocumentGraphQLTransform = __toModule(require("./transforms/annotateDocumentGraphQLTransform"));
package/lib/index.mjs CHANGED
@@ -1,31 +1,15 @@
1
- var __async = (__this, __arguments, generator) => {
2
- return new Promise((resolve, reject) => {
3
- var fulfilled = (value) => {
4
- try {
5
- step(generator.next(value));
6
- } catch (e) {
7
- reject(e);
8
- }
9
- };
10
- var rejected = (value) => {
11
- try {
12
- step(generator.throw(value));
13
- } catch (e) {
14
- reject(e);
15
- }
16
- };
17
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
- step((generator = generator.apply(__this, __arguments)).next());
19
- });
20
- };
21
- import {GraphQLError} from "graphql";
22
- function execute(args) {
23
- return __async(this, null, function* () {
24
- return {
25
- errors: [new GraphQLError("Not implemented")]
26
- };
27
- });
28
- }
1
+ // src/index.ts
2
+ import {executeWithoutSchema} from "./executeWithoutSchema.mjs";
3
+ import {executeWithSchema} from "./executeWithSchema.mjs";
4
+ import {addTypesToRequestDocument} from "./ast/addTypesToRequestDocument.mjs";
5
+ import {extractImplicitTypes} from "./extractImplicitTypesRuntime.mjs";
6
+ import {specifiedScalars} from "./values.mjs";
7
+ import {annotateDocumentGraphQLTransform} from "./transforms/annotateDocumentGraphQLTransform.mjs";
29
8
  export {
30
- execute
9
+ addTypesToRequestDocument,
10
+ annotateDocumentGraphQLTransform,
11
+ executeWithSchema,
12
+ executeWithoutSchema,
13
+ extractImplicitTypes,
14
+ specifiedScalars
31
15
  };
@@ -0,0 +1,3 @@
1
+ /** Conveniently represents flow's "Maybe" type https://flow.org/en/docs/types/maybe/ */
2
+ export declare type Maybe<T> = null | undefined | T;
3
+ //# sourceMappingURL=Maybe.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Maybe.d.ts","sourceRoot":"","sources":["../../src/jsutils/Maybe.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,oBAAY,KAAK,CAAC,CAAC,IAAI,IAAI,GAAG,SAAS,GAAG,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
3
+ __markAsModule(exports);
File without changes
@@ -0,0 +1,13 @@
1
+ export interface ObjMap<T> {
2
+ [key: string]: T;
3
+ }
4
+ export declare type ObjMapLike<T> = ObjMap<T> | {
5
+ [key: string]: T;
6
+ };
7
+ export interface ReadOnlyObjMap<T> {
8
+ readonly [key: string]: T;
9
+ }
10
+ export declare type ReadOnlyObjMapLike<T> = ReadOnlyObjMap<T> | {
11
+ readonly [key: string]: T;
12
+ };
13
+ //# sourceMappingURL=ObjMap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ObjMap.d.ts","sourceRoot":"","sources":["../../src/jsutils/ObjMap.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,MAAM,CAAC,CAAC;IACvB,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,CAAC;CAClB;AAED,oBAAY,UAAU,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,CAAA;CAAE,CAAC;AAE7D,MAAM,WAAW,cAAc,CAAC,CAAC;IAC/B,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,CAAC;CAC3B;AAED,oBAAY,kBAAkB,CAAC,CAAC,IAC5B,cAAc,CAAC,CAAC,CAAC,GACjB;IAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,CAAA;CAAE,CAAC"}
@@ -0,0 +1,3 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
3
+ __markAsModule(exports);
File without changes
@@ -0,0 +1,15 @@
1
+ import type { Maybe } from './Maybe';
2
+ export interface Path {
3
+ readonly prev: Path | undefined;
4
+ readonly key: string | number;
5
+ readonly typename: string | undefined;
6
+ }
7
+ /**
8
+ * Given a Path and a key, return a new Path containing the new key.
9
+ */
10
+ export declare function addPath(prev: Readonly<Path> | undefined, key: string | number, typename: string | undefined): Path;
11
+ /**
12
+ * Given a Path, return an Array of the path keys.
13
+ */
14
+ export declare function pathToArray(path: Maybe<Readonly<Path>>): Array<string | number>;
15
+ //# sourceMappingURL=Path.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Path.d.ts","sourceRoot":"","sources":["../../src/jsutils/Path.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAErC,MAAM,WAAW,IAAI;IACnB,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,SAAS,CAAC;IAChC,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;IAC9B,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;CACvC;AAED;;GAEG;AACH,wBAAgB,OAAO,CACrB,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,GAAG,SAAS,EAChC,GAAG,EAAE,MAAM,GAAG,MAAM,EACpB,QAAQ,EAAE,MAAM,GAAG,SAAS,GAC3B,IAAI,CAEN;AAED;;GAEG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,GAC1B,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,CAQxB"}
@@ -0,0 +1,23 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
3
+ var __export = (target, all) => {
4
+ for (var name in all)
5
+ __defProp(target, name, {get: all[name], enumerable: true});
6
+ };
7
+ __markAsModule(exports);
8
+ __export(exports, {
9
+ addPath: () => addPath,
10
+ pathToArray: () => pathToArray
11
+ });
12
+ function addPath(prev, key, typename) {
13
+ return {prev, key, typename};
14
+ }
15
+ function pathToArray(path) {
16
+ const flattened = [];
17
+ let curr = path;
18
+ while (curr) {
19
+ flattened.push(curr.key);
20
+ curr = curr.prev;
21
+ }
22
+ return flattened.reverse();
23
+ }
@@ -0,0 +1,17 @@
1
+ // src/jsutils/Path.ts
2
+ function addPath(prev, key, typename) {
3
+ return {prev, key, typename};
4
+ }
5
+ function pathToArray(path) {
6
+ const flattened = [];
7
+ let curr = path;
8
+ while (curr) {
9
+ flattened.push(curr.key);
10
+ curr = curr.prev;
11
+ }
12
+ return flattened.reverse();
13
+ }
14
+ export {
15
+ addPath,
16
+ pathToArray
17
+ };
@@ -0,0 +1,2 @@
1
+ export declare type PromiseOrValue<T> = Promise<T> | T;
2
+ //# sourceMappingURL=PromiseOrValue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PromiseOrValue.d.ts","sourceRoot":"","sources":["../../src/jsutils/PromiseOrValue.ts"],"names":[],"mappings":"AAAA,oBAAY,cAAc,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
3
+ __markAsModule(exports);
File without changes
@@ -0,0 +1,2 @@
1
+ export declare function devAssert(condition: unknown, message: string): void;
2
+ //# sourceMappingURL=devAssert.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"devAssert.d.ts","sourceRoot":"","sources":["../../src/jsutils/devAssert.ts"],"names":[],"mappings":"AAAA,wBAAgB,SAAS,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAMnE"}
@@ -0,0 +1,16 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
3
+ var __export = (target, all) => {
4
+ for (var name in all)
5
+ __defProp(target, name, {get: all[name], enumerable: true});
6
+ };
7
+ __markAsModule(exports);
8
+ __export(exports, {
9
+ devAssert: () => devAssert
10
+ });
11
+ function devAssert(condition, message) {
12
+ const booleanCondition = Boolean(condition);
13
+ if (!booleanCondition) {
14
+ throw new Error(message);
15
+ }
16
+ }
@@ -0,0 +1,10 @@
1
+ // src/jsutils/devAssert.ts
2
+ function devAssert(condition, message) {
3
+ const booleanCondition = Boolean(condition);
4
+ if (!booleanCondition) {
5
+ throw new Error(message);
6
+ }
7
+ }
8
+ export {
9
+ devAssert
10
+ };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Given [ A, B, C ] return ' Did you mean A, B, or C?'.
3
+ */
4
+ export declare function didYouMean(suggestions: ReadonlyArray<string>): string;
5
+ export declare function didYouMean(subMessage: string, suggestions: ReadonlyArray<string>): string;
6
+ //# sourceMappingURL=didYouMean.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"didYouMean.d.ts","sourceRoot":"","sources":["../../src/jsutils/didYouMean.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,wBAAgB,UAAU,CAAC,WAAW,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC;AACvE,wBAAgB,UAAU,CACxB,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,aAAa,CAAC,MAAM,CAAC,GACjC,MAAM,CAAC"}
@@ -0,0 +1,30 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
3
+ var __export = (target, all) => {
4
+ for (var name in all)
5
+ __defProp(target, name, {get: all[name], enumerable: true});
6
+ };
7
+ __markAsModule(exports);
8
+ __export(exports, {
9
+ didYouMean: () => didYouMean
10
+ });
11
+ const MAX_SUGGESTIONS = 5;
12
+ function didYouMean(firstArg, secondArg) {
13
+ const [subMessage, suggestionsArg] = secondArg ? [firstArg, secondArg] : [void 0, firstArg];
14
+ let message = " Did you mean ";
15
+ if (subMessage) {
16
+ message += subMessage + " ";
17
+ }
18
+ const suggestions = suggestionsArg.map((x) => `"${x}"`);
19
+ switch (suggestions.length) {
20
+ case 0:
21
+ return "";
22
+ case 1:
23
+ return message + suggestions[0] + "?";
24
+ case 2:
25
+ return message + suggestions[0] + " or " + suggestions[1] + "?";
26
+ }
27
+ const selected = suggestions.slice(0, MAX_SUGGESTIONS);
28
+ const lastItem = selected.pop();
29
+ return message + selected.join(", ") + ", or " + lastItem + "?";
30
+ }