@graphitation/supermassive 0.1.3 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintcache +1 -1
- package/CHANGELOG.md +10 -2
- package/README.md +88 -0
- package/bin/supermassive.js +5 -0
- package/graphitation-supermassive-0.1.3-1.tgz +0 -0
- package/graphitation-supermassive-0.1.3-2.tgz +0 -0
- package/graphitation-supermassive-0.1.3.tgz +0 -0
- package/lib/{src/ast → ast}/TypedAST.d.ts +2 -0
- package/lib/ast/TypedAST.d.ts.map +1 -0
- package/lib/{src/ast → ast}/addTypesToRequestDocument.d.ts +0 -0
- package/lib/ast/addTypesToRequestDocument.d.ts.map +1 -0
- package/lib/ast/addTypesToRequestDocument.js +8 -5
- package/lib/ast/addTypesToRequestDocument.mjs +9 -5
- package/lib/benchmarks/index.d.ts.map +1 -1
- package/lib/benchmarks/index.js +127 -0
- package/lib/benchmarks/index.mjs +109 -0
- package/lib/benchmarks/nice-benchmark.d.ts +1 -1
- package/lib/benchmarks/nice-benchmark.d.ts.map +1 -1
- package/lib/benchmarks/nice-benchmark.js +72 -0
- package/lib/benchmarks/nice-benchmark.mjs +49 -0
- package/lib/benchmarks/swapi-schema/index.d.ts +1 -0
- package/lib/benchmarks/swapi-schema/index.d.ts.map +1 -1
- package/lib/benchmarks/swapi-schema/index.js +39 -0
- package/lib/benchmarks/swapi-schema/index.mjs +16 -0
- package/lib/benchmarks/swapi-schema/models.d.ts.map +1 -1
- package/lib/benchmarks/swapi-schema/models.js +29 -0
- package/lib/benchmarks/swapi-schema/models.mjs +6 -0
- package/lib/benchmarks/swapi-schema/resolvers.d.ts.map +1 -1
- package/lib/benchmarks/swapi-schema/resolvers.js +237 -0
- package/lib/benchmarks/swapi-schema/resolvers.mjs +231 -0
- package/lib/bin/supermassive.d.ts +3 -0
- package/lib/bin/supermassive.d.ts.map +1 -0
- package/lib/bin/supermassive.js +83 -0
- package/lib/bin/supermassive.mjs +60 -0
- package/lib/bin/typeDefsToImplicitResolvers.d.ts +3 -0
- package/lib/bin/typeDefsToImplicitResolvers.d.ts.map +1 -0
- package/lib/bin/typeDefsToImplicitResolvers.js +82 -0
- package/lib/bin/typeDefsToImplicitResolvers.mjs +59 -0
- package/lib/collectFields.d.ts +17 -0
- package/lib/collectFields.d.ts.map +1 -0
- package/lib/collectFields.js +83 -0
- package/lib/collectFields.mjs +60 -0
- package/lib/compiledQuery.d.ts +1 -0
- package/lib/compiledQuery.d.ts.map +1 -0
- package/lib/compiledQuery.js +0 -0
- package/lib/compiledQuery.mjs +0 -0
- package/lib/execute.d.ts +128 -0
- package/lib/execute.d.ts.map +1 -0
- package/lib/execute.js +376 -0
- package/lib/execute.mjs +365 -0
- package/lib/executeWithSchema.d.ts +4 -0
- package/lib/executeWithSchema.d.ts.map +1 -0
- package/lib/{index.test.js → executeWithSchema.js} +44 -45
- package/lib/executeWithSchema.mjs +62 -0
- package/lib/executeWithoutSchema.d.ts +99 -0
- package/lib/executeWithoutSchema.d.ts.map +1 -0
- package/lib/executeWithoutSchema.js +376 -0
- package/lib/executeWithoutSchema.mjs +365 -0
- package/lib/extractImplicitTypes.d.ts +6 -0
- package/lib/extractImplicitTypes.d.ts.map +1 -0
- package/lib/extractImplicitTypes.js +246 -0
- package/lib/extractImplicitTypes.mjs +233 -0
- package/lib/extractImplicitTypesRuntime.d.ts +4 -0
- package/lib/extractImplicitTypesRuntime.d.ts.map +1 -0
- package/lib/extractImplicitTypesRuntime.js +103 -0
- package/lib/extractImplicitTypesRuntime.mjs +90 -0
- package/lib/extractImplicitTypesToTypescript.d.ts +4 -0
- package/lib/extractImplicitTypesToTypescript.d.ts.map +1 -0
- package/lib/extractImplicitTypesToTypescript.js +169 -0
- package/lib/extractImplicitTypesToTypescript.mjs +148 -0
- package/lib/index.d.ts +8 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +14 -29
- package/lib/index.mjs +14 -29
- package/lib/jsutils/Maybe.d.ts +3 -0
- package/lib/jsutils/Maybe.d.ts.map +1 -0
- package/lib/jsutils/Maybe.js +3 -0
- package/lib/jsutils/Maybe.mjs +0 -0
- package/lib/jsutils/ObjMap.d.ts +13 -0
- package/lib/jsutils/ObjMap.d.ts.map +1 -0
- package/lib/jsutils/ObjMap.js +3 -0
- package/lib/jsutils/ObjMap.mjs +0 -0
- package/lib/jsutils/Path.d.ts +15 -0
- package/lib/jsutils/Path.d.ts.map +1 -0
- package/lib/jsutils/Path.js +23 -0
- package/lib/jsutils/Path.mjs +16 -0
- package/lib/jsutils/PromiseOrValue.d.ts +2 -0
- package/lib/jsutils/PromiseOrValue.d.ts.map +1 -0
- package/lib/jsutils/PromiseOrValue.js +3 -0
- package/lib/jsutils/PromiseOrValue.mjs +0 -0
- package/lib/jsutils/devAssert.d.ts +2 -0
- package/lib/jsutils/devAssert.d.ts.map +1 -0
- package/lib/jsutils/devAssert.js +16 -0
- package/lib/jsutils/devAssert.mjs +9 -0
- package/lib/jsutils/didYouMean.d.ts +6 -0
- package/lib/jsutils/didYouMean.d.ts.map +1 -0
- package/lib/jsutils/didYouMean.js +30 -0
- package/lib/jsutils/didYouMean.mjs +23 -0
- package/lib/jsutils/identityFunc.d.ts +5 -0
- package/lib/jsutils/identityFunc.d.ts.map +1 -0
- package/lib/jsutils/identityFunc.js +13 -0
- package/lib/jsutils/identityFunc.mjs +6 -0
- package/lib/jsutils/inspect.d.ts +5 -0
- package/lib/jsutils/inspect.d.ts.map +1 -0
- package/lib/jsutils/inspect.js +89 -0
- package/lib/jsutils/inspect.mjs +82 -0
- package/lib/jsutils/instanceOf.d.ts +14 -0
- package/lib/jsutils/instanceOf.d.ts.map +1 -0
- package/lib/jsutils/instanceOf.js +55 -0
- package/lib/jsutils/instanceOf.mjs +32 -0
- package/lib/jsutils/invariant.d.ts +2 -0
- package/lib/jsutils/invariant.d.ts.map +1 -0
- package/lib/jsutils/invariant.js +16 -0
- package/lib/jsutils/invariant.mjs +9 -0
- package/lib/jsutils/isAsyncIterable.d.ts +6 -0
- package/lib/jsutils/isAsyncIterable.d.ts.map +1 -0
- package/lib/jsutils/isAsyncIterable.js +13 -0
- package/lib/jsutils/isAsyncIterable.mjs +6 -0
- package/lib/jsutils/isIterableObject.d.ts +18 -0
- package/lib/jsutils/isIterableObject.d.ts.map +1 -0
- package/lib/jsutils/isIterableObject.js +13 -0
- package/lib/jsutils/isIterableObject.mjs +6 -0
- package/lib/jsutils/isObjectLike.d.ts +8 -0
- package/lib/jsutils/isObjectLike.d.ts.map +1 -0
- package/lib/jsutils/isObjectLike.js +13 -0
- package/lib/jsutils/isObjectLike.mjs +6 -0
- package/lib/jsutils/isPromise.d.ts +6 -0
- package/lib/jsutils/isPromise.d.ts.map +1 -0
- package/lib/jsutils/isPromise.js +13 -0
- package/lib/jsutils/isPromise.mjs +6 -0
- package/lib/jsutils/keyMap.d.ts +26 -0
- package/lib/jsutils/keyMap.d.ts.map +1 -0
- package/lib/jsutils/keyMap.js +17 -0
- package/lib/jsutils/keyMap.mjs +10 -0
- package/lib/jsutils/keyValMap.d.ts +20 -0
- package/lib/jsutils/keyValMap.d.ts.map +1 -0
- package/lib/jsutils/keyValMap.js +17 -0
- package/lib/jsutils/keyValMap.mjs +10 -0
- package/lib/jsutils/mapValue.d.ts +7 -0
- package/lib/jsutils/mapValue.d.ts.map +1 -0
- package/lib/jsutils/mapValue.js +17 -0
- package/lib/jsutils/mapValue.mjs +10 -0
- package/lib/jsutils/memoize3.d.ts +5 -0
- package/lib/jsutils/memoize3.d.ts.map +1 -0
- package/lib/jsutils/memoize3.js +34 -0
- package/lib/jsutils/memoize3.mjs +27 -0
- package/lib/jsutils/naturalCompare.d.ts +9 -0
- package/lib/jsutils/naturalCompare.d.ts.map +1 -0
- package/lib/jsutils/naturalCompare.js +53 -0
- package/lib/jsutils/naturalCompare.mjs +46 -0
- package/lib/jsutils/printPathArray.d.ts +5 -0
- package/lib/jsutils/printPathArray.d.ts.map +1 -0
- package/lib/jsutils/printPathArray.js +13 -0
- package/lib/jsutils/printPathArray.mjs +6 -0
- package/lib/jsutils/promiseForObject.d.ts +10 -0
- package/lib/jsutils/promiseForObject.d.ts.map +1 -0
- package/lib/jsutils/promiseForObject.js +19 -0
- package/lib/jsutils/promiseForObject.mjs +12 -0
- package/lib/jsutils/promiseReduce.d.ts +10 -0
- package/lib/jsutils/promiseReduce.d.ts.map +1 -0
- package/lib/jsutils/promiseReduce.js +34 -0
- package/lib/jsutils/promiseReduce.mjs +11 -0
- package/lib/jsutils/suggestionList.d.ts +6 -0
- package/lib/jsutils/suggestionList.d.ts.map +1 -0
- package/lib/jsutils/suggestionList.js +109 -0
- package/lib/jsutils/suggestionList.mjs +86 -0
- package/lib/jsutils/toObjMap.d.ts +4 -0
- package/lib/jsutils/toObjMap.d.ts.map +1 -0
- package/lib/jsutils/toObjMap.js +20 -0
- package/lib/jsutils/toObjMap.mjs +13 -0
- package/lib/transforms/annotateDocumentGraphQLTransform.d.ts +3 -0
- package/lib/transforms/annotateDocumentGraphQLTransform.d.ts.map +1 -0
- package/lib/transforms/annotateDocumentGraphQLTransform.js +37 -0
- package/lib/transforms/annotateDocumentGraphQLTransform.mjs +16 -0
- package/lib/transforms/transformerTestUtils.d.ts +79 -0
- package/lib/transforms/transformerTestUtils.d.ts.map +1 -0
- package/lib/transforms/transformerTestUtils.js +175 -0
- package/lib/transforms/transformerTestUtils.mjs +154 -0
- package/lib/types.d.ts +74 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +3 -0
- package/lib/types.mjs +0 -0
- package/lib/utilities/typeNameFromAST.d.ts +3 -0
- package/lib/utilities/typeNameFromAST.d.ts.map +1 -0
- package/lib/utilities/typeNameFromAST.js +34 -0
- package/lib/utilities/typeNameFromAST.mjs +11 -0
- package/lib/values.d.ts +64 -0
- package/lib/values.d.ts.map +1 -0
- package/lib/values.js +145 -0
- package/lib/values.mjs +137 -0
- package/package.json +9 -4
- package/CHANGELOG.json +0 -65
- package/benchmarks/fixtures/query1.graphql +0 -20
- package/benchmarks/index.ts +0 -68
- package/benchmarks/nice-benchmark.ts +0 -32
- package/benchmarks/swapi-schema/index.ts +0 -13
- package/benchmarks/swapi-schema/models.ts +0 -4
- package/benchmarks/swapi-schema/resolvers.ts +0 -331
- package/benchmarks/swapi-schema/schema.graphql +0 -164
- package/benchmarks/swapi-schema/starwars.json +0 -5991
- package/lib/index.test.mjs +0 -63
- package/lib/src/ast/TypedAST.d.ts.map +0 -1
- package/lib/src/ast/addTypesToRequestDocument.d.ts.map +0 -1
- package/lib/src/index.d.ts +0 -16
- package/lib/src/index.d.ts.map +0 -1
- package/lib/src/index.test.d.ts +0 -2
- package/lib/src/index.test.d.ts.map +0 -1
- package/starwars.json +0 -1
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,137 @@
|
|
|
1
|
+
import {
|
|
2
|
+
GraphQLBoolean,
|
|
3
|
+
GraphQLError,
|
|
4
|
+
GraphQLFloat,
|
|
5
|
+
GraphQLID,
|
|
6
|
+
GraphQLInt,
|
|
7
|
+
GraphQLList,
|
|
8
|
+
GraphQLNonNull,
|
|
9
|
+
GraphQLString,
|
|
10
|
+
isInputType,
|
|
11
|
+
isNonNullType,
|
|
12
|
+
Kind,
|
|
13
|
+
print,
|
|
14
|
+
valueFromAST,
|
|
15
|
+
coerceInputValue
|
|
16
|
+
} from "graphql";
|
|
17
|
+
import {inspect} from "./jsutils/inspect";
|
|
18
|
+
import {keyMap} from "./jsutils/keyMap";
|
|
19
|
+
import {printPathArray} from "./jsutils/printPathArray";
|
|
20
|
+
function getVariableValues(resolvers, varDefNodes, inputs, options) {
|
|
21
|
+
const errors = [];
|
|
22
|
+
const maxErrors = options == null ? void 0 : options.maxErrors;
|
|
23
|
+
try {
|
|
24
|
+
const coerced = coerceVariableValues(resolvers, varDefNodes, inputs, (error) => {
|
|
25
|
+
if (maxErrors != null && errors.length >= maxErrors) {
|
|
26
|
+
throw new GraphQLError("Too many errors processing variables, error limit reached. Execution aborted.");
|
|
27
|
+
}
|
|
28
|
+
errors.push(error);
|
|
29
|
+
});
|
|
30
|
+
if (errors.length === 0) {
|
|
31
|
+
return {coerced};
|
|
32
|
+
}
|
|
33
|
+
} catch (error) {
|
|
34
|
+
errors.push(error);
|
|
35
|
+
}
|
|
36
|
+
return {errors};
|
|
37
|
+
}
|
|
38
|
+
function coerceVariableValues(resolvers, varDefNodes, inputs, onError) {
|
|
39
|
+
const coercedValues = {};
|
|
40
|
+
for (const varDefNode of varDefNodes) {
|
|
41
|
+
const varName = varDefNode.variable.name.value;
|
|
42
|
+
const varTypeAst = varDefNode.type;
|
|
43
|
+
const varType = graphqlTypeFromTypeAst(resolvers, varTypeAst);
|
|
44
|
+
if (!isInputType(varType)) {
|
|
45
|
+
const varTypeStr = inspect(varType);
|
|
46
|
+
onError(new GraphQLError(`Variable "$${varName}" expected value of type "${varTypeStr}" which cannot be used as an input type.`, varDefNode.type));
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
if (!hasOwnProperty(inputs, varName)) {
|
|
50
|
+
if (varDefNode.defaultValue) {
|
|
51
|
+
coercedValues[varName] = valueFromAST(varDefNode.defaultValue, varType);
|
|
52
|
+
} else if (isNonNullType(varType)) {
|
|
53
|
+
const varTypeStr = print(varDefNode.type);
|
|
54
|
+
onError(new GraphQLError(`Variable "$${varName}" of required type "${varTypeStr}" was not provided.`, varDefNode));
|
|
55
|
+
}
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
const value = inputs[varName];
|
|
59
|
+
if (value === null && isNonNullType(varType)) {
|
|
60
|
+
const varTypeStr = inspect(varType);
|
|
61
|
+
onError(new GraphQLError(`Variable "$${varName}" of non-null type "${varTypeStr}" must not be null.`, varDefNode));
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
coercedValues[varName] = coerceInputValue(value, varType, (path, invalidValue, error) => {
|
|
65
|
+
let prefix = `Variable "$${varName}" got invalid value ` + inspect(invalidValue);
|
|
66
|
+
if (path.length > 0) {
|
|
67
|
+
prefix += ` at "${varName}${printPathArray(path)}"`;
|
|
68
|
+
}
|
|
69
|
+
onError(new GraphQLError(prefix + "; " + error.message, varDefNode, void 0, void 0, void 0, error.originalError));
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
return coercedValues;
|
|
73
|
+
}
|
|
74
|
+
function getArgumentValues(resolvers, node, variableValues) {
|
|
75
|
+
var _a;
|
|
76
|
+
const coercedValues = {};
|
|
77
|
+
const argumentNodes = (_a = node.arguments) != null ? _a : [];
|
|
78
|
+
const argNodeMap = keyMap(argumentNodes, (arg) => arg.name.value);
|
|
79
|
+
for (const argumentNode of argumentNodes) {
|
|
80
|
+
const name = argumentNode.name.value;
|
|
81
|
+
const argTypeNode = argumentNode.__type;
|
|
82
|
+
const argType = graphqlTypeFromTypeAst(resolvers, argTypeNode);
|
|
83
|
+
if (!isInputType(argType)) {
|
|
84
|
+
console.log(argType, isInputType(argType));
|
|
85
|
+
throw new GraphQLError(`Argument "$${name}" expected value of type "${inspect(argType)}" which cannot be used as an input type.`, argumentNode);
|
|
86
|
+
}
|
|
87
|
+
let valueNode = argumentNode.value;
|
|
88
|
+
let isNull = valueNode.kind === Kind.NULL;
|
|
89
|
+
if (valueNode.kind === Kind.VARIABLE) {
|
|
90
|
+
const variableName = valueNode.name.value;
|
|
91
|
+
if (variableValues == null || !hasOwnProperty(variableValues, variableName)) {
|
|
92
|
+
if (argumentNode.__defaultValue != void 0) {
|
|
93
|
+
valueNode = argumentNode.__defaultValue;
|
|
94
|
+
} else if (isNonNullType(argType)) {
|
|
95
|
+
throw new GraphQLError(`Argument "${name}" of required type "${inspect(argType)}" was provided the variable "$${variableName}" which was not provided a runtime value.`, valueNode);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
isNull = !variableValues || variableValues[variableName] == null;
|
|
99
|
+
}
|
|
100
|
+
const coercedValue = valueFromAST(valueNode, argType, variableValues);
|
|
101
|
+
if (coercedValue === void 0) {
|
|
102
|
+
throw new GraphQLError(`Argument "${name}" has invalid value ${print(valueNode)}.`, valueNode);
|
|
103
|
+
}
|
|
104
|
+
coercedValues[name] = coercedValue;
|
|
105
|
+
}
|
|
106
|
+
return coercedValues;
|
|
107
|
+
}
|
|
108
|
+
function getDirectiveValues(resolvers, node, variableValues) {
|
|
109
|
+
throw new Error("Todo");
|
|
110
|
+
}
|
|
111
|
+
function hasOwnProperty(obj, prop) {
|
|
112
|
+
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
113
|
+
}
|
|
114
|
+
const specifiedScalars = {
|
|
115
|
+
ID: GraphQLID,
|
|
116
|
+
String: GraphQLString,
|
|
117
|
+
Int: GraphQLInt,
|
|
118
|
+
Float: GraphQLFloat,
|
|
119
|
+
Boolean: GraphQLBoolean
|
|
120
|
+
};
|
|
121
|
+
function graphqlTypeFromTypeAst(resolvers, node) {
|
|
122
|
+
if (node.kind === Kind.NON_NULL_TYPE) {
|
|
123
|
+
return new GraphQLNonNull(graphqlTypeFromTypeAst(resolvers, node.type));
|
|
124
|
+
} else if (node.kind === Kind.LIST_TYPE) {
|
|
125
|
+
return new GraphQLList(graphqlTypeFromTypeAst(resolvers, node.type));
|
|
126
|
+
} else {
|
|
127
|
+
const typeName = node.name.value;
|
|
128
|
+
const type = specifiedScalars[typeName] || resolvers[typeName];
|
|
129
|
+
return type;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
export {
|
|
133
|
+
getArgumentValues,
|
|
134
|
+
getDirectiveValues,
|
|
135
|
+
getVariableValues,
|
|
136
|
+
specifiedScalars
|
|
137
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphitation/supermassive",
|
|
3
3
|
"license": "MIT",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.2.0",
|
|
5
5
|
"main": "./lib/index",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "monorepo-scripts build",
|
|
@@ -9,16 +9,15 @@
|
|
|
9
9
|
"test": "monorepo-scripts test",
|
|
10
10
|
"types": "monorepo-scripts types",
|
|
11
11
|
"just": "monorepo-scripts",
|
|
12
|
-
"benchmark": "ts-node -T -O '{\"module\":\"commonjs\"}' ./benchmarks/index.ts"
|
|
12
|
+
"benchmark": "ts-node -T -O '{\"module\":\"commonjs\"}' ./src/benchmarks/index.ts"
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {
|
|
15
15
|
"@graphitation/graphql-js-tag": "*",
|
|
16
|
-
"@
|
|
16
|
+
"@ts-morph/bootstrap": "^0.11.0",
|
|
17
17
|
"@types/benchmark": "^2.1.0",
|
|
18
18
|
"@types/jest": "^26.0.22",
|
|
19
19
|
"@types/node-json-db": "^0.9.3",
|
|
20
20
|
"benchmark": "^2.1.4",
|
|
21
|
-
"graphql": "^15.0.0",
|
|
22
21
|
"graphql-jit": "^0.5.1",
|
|
23
22
|
"monorepo-scripts": "*",
|
|
24
23
|
"node-json-db": "^1.3.0",
|
|
@@ -27,5 +26,11 @@
|
|
|
27
26
|
"publishConfig": {
|
|
28
27
|
"access": "public"
|
|
29
28
|
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@graphql-tools/schema": "^7.1.5",
|
|
31
|
+
"commander": "^8.3.0",
|
|
32
|
+
"graphql": "^15.6.1",
|
|
33
|
+
"typescript": "4.4.3"
|
|
34
|
+
},
|
|
30
35
|
"types": "./lib/index.d.ts"
|
|
31
36
|
}
|
package/CHANGELOG.json
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@graphitation/supermassive",
|
|
3
|
-
"entries": [
|
|
4
|
-
{
|
|
5
|
-
"date": "Tue, 26 Oct 2021 21:09:16 GMT",
|
|
6
|
-
"tag": "@graphitation/supermassive_v0.1.3",
|
|
7
|
-
"version": "0.1.3",
|
|
8
|
-
"comments": {
|
|
9
|
-
"patch": [
|
|
10
|
-
{
|
|
11
|
-
"comment": "Bump @graphitation/graphql-js-tag to v0.5.5",
|
|
12
|
-
"author": "modevold@microsoft.com",
|
|
13
|
-
"commit": "6fbd717cb21f2e9f49ddca58e0365b5381358b46",
|
|
14
|
-
"package": "@graphitation/supermassive"
|
|
15
|
-
}
|
|
16
|
-
]
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
"date": "Tue, 26 Oct 2021 12:46:12 GMT",
|
|
21
|
-
"tag": "@graphitation/supermassive_v0.1.2",
|
|
22
|
-
"version": "0.1.2",
|
|
23
|
-
"comments": {
|
|
24
|
-
"patch": [
|
|
25
|
-
{
|
|
26
|
-
"comment": "Align graphql dependency to version ^15.0.0 across packages",
|
|
27
|
-
"author": "modevold@microsoft.com",
|
|
28
|
-
"commit": "d8b94fe7725a968abfac81953b97a879b2bdaeb3",
|
|
29
|
-
"package": "@graphitation/supermassive"
|
|
30
|
-
}
|
|
31
|
-
]
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
"date": "Mon, 04 Oct 2021 13:48:04 GMT",
|
|
36
|
-
"tag": "@graphitation/supermassive_v0.1.1",
|
|
37
|
-
"version": "0.1.1",
|
|
38
|
-
"comments": {
|
|
39
|
-
"patch": [
|
|
40
|
-
{
|
|
41
|
-
"comment": "Bump @graphitation/graphql-js-tag to v0.5.4",
|
|
42
|
-
"author": "eloy.de.enige@gmail.com",
|
|
43
|
-
"commit": "ceb24aa25210090e38251be53d010d75abdad9ba",
|
|
44
|
-
"package": "@graphitation/supermassive"
|
|
45
|
-
}
|
|
46
|
-
]
|
|
47
|
-
}
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
"date": "Thu, 24 Jun 2021 12:32:15 GMT",
|
|
51
|
-
"tag": "@graphitation/supermassive_v0.1.0",
|
|
52
|
-
"version": "0.1.0",
|
|
53
|
-
"comments": {
|
|
54
|
-
"none": [
|
|
55
|
-
{
|
|
56
|
-
"comment": "Test and benchmark setup for supermassive",
|
|
57
|
-
"author": "eloy.de.enige@gmail.com",
|
|
58
|
-
"commit": "ebbad29ec11dae814bbe8c2e492d1baf5382c138",
|
|
59
|
-
"package": "@graphitation/supermassive"
|
|
60
|
-
}
|
|
61
|
-
]
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
]
|
|
65
|
-
}
|
package/benchmarks/index.ts
DELETED
|
@@ -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
|
-
});
|