@graphitation/supermassive 0.1.1 → 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 (192) hide show
  1. package/CHANGELOG.md +34 -2
  2. package/README.md +264 -2
  3. package/bin/supermassive.js +7 -0
  4. package/lib/{src/ast → ast}/TypedAST.d.ts +2 -0
  5. package/lib/ast/TypedAST.d.ts.map +1 -0
  6. package/lib/{src/ast → ast}/addTypesToRequestDocument.d.ts +0 -0
  7. package/lib/ast/addTypesToRequestDocument.d.ts.map +1 -0
  8. package/lib/ast/addTypesToRequestDocument.js +8 -5
  9. package/lib/ast/addTypesToRequestDocument.mjs +12 -6
  10. package/lib/benchmarks/index.d.ts.map +1 -1
  11. package/lib/benchmarks/index.js +127 -0
  12. package/lib/benchmarks/index.mjs +111 -0
  13. package/lib/benchmarks/nice-benchmark.d.ts +1 -1
  14. package/lib/benchmarks/nice-benchmark.d.ts.map +1 -1
  15. package/lib/benchmarks/nice-benchmark.js +72 -0
  16. package/lib/benchmarks/nice-benchmark.mjs +52 -0
  17. package/lib/benchmarks/swapi-schema/index.d.ts +1 -0
  18. package/lib/benchmarks/swapi-schema/index.d.ts.map +1 -1
  19. package/lib/benchmarks/swapi-schema/index.js +39 -0
  20. package/lib/benchmarks/swapi-schema/index.mjs +17 -0
  21. package/lib/benchmarks/swapi-schema/models.d.ts.map +1 -1
  22. package/lib/benchmarks/swapi-schema/models.js +29 -0
  23. package/lib/benchmarks/swapi-schema/models.mjs +7 -0
  24. package/lib/benchmarks/swapi-schema/resolvers.d.ts.map +1 -1
  25. package/lib/benchmarks/swapi-schema/resolvers.js +237 -0
  26. package/lib/benchmarks/swapi-schema/resolvers.mjs +230 -0
  27. package/lib/bin/supermassive.d.ts +3 -0
  28. package/lib/bin/supermassive.d.ts.map +1 -0
  29. package/lib/bin/supermassive.js +83 -0
  30. package/lib/bin/supermassive.mjs +62 -0
  31. package/lib/collectFields.d.ts +17 -0
  32. package/lib/collectFields.d.ts.map +1 -0
  33. package/lib/collectFields.js +83 -0
  34. package/lib/collectFields.mjs +61 -0
  35. package/lib/compiledQuery.d.ts +1 -0
  36. package/lib/compiledQuery.d.ts.map +1 -0
  37. package/lib/compiledQuery.js +0 -0
  38. package/lib/compiledQuery.mjs +0 -0
  39. package/lib/executeWithSchema.d.ts +4 -0
  40. package/lib/executeWithSchema.d.ts.map +1 -0
  41. package/lib/{index.test.js → executeWithSchema.js} +45 -46
  42. package/lib/executeWithSchema.mjs +64 -0
  43. package/lib/executeWithoutSchema.d.ts +99 -0
  44. package/lib/executeWithoutSchema.d.ts.map +1 -0
  45. package/lib/executeWithoutSchema.js +376 -0
  46. package/lib/executeWithoutSchema.mjs +363 -0
  47. package/lib/extractImplicitTypesRuntime.d.ts +4 -0
  48. package/lib/extractImplicitTypesRuntime.d.ts.map +1 -0
  49. package/lib/extractImplicitTypesRuntime.js +103 -0
  50. package/lib/extractImplicitTypesRuntime.mjs +91 -0
  51. package/lib/extractImplicitTypesToTypescript.d.ts +4 -0
  52. package/lib/extractImplicitTypesToTypescript.d.ts.map +1 -0
  53. package/lib/extractImplicitTypesToTypescript.js +169 -0
  54. package/lib/extractImplicitTypesToTypescript.mjs +149 -0
  55. package/lib/index.d.ts +8 -0
  56. package/lib/index.d.ts.map +1 -0
  57. package/lib/index.js +12 -29
  58. package/lib/index.mjs +13 -29
  59. package/lib/jsutils/Maybe.d.ts +3 -0
  60. package/lib/jsutils/Maybe.d.ts.map +1 -0
  61. package/lib/jsutils/Maybe.js +3 -0
  62. package/lib/jsutils/Maybe.mjs +0 -0
  63. package/lib/jsutils/ObjMap.d.ts +13 -0
  64. package/lib/jsutils/ObjMap.d.ts.map +1 -0
  65. package/lib/jsutils/ObjMap.js +3 -0
  66. package/lib/jsutils/ObjMap.mjs +0 -0
  67. package/lib/jsutils/Path.d.ts +15 -0
  68. package/lib/jsutils/Path.d.ts.map +1 -0
  69. package/lib/jsutils/Path.js +23 -0
  70. package/lib/jsutils/Path.mjs +17 -0
  71. package/lib/jsutils/PromiseOrValue.d.ts +2 -0
  72. package/lib/jsutils/PromiseOrValue.d.ts.map +1 -0
  73. package/lib/jsutils/PromiseOrValue.js +3 -0
  74. package/lib/jsutils/PromiseOrValue.mjs +0 -0
  75. package/lib/jsutils/devAssert.d.ts +2 -0
  76. package/lib/jsutils/devAssert.d.ts.map +1 -0
  77. package/lib/jsutils/devAssert.js +16 -0
  78. package/lib/jsutils/devAssert.mjs +10 -0
  79. package/lib/jsutils/didYouMean.d.ts +6 -0
  80. package/lib/jsutils/didYouMean.d.ts.map +1 -0
  81. package/lib/jsutils/didYouMean.js +30 -0
  82. package/lib/jsutils/didYouMean.mjs +24 -0
  83. package/lib/jsutils/identityFunc.d.ts +5 -0
  84. package/lib/jsutils/identityFunc.d.ts.map +1 -0
  85. package/lib/jsutils/identityFunc.js +13 -0
  86. package/lib/jsutils/identityFunc.mjs +7 -0
  87. package/lib/jsutils/inspect.d.ts +5 -0
  88. package/lib/jsutils/inspect.d.ts.map +1 -0
  89. package/lib/jsutils/inspect.js +89 -0
  90. package/lib/jsutils/inspect.mjs +83 -0
  91. package/lib/jsutils/instanceOf.d.ts +14 -0
  92. package/lib/jsutils/instanceOf.d.ts.map +1 -0
  93. package/lib/jsutils/instanceOf.js +55 -0
  94. package/lib/jsutils/instanceOf.mjs +33 -0
  95. package/lib/jsutils/invariant.d.ts +2 -0
  96. package/lib/jsutils/invariant.d.ts.map +1 -0
  97. package/lib/jsutils/invariant.js +16 -0
  98. package/lib/jsutils/invariant.mjs +10 -0
  99. package/lib/jsutils/isAsyncIterable.d.ts +6 -0
  100. package/lib/jsutils/isAsyncIterable.d.ts.map +1 -0
  101. package/lib/jsutils/isAsyncIterable.js +13 -0
  102. package/lib/jsutils/isAsyncIterable.mjs +7 -0
  103. package/lib/jsutils/isIterableObject.d.ts +18 -0
  104. package/lib/jsutils/isIterableObject.d.ts.map +1 -0
  105. package/lib/jsutils/isIterableObject.js +13 -0
  106. package/lib/jsutils/isIterableObject.mjs +7 -0
  107. package/lib/jsutils/isObjectLike.d.ts +8 -0
  108. package/lib/jsutils/isObjectLike.d.ts.map +1 -0
  109. package/lib/jsutils/isObjectLike.js +13 -0
  110. package/lib/jsutils/isObjectLike.mjs +7 -0
  111. package/lib/jsutils/isPromise.d.ts +6 -0
  112. package/lib/jsutils/isPromise.d.ts.map +1 -0
  113. package/lib/jsutils/isPromise.js +13 -0
  114. package/lib/jsutils/isPromise.mjs +7 -0
  115. package/lib/jsutils/keyMap.d.ts +26 -0
  116. package/lib/jsutils/keyMap.d.ts.map +1 -0
  117. package/lib/jsutils/keyMap.js +17 -0
  118. package/lib/jsutils/keyMap.mjs +11 -0
  119. package/lib/jsutils/keyValMap.d.ts +20 -0
  120. package/lib/jsutils/keyValMap.d.ts.map +1 -0
  121. package/lib/jsutils/keyValMap.js +17 -0
  122. package/lib/jsutils/keyValMap.mjs +11 -0
  123. package/lib/jsutils/mapValue.d.ts +7 -0
  124. package/lib/jsutils/mapValue.d.ts.map +1 -0
  125. package/lib/jsutils/mapValue.js +17 -0
  126. package/lib/jsutils/mapValue.mjs +11 -0
  127. package/lib/jsutils/memoize3.d.ts +5 -0
  128. package/lib/jsutils/memoize3.d.ts.map +1 -0
  129. package/lib/jsutils/memoize3.js +34 -0
  130. package/lib/jsutils/memoize3.mjs +28 -0
  131. package/lib/jsutils/naturalCompare.d.ts +9 -0
  132. package/lib/jsutils/naturalCompare.d.ts.map +1 -0
  133. package/lib/jsutils/naturalCompare.js +53 -0
  134. package/lib/jsutils/naturalCompare.mjs +47 -0
  135. package/lib/jsutils/printPathArray.d.ts +5 -0
  136. package/lib/jsutils/printPathArray.d.ts.map +1 -0
  137. package/lib/jsutils/printPathArray.js +13 -0
  138. package/lib/jsutils/printPathArray.mjs +7 -0
  139. package/lib/jsutils/promiseForObject.d.ts +10 -0
  140. package/lib/jsutils/promiseForObject.d.ts.map +1 -0
  141. package/lib/jsutils/promiseForObject.js +19 -0
  142. package/lib/jsutils/promiseForObject.mjs +13 -0
  143. package/lib/jsutils/promiseReduce.d.ts +10 -0
  144. package/lib/jsutils/promiseReduce.d.ts.map +1 -0
  145. package/lib/jsutils/promiseReduce.js +34 -0
  146. package/lib/jsutils/promiseReduce.mjs +12 -0
  147. package/lib/jsutils/suggestionList.d.ts +6 -0
  148. package/lib/jsutils/suggestionList.d.ts.map +1 -0
  149. package/lib/jsutils/suggestionList.js +109 -0
  150. package/lib/jsutils/suggestionList.mjs +87 -0
  151. package/lib/jsutils/toObjMap.d.ts +4 -0
  152. package/lib/jsutils/toObjMap.d.ts.map +1 -0
  153. package/lib/jsutils/toObjMap.js +20 -0
  154. package/lib/jsutils/toObjMap.mjs +14 -0
  155. package/lib/transforms/annotateDocumentGraphQLTransform.d.ts +3 -0
  156. package/lib/transforms/annotateDocumentGraphQLTransform.d.ts.map +1 -0
  157. package/lib/transforms/annotateDocumentGraphQLTransform.js +37 -0
  158. package/lib/transforms/annotateDocumentGraphQLTransform.mjs +17 -0
  159. package/lib/transforms/transformerTestUtils.d.ts +79 -0
  160. package/lib/transforms/transformerTestUtils.d.ts.map +1 -0
  161. package/lib/transforms/transformerTestUtils.js +175 -0
  162. package/lib/transforms/transformerTestUtils.mjs +160 -0
  163. package/lib/types.d.ts +74 -0
  164. package/lib/types.d.ts.map +1 -0
  165. package/lib/types.js +3 -0
  166. package/lib/types.mjs +0 -0
  167. package/lib/utilities/typeNameFromAST.d.ts +3 -0
  168. package/lib/utilities/typeNameFromAST.d.ts.map +1 -0
  169. package/lib/utilities/typeNameFromAST.js +34 -0
  170. package/lib/utilities/typeNameFromAST.mjs +12 -0
  171. package/lib/values.d.ts +64 -0
  172. package/lib/values.d.ts.map +1 -0
  173. package/lib/values.js +145 -0
  174. package/lib/values.mjs +138 -0
  175. package/package.json +21 -6
  176. package/.eslintcache +0 -1
  177. package/CHANGELOG.json +0 -35
  178. package/benchmarks/fixtures/query1.graphql +0 -20
  179. package/benchmarks/index.ts +0 -68
  180. package/benchmarks/nice-benchmark.ts +0 -32
  181. package/benchmarks/swapi-schema/index.ts +0 -13
  182. package/benchmarks/swapi-schema/models.ts +0 -4
  183. package/benchmarks/swapi-schema/resolvers.ts +0 -331
  184. package/benchmarks/swapi-schema/schema.graphql +0 -164
  185. package/benchmarks/swapi-schema/starwars.json +0 -5991
  186. package/lib/index.test.mjs +0 -63
  187. package/lib/src/ast/TypedAST.d.ts.map +0 -1
  188. package/lib/src/ast/addTypesToRequestDocument.d.ts.map +0 -1
  189. package/lib/src/index.d.ts +0 -16
  190. package/lib/src/index.d.ts.map +0 -1
  191. package/lib/src/index.test.d.ts +0 -2
  192. package/lib/src/index.test.d.ts.map +0 -1
@@ -0,0 +1,64 @@
1
+ import { GraphQLError, GraphQLScalarType } from "graphql";
2
+ import { DirectiveNode, FieldNode, VariableDefinitionNode } from "./ast/TypedAST";
3
+ import type { Maybe } from "./jsutils/Maybe";
4
+ import type { ObjMap } from "./jsutils/ObjMap";
5
+ import { Resolvers } from "./types";
6
+ declare type CoercedVariableValues = {
7
+ errors: Array<GraphQLError>;
8
+ coerced?: never;
9
+ } | {
10
+ coerced: {
11
+ [variable: string]: unknown;
12
+ };
13
+ errors?: never;
14
+ };
15
+ /**
16
+ * Prepares an object map of variableValues of the correct type based on the
17
+ * provided variable definitions and arbitrary input. If the input cannot be
18
+ * parsed to match the variable definitions, a GraphQLError will be thrown.
19
+ *
20
+ * Note: The returned value is a plain Object with a prototype, since it is
21
+ * exposed to user code. Care should be taken to not pull values from the
22
+ * Object prototype.
23
+ *
24
+ * @internal
25
+ */
26
+ export declare function getVariableValues(resolvers: Resolvers, varDefNodes: ReadonlyArray<VariableDefinitionNode>, inputs: {
27
+ [variable: string]: unknown;
28
+ }, options?: {
29
+ maxErrors?: number;
30
+ }): CoercedVariableValues;
31
+ /**
32
+ * Prepares an object map of argument values given a list of argument
33
+ * definitions and list of argument AST nodes.
34
+ *
35
+ * Note: The returned value is a plain Object with a prototype, since it is
36
+ * exposed to user code. Care should be taken to not pull values from the
37
+ * Object prototype.
38
+ *
39
+ * @internal
40
+ */
41
+ export declare function getArgumentValues(resolvers: Resolvers, node: FieldNode | DirectiveNode, variableValues?: Maybe<ObjMap<unknown>>): {
42
+ [argument: string]: unknown;
43
+ };
44
+ /**
45
+ * Prepares an object map of argument values given a directive definition
46
+ * and a AST node which may contain directives. Optionally also accepts a map
47
+ * of variable values.
48
+ *
49
+ * If the directive does not exist on the node, returns undefined.
50
+ *
51
+ * Note: The returned value is a plain Object with a prototype, since it is
52
+ * exposed to user code. Care should be taken to not pull values from the
53
+ * Object prototype.
54
+ */
55
+ export declare function getDirectiveValues(resolvers: Resolvers, node: {
56
+ directives?: Array<DirectiveNode>;
57
+ }, variableValues?: Maybe<ObjMap<unknown>>): undefined | {
58
+ [argument: string]: unknown;
59
+ };
60
+ export declare const specifiedScalars: {
61
+ [key: string]: GraphQLScalarType;
62
+ };
63
+ export {};
64
+ //# sourceMappingURL=values.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"values.d.ts","sourceRoot":"","sources":["../src/values.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,YAAY,EAMZ,iBAAiB,EAYlB,MAAM,SAAS,CAAC;AACjB,OAAO,EAEL,aAAa,EACb,SAAS,EAET,sBAAsB,EACvB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEpC,aAAK,qBAAqB,GACtB;IAAE,MAAM,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC;IAAC,OAAO,CAAC,EAAE,KAAK,CAAA;CAAE,GAChD;IAAE,OAAO,EAAE;QAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC;IAAC,MAAM,CAAC,EAAE,KAAK,CAAA;CAAE,CAAC;AAEjE;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAC/B,SAAS,EAAE,SAAS,EACpB,WAAW,EAAE,aAAa,CAAC,sBAAsB,CAAC,EAClD,MAAM,EAAE;IAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,EACvC,OAAO,CAAC,EAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,GAC/B,qBAAqB,CA0BvB;AAmFD;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAC/B,SAAS,EAAE,SAAS,EACpB,IAAI,EAAE,SAAS,GAAG,aAAa,EAC/B,cAAc,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,GACtC;IAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,CAmEjC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,SAAS,EACpB,IAAI,EAAE;IAAE,UAAU,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC,CAAA;CAAE,EAC3C,cAAc,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,GACtC,SAAS,GAAG;IAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,CAU7C;AAMD,eAAO,MAAM,gBAAgB,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,iBAAiB,CAAA;CAMhE,CAAC"}
package/lib/values.js ADDED
@@ -0,0 +1,145 @@
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
+ getArgumentValues: () => getArgumentValues,
26
+ getDirectiveValues: () => getDirectiveValues,
27
+ getVariableValues: () => getVariableValues,
28
+ specifiedScalars: () => specifiedScalars
29
+ });
30
+ var import_graphql = __toModule(require("graphql"));
31
+ var import_inspect = __toModule(require("./jsutils/inspect"));
32
+ var import_keyMap = __toModule(require("./jsutils/keyMap"));
33
+ var import_printPathArray = __toModule(require("./jsutils/printPathArray"));
34
+ function getVariableValues(resolvers, varDefNodes, inputs, options) {
35
+ const errors = [];
36
+ const maxErrors = options == null ? void 0 : options.maxErrors;
37
+ try {
38
+ const coerced = coerceVariableValues(resolvers, varDefNodes, inputs, (error) => {
39
+ if (maxErrors != null && errors.length >= maxErrors) {
40
+ throw new import_graphql.GraphQLError("Too many errors processing variables, error limit reached. Execution aborted.");
41
+ }
42
+ errors.push(error);
43
+ });
44
+ if (errors.length === 0) {
45
+ return {coerced};
46
+ }
47
+ } catch (error) {
48
+ errors.push(error);
49
+ }
50
+ return {errors};
51
+ }
52
+ function coerceVariableValues(resolvers, varDefNodes, inputs, onError) {
53
+ const coercedValues = {};
54
+ for (const varDefNode of varDefNodes) {
55
+ const varName = varDefNode.variable.name.value;
56
+ const varTypeAst = varDefNode.type;
57
+ const varType = graphqlTypeFromTypeAst(resolvers, varTypeAst);
58
+ if (!(0, import_graphql.isInputType)(varType)) {
59
+ const varTypeStr = (0, import_inspect.inspect)(varType);
60
+ onError(new import_graphql.GraphQLError(`Variable "$${varName}" expected value of type "${varTypeStr}" which cannot be used as an input type.`, varDefNode.type));
61
+ continue;
62
+ }
63
+ if (!hasOwnProperty(inputs, varName)) {
64
+ if (varDefNode.defaultValue) {
65
+ coercedValues[varName] = (0, import_graphql.valueFromAST)(varDefNode.defaultValue, varType);
66
+ } else if ((0, import_graphql.isNonNullType)(varType)) {
67
+ const varTypeStr = (0, import_graphql.print)(varDefNode.type);
68
+ onError(new import_graphql.GraphQLError(`Variable "$${varName}" of required type "${varTypeStr}" was not provided.`, varDefNode));
69
+ }
70
+ continue;
71
+ }
72
+ const value = inputs[varName];
73
+ if (value === null && (0, import_graphql.isNonNullType)(varType)) {
74
+ const varTypeStr = (0, import_inspect.inspect)(varType);
75
+ onError(new import_graphql.GraphQLError(`Variable "$${varName}" of non-null type "${varTypeStr}" must not be null.`, varDefNode));
76
+ continue;
77
+ }
78
+ coercedValues[varName] = (0, import_graphql.coerceInputValue)(value, varType, (path, invalidValue, error) => {
79
+ let prefix = `Variable "$${varName}" got invalid value ` + (0, import_inspect.inspect)(invalidValue);
80
+ if (path.length > 0) {
81
+ prefix += ` at "${varName}${(0, import_printPathArray.printPathArray)(path)}"`;
82
+ }
83
+ onError(new import_graphql.GraphQLError(prefix + "; " + error.message, varDefNode, void 0, void 0, void 0, error.originalError));
84
+ });
85
+ }
86
+ return coercedValues;
87
+ }
88
+ function getArgumentValues(resolvers, node, variableValues) {
89
+ var _a;
90
+ const coercedValues = {};
91
+ const argumentNodes = (_a = node.arguments) != null ? _a : [];
92
+ const argNodeMap = (0, import_keyMap.keyMap)(argumentNodes, (arg) => arg.name.value);
93
+ for (const argumentNode of argumentNodes) {
94
+ const name = argumentNode.name.value;
95
+ const argTypeNode = argumentNode.__type;
96
+ const argType = graphqlTypeFromTypeAst(resolvers, argTypeNode);
97
+ if (!(0, import_graphql.isInputType)(argType)) {
98
+ console.log(argType, (0, import_graphql.isInputType)(argType));
99
+ throw new import_graphql.GraphQLError(`Argument "$${name}" expected value of type "${(0, import_inspect.inspect)(argType)}" which cannot be used as an input type.`, argumentNode);
100
+ }
101
+ let valueNode = argumentNode.value;
102
+ let isNull = valueNode.kind === import_graphql.Kind.NULL;
103
+ if (valueNode.kind === import_graphql.Kind.VARIABLE) {
104
+ const variableName = valueNode.name.value;
105
+ if (variableValues == null || !hasOwnProperty(variableValues, variableName)) {
106
+ if (argumentNode.__defaultValue != void 0) {
107
+ valueNode = argumentNode.__defaultValue;
108
+ } else if ((0, import_graphql.isNonNullType)(argType)) {
109
+ throw new import_graphql.GraphQLError(`Argument "${name}" of required type "${(0, import_inspect.inspect)(argType)}" was provided the variable "$${variableName}" which was not provided a runtime value.`, valueNode);
110
+ }
111
+ }
112
+ isNull = !variableValues || variableValues[variableName] == null;
113
+ }
114
+ const coercedValue = (0, import_graphql.valueFromAST)(valueNode, argType, variableValues);
115
+ if (coercedValue === void 0) {
116
+ throw new import_graphql.GraphQLError(`Argument "${name}" has invalid value ${(0, import_graphql.print)(valueNode)}.`, valueNode);
117
+ }
118
+ coercedValues[name] = coercedValue;
119
+ }
120
+ return coercedValues;
121
+ }
122
+ function getDirectiveValues(resolvers, node, variableValues) {
123
+ throw new Error("Todo");
124
+ }
125
+ function hasOwnProperty(obj, prop) {
126
+ return Object.prototype.hasOwnProperty.call(obj, prop);
127
+ }
128
+ const specifiedScalars = {
129
+ ID: import_graphql.GraphQLID,
130
+ String: import_graphql.GraphQLString,
131
+ Int: import_graphql.GraphQLInt,
132
+ Float: import_graphql.GraphQLFloat,
133
+ Boolean: import_graphql.GraphQLBoolean
134
+ };
135
+ function graphqlTypeFromTypeAst(resolvers, node) {
136
+ if (node.kind === import_graphql.Kind.NON_NULL_TYPE) {
137
+ return new import_graphql.GraphQLNonNull(graphqlTypeFromTypeAst(resolvers, node.type));
138
+ } else if (node.kind === import_graphql.Kind.LIST_TYPE) {
139
+ return new import_graphql.GraphQLList(graphqlTypeFromTypeAst(resolvers, node.type));
140
+ } else {
141
+ const typeName = node.name.value;
142
+ const type = specifiedScalars[typeName] || resolvers[typeName];
143
+ return type;
144
+ }
145
+ }
package/lib/values.mjs ADDED
@@ -0,0 +1,138 @@
1
+ // src/values.ts
2
+ import {
3
+ GraphQLBoolean,
4
+ GraphQLError,
5
+ GraphQLFloat,
6
+ GraphQLID,
7
+ GraphQLInt,
8
+ GraphQLList,
9
+ GraphQLNonNull,
10
+ GraphQLString,
11
+ isInputType,
12
+ isNonNullType,
13
+ Kind,
14
+ print,
15
+ valueFromAST,
16
+ coerceInputValue
17
+ } from "graphql";
18
+ import {inspect} from "./jsutils/inspect.mjs";
19
+ import {keyMap} from "./jsutils/keyMap.mjs";
20
+ import {printPathArray} from "./jsutils/printPathArray.mjs";
21
+ function getVariableValues(resolvers, varDefNodes, inputs, options) {
22
+ const errors = [];
23
+ const maxErrors = options == null ? void 0 : options.maxErrors;
24
+ try {
25
+ const coerced = coerceVariableValues(resolvers, varDefNodes, inputs, (error) => {
26
+ if (maxErrors != null && errors.length >= maxErrors) {
27
+ throw new GraphQLError("Too many errors processing variables, error limit reached. Execution aborted.");
28
+ }
29
+ errors.push(error);
30
+ });
31
+ if (errors.length === 0) {
32
+ return {coerced};
33
+ }
34
+ } catch (error) {
35
+ errors.push(error);
36
+ }
37
+ return {errors};
38
+ }
39
+ function coerceVariableValues(resolvers, varDefNodes, inputs, onError) {
40
+ const coercedValues = {};
41
+ for (const varDefNode of varDefNodes) {
42
+ const varName = varDefNode.variable.name.value;
43
+ const varTypeAst = varDefNode.type;
44
+ const varType = graphqlTypeFromTypeAst(resolvers, varTypeAst);
45
+ if (!isInputType(varType)) {
46
+ const varTypeStr = inspect(varType);
47
+ onError(new GraphQLError(`Variable "$${varName}" expected value of type "${varTypeStr}" which cannot be used as an input type.`, varDefNode.type));
48
+ continue;
49
+ }
50
+ if (!hasOwnProperty(inputs, varName)) {
51
+ if (varDefNode.defaultValue) {
52
+ coercedValues[varName] = valueFromAST(varDefNode.defaultValue, varType);
53
+ } else if (isNonNullType(varType)) {
54
+ const varTypeStr = print(varDefNode.type);
55
+ onError(new GraphQLError(`Variable "$${varName}" of required type "${varTypeStr}" was not provided.`, varDefNode));
56
+ }
57
+ continue;
58
+ }
59
+ const value = inputs[varName];
60
+ if (value === null && isNonNullType(varType)) {
61
+ const varTypeStr = inspect(varType);
62
+ onError(new GraphQLError(`Variable "$${varName}" of non-null type "${varTypeStr}" must not be null.`, varDefNode));
63
+ continue;
64
+ }
65
+ coercedValues[varName] = coerceInputValue(value, varType, (path, invalidValue, error) => {
66
+ let prefix = `Variable "$${varName}" got invalid value ` + inspect(invalidValue);
67
+ if (path.length > 0) {
68
+ prefix += ` at "${varName}${printPathArray(path)}"`;
69
+ }
70
+ onError(new GraphQLError(prefix + "; " + error.message, varDefNode, void 0, void 0, void 0, error.originalError));
71
+ });
72
+ }
73
+ return coercedValues;
74
+ }
75
+ function getArgumentValues(resolvers, node, variableValues) {
76
+ var _a;
77
+ const coercedValues = {};
78
+ const argumentNodes = (_a = node.arguments) != null ? _a : [];
79
+ const argNodeMap = keyMap(argumentNodes, (arg) => arg.name.value);
80
+ for (const argumentNode of argumentNodes) {
81
+ const name = argumentNode.name.value;
82
+ const argTypeNode = argumentNode.__type;
83
+ const argType = graphqlTypeFromTypeAst(resolvers, argTypeNode);
84
+ if (!isInputType(argType)) {
85
+ console.log(argType, isInputType(argType));
86
+ throw new GraphQLError(`Argument "$${name}" expected value of type "${inspect(argType)}" which cannot be used as an input type.`, argumentNode);
87
+ }
88
+ let valueNode = argumentNode.value;
89
+ let isNull = valueNode.kind === Kind.NULL;
90
+ if (valueNode.kind === Kind.VARIABLE) {
91
+ const variableName = valueNode.name.value;
92
+ if (variableValues == null || !hasOwnProperty(variableValues, variableName)) {
93
+ if (argumentNode.__defaultValue != void 0) {
94
+ valueNode = argumentNode.__defaultValue;
95
+ } else if (isNonNullType(argType)) {
96
+ throw new GraphQLError(`Argument "${name}" of required type "${inspect(argType)}" was provided the variable "$${variableName}" which was not provided a runtime value.`, valueNode);
97
+ }
98
+ }
99
+ isNull = !variableValues || variableValues[variableName] == null;
100
+ }
101
+ const coercedValue = valueFromAST(valueNode, argType, variableValues);
102
+ if (coercedValue === void 0) {
103
+ throw new GraphQLError(`Argument "${name}" has invalid value ${print(valueNode)}.`, valueNode);
104
+ }
105
+ coercedValues[name] = coercedValue;
106
+ }
107
+ return coercedValues;
108
+ }
109
+ function getDirectiveValues(resolvers, node, variableValues) {
110
+ throw new Error("Todo");
111
+ }
112
+ function hasOwnProperty(obj, prop) {
113
+ return Object.prototype.hasOwnProperty.call(obj, prop);
114
+ }
115
+ var specifiedScalars = {
116
+ ID: GraphQLID,
117
+ String: GraphQLString,
118
+ Int: GraphQLInt,
119
+ Float: GraphQLFloat,
120
+ Boolean: GraphQLBoolean
121
+ };
122
+ function graphqlTypeFromTypeAst(resolvers, node) {
123
+ if (node.kind === Kind.NON_NULL_TYPE) {
124
+ return new GraphQLNonNull(graphqlTypeFromTypeAst(resolvers, node.type));
125
+ } else if (node.kind === Kind.LIST_TYPE) {
126
+ return new GraphQLList(graphqlTypeFromTypeAst(resolvers, node.type));
127
+ } else {
128
+ const typeName = node.name.value;
129
+ const type = specifiedScalars[typeName] || resolvers[typeName];
130
+ return type;
131
+ }
132
+ }
133
+ export {
134
+ getArgumentValues,
135
+ getDirectiveValues,
136
+ getVariableValues,
137
+ specifiedScalars
138
+ };
package/package.json CHANGED
@@ -1,24 +1,26 @@
1
1
  {
2
2
  "name": "@graphitation/supermassive",
3
3
  "license": "MIT",
4
- "version": "0.1.1",
5
- "main": "./lib/index",
4
+ "version": "0.3.0",
5
+ "bin": {
6
+ "supermassive": "./bin/supermassive.js"
7
+ },
8
+ "main": "./lib/index.js",
6
9
  "scripts": {
7
10
  "build": "monorepo-scripts build",
8
11
  "lint": "monorepo-scripts lint",
9
12
  "test": "monorepo-scripts test",
10
13
  "types": "monorepo-scripts types",
11
14
  "just": "monorepo-scripts",
12
- "benchmark": "ts-node -T -O '{\"module\":\"commonjs\"}' ./benchmarks/index.ts"
15
+ "benchmark": "ts-node -T -O '{\"module\":\"commonjs\"}' ./src/benchmarks/index.ts"
13
16
  },
14
17
  "devDependencies": {
15
18
  "@graphitation/graphql-js-tag": "*",
16
- "@graphql-tools/schema": "^7.1.5",
19
+ "@ts-morph/bootstrap": "^0.11.0",
17
20
  "@types/benchmark": "^2.1.0",
18
21
  "@types/jest": "^26.0.22",
19
22
  "@types/node-json-db": "^0.9.3",
20
23
  "benchmark": "^2.1.4",
21
- "graphql": "^15.5.0",
22
24
  "graphql-jit": "^0.5.1",
23
25
  "monorepo-scripts": "*",
24
26
  "node-json-db": "^1.3.0",
@@ -27,5 +29,18 @@
27
29
  "publishConfig": {
28
30
  "access": "public"
29
31
  },
30
- "types": "./lib/index.d.ts"
32
+ "dependencies": {
33
+ "@graphql-tools/schema": "^7.1.5",
34
+ "commander": "^8.3.0",
35
+ "graphql": "^15.6.1",
36
+ "typescript": "4.4.3"
37
+ },
38
+ "types": "./lib/index.d.ts",
39
+ "module": "./lib/index.mjs",
40
+ "exports": {
41
+ ".": {
42
+ "import": "./lib/index.mjs",
43
+ "require": "./lib/index.js"
44
+ }
45
+ }
31
46
  }
package/.eslintcache DELETED
@@ -1 +0,0 @@
1
- [{"/home/runner/work/graphitation/graphitation/packages/supermassive/src/ast/TypedAST.ts":"1","/home/runner/work/graphitation/graphitation/packages/supermassive/src/ast/__tests__/addTypesToRequestDocument.test.ts":"2","/home/runner/work/graphitation/graphitation/packages/supermassive/src/ast/addTypesToRequestDocument.ts":"3","/home/runner/work/graphitation/graphitation/packages/supermassive/src/index.test.ts":"4","/home/runner/work/graphitation/graphitation/packages/supermassive/src/index.ts":"5"},{"size":14221,"mtime":1633355136318,"results":"6","hashOfConfig":"7"},{"size":5291,"mtime":1633355136318,"results":"8","hashOfConfig":"7"},{"size":2022,"mtime":1633355136318,"results":"9","hashOfConfig":"7"},{"size":756,"mtime":1633355136318,"results":"10","hashOfConfig":"7"},{"size":579,"mtime":1633355136318,"results":"11","hashOfConfig":"7"},{"filePath":"12","messages":"13","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"urmpsg",{"filePath":"14","messages":"15","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"16","messages":"17","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"18","messages":"19","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"20","messages":"21","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"/home/runner/work/graphitation/graphitation/packages/supermassive/src/ast/TypedAST.ts",[],"/home/runner/work/graphitation/graphitation/packages/supermassive/src/ast/__tests__/addTypesToRequestDocument.test.ts",[],"/home/runner/work/graphitation/graphitation/packages/supermassive/src/ast/addTypesToRequestDocument.ts",[],"/home/runner/work/graphitation/graphitation/packages/supermassive/src/index.test.ts",[],"/home/runner/work/graphitation/graphitation/packages/supermassive/src/index.ts",[]]
package/CHANGELOG.json DELETED
@@ -1,35 +0,0 @@
1
- {
2
- "name": "@graphitation/supermassive",
3
- "entries": [
4
- {
5
- "date": "Mon, 04 Oct 2021 13:47:53 GMT",
6
- "tag": "@graphitation/supermassive_v0.1.1",
7
- "version": "0.1.1",
8
- "comments": {
9
- "patch": [
10
- {
11
- "comment": "Bump @graphitation/graphql-js-tag to v0.5.4",
12
- "author": "eloy.de.enige@gmail.com",
13
- "commit": "ceb24aa25210090e38251be53d010d75abdad9ba",
14
- "package": "@graphitation/supermassive"
15
- }
16
- ]
17
- }
18
- },
19
- {
20
- "date": "Thu, 24 Jun 2021 12:32:15 GMT",
21
- "tag": "@graphitation/supermassive_v0.1.0",
22
- "version": "0.1.0",
23
- "comments": {
24
- "none": [
25
- {
26
- "comment": "Test and benchmark setup for supermassive",
27
- "author": "eloy.de.enige@gmail.com",
28
- "commit": "ebbad29ec11dae814bbe8c2e492d1baf5382c138",
29
- "package": "@graphitation/supermassive"
30
- }
31
- ]
32
- }
33
- }
34
- ]
35
- }
@@ -1,20 +0,0 @@
1
- {
2
- empireHero: person(id: 1) {
3
- ...PersonFields
4
- height
5
- mass
6
- }
7
-
8
- jediHero: person(id: 4) {
9
- ...PersonFields
10
- }
11
- }
12
-
13
- fragment PersonFields on Person {
14
- name
15
- gender
16
- birth_year
17
- starships {
18
- name
19
- }
20
- }
@@ -1,68 +0,0 @@
1
- import fs from "fs";
2
- import path from "path";
3
- import NiceBenchmark from "./nice-benchmark";
4
- import schema from "./swapi-schema";
5
- import models from "./swapi-schema/models";
6
- import { graphql, execute, parse } from "graphql";
7
- import { compileQuery, isCompiledQuery } from "graphql-jit";
8
-
9
- const query = fs.readFileSync(
10
- path.join(__dirname, "./fixtures/query1.graphql"),
11
- {
12
- encoding: "utf-8",
13
- }
14
- );
15
-
16
- const parsedQuery = parse(query);
17
-
18
- const compiledQuery = compileQuery(schema, parsedQuery);
19
-
20
- const queryRunningSuite = new NiceBenchmark("Query Running");
21
- queryRunningSuite.add("string queries graphql-js", async () => {
22
- const result = await graphql({
23
- schema,
24
- source: query,
25
- contextValue: { models },
26
- });
27
- if (result.errors || !result.data) {
28
- throw new Error("Stuff ain't executing");
29
- }
30
- });
31
- queryRunningSuite.add("parsed queries graphql-js", async () => {
32
- const result = await execute({
33
- schema,
34
- document: parsedQuery,
35
- contextValue: { models },
36
- });
37
- if (result.errors || !result.data) {
38
- throw new Error("Stuff ain't executing");
39
- }
40
- });
41
- queryRunningSuite.add("graphql-jit", async () => {
42
- if (isCompiledQuery(compiledQuery)) {
43
- const result = await compiledQuery.query({}, { models }, {});
44
- if (result.errors || !result.data) {
45
- throw new Error("Stuff ain't executing");
46
- }
47
- } else {
48
- throw new Error("Wrong query");
49
- }
50
- });
51
-
52
- const queryParsingSuite = new NiceBenchmark("Query parsing");
53
- queryParsingSuite.add("graphql-js", async () => {
54
- parse(query);
55
- });
56
-
57
- const queryCompilingSuite = new NiceBenchmark("Query compiling");
58
- queryCompilingSuite.add("graphql-jit", async () => {
59
- await compileQuery(schema, parsedQuery);
60
- });
61
-
62
- async function main() {
63
- await queryParsingSuite.run();
64
- await queryCompilingSuite.run();
65
- await queryRunningSuite.run();
66
- }
67
-
68
- main();
@@ -1,32 +0,0 @@
1
- import { Suite } from "benchmark";
2
-
3
- export default class NiceBenchmark {
4
- private name: string;
5
- private suite: Suite;
6
-
7
- constructor(name: string) {
8
- this.name = name;
9
- this.suite = new Suite(name);
10
- this.suite.on("cycle", function (event: any) {
11
- console.log(String(event.target));
12
- });
13
- }
14
-
15
- add(name: string, fn: () => Promise<any>) {
16
- this.suite.add(name, {
17
- defer: true,
18
- fn: async (deferred: any) => {
19
- await fn();
20
- deferred.resolve();
21
- },
22
- });
23
- }
24
-
25
- run(options?: any): Promise<any> {
26
- return new Promise((resolve) => {
27
- this.suite.on("complete", resolve);
28
- console.log(this.name);
29
- this.suite.run(options);
30
- });
31
- }
32
- }
@@ -1,13 +0,0 @@
1
- import { makeExecutableSchema } from "@graphql-tools/schema";
2
- import { join } from "path";
3
- import { readFileSync } from "fs";
4
- import resolvers from "./resolvers";
5
-
6
- const typeDefs = readFileSync(join(__dirname, "./schema.graphql"), {
7
- encoding: "utf-8",
8
- });
9
-
10
- export default makeExecutableSchema({
11
- typeDefs,
12
- resolvers,
13
- });
@@ -1,4 +0,0 @@
1
- import path from "path";
2
- import { JsonDB } from "node-json-db";
3
-
4
- export default new JsonDB(path.join(__dirname, "./starwars"));