quicktype 18.0.6 → 19.0.4
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/README.md +1 -1
- package/dist/{cli/CompressedJSONFromStream.d.ts → CompressedJSONFromStream.d.ts} +1 -1
- package/dist/{cli/CompressedJSONFromStream.js → CompressedJSONFromStream.js} +2 -2
- package/dist/{cli/GraphQLIntrospection.d.ts → GraphQLIntrospection.d.ts} +0 -0
- package/dist/{cli/GraphQLIntrospection.js → GraphQLIntrospection.js} +1 -1
- package/dist/{cli/TypeSource.d.ts → TypeSource.d.ts} +2 -2
- package/dist/{cli/TypeSource.js → TypeSource.js} +0 -0
- package/dist/{cli/URLGrammar.d.ts → URLGrammar.d.ts} +0 -0
- package/dist/{cli/URLGrammar.js → URLGrammar.js} +1 -1
- package/dist/{cli/index.d.ts → index.d.ts} +1 -1
- package/dist/{cli/index.js → index.js} +4 -5
- package/package.json +61 -77
- package/dist/quicktype-core/Annotation.d.ts +0 -8
- package/dist/quicktype-core/Annotation.js +0 -16
- package/dist/quicktype-core/ConvenienceRenderer.d.ts +0 -138
- package/dist/quicktype-core/ConvenienceRenderer.js +0 -668
- package/dist/quicktype-core/DateTime.d.ts +0 -10
- package/dist/quicktype-core/DateTime.js +0 -57
- package/dist/quicktype-core/DeclarationIR.d.ts +0 -14
- package/dist/quicktype-core/DeclarationIR.js +0 -167
- package/dist/quicktype-core/EncodedMarkovChain.d.ts +0 -1
- package/dist/quicktype-core/EncodedMarkovChain.js +0 -4
- package/dist/quicktype-core/GatherNames.d.ts +0 -2
- package/dist/quicktype-core/GatherNames.js +0 -333
- package/dist/quicktype-core/Graph.d.ts +0 -12
- package/dist/quicktype-core/Graph.js +0 -220
- package/dist/quicktype-core/GraphRewriting.d.ts +0 -87
- package/dist/quicktype-core/GraphRewriting.js +0 -421
- package/dist/quicktype-core/MakeTransformations.d.ts +0 -4
- package/dist/quicktype-core/MakeTransformations.js +0 -193
- package/dist/quicktype-core/MarkovChain.d.ts +0 -15
- package/dist/quicktype-core/MarkovChain.js +0 -154
- package/dist/quicktype-core/Messages.d.ts +0 -294
- package/dist/quicktype-core/Messages.js +0 -105
- package/dist/quicktype-core/Naming.d.ts +0 -64
- package/dist/quicktype-core/Naming.js +0 -356
- package/dist/quicktype-core/Renderer.d.ts +0 -50
- package/dist/quicktype-core/Renderer.js +0 -274
- package/dist/quicktype-core/RendererOptions.d.ts +0 -71
- package/dist/quicktype-core/RendererOptions.js +0 -141
- package/dist/quicktype-core/Run.d.ts +0 -174
- package/dist/quicktype-core/Run.js +0 -393
- package/dist/quicktype-core/Source.d.ts +0 -65
- package/dist/quicktype-core/Source.js +0 -204
- package/dist/quicktype-core/TargetLanguage.d.ts +0 -34
- package/dist/quicktype-core/TargetLanguage.js +0 -66
- package/dist/quicktype-core/Transformers.d.ts +0 -209
- package/dist/quicktype-core/Transformers.js +0 -836
- package/dist/quicktype-core/Type.d.ts +0 -206
- package/dist/quicktype-core/Type.js +0 -716
- package/dist/quicktype-core/TypeBuilder.d.ts +0 -61
- package/dist/quicktype-core/TypeBuilder.js +0 -324
- package/dist/quicktype-core/TypeGraph.d.ts +0 -75
- package/dist/quicktype-core/TypeGraph.js +0 -420
- package/dist/quicktype-core/TypeUtils.d.ts +0 -33
- package/dist/quicktype-core/TypeUtils.js +0 -230
- package/dist/quicktype-core/UnifyClasses.d.ts +0 -16
- package/dist/quicktype-core/UnifyClasses.js +0 -159
- package/dist/quicktype-core/UnionBuilder.d.ts +0 -49
- package/dist/quicktype-core/UnionBuilder.js +0 -282
- package/dist/quicktype-core/attributes/AccessorNames.d.ts +0 -18
- package/dist/quicktype-core/attributes/AccessorNames.js +0 -182
- package/dist/quicktype-core/attributes/Constraints.d.ts +0 -38
- package/dist/quicktype-core/attributes/Constraints.js +0 -172
- package/dist/quicktype-core/attributes/Description.d.ts +0 -9
- package/dist/quicktype-core/attributes/Description.js +0 -97
- package/dist/quicktype-core/attributes/EnumValues.d.ts +0 -8
- package/dist/quicktype-core/attributes/EnumValues.js +0 -31
- package/dist/quicktype-core/attributes/StringTypes.d.ts +0 -28
- package/dist/quicktype-core/attributes/StringTypes.js +0 -189
- package/dist/quicktype-core/attributes/TypeAttributes.d.ts +0 -34
- package/dist/quicktype-core/attributes/TypeAttributes.js +0 -119
- package/dist/quicktype-core/attributes/TypeNames.d.ts +0 -46
- package/dist/quicktype-core/attributes/TypeNames.js +0 -274
- package/dist/quicktype-core/attributes/URIAttributes.d.ts +0 -8
- package/dist/quicktype-core/attributes/URIAttributes.js +0 -85
- package/dist/quicktype-core/index.d.ts +0 -48
- package/dist/quicktype-core/index.js +0 -180
- package/dist/quicktype-core/input/CompressedJSON.d.ts +0 -69
- package/dist/quicktype-core/input/CompressedJSON.js +0 -276
- package/dist/quicktype-core/input/FetchingJSONSchemaStore.d.ts +0 -6
- package/dist/quicktype-core/input/FetchingJSONSchemaStore.js +0 -18
- package/dist/quicktype-core/input/Inference.d.ts +0 -22
- package/dist/quicktype-core/input/Inference.js +0 -240
- package/dist/quicktype-core/input/Inputs.d.ts +0 -48
- package/dist/quicktype-core/input/Inputs.js +0 -145
- package/dist/quicktype-core/input/JSONSchemaInput.d.ts +0 -91
- package/dist/quicktype-core/input/JSONSchemaInput.js +0 -1041
- package/dist/quicktype-core/input/JSONSchemaStore.d.ts +0 -8
- package/dist/quicktype-core/input/JSONSchemaStore.js +0 -36
- package/dist/quicktype-core/input/PostmanCollection.d.ts +0 -5
- package/dist/quicktype-core/input/PostmanCollection.js +0 -60
- package/dist/quicktype-core/input/io/NodeIO.d.ts +0 -3
- package/dist/quicktype-core/input/io/NodeIO.js +0 -87
- package/dist/quicktype-core/input/io/get-stream/buffer-stream.d.ts +0 -2
- package/dist/quicktype-core/input/io/get-stream/buffer-stream.js +0 -45
- package/dist/quicktype-core/input/io/get-stream/index.d.ts +0 -9
- package/dist/quicktype-core/input/io/get-stream/index.js +0 -52
- package/dist/quicktype-core/language/All.d.ts +0 -3
- package/dist/quicktype-core/language/All.js +0 -57
- package/dist/quicktype-core/language/CPlusPlus.d.ts +0 -241
- package/dist/quicktype-core/language/CPlusPlus.js +0 -1847
- package/dist/quicktype-core/language/CSharp.d.ts +0 -201
- package/dist/quicktype-core/language/CSharp.js +0 -1850
- package/dist/quicktype-core/language/Crystal.d.ts +0 -37
- package/dist/quicktype-core/language/Crystal.js +0 -337
- package/dist/quicktype-core/language/Dart.d.ts +0 -66
- package/dist/quicktype-core/language/Dart.js +0 -576
- package/dist/quicktype-core/language/Elm.d.ts +0 -58
- package/dist/quicktype-core/language/Elm.js +0 -522
- package/dist/quicktype-core/language/Golang.d.ts +0 -51
- package/dist/quicktype-core/language/Golang.js +0 -460
- package/dist/quicktype-core/language/Haskell.d.ts +0 -56
- package/dist/quicktype-core/language/Haskell.js +0 -411
- package/dist/quicktype-core/language/JSONSchema.d.ts +0 -31
- package/dist/quicktype-core/language/JSONSchema.js +0 -169
- package/dist/quicktype-core/language/Java.d.ts +0 -125
- package/dist/quicktype-core/language/Java.js +0 -1081
- package/dist/quicktype-core/language/JavaScript.d.ts +0 -68
- package/dist/quicktype-core/language/JavaScript.js +0 -435
- package/dist/quicktype-core/language/JavaScriptPropTypes.d.ts +0 -40
- package/dist/quicktype-core/language/JavaScriptPropTypes.js +0 -213
- package/dist/quicktype-core/language/JavaScriptUnicodeMaps.d.ts +0 -2
- package/dist/quicktype-core/language/JavaScriptUnicodeMaps.js +0 -134
- package/dist/quicktype-core/language/Kotlin.d.ts +0 -109
- package/dist/quicktype-core/language/Kotlin.js +0 -832
- package/dist/quicktype-core/language/Objective-C.d.ts +0 -79
- package/dist/quicktype-core/language/Objective-C.js +0 -777
- package/dist/quicktype-core/language/Php.d.ts +0 -80
- package/dist/quicktype-core/language/Php.js +0 -702
- package/dist/quicktype-core/language/Pike.d.ts +0 -37
- package/dist/quicktype-core/language/Pike.js +0 -276
- package/dist/quicktype-core/language/Python.d.ts +0 -107
- package/dist/quicktype-core/language/Python.js +0 -969
- package/dist/quicktype-core/language/Rust.d.ts +0 -56
- package/dist/quicktype-core/language/Rust.js +0 -309
- package/dist/quicktype-core/language/Swift.d.ts +0 -96
- package/dist/quicktype-core/language/Swift.js +0 -1211
- package/dist/quicktype-core/language/TypeScriptFlow.d.ts +0 -77
- package/dist/quicktype-core/language/TypeScriptFlow.js +0 -286
- package/dist/quicktype-core/language/ruby/index.d.ts +0 -52
- package/dist/quicktype-core/language/ruby/index.js +0 -557
- package/dist/quicktype-core/language/ruby/keywords.d.ts +0 -3
- package/dist/quicktype-core/language/ruby/keywords.js +0 -358
- package/dist/quicktype-core/rewrites/CombineClasses.d.ts +0 -3
- package/dist/quicktype-core/rewrites/CombineClasses.js +0 -125
- package/dist/quicktype-core/rewrites/ExpandStrings.d.ts +0 -4
- package/dist/quicktype-core/rewrites/ExpandStrings.js +0 -143
- package/dist/quicktype-core/rewrites/FlattenStrings.d.ts +0 -3
- package/dist/quicktype-core/rewrites/FlattenStrings.js +0 -45
- package/dist/quicktype-core/rewrites/FlattenUnions.d.ts +0 -3
- package/dist/quicktype-core/rewrites/FlattenUnions.js +0 -47
- package/dist/quicktype-core/rewrites/InferMaps.d.ts +0 -3
- package/dist/quicktype-core/rewrites/InferMaps.js +0 -117
- package/dist/quicktype-core/rewrites/ReplaceObjectType.d.ts +0 -3
- package/dist/quicktype-core/rewrites/ReplaceObjectType.js +0 -60
- package/dist/quicktype-core/rewrites/ResolveIntersections.d.ts +0 -3
- package/dist/quicktype-core/rewrites/ResolveIntersections.js +0 -244
- package/dist/quicktype-core/support/Acronyms.d.ts +0 -10
- package/dist/quicktype-core/support/Acronyms.js +0 -1128
- package/dist/quicktype-core/support/Chance.d.ts +0 -38
- package/dist/quicktype-core/support/Chance.js +0 -2146
- package/dist/quicktype-core/support/Converters.d.ts +0 -6
- package/dist/quicktype-core/support/Converters.js +0 -16
- package/dist/quicktype-core/support/Strings.d.ts +0 -44
- package/dist/quicktype-core/support/Strings.js +0 -525
- package/dist/quicktype-core/support/Support.d.ts +0 -29
- package/dist/quicktype-core/support/Support.js +0 -162
- package/dist/quicktype-graphql-input/GraphQLSchema.d.ts +0 -645
- package/dist/quicktype-graphql-input/GraphQLSchema.js +0 -39
- package/dist/quicktype-graphql-input/index.d.ts +0 -17
- package/dist/quicktype-graphql-input/index.js +0 -407
- package/dist/quicktype-typescript-input/index.d.ts +0 -2
- package/dist/quicktype-typescript-input/index.js +0 -98
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { TypeBuilder, Input, RunContext } from "../quicktype-core";
|
|
2
|
-
export type GraphQLSourceData = {
|
|
3
|
-
name: string;
|
|
4
|
-
schema: any;
|
|
5
|
-
query: string;
|
|
6
|
-
};
|
|
7
|
-
export declare class GraphQLInput implements Input<GraphQLSourceData> {
|
|
8
|
-
readonly kind: string;
|
|
9
|
-
readonly needIR: boolean;
|
|
10
|
-
readonly needSchemaProcessing: boolean;
|
|
11
|
-
private readonly _topLevels;
|
|
12
|
-
addSource(source: GraphQLSourceData): Promise<void>;
|
|
13
|
-
addSourceSync(source: GraphQLSourceData): void;
|
|
14
|
-
singleStringSchemaSource(): undefined;
|
|
15
|
-
addTypes(ctx: RunContext, typeBuilder: TypeBuilder): Promise<void>;
|
|
16
|
-
addTypesSync(_ctx: RunContext, typeBuilder: TypeBuilder): void;
|
|
17
|
-
}
|
|
@@ -1,407 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/* tslint:disable:strict-boolean-expressions */
|
|
3
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
-
if (k2 === undefined) k2 = k;
|
|
5
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
-
}
|
|
9
|
-
Object.defineProperty(o, k2, desc);
|
|
10
|
-
}) : (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k;
|
|
12
|
-
o[k2] = m[k];
|
|
13
|
-
}));
|
|
14
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
-
}) : function(o, v) {
|
|
17
|
-
o["default"] = v;
|
|
18
|
-
});
|
|
19
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
20
|
-
if (mod && mod.__esModule) return mod;
|
|
21
|
-
var result = {};
|
|
22
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
23
|
-
__setModuleDefault(result, mod);
|
|
24
|
-
return result;
|
|
25
|
-
};
|
|
26
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
-
exports.GraphQLInput = void 0;
|
|
28
|
-
const graphql = __importStar(require("graphql/language"));
|
|
29
|
-
const collection_utils_1 = require("collection-utils");
|
|
30
|
-
const quicktype_core_1 = require("../quicktype-core");
|
|
31
|
-
const GraphQLSchema_1 = require("./GraphQLSchema");
|
|
32
|
-
function getField(t, name) {
|
|
33
|
-
if (!t.fields)
|
|
34
|
-
return (0, quicktype_core_1.panic)(`Required field ${name} in type ${t.name} which doesn't have fields.`);
|
|
35
|
-
for (const f of t.fields) {
|
|
36
|
-
if (f.name === name) {
|
|
37
|
-
return f;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return (0, quicktype_core_1.panic)(`Required field ${name} not defined on type ${t.name}.`);
|
|
41
|
-
}
|
|
42
|
-
function makeNames(name, fieldName, containingTypeName) {
|
|
43
|
-
const alternatives = [];
|
|
44
|
-
if (fieldName)
|
|
45
|
-
alternatives.push(fieldName);
|
|
46
|
-
if (containingTypeName)
|
|
47
|
-
alternatives.push(`${containingTypeName}_${name}`);
|
|
48
|
-
if (fieldName && containingTypeName)
|
|
49
|
-
alternatives.push(`${containingTypeName}_${fieldName}`);
|
|
50
|
-
return quicktype_core_1.namesTypeAttributeKind.makeAttributes(quicktype_core_1.TypeNames.make(new Set([name]), new Set(alternatives), false));
|
|
51
|
-
}
|
|
52
|
-
function makeNullable(builder, tref, name, fieldName, containingTypeName) {
|
|
53
|
-
const typeNames = makeNames(name, fieldName, containingTypeName);
|
|
54
|
-
const t = (0, quicktype_core_1.derefTypeRef)(tref, builder.typeGraph);
|
|
55
|
-
if (!(t instanceof quicktype_core_1.UnionType)) {
|
|
56
|
-
return builder.getUnionType(typeNames, new Set([tref, builder.getPrimitiveType("null")]));
|
|
57
|
-
}
|
|
58
|
-
const [maybeNull, nonNulls] = (0, quicktype_core_1.removeNullFromUnion)(t);
|
|
59
|
-
if (maybeNull)
|
|
60
|
-
return tref;
|
|
61
|
-
return builder.getUnionType(typeNames, (0, collection_utils_1.setMap)(nonNulls, nn => nn.typeRef).add(builder.getPrimitiveType("null")));
|
|
62
|
-
}
|
|
63
|
-
// This is really not the way to do this, but it's easy and works. By default
|
|
64
|
-
// all types in GraphQL are nullable, and non-nullability must be specially marked,
|
|
65
|
-
// so we just construct a nullable type first, and then remove the null from the
|
|
66
|
-
// union if the type is modified to be non-nullable. That means that the union
|
|
67
|
-
// (and the null) might be left unreachable in the graph. Provenance checking
|
|
68
|
-
// won't work in this case, which is why it's disabled in testing for GraphQL.
|
|
69
|
-
function removeNull(builder, tref) {
|
|
70
|
-
const t = (0, quicktype_core_1.derefTypeRef)(tref, builder.typeGraph);
|
|
71
|
-
if (!(t instanceof quicktype_core_1.UnionType)) {
|
|
72
|
-
return tref;
|
|
73
|
-
}
|
|
74
|
-
const nonNulls = (0, quicktype_core_1.removeNullFromUnion)(t)[1];
|
|
75
|
-
const first = (0, collection_utils_1.iterableFirst)(nonNulls);
|
|
76
|
-
if (first) {
|
|
77
|
-
if (nonNulls.size === 1)
|
|
78
|
-
return first.typeRef;
|
|
79
|
-
return builder.getUnionType(t.getAttributes(), (0, collection_utils_1.setMap)(nonNulls, nn => nn.typeRef));
|
|
80
|
-
}
|
|
81
|
-
return (0, quicktype_core_1.panic)("Trying to remove null results in empty union.");
|
|
82
|
-
}
|
|
83
|
-
function makeScalar(builder, ft) {
|
|
84
|
-
switch (ft.name) {
|
|
85
|
-
case "Boolean":
|
|
86
|
-
return builder.getPrimitiveType("bool");
|
|
87
|
-
case "Int":
|
|
88
|
-
return builder.getPrimitiveType("integer");
|
|
89
|
-
case "Float":
|
|
90
|
-
return builder.getPrimitiveType("double");
|
|
91
|
-
default:
|
|
92
|
-
// FIXME: support ID specifically?
|
|
93
|
-
return builder.getStringType(quicktype_core_1.emptyTypeAttributes, quicktype_core_1.StringTypes.unrestricted);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
function hasOptionalDirectives(directives) {
|
|
97
|
-
if (!directives)
|
|
98
|
-
return false;
|
|
99
|
-
for (const d of directives) {
|
|
100
|
-
const name = d.name.value;
|
|
101
|
-
if (name === "include" || name === "skip")
|
|
102
|
-
return true;
|
|
103
|
-
}
|
|
104
|
-
return false;
|
|
105
|
-
}
|
|
106
|
-
function expandSelectionSet(selectionSet, inType, optional) {
|
|
107
|
-
return selectionSet.selections
|
|
108
|
-
.reverse()
|
|
109
|
-
.map(s => ({ selection: s, inType, optional: optional || hasOptionalDirectives(s.directives) }));
|
|
110
|
-
}
|
|
111
|
-
class GQLQuery {
|
|
112
|
-
_schema;
|
|
113
|
-
_fragments;
|
|
114
|
-
queries;
|
|
115
|
-
constructor(schema, queryString) {
|
|
116
|
-
this._schema = schema;
|
|
117
|
-
this._fragments = {};
|
|
118
|
-
const queryDocument = graphql.parse(queryString);
|
|
119
|
-
const queries = [];
|
|
120
|
-
for (const def of queryDocument.definitions) {
|
|
121
|
-
if (def.kind === "OperationDefinition") {
|
|
122
|
-
if (def.operation === "query" || def.operation === "mutation") {
|
|
123
|
-
queries.push(def);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
else if (def.kind === "FragmentDefinition") {
|
|
127
|
-
this._fragments[def.name.value] = def;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
(0, quicktype_core_1.messageAssert)(queries.length >= 1, "GraphQLNoQueriesDefined", {});
|
|
131
|
-
this.queries = queries;
|
|
132
|
-
}
|
|
133
|
-
makeIRTypeFromFieldNode = (builder, fieldNode, fieldType, containingTypeName) => {
|
|
134
|
-
let optional = hasOptionalDirectives(fieldNode.directives);
|
|
135
|
-
let result;
|
|
136
|
-
switch (fieldType.kind) {
|
|
137
|
-
case GraphQLSchema_1.TypeKind.SCALAR:
|
|
138
|
-
result = makeScalar(builder, fieldType);
|
|
139
|
-
optional = true;
|
|
140
|
-
break;
|
|
141
|
-
case GraphQLSchema_1.TypeKind.OBJECT:
|
|
142
|
-
case GraphQLSchema_1.TypeKind.INTERFACE:
|
|
143
|
-
case GraphQLSchema_1.TypeKind.UNION:
|
|
144
|
-
if (!fieldNode.selectionSet) {
|
|
145
|
-
return (0, quicktype_core_1.panic)("No selection set on object or interface");
|
|
146
|
-
}
|
|
147
|
-
return makeNullable(builder, this.makeIRTypeFromSelectionSet(builder, fieldNode.selectionSet, fieldType, fieldNode.name.value, containingTypeName), fieldNode.name.value, null, containingTypeName);
|
|
148
|
-
case GraphQLSchema_1.TypeKind.ENUM:
|
|
149
|
-
if (!fieldType.enumValues) {
|
|
150
|
-
return (0, quicktype_core_1.panic)("Enum type doesn't have values");
|
|
151
|
-
}
|
|
152
|
-
const values = fieldType.enumValues.map(ev => ev.name);
|
|
153
|
-
let name;
|
|
154
|
-
let fieldName;
|
|
155
|
-
if (fieldType.name) {
|
|
156
|
-
name = fieldType.name;
|
|
157
|
-
fieldName = fieldNode.name.value;
|
|
158
|
-
}
|
|
159
|
-
else {
|
|
160
|
-
name = fieldNode.name.value;
|
|
161
|
-
fieldName = null;
|
|
162
|
-
}
|
|
163
|
-
optional = true;
|
|
164
|
-
result = builder.getEnumType(makeNames(name, fieldName, containingTypeName), new Set(values));
|
|
165
|
-
break;
|
|
166
|
-
case GraphQLSchema_1.TypeKind.INPUT_OBJECT:
|
|
167
|
-
// FIXME: Support input objects
|
|
168
|
-
return (0, quicktype_core_1.panic)("Input objects not supported");
|
|
169
|
-
case GraphQLSchema_1.TypeKind.LIST:
|
|
170
|
-
if (!fieldType.ofType) {
|
|
171
|
-
return (0, quicktype_core_1.panic)("No type for list");
|
|
172
|
-
}
|
|
173
|
-
result = builder.getArrayType(quicktype_core_1.emptyTypeAttributes, this.makeIRTypeFromFieldNode(builder, fieldNode, fieldType.ofType, containingTypeName));
|
|
174
|
-
break;
|
|
175
|
-
case GraphQLSchema_1.TypeKind.NON_NULL:
|
|
176
|
-
if (!fieldType.ofType) {
|
|
177
|
-
return (0, quicktype_core_1.panic)("No type for non-null");
|
|
178
|
-
}
|
|
179
|
-
result = removeNull(builder, this.makeIRTypeFromFieldNode(builder, fieldNode, fieldType.ofType, containingTypeName));
|
|
180
|
-
break;
|
|
181
|
-
default:
|
|
182
|
-
return (0, quicktype_core_1.assertNever)(fieldType.kind);
|
|
183
|
-
}
|
|
184
|
-
if (optional) {
|
|
185
|
-
result = makeNullable(builder, result, fieldNode.name.value, null, containingTypeName);
|
|
186
|
-
}
|
|
187
|
-
return result;
|
|
188
|
-
};
|
|
189
|
-
getFragment = (name) => {
|
|
190
|
-
const fragment = this._fragments[name];
|
|
191
|
-
if (!fragment)
|
|
192
|
-
return (0, quicktype_core_1.panic)(`Fragment ${name} is not defined.`);
|
|
193
|
-
return fragment;
|
|
194
|
-
};
|
|
195
|
-
makeIRTypeFromSelectionSet = (builder, selectionSet, gqlType, containingFieldName, containingTypeName, overrideName) => {
|
|
196
|
-
if (gqlType.kind !== GraphQLSchema_1.TypeKind.OBJECT &&
|
|
197
|
-
gqlType.kind !== GraphQLSchema_1.TypeKind.INTERFACE &&
|
|
198
|
-
gqlType.kind !== GraphQLSchema_1.TypeKind.UNION) {
|
|
199
|
-
return (0, quicktype_core_1.panic)("Type for selection set is not object, interface, or union.");
|
|
200
|
-
}
|
|
201
|
-
if (!gqlType.name) {
|
|
202
|
-
return (0, quicktype_core_1.panic)("Object, interface, or union type doesn't have a name.");
|
|
203
|
-
}
|
|
204
|
-
const nameOrOverride = overrideName || gqlType.name;
|
|
205
|
-
const properties = new Map();
|
|
206
|
-
let selections = expandSelectionSet(selectionSet, gqlType, false);
|
|
207
|
-
for (;;) {
|
|
208
|
-
const nextItem = selections.pop();
|
|
209
|
-
if (!nextItem)
|
|
210
|
-
break;
|
|
211
|
-
const { selection, optional, inType } = nextItem;
|
|
212
|
-
switch (selection.kind) {
|
|
213
|
-
case "Field":
|
|
214
|
-
const fieldName = selection.name.value;
|
|
215
|
-
const givenName = selection.alias ? selection.alias.value : fieldName;
|
|
216
|
-
const field = getField(inType, fieldName);
|
|
217
|
-
let fieldType = this.makeIRTypeFromFieldNode(builder, selection, field.type, nameOrOverride);
|
|
218
|
-
properties.set(givenName, builder.makeClassProperty(fieldType, optional));
|
|
219
|
-
break;
|
|
220
|
-
case "FragmentSpread": {
|
|
221
|
-
const fragment = this.getFragment(selection.name.value);
|
|
222
|
-
const fragmentType = this._schema.types[fragment.typeCondition.name.value];
|
|
223
|
-
const fragmentOptional = optional || fragmentType.name !== inType.name;
|
|
224
|
-
const expanded = expandSelectionSet(fragment.selectionSet, fragmentType, fragmentOptional);
|
|
225
|
-
selections = selections.concat(expanded);
|
|
226
|
-
break;
|
|
227
|
-
}
|
|
228
|
-
case "InlineFragment": {
|
|
229
|
-
// FIXME: support type conditions with discriminated unions
|
|
230
|
-
const fragmentType = selection.typeCondition
|
|
231
|
-
? this._schema.types[selection.typeCondition.name.value]
|
|
232
|
-
: inType;
|
|
233
|
-
const fragmentOptional = optional || fragmentType.name !== inType.name || hasOptionalDirectives(selection.directives);
|
|
234
|
-
const expanded = expandSelectionSet(selection.selectionSet, fragmentType, fragmentOptional);
|
|
235
|
-
selections = selections.concat(expanded);
|
|
236
|
-
break;
|
|
237
|
-
}
|
|
238
|
-
default:
|
|
239
|
-
(0, quicktype_core_1.assertNever)(selection);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
return builder.getClassType(makeNames(nameOrOverride, containingFieldName, containingTypeName), properties);
|
|
243
|
-
};
|
|
244
|
-
makeType(builder, query, queryName) {
|
|
245
|
-
if (query.operation === "query") {
|
|
246
|
-
return this.makeIRTypeFromSelectionSet(builder, query.selectionSet, this._schema.queryType, null, queryName, "data");
|
|
247
|
-
}
|
|
248
|
-
if (query.operation === "mutation") {
|
|
249
|
-
if (this._schema.mutationType === undefined) {
|
|
250
|
-
return (0, quicktype_core_1.panic)("This GraphQL endpoint has no mutations.");
|
|
251
|
-
}
|
|
252
|
-
return this.makeIRTypeFromSelectionSet(builder, query.selectionSet, this._schema.mutationType, null, queryName, "data");
|
|
253
|
-
}
|
|
254
|
-
return (0, quicktype_core_1.panic)(`Unknown query operation type: "${query.operation}"`);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
class GQLSchemaFromJSON {
|
|
258
|
-
types = {};
|
|
259
|
-
// @ts-ignore: The constructor can return early, but only by throwing.
|
|
260
|
-
queryType;
|
|
261
|
-
// @ts-ignore: The constructor can return early, but only by throwing.
|
|
262
|
-
mutationType;
|
|
263
|
-
constructor(json) {
|
|
264
|
-
const schema = json.data;
|
|
265
|
-
if (schema.__schema.queryType.name === null) {
|
|
266
|
-
return (0, quicktype_core_1.panic)("Query type doesn't have a name.");
|
|
267
|
-
}
|
|
268
|
-
for (const t of schema.__schema.types) {
|
|
269
|
-
if (!t.name)
|
|
270
|
-
return (0, quicktype_core_1.panic)("No top-level type name given");
|
|
271
|
-
this.types[t.name] = { kind: t.kind, name: t.name, description: t.description };
|
|
272
|
-
}
|
|
273
|
-
for (const t of schema.__schema.types) {
|
|
274
|
-
if (!t.name)
|
|
275
|
-
return (0, quicktype_core_1.panic)("This cannot happen");
|
|
276
|
-
const type = this.types[t.name];
|
|
277
|
-
this.addTypeFields(type, t);
|
|
278
|
-
// console.log(`type ${type.name} is ${type.kind}`);
|
|
279
|
-
}
|
|
280
|
-
const queryType = this.types[schema.__schema.queryType.name];
|
|
281
|
-
if (queryType === undefined) {
|
|
282
|
-
return (0, quicktype_core_1.panic)("Query type not found.");
|
|
283
|
-
}
|
|
284
|
-
// console.log(`query type ${queryType.name} is ${queryType.kind}`);
|
|
285
|
-
this.queryType = queryType;
|
|
286
|
-
if (schema.__schema.mutationType === null) {
|
|
287
|
-
return;
|
|
288
|
-
}
|
|
289
|
-
if (schema.__schema.mutationType.name === null) {
|
|
290
|
-
return (0, quicktype_core_1.panic)("Mutation type doesn't have a name.");
|
|
291
|
-
}
|
|
292
|
-
const mutationType = this.types[schema.__schema.mutationType.name];
|
|
293
|
-
if (mutationType === undefined) {
|
|
294
|
-
return (0, quicktype_core_1.panic)("Mutation type not found.");
|
|
295
|
-
}
|
|
296
|
-
this.mutationType = mutationType;
|
|
297
|
-
}
|
|
298
|
-
addTypeFields = (target, source) => {
|
|
299
|
-
if (source.fields) {
|
|
300
|
-
target.fields = source.fields.map(f => {
|
|
301
|
-
return {
|
|
302
|
-
name: f.name,
|
|
303
|
-
description: f.description,
|
|
304
|
-
type: this.makeType(f.type),
|
|
305
|
-
args: f.args.map(this.makeInputValue)
|
|
306
|
-
};
|
|
307
|
-
});
|
|
308
|
-
// console.log(`${target.name} has ${target.fields.length} fields`);
|
|
309
|
-
}
|
|
310
|
-
if (source.interfaces) {
|
|
311
|
-
target.interfaces = source.interfaces.map(this.makeType);
|
|
312
|
-
// console.log(`${target.name} has ${target.interfaces.length} interfaces`);
|
|
313
|
-
}
|
|
314
|
-
if (source.possibleTypes) {
|
|
315
|
-
target.possibleTypes = source.possibleTypes.map(this.makeType);
|
|
316
|
-
// console.log(`${target.name} has ${target.possibleTypes.length} possibleTypes`);
|
|
317
|
-
}
|
|
318
|
-
if (source.inputFields) {
|
|
319
|
-
target.inputFields = source.inputFields.map(this.makeInputValue);
|
|
320
|
-
// console.log(`${target.name} has ${target.inputFields.length} inputFields`);
|
|
321
|
-
}
|
|
322
|
-
if (source.enumValues) {
|
|
323
|
-
target.enumValues = source.enumValues.map(ev => {
|
|
324
|
-
return { name: ev.name, description: ev.description };
|
|
325
|
-
});
|
|
326
|
-
// console.log(`${target.name} has ${target.enumValues.length} enumValues`);
|
|
327
|
-
}
|
|
328
|
-
};
|
|
329
|
-
makeInputValue = (iv) => {
|
|
330
|
-
return {
|
|
331
|
-
name: iv.name,
|
|
332
|
-
description: iv.description,
|
|
333
|
-
type: this.makeType(iv.type),
|
|
334
|
-
defaultValue: iv.defaultValue
|
|
335
|
-
};
|
|
336
|
-
};
|
|
337
|
-
makeType = (t) => {
|
|
338
|
-
if (t.name) {
|
|
339
|
-
const namedType = this.types[t.name];
|
|
340
|
-
if (!namedType)
|
|
341
|
-
return (0, quicktype_core_1.panic)(`Type ${t.name} not found`);
|
|
342
|
-
return namedType;
|
|
343
|
-
}
|
|
344
|
-
if (!t.ofType)
|
|
345
|
-
return (0, quicktype_core_1.panic)(`Type of kind ${t.kind} has neither name nor ofType`);
|
|
346
|
-
const type = {
|
|
347
|
-
kind: t.kind,
|
|
348
|
-
description: t.description,
|
|
349
|
-
ofType: this.makeType(t.ofType)
|
|
350
|
-
};
|
|
351
|
-
this.addTypeFields(type, t);
|
|
352
|
-
return type;
|
|
353
|
-
};
|
|
354
|
-
}
|
|
355
|
-
function makeGraphQLQueryTypes(topLevelName, builder, json, queryString) {
|
|
356
|
-
const schema = new GQLSchemaFromJSON(json);
|
|
357
|
-
const query = new GQLQuery(schema, queryString);
|
|
358
|
-
const types = new Map();
|
|
359
|
-
for (const odn of query.queries) {
|
|
360
|
-
const queryName = odn.name ? odn.name.value : topLevelName;
|
|
361
|
-
if (types.has(queryName)) {
|
|
362
|
-
return (0, quicktype_core_1.panic)(`Duplicate query name ${queryName}`);
|
|
363
|
-
}
|
|
364
|
-
const dataType = query.makeType(builder, odn, queryName);
|
|
365
|
-
const dataOrNullType = builder.getUnionType(quicktype_core_1.emptyTypeAttributes, new Set([dataType, builder.getPrimitiveType("null")]));
|
|
366
|
-
const errorType = builder.getClassType(quicktype_core_1.namesTypeAttributeKind.makeAttributes(quicktype_core_1.TypeNames.make(new Set(["error"]), new Set(["graphQLError"]), false)), (0, collection_utils_1.mapFromObject)({
|
|
367
|
-
message: builder.makeClassProperty(builder.getStringType(quicktype_core_1.emptyTypeAttributes, quicktype_core_1.StringTypes.unrestricted), false)
|
|
368
|
-
}));
|
|
369
|
-
const errorArray = builder.getArrayType(quicktype_core_1.namesTypeAttributeKind.makeAttributes(quicktype_core_1.TypeNames.make(new Set(["errors"]), new Set(["graphQLErrors"]), false)), errorType);
|
|
370
|
-
const t = builder.getClassType((0, quicktype_core_1.makeNamesTypeAttributes)(queryName, false), (0, collection_utils_1.mapFromObject)({
|
|
371
|
-
data: builder.makeClassProperty(dataOrNullType, false),
|
|
372
|
-
errors: builder.makeClassProperty(errorArray, true)
|
|
373
|
-
}));
|
|
374
|
-
types.set(queryName, t);
|
|
375
|
-
}
|
|
376
|
-
return types;
|
|
377
|
-
}
|
|
378
|
-
class GraphQLInput {
|
|
379
|
-
kind = "graphql";
|
|
380
|
-
needIR = true;
|
|
381
|
-
needSchemaProcessing = false;
|
|
382
|
-
_topLevels = new Map();
|
|
383
|
-
async addSource(source) {
|
|
384
|
-
this.addSourceSync(source);
|
|
385
|
-
}
|
|
386
|
-
addSourceSync(source) {
|
|
387
|
-
this._topLevels.set(source.name, {
|
|
388
|
-
schema: source.schema,
|
|
389
|
-
query: source.query
|
|
390
|
-
});
|
|
391
|
-
}
|
|
392
|
-
singleStringSchemaSource() {
|
|
393
|
-
return undefined;
|
|
394
|
-
}
|
|
395
|
-
async addTypes(ctx, typeBuilder) {
|
|
396
|
-
return this.addTypesSync(ctx, typeBuilder);
|
|
397
|
-
}
|
|
398
|
-
addTypesSync(_ctx, typeBuilder) {
|
|
399
|
-
for (const [name, { schema, query }] of this._topLevels) {
|
|
400
|
-
const newTopLevels = makeGraphQLQueryTypes(name, typeBuilder, schema, query);
|
|
401
|
-
for (const [actualName, t] of newTopLevels) {
|
|
402
|
-
typeBuilder.addTopLevel(this._topLevels.size === 1 ? name : actualName, t);
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
exports.GraphQLInput = GraphQLInput;
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.schemaForTypeScriptSources = void 0;
|
|
27
|
-
const ts = __importStar(require("typescript"));
|
|
28
|
-
const typescript_json_schema_1 = require("@mark.probst/typescript-json-schema");
|
|
29
|
-
const quicktype_core_1 = require("../quicktype-core");
|
|
30
|
-
const settings = {
|
|
31
|
-
required: true,
|
|
32
|
-
titles: true,
|
|
33
|
-
topRef: true,
|
|
34
|
-
noExtraProps: true
|
|
35
|
-
};
|
|
36
|
-
const compilerOptions = {
|
|
37
|
-
noEmit: true,
|
|
38
|
-
emitDecoratorMetadata: true,
|
|
39
|
-
experimentalDecorators: true,
|
|
40
|
-
target: ts.ScriptTarget.ES5,
|
|
41
|
-
module: ts.ModuleKind.CommonJS,
|
|
42
|
-
strictNullChecks: true,
|
|
43
|
-
typeRoots: [],
|
|
44
|
-
rootDir: "."
|
|
45
|
-
};
|
|
46
|
-
// FIXME: We're stringifying and then parsing this schema again. Just pass around
|
|
47
|
-
// the schema directly.
|
|
48
|
-
function schemaForTypeScriptSources(sourceFileNames) {
|
|
49
|
-
const program = ts.createProgram(sourceFileNames, compilerOptions);
|
|
50
|
-
const diagnostics = ts.getPreEmitDiagnostics(program);
|
|
51
|
-
const error = diagnostics.find(d => d.category === ts.DiagnosticCategory.Error);
|
|
52
|
-
if (error !== undefined) {
|
|
53
|
-
return (0, quicktype_core_1.messageError)("TypeScriptCompilerError", {
|
|
54
|
-
message: ts.flattenDiagnosticMessageText(error.messageText, "\n")
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
const schema = (0, typescript_json_schema_1.generateSchema)(program, "*", settings);
|
|
58
|
-
const uris = [];
|
|
59
|
-
let topLevelName = undefined;
|
|
60
|
-
if (schema !== null && typeof schema === "object" && typeof schema.definitions === "object") {
|
|
61
|
-
for (const name of Object.getOwnPropertyNames(schema.definitions)) {
|
|
62
|
-
const definition = schema.definitions[name];
|
|
63
|
-
if (definition === null ||
|
|
64
|
-
Array.isArray(definition) ||
|
|
65
|
-
typeof definition !== "object" ||
|
|
66
|
-
typeof definition.description !== "string") {
|
|
67
|
-
continue;
|
|
68
|
-
}
|
|
69
|
-
const description = definition.description;
|
|
70
|
-
const matches = description.match(/#TopLevel/);
|
|
71
|
-
if (matches === null) {
|
|
72
|
-
continue;
|
|
73
|
-
}
|
|
74
|
-
const index = (0, quicktype_core_1.defined)(matches.index);
|
|
75
|
-
definition.description = description.slice(0, index) + description.slice(index + matches[0].length);
|
|
76
|
-
uris.push(`#/definitions/${name}`);
|
|
77
|
-
if (topLevelName === undefined) {
|
|
78
|
-
if (typeof definition.title === "string") {
|
|
79
|
-
topLevelName = definition.title;
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
topLevelName = name;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
topLevelName = "";
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
if (uris.length === 0) {
|
|
91
|
-
uris.push("#/definitions/");
|
|
92
|
-
}
|
|
93
|
-
if (topLevelName === undefined) {
|
|
94
|
-
topLevelName = "";
|
|
95
|
-
}
|
|
96
|
-
return { schema: JSON.stringify(schema), name: topLevelName, uris, isConverted: true };
|
|
97
|
-
}
|
|
98
|
-
exports.schemaForTypeScriptSources = schemaForTypeScriptSources;
|