@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
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import ts, {factory} from "typescript";
|
|
2
|
+
import {
|
|
3
|
+
getDirectiveValues,
|
|
4
|
+
GraphQLDeprecatedDirective,
|
|
5
|
+
GraphQLEnumType,
|
|
6
|
+
GraphQLScalarType,
|
|
7
|
+
Kind,
|
|
8
|
+
GraphQLInputObjectType,
|
|
9
|
+
valueFromAST,
|
|
10
|
+
GraphQLNonNull,
|
|
11
|
+
GraphQLList
|
|
12
|
+
} from "graphql";
|
|
13
|
+
const SPECIFIED_SCALARS = {
|
|
14
|
+
ID: "GraphQLID",
|
|
15
|
+
String: "GraphQLString",
|
|
16
|
+
Int: "GraphQLInt",
|
|
17
|
+
Float: "GraphQLFloat",
|
|
18
|
+
Boolean: "GraphQLBoolean"
|
|
19
|
+
};
|
|
20
|
+
function extractImplicitTypesToTypescript(document) {
|
|
21
|
+
const definitions = [];
|
|
22
|
+
const imports = [
|
|
23
|
+
"GraphQLList",
|
|
24
|
+
"GraphQLNonNull",
|
|
25
|
+
"GraphQLID",
|
|
26
|
+
"GraphQLString",
|
|
27
|
+
"GraphQLInt",
|
|
28
|
+
"GraphQLFloat",
|
|
29
|
+
"GraphQLBoolean"
|
|
30
|
+
];
|
|
31
|
+
const identifiers = [];
|
|
32
|
+
for (let astNode of document.definitions) {
|
|
33
|
+
if (astNode.kind === Kind.SCALAR_TYPE_DEFINITION) {
|
|
34
|
+
definitions.push(createScalarType(astNode));
|
|
35
|
+
addToSetArray(imports, "GraphQLScalarType");
|
|
36
|
+
addToSetArray(identifiers, astNode.name.value);
|
|
37
|
+
} else if (astNode.kind === Kind.INPUT_OBJECT_TYPE_DEFINITION) {
|
|
38
|
+
definitions.push(createInputObjectType(astNode));
|
|
39
|
+
addToSetArray(imports, "GraphQLInputObjectType");
|
|
40
|
+
addToSetArray(identifiers, astNode.name.value);
|
|
41
|
+
} else if (astNode.kind === Kind.ENUM_TYPE_DEFINITION) {
|
|
42
|
+
definitions.push(createEnumType(astNode));
|
|
43
|
+
addToSetArray(imports, "GraphQLEnumType");
|
|
44
|
+
addToSetArray(identifiers, astNode.name.value);
|
|
45
|
+
} else if (astNode.kind === Kind.UNION_TYPE_DEFINITION || astNode.kind === Kind.INTERFACE_TYPE_DEFINITION) {
|
|
46
|
+
definitions.push(createAbstractType(astNode));
|
|
47
|
+
addToSetArray(identifiers, astNode.name.value);
|
|
48
|
+
} else if (astNode.kind === Kind.OBJECT_TYPE_DEFINITION) {
|
|
49
|
+
definitions.push(createObjectType(astNode));
|
|
50
|
+
addToSetArray(identifiers, astNode.name.value);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
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"));
|
|
54
|
+
const exportDefinition = factory.createVariableStatement([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createVariableDeclarationList([
|
|
55
|
+
factory.createVariableDeclaration(factory.createIdentifier("resolvers"), void 0, void 0, factory.createObjectLiteralExpression(identifiers.map((def) => factory.createShorthandPropertyAssignment(factory.createIdentifier(def), void 0))))
|
|
56
|
+
], ts.NodeFlags.Const));
|
|
57
|
+
return factory.createSourceFile([importDefinition, ...definitions, exportDefinition], factory.createToken(ts.SyntaxKind.EndOfFileToken), 0);
|
|
58
|
+
}
|
|
59
|
+
function createDeclaration(name, decl) {
|
|
60
|
+
return factory.createVariableStatement(void 0, factory.createVariableDeclarationList([
|
|
61
|
+
factory.createVariableDeclaration(factory.createIdentifier(name), void 0, void 0, decl)
|
|
62
|
+
], ts.NodeFlags.Const));
|
|
63
|
+
}
|
|
64
|
+
function createScalarType(astNode) {
|
|
65
|
+
var _a;
|
|
66
|
+
return createDeclaration(astNode.name.value, factory.createNewExpression(factory.createIdentifier("GraphQLScalarType"), void 0, [
|
|
67
|
+
factory.createObjectLiteralExpression([
|
|
68
|
+
factory.createPropertyAssignment(factory.createIdentifier("name"), factory.createStringLiteral(astNode.name.value)),
|
|
69
|
+
factory.createPropertyAssignment(factory.createIdentifier("description"), factory.createStringLiteral(((_a = astNode.description) == null ? void 0 : _a.value) || ""))
|
|
70
|
+
], true)
|
|
71
|
+
]));
|
|
72
|
+
}
|
|
73
|
+
function createInputObjectType(astNode) {
|
|
74
|
+
var _a;
|
|
75
|
+
return createDeclaration(astNode.name.value, factory.createNewExpression(factory.createIdentifier("GraphQLInputObjectType"), void 0, [
|
|
76
|
+
factory.createObjectLiteralExpression([
|
|
77
|
+
factory.createPropertyAssignment(factory.createIdentifier("name"), factory.createStringLiteral(astNode.name.value)),
|
|
78
|
+
factory.createPropertyAssignment(factory.createIdentifier("description"), factory.createStringLiteral(((_a = astNode.description) == null ? void 0 : _a.value) || "")),
|
|
79
|
+
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))))
|
|
80
|
+
], true)
|
|
81
|
+
]));
|
|
82
|
+
}
|
|
83
|
+
function createInputFields(astNodes) {
|
|
84
|
+
return astNodes.map((astNode) => {
|
|
85
|
+
var _a;
|
|
86
|
+
const fields = [
|
|
87
|
+
factory.createPropertyAssignment(factory.createIdentifier("type"), createType(astNode.type)),
|
|
88
|
+
factory.createPropertyAssignment(factory.createIdentifier("description"), factory.createStringLiteral(((_a = astNode.description) == null ? void 0 : _a.value) || ""))
|
|
89
|
+
];
|
|
90
|
+
if (astNode.defaultValue) {
|
|
91
|
+
fields.push(factory.createPropertyAssignment(factory.createIdentifier("defaultValue"), createValue(astNode.defaultValue)));
|
|
92
|
+
}
|
|
93
|
+
return factory.createPropertyAssignment(factory.createIdentifier(astNode.name.value), factory.createObjectLiteralExpression(fields, true));
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
function createEnumType(astNode) {
|
|
97
|
+
var _a;
|
|
98
|
+
return createDeclaration(astNode.name.value, factory.createNewExpression(factory.createIdentifier("GraphQLEnumType"), void 0, [
|
|
99
|
+
factory.createObjectLiteralExpression([
|
|
100
|
+
factory.createPropertyAssignment(factory.createIdentifier("name"), factory.createStringLiteral(astNode.name.value)),
|
|
101
|
+
factory.createPropertyAssignment(factory.createIdentifier("description"), factory.createStringLiteral(((_a = astNode.description) == null ? void 0 : _a.value) || "")),
|
|
102
|
+
factory.createPropertyAssignment(factory.createIdentifier("values"), factory.createObjectLiteralExpression((astNode.values || []).map((valueNode) => {
|
|
103
|
+
var _a2;
|
|
104
|
+
return factory.createPropertyAssignment(factory.createIdentifier(valueNode.name.value), factory.createObjectLiteralExpression([
|
|
105
|
+
factory.createPropertyAssignment(factory.createIdentifier("description"), factory.createStringLiteral(((_a2 = valueNode.description) == null ? void 0 : _a2.value) || ""))
|
|
106
|
+
]));
|
|
107
|
+
})))
|
|
108
|
+
])
|
|
109
|
+
]));
|
|
110
|
+
}
|
|
111
|
+
function createAbstractType(astNode) {
|
|
112
|
+
return createDeclaration(astNode.name.value, factory.createObjectLiteralExpression([
|
|
113
|
+
factory.createPropertyAssignment(factory.createIdentifier("__resolveType"), factory.createIdentifier("undefined"))
|
|
114
|
+
]));
|
|
115
|
+
}
|
|
116
|
+
function createObjectType(astNode) {
|
|
117
|
+
return createDeclaration(astNode.name.value, factory.createObjectLiteralExpression());
|
|
118
|
+
}
|
|
119
|
+
function createType(astNode) {
|
|
120
|
+
if (astNode.kind === Kind.LIST_TYPE) {
|
|
121
|
+
return factory.createNewExpression(factory.createIdentifier("GraphQLList"), void 0, [createType(astNode.type)]);
|
|
122
|
+
} else if (astNode.kind === Kind.NON_NULL_TYPE) {
|
|
123
|
+
return factory.createNewExpression(factory.createIdentifier("GraphQLNonNull"), void 0, [createType(astNode.type)]);
|
|
124
|
+
} else {
|
|
125
|
+
if (SPECIFIED_SCALARS[astNode.name.value]) {
|
|
126
|
+
return factory.createIdentifier(SPECIFIED_SCALARS[astNode.name.value]);
|
|
127
|
+
} else {
|
|
128
|
+
return factory.createIdentifier(astNode.name.value);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
function createValue(astNode) {
|
|
133
|
+
if (astNode.kind === Kind.INT || astNode.kind === Kind.FLOAT) {
|
|
134
|
+
return factory.createNumericLiteral(astNode.value);
|
|
135
|
+
} else if (astNode.kind === Kind.BOOLEAN) {
|
|
136
|
+
return astNode.value ? factory.createTrue() : factory.createFalse();
|
|
137
|
+
} else if (astNode.kind === Kind.STRING || astNode.kind === Kind.ENUM) {
|
|
138
|
+
return factory.createStringLiteral(astNode.value);
|
|
139
|
+
} else if (astNode.kind === Kind.NULL) {
|
|
140
|
+
return factory.createNull();
|
|
141
|
+
} else if (astNode.kind === Kind.LIST) {
|
|
142
|
+
return factory.createArrayLiteralExpression(astNode.values.map((valueNode) => createValue(valueNode)));
|
|
143
|
+
} else if (astNode.kind === Kind.OBJECT) {
|
|
144
|
+
return factory.createObjectLiteralExpression(astNode.fields.map((fieldNode) => factory.createPropertyAssignment(fieldNode.name.value, createValue(fieldNode.value))));
|
|
145
|
+
} else {
|
|
146
|
+
throw new Error("Invalid value");
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
function addToSetArray(array, item) {
|
|
150
|
+
if (array.indexOf(item) === -1) {
|
|
151
|
+
array.push(item);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
function extractImplicitTypes(document, getTypeByName) {
|
|
155
|
+
var _a;
|
|
156
|
+
const result = Object.create(null);
|
|
157
|
+
for (let astNode of document.definitions) {
|
|
158
|
+
if (astNode.kind === Kind.SCALAR_TYPE_DEFINITION) {
|
|
159
|
+
const name = astNode.name.value;
|
|
160
|
+
result[name] = new GraphQLScalarType({
|
|
161
|
+
name,
|
|
162
|
+
description: (_a = astNode.description) == null ? void 0 : _a.value
|
|
163
|
+
});
|
|
164
|
+
} else if (astNode.kind === Kind.INPUT_OBJECT_TYPE_DEFINITION) {
|
|
165
|
+
result[astNode.name.value] = makeInputObject(astNode, getTypeByName);
|
|
166
|
+
} else if (astNode.kind === Kind.ENUM_TYPE_DEFINITION) {
|
|
167
|
+
result[astNode.name.value] = makeEnum(astNode);
|
|
168
|
+
} else if (astNode.kind === Kind.UNION_TYPE_DEFINITION || astNode.kind === Kind.INTERFACE_TYPE_DEFINITION) {
|
|
169
|
+
result[astNode.name.value] = {__resolveType: void 0};
|
|
170
|
+
} else if (astNode.kind === Kind.OBJECT_TYPE_DEFINITION) {
|
|
171
|
+
result[astNode.name.value] = {};
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return result;
|
|
175
|
+
}
|
|
176
|
+
function makeEnum(astNode) {
|
|
177
|
+
var _a, _b;
|
|
178
|
+
const enumValueMap = Object.create(null);
|
|
179
|
+
for (const value of astNode.values || []) {
|
|
180
|
+
enumValueMap[value.name.value] = {
|
|
181
|
+
description: (_a = value.description) == null ? void 0 : _a.value,
|
|
182
|
+
deprecationReason: getDeprecationReason(value),
|
|
183
|
+
astNode: value
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
return new GraphQLEnumType({
|
|
187
|
+
name: astNode.name.value,
|
|
188
|
+
description: (_b = astNode.description) == null ? void 0 : _b.value,
|
|
189
|
+
values: enumValueMap
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
function makeInputObject(astNode, getTypeByName) {
|
|
193
|
+
var _a;
|
|
194
|
+
const name = astNode.name.value;
|
|
195
|
+
return new GraphQLInputObjectType({
|
|
196
|
+
name,
|
|
197
|
+
description: (_a = astNode.description) == null ? void 0 : _a.value,
|
|
198
|
+
fields: () => buildInputFieldMap(astNode.fields || [], getTypeByName),
|
|
199
|
+
astNode
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
function buildInputFieldMap(fieldNodes, getTypeByName) {
|
|
203
|
+
var _a;
|
|
204
|
+
const inputFieldMap = Object.create(null);
|
|
205
|
+
for (const field of fieldNodes) {
|
|
206
|
+
const type = getWrappedType(field.type, getTypeByName);
|
|
207
|
+
inputFieldMap[field.name.value] = {
|
|
208
|
+
type,
|
|
209
|
+
description: (_a = field.description) == null ? void 0 : _a.value,
|
|
210
|
+
defaultValue: valueFromAST(field.defaultValue, type),
|
|
211
|
+
deprecationReason: getDeprecationReason(field),
|
|
212
|
+
astNode: field
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
return inputFieldMap;
|
|
216
|
+
}
|
|
217
|
+
function getWrappedType(type, getTypeByName) {
|
|
218
|
+
if (type.kind === Kind.LIST_TYPE) {
|
|
219
|
+
return new GraphQLList(getWrappedType(type.type, getTypeByName));
|
|
220
|
+
} else if (type.kind === Kind.NON_NULL_TYPE) {
|
|
221
|
+
return new GraphQLNonNull(getWrappedType(type.type, getTypeByName));
|
|
222
|
+
} else {
|
|
223
|
+
return getTypeByName(type.name.value);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
function getDeprecationReason(node) {
|
|
227
|
+
const deprecated = getDirectiveValues(GraphQLDeprecatedDirective, node);
|
|
228
|
+
return deprecated == null ? void 0 : deprecated.reason;
|
|
229
|
+
}
|
|
230
|
+
export {
|
|
231
|
+
extractImplicitTypes,
|
|
232
|
+
extractImplicitTypesToTypescript
|
|
233
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { DocumentNode, GraphQLInputType } from "graphql";
|
|
2
|
+
import { Resolvers } from "./types";
|
|
3
|
+
export declare function extractImplicitTypes<TSource = any, TContext = any>(document: DocumentNode, getTypeByName: (name: string) => GraphQLInputType): Resolvers<TSource, TContext>;
|
|
4
|
+
//# sourceMappingURL=extractImplicitTypesRuntime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractImplicitTypesRuntime.d.ts","sourceRoot":"","sources":["../src/extractImplicitTypesRuntime.ts"],"names":[],"mappings":"AACA,OAAO,EACL,YAAY,EAcZ,gBAAgB,EAKjB,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEpC,wBAAgB,oBAAoB,CAAC,OAAO,GAAG,GAAG,EAAE,QAAQ,GAAG,GAAG,EAChE,QAAQ,EAAE,YAAY,EACtB,aAAa,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,gBAAgB,GAChD,SAAS,CAAC,OAAO,EAAE,QAAQ,CAAC,CAuB9B"}
|
|
@@ -0,0 +1,103 @@
|
|
|
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
|
+
extractImplicitTypes: () => extractImplicitTypes
|
|
26
|
+
});
|
|
27
|
+
var import_graphql = __toModule(require("graphql"));
|
|
28
|
+
function extractImplicitTypes(document, getTypeByName) {
|
|
29
|
+
var _a;
|
|
30
|
+
const result = Object.create(null);
|
|
31
|
+
for (let astNode of document.definitions) {
|
|
32
|
+
if (astNode.kind === import_graphql.Kind.SCALAR_TYPE_DEFINITION) {
|
|
33
|
+
const name = astNode.name.value;
|
|
34
|
+
result[name] = new import_graphql.GraphQLScalarType({
|
|
35
|
+
name,
|
|
36
|
+
description: (_a = astNode.description) == null ? void 0 : _a.value
|
|
37
|
+
});
|
|
38
|
+
} else if (astNode.kind === import_graphql.Kind.INPUT_OBJECT_TYPE_DEFINITION) {
|
|
39
|
+
result[astNode.name.value] = makeInputObject(astNode, getTypeByName);
|
|
40
|
+
} else if (astNode.kind === import_graphql.Kind.ENUM_TYPE_DEFINITION) {
|
|
41
|
+
result[astNode.name.value] = makeEnum(astNode);
|
|
42
|
+
} else if (astNode.kind === import_graphql.Kind.UNION_TYPE_DEFINITION || astNode.kind === import_graphql.Kind.INTERFACE_TYPE_DEFINITION) {
|
|
43
|
+
result[astNode.name.value] = {__resolveType: void 0};
|
|
44
|
+
} else if (astNode.kind === import_graphql.Kind.OBJECT_TYPE_DEFINITION) {
|
|
45
|
+
result[astNode.name.value] = {};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
function makeEnum(astNode) {
|
|
51
|
+
var _a, _b;
|
|
52
|
+
const enumValueMap = Object.create(null);
|
|
53
|
+
for (const value of astNode.values || []) {
|
|
54
|
+
enumValueMap[value.name.value] = {
|
|
55
|
+
description: (_a = value.description) == null ? void 0 : _a.value,
|
|
56
|
+
deprecationReason: getDeprecationReason(value),
|
|
57
|
+
astNode: value
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
return new import_graphql.GraphQLEnumType({
|
|
61
|
+
name: astNode.name.value,
|
|
62
|
+
description: (_b = astNode.description) == null ? void 0 : _b.value,
|
|
63
|
+
values: enumValueMap
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
function makeInputObject(astNode, getTypeByName) {
|
|
67
|
+
var _a;
|
|
68
|
+
const name = astNode.name.value;
|
|
69
|
+
return new import_graphql.GraphQLInputObjectType({
|
|
70
|
+
name,
|
|
71
|
+
description: (_a = astNode.description) == null ? void 0 : _a.value,
|
|
72
|
+
fields: () => buildInputFieldMap(astNode.fields || [], getTypeByName),
|
|
73
|
+
astNode
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
function buildInputFieldMap(fieldNodes, getTypeByName) {
|
|
77
|
+
var _a;
|
|
78
|
+
const inputFieldMap = Object.create(null);
|
|
79
|
+
for (const field of fieldNodes) {
|
|
80
|
+
const type = getWrappedType(field.type, getTypeByName);
|
|
81
|
+
inputFieldMap[field.name.value] = {
|
|
82
|
+
type,
|
|
83
|
+
description: (_a = field.description) == null ? void 0 : _a.value,
|
|
84
|
+
defaultValue: (0, import_graphql.valueFromAST)(field.defaultValue, type),
|
|
85
|
+
deprecationReason: getDeprecationReason(field),
|
|
86
|
+
astNode: field
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
return inputFieldMap;
|
|
90
|
+
}
|
|
91
|
+
function getWrappedType(type, getTypeByName) {
|
|
92
|
+
if (type.kind === import_graphql.Kind.LIST_TYPE) {
|
|
93
|
+
return new import_graphql.GraphQLList(getWrappedType(type.type, getTypeByName));
|
|
94
|
+
} else if (type.kind === import_graphql.Kind.NON_NULL_TYPE) {
|
|
95
|
+
return new import_graphql.GraphQLNonNull(getWrappedType(type.type, getTypeByName));
|
|
96
|
+
} else {
|
|
97
|
+
return getTypeByName(type.name.value);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function getDeprecationReason(node) {
|
|
101
|
+
const deprecated = (0, import_graphql.getDirectiveValues)(import_graphql.GraphQLDeprecatedDirective, node);
|
|
102
|
+
return deprecated == null ? void 0 : deprecated.reason;
|
|
103
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getDirectiveValues,
|
|
3
|
+
GraphQLDeprecatedDirective,
|
|
4
|
+
GraphQLEnumType,
|
|
5
|
+
GraphQLScalarType,
|
|
6
|
+
Kind,
|
|
7
|
+
GraphQLInputObjectType,
|
|
8
|
+
valueFromAST,
|
|
9
|
+
GraphQLNonNull,
|
|
10
|
+
GraphQLList
|
|
11
|
+
} from "graphql";
|
|
12
|
+
function extractImplicitTypes(document, getTypeByName) {
|
|
13
|
+
var _a;
|
|
14
|
+
const result = Object.create(null);
|
|
15
|
+
for (let astNode of document.definitions) {
|
|
16
|
+
if (astNode.kind === Kind.SCALAR_TYPE_DEFINITION) {
|
|
17
|
+
const name = astNode.name.value;
|
|
18
|
+
result[name] = new GraphQLScalarType({
|
|
19
|
+
name,
|
|
20
|
+
description: (_a = astNode.description) == null ? void 0 : _a.value
|
|
21
|
+
});
|
|
22
|
+
} else if (astNode.kind === Kind.INPUT_OBJECT_TYPE_DEFINITION) {
|
|
23
|
+
result[astNode.name.value] = makeInputObject(astNode, getTypeByName);
|
|
24
|
+
} else if (astNode.kind === Kind.ENUM_TYPE_DEFINITION) {
|
|
25
|
+
result[astNode.name.value] = makeEnum(astNode);
|
|
26
|
+
} else if (astNode.kind === Kind.UNION_TYPE_DEFINITION || astNode.kind === Kind.INTERFACE_TYPE_DEFINITION) {
|
|
27
|
+
result[astNode.name.value] = {__resolveType: void 0};
|
|
28
|
+
} else if (astNode.kind === Kind.OBJECT_TYPE_DEFINITION) {
|
|
29
|
+
result[astNode.name.value] = {};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
function makeEnum(astNode) {
|
|
35
|
+
var _a, _b;
|
|
36
|
+
const enumValueMap = Object.create(null);
|
|
37
|
+
for (const value of astNode.values || []) {
|
|
38
|
+
enumValueMap[value.name.value] = {
|
|
39
|
+
description: (_a = value.description) == null ? void 0 : _a.value,
|
|
40
|
+
deprecationReason: getDeprecationReason(value),
|
|
41
|
+
astNode: value
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
return new GraphQLEnumType({
|
|
45
|
+
name: astNode.name.value,
|
|
46
|
+
description: (_b = astNode.description) == null ? void 0 : _b.value,
|
|
47
|
+
values: enumValueMap
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
function makeInputObject(astNode, getTypeByName) {
|
|
51
|
+
var _a;
|
|
52
|
+
const name = astNode.name.value;
|
|
53
|
+
return new GraphQLInputObjectType({
|
|
54
|
+
name,
|
|
55
|
+
description: (_a = astNode.description) == null ? void 0 : _a.value,
|
|
56
|
+
fields: () => buildInputFieldMap(astNode.fields || [], getTypeByName),
|
|
57
|
+
astNode
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
function buildInputFieldMap(fieldNodes, getTypeByName) {
|
|
61
|
+
var _a;
|
|
62
|
+
const inputFieldMap = Object.create(null);
|
|
63
|
+
for (const field of fieldNodes) {
|
|
64
|
+
const type = getWrappedType(field.type, getTypeByName);
|
|
65
|
+
inputFieldMap[field.name.value] = {
|
|
66
|
+
type,
|
|
67
|
+
description: (_a = field.description) == null ? void 0 : _a.value,
|
|
68
|
+
defaultValue: valueFromAST(field.defaultValue, type),
|
|
69
|
+
deprecationReason: getDeprecationReason(field),
|
|
70
|
+
astNode: field
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
return inputFieldMap;
|
|
74
|
+
}
|
|
75
|
+
function getWrappedType(type, getTypeByName) {
|
|
76
|
+
if (type.kind === Kind.LIST_TYPE) {
|
|
77
|
+
return new GraphQLList(getWrappedType(type.type, getTypeByName));
|
|
78
|
+
} else if (type.kind === Kind.NON_NULL_TYPE) {
|
|
79
|
+
return new GraphQLNonNull(getWrappedType(type.type, getTypeByName));
|
|
80
|
+
} else {
|
|
81
|
+
return getTypeByName(type.name.value);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function getDeprecationReason(node) {
|
|
85
|
+
const deprecated = getDirectiveValues(GraphQLDeprecatedDirective, node);
|
|
86
|
+
return deprecated == null ? void 0 : deprecated.reason;
|
|
87
|
+
}
|
|
88
|
+
export {
|
|
89
|
+
extractImplicitTypes
|
|
90
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractImplicitTypesToTypescript.d.ts","sourceRoot":"","sources":["../src/extractImplicitTypesToTypescript.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,MAAM,YAAY,CAAC;AACzC,OAAO,EACL,YAAY,EAYb,MAAM,SAAS,CAAC;AAUjB,wBAAgB,gCAAgC,CAC9C,QAAQ,EAAE,YAAY,GACrB,EAAE,CAAC,UAAU,CAmFf"}
|
|
@@ -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
|
+
}
|