relay-compiler 0.0.0-main-f0b65f0b → 0.0.0-main-e0026a71
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/cli.js +23 -0
- package/index.js +19 -3
- package/linux-x64/relay +0 -0
- package/macos-x64/relay +0 -0
- package/package.json +2 -24
- package/win-x64/relay.exe +0 -0
- package/bin/RelayCompilerBin.js.flow +0 -168
- package/bin/RelayCompilerMain.js.flow +0 -515
- package/bin/__fixtures__/plugin-module.js.flow +0 -17
- package/bin/relay-compiler +0 -19068
- package/codegen/CodegenDirectory.js.flow +0 -372
- package/codegen/CodegenRunner.js.flow +0 -424
- package/codegen/CodegenTypes.js.flow +0 -28
- package/codegen/CodegenWatcher.js.flow +0 -250
- package/codegen/NormalizationCodeGenerator.js.flow +0 -566
- package/codegen/ReaderCodeGenerator.js.flow +0 -510
- package/codegen/RelayCodeGenerator.js.flow +0 -85
- package/codegen/RelayFileWriter.js.flow +0 -365
- package/codegen/SourceControl.js.flow +0 -58
- package/codegen/compileRelayArtifacts.js.flow +0 -181
- package/codegen/createPrintRequireModuleDependency.js.flow +0 -19
- package/codegen/sortObjectByKey.js.flow +0 -25
- package/codegen/writeRelayGeneratedFile.js.flow +0 -235
- package/core/ASTCache.js.flow +0 -73
- package/core/ASTConvert.js.flow +0 -230
- package/core/CompilerContext.js.flow +0 -189
- package/core/CompilerError.js.flow +0 -255
- package/core/DotGraphQLParser.js.flow +0 -37
- package/core/GraphQLCompilerProfiler.js.flow +0 -341
- package/core/GraphQLDerivedFromMetadata.js.flow +0 -36
- package/core/GraphQLWatchmanClient.js.flow +0 -109
- package/core/IR.js.flow +0 -326
- package/core/IRPrinter.js.flow +0 -472
- package/core/IRTransformer.js.flow +0 -376
- package/core/IRValidator.js.flow +0 -259
- package/core/IRVisitor.js.flow +0 -150
- package/core/JSModuleParser.js.flow +0 -24
- package/core/RelayCompilerScope.js.flow +0 -199
- package/core/RelayFindGraphQLTags.js.flow +0 -118
- package/core/RelayGraphQLEnumsGenerator.js.flow +0 -55
- package/core/RelayIRTransforms.js.flow +0 -138
- package/core/RelayParser.js.flow +0 -1741
- package/core/RelaySourceModuleParser.js.flow +0 -133
- package/core/Schema.js.flow +0 -2035
- package/core/SchemaUtils.js.flow +0 -120
- package/core/filterContextForNode.js.flow +0 -49
- package/core/getFieldDefinition.js.flow +0 -156
- package/core/getIdentifierForArgumentValue.js.flow +0 -49
- package/core/getIdentifierForSelection.js.flow +0 -68
- package/core/getLiteralArgumentValues.js.flow +0 -32
- package/core/getNormalizationOperationName.js.flow +0 -19
- package/core/inferRootArgumentDefinitions.js.flow +0 -322
- package/index.js.flow +0 -198
- package/language/RelayLanguagePluginInterface.js.flow +0 -283
- package/language/javascript/FindGraphQLTags.js.flow +0 -136
- package/language/javascript/RelayFlowBabelFactories.js.flow +0 -176
- package/language/javascript/RelayFlowGenerator.js.flow +0 -1096
- package/language/javascript/RelayFlowTypeTransformers.js.flow +0 -181
- package/language/javascript/RelayLanguagePluginJavaScript.js.flow +0 -33
- package/language/javascript/formatGeneratedModule.js.flow +0 -65
- package/lib/bin/RelayCompilerBin.js +0 -143
- package/lib/bin/RelayCompilerMain.js +0 -488
- package/lib/bin/__fixtures__/plugin-module.js +0 -16
- package/lib/codegen/CodegenDirectory.js +0 -335
- package/lib/codegen/CodegenRunner.js +0 -433
- package/lib/codegen/CodegenTypes.js +0 -11
- package/lib/codegen/CodegenWatcher.js +0 -271
- package/lib/codegen/NormalizationCodeGenerator.js +0 -487
- package/lib/codegen/ReaderCodeGenerator.js +0 -473
- package/lib/codegen/RelayCodeGenerator.js +0 -75
- package/lib/codegen/RelayFileWriter.js +0 -270
- package/lib/codegen/SourceControl.js +0 -60
- package/lib/codegen/compileRelayArtifacts.js +0 -157
- package/lib/codegen/createPrintRequireModuleDependency.js +0 -19
- package/lib/codegen/sortObjectByKey.js +0 -41
- package/lib/codegen/writeRelayGeneratedFile.js +0 -206
- package/lib/core/ASTCache.js +0 -70
- package/lib/core/ASTConvert.js +0 -198
- package/lib/core/CompilerContext.js +0 -165
- package/lib/core/CompilerError.js +0 -252
- package/lib/core/DotGraphQLParser.js +0 -40
- package/lib/core/GraphQLCompilerProfiler.js +0 -299
- package/lib/core/GraphQLDerivedFromMetadata.js +0 -31
- package/lib/core/GraphQLWatchmanClient.js +0 -150
- package/lib/core/IR.js +0 -11
- package/lib/core/IRPrinter.js +0 -388
- package/lib/core/IRTransformer.js +0 -345
- package/lib/core/IRValidator.js +0 -226
- package/lib/core/IRVisitor.js +0 -45
- package/lib/core/JSModuleParser.js +0 -18
- package/lib/core/RelayCompilerScope.js +0 -183
- package/lib/core/RelayFindGraphQLTags.js +0 -79
- package/lib/core/RelayGraphQLEnumsGenerator.js +0 -50
- package/lib/core/RelayIRTransforms.js +0 -109
- package/lib/core/RelayParser.js +0 -1381
- package/lib/core/RelaySourceModuleParser.js +0 -104
- package/lib/core/Schema.js +0 -1877
- package/lib/core/SchemaUtils.js +0 -98
- package/lib/core/filterContextForNode.js +0 -50
- package/lib/core/getFieldDefinition.js +0 -145
- package/lib/core/getIdentifierForArgumentValue.js +0 -54
- package/lib/core/getIdentifierForSelection.js +0 -49
- package/lib/core/getLiteralArgumentValues.js +0 -26
- package/lib/core/getNormalizationOperationName.js +0 -17
- package/lib/core/inferRootArgumentDefinitions.js +0 -351
- package/lib/index.js +0 -178
- package/lib/language/RelayLanguagePluginInterface.js +0 -26
- package/lib/language/javascript/FindGraphQLTags.js +0 -126
- package/lib/language/javascript/RelayFlowBabelFactories.js +0 -160
- package/lib/language/javascript/RelayFlowGenerator.js +0 -856
- package/lib/language/javascript/RelayFlowTypeTransformers.js +0 -119
- package/lib/language/javascript/RelayLanguagePluginJavaScript.js +0 -30
- package/lib/language/javascript/formatGeneratedModule.js +0 -36
- package/lib/reporters/ConsoleReporter.js +0 -61
- package/lib/reporters/MultiReporter.js +0 -45
- package/lib/reporters/Reporter.js +0 -11
- package/lib/runner/Artifacts.js +0 -323
- package/lib/runner/BufferedFilesystem.js +0 -262
- package/lib/runner/GraphQLASTNodeGroup.js +0 -256
- package/lib/runner/GraphQLASTUtils.js +0 -23
- package/lib/runner/GraphQLNodeMap.js +0 -81
- package/lib/runner/Sources.js +0 -271
- package/lib/runner/StrictMap.js +0 -134
- package/lib/runner/compileArtifacts.js +0 -39
- package/lib/runner/extractAST.js +0 -77
- package/lib/runner/getChangedNodeNames.js +0 -82
- package/lib/runner/getSchemaInstance.js +0 -30
- package/lib/runner/types.js +0 -12
- package/lib/test-utils/TestSchema.js +0 -27
- package/lib/test-utils/parseGraphQLText.js +0 -30
- package/lib/transforms/ApplyFragmentArgumentTransform.js +0 -393
- package/lib/transforms/ClientExtensionsTransform.js +0 -221
- package/lib/transforms/ConnectionTransform.js +0 -639
- package/lib/transforms/DeclarativeConnectionMutationTransform.js +0 -218
- package/lib/transforms/DeferStreamTransform.js +0 -246
- package/lib/transforms/DisallowIdAsAlias.js +0 -40
- package/lib/transforms/DisallowTypenameOnRoot.js +0 -53
- package/lib/transforms/FieldHandleTransform.js +0 -79
- package/lib/transforms/FilterCompilerDirectivesTransform.js +0 -29
- package/lib/transforms/FilterDirectivesTransform.js +0 -42
- package/lib/transforms/FlattenTransform.js +0 -306
- package/lib/transforms/GenerateIDFieldTransform.js +0 -135
- package/lib/transforms/GenerateTypeNameTransform.js +0 -149
- package/lib/transforms/InlineDataFragmentTransform.js +0 -100
- package/lib/transforms/InlineFragmentsTransform.js +0 -61
- package/lib/transforms/MaskTransform.js +0 -117
- package/lib/transforms/MatchTransform.js +0 -434
- package/lib/transforms/ReactFlightComponentTransform.js +0 -158
- package/lib/transforms/RefetchableFragmentTransform.js +0 -249
- package/lib/transforms/RelayDirectiveTransform.js +0 -83
- package/lib/transforms/RequiredFieldTransform.js +0 -369
- package/lib/transforms/SkipClientExtensionsTransform.js +0 -46
- package/lib/transforms/SkipHandleFieldTransform.js +0 -45
- package/lib/transforms/SkipRedundantNodesTransform.js +0 -261
- package/lib/transforms/SkipSplitOperationTransform.js +0 -32
- package/lib/transforms/SkipUnreachableNodeTransform.js +0 -158
- package/lib/transforms/SkipUnusedVariablesTransform.js +0 -75
- package/lib/transforms/SplitModuleImportTransform.js +0 -82
- package/lib/transforms/TestOperationTransform.js +0 -144
- package/lib/transforms/TransformUtils.js +0 -21
- package/lib/transforms/ValidateGlobalVariablesTransform.js +0 -92
- package/lib/transforms/ValidateRequiredArgumentsTransform.js +0 -114
- package/lib/transforms/ValidateServerOnlyDirectivesTransform.js +0 -108
- package/lib/transforms/ValidateUnusedVariablesTransform.js +0 -96
- package/lib/transforms/query-generators/FetchableQueryGenerator.js +0 -157
- package/lib/transforms/query-generators/NodeQueryGenerator.js +0 -166
- package/lib/transforms/query-generators/QueryQueryGenerator.js +0 -48
- package/lib/transforms/query-generators/ViewerQueryGenerator.js +0 -77
- package/lib/transforms/query-generators/index.js +0 -60
- package/lib/transforms/query-generators/utils.js +0 -92
- package/lib/util/CodeMarker.js +0 -80
- package/lib/util/DefaultHandleKey.js +0 -15
- package/lib/util/RelayCompilerCache.js +0 -97
- package/lib/util/Rollout.js +0 -40
- package/lib/util/TimeReporter.js +0 -83
- package/lib/util/areEqualArgValues.js +0 -135
- package/lib/util/argumentContainsVariables.js +0 -37
- package/lib/util/dedupeJSONStringify.js +0 -160
- package/lib/util/generateAbstractTypeRefinementKey.js +0 -24
- package/lib/util/getDefinitionNodeHash.js +0 -22
- package/lib/util/getModuleName.js +0 -32
- package/lib/util/joinArgumentDefinitions.js +0 -67
- package/lib/util/md5.js +0 -17
- package/lib/util/murmurHash.js +0 -86
- package/lib/util/nullthrowsOSS.js +0 -23
- package/lib/util/orList.js +0 -36
- package/lib/util/partitionArray.js +0 -35
- package/relay-compiler.js +0 -17
- package/relay-compiler.min.js +0 -22
- package/reporters/ConsoleReporter.js.flow +0 -81
- package/reporters/MultiReporter.js.flow +0 -43
- package/reporters/Reporter.js.flow +0 -19
- package/runner/Artifacts.js.flow +0 -215
- package/runner/BufferedFilesystem.js.flow +0 -194
- package/runner/GraphQLASTNodeGroup.js.flow +0 -174
- package/runner/GraphQLASTUtils.js.flow +0 -26
- package/runner/GraphQLNodeMap.js.flow +0 -55
- package/runner/Sources.js.flow +0 -227
- package/runner/StrictMap.js.flow +0 -96
- package/runner/compileArtifacts.js.flow +0 -75
- package/runner/extractAST.js.flow +0 -98
- package/runner/getChangedNodeNames.js.flow +0 -48
- package/runner/getSchemaInstance.js.flow +0 -36
- package/runner/types.js.flow +0 -37
- package/test-utils/TestSchema.js.flow +0 -30
- package/test-utils/parseGraphQLText.js.flow +0 -41
- package/transforms/ApplyFragmentArgumentTransform.js.flow +0 -524
- package/transforms/ClientExtensionsTransform.js.flow +0 -224
- package/transforms/ConnectionTransform.js.flow +0 -850
- package/transforms/DeclarativeConnectionMutationTransform.js.flow +0 -245
- package/transforms/DeferStreamTransform.js.flow +0 -263
- package/transforms/DisallowIdAsAlias.js.flow +0 -46
- package/transforms/DisallowTypenameOnRoot.js.flow +0 -44
- package/transforms/FieldHandleTransform.js.flow +0 -77
- package/transforms/FilterCompilerDirectivesTransform.js.flow +0 -33
- package/transforms/FilterDirectivesTransform.js.flow +0 -45
- package/transforms/FlattenTransform.js.flow +0 -458
- package/transforms/GenerateIDFieldTransform.js.flow +0 -151
- package/transforms/GenerateTypeNameTransform.js.flow +0 -159
- package/transforms/InlineDataFragmentTransform.js.flow +0 -123
- package/transforms/InlineFragmentsTransform.js.flow +0 -70
- package/transforms/MaskTransform.js.flow +0 -124
- package/transforms/MatchTransform.js.flow +0 -587
- package/transforms/ReactFlightComponentTransform.js.flow +0 -207
- package/transforms/RefetchableFragmentTransform.js.flow +0 -266
- package/transforms/RelayDirectiveTransform.js.flow +0 -96
- package/transforms/RequiredFieldTransform.js.flow +0 -413
- package/transforms/SkipClientExtensionsTransform.js.flow +0 -54
- package/transforms/SkipHandleFieldTransform.js.flow +0 -44
- package/transforms/SkipRedundantNodesTransform.js.flow +0 -277
- package/transforms/SkipSplitOperationTransform.js.flow +0 -37
- package/transforms/SkipUnreachableNodeTransform.js.flow +0 -148
- package/transforms/SkipUnusedVariablesTransform.js.flow +0 -59
- package/transforms/SplitModuleImportTransform.js.flow +0 -97
- package/transforms/TestOperationTransform.js.flow +0 -142
- package/transforms/TransformUtils.js.flow +0 -26
- package/transforms/ValidateGlobalVariablesTransform.js.flow +0 -80
- package/transforms/ValidateRequiredArgumentsTransform.js.flow +0 -130
- package/transforms/ValidateServerOnlyDirectivesTransform.js.flow +0 -128
- package/transforms/ValidateUnusedVariablesTransform.js.flow +0 -88
- package/transforms/query-generators/FetchableQueryGenerator.js.flow +0 -188
- package/transforms/query-generators/NodeQueryGenerator.js.flow +0 -217
- package/transforms/query-generators/QueryQueryGenerator.js.flow +0 -57
- package/transforms/query-generators/ViewerQueryGenerator.js.flow +0 -97
- package/transforms/query-generators/index.js.flow +0 -89
- package/transforms/query-generators/utils.js.flow +0 -76
- package/util/CodeMarker.js.flow +0 -79
- package/util/DefaultHandleKey.js.flow +0 -17
- package/util/RelayCompilerCache.js.flow +0 -86
- package/util/Rollout.js.flow +0 -39
- package/util/TimeReporter.js.flow +0 -79
- package/util/areEqualArgValues.js.flow +0 -126
- package/util/argumentContainsVariables.js.flow +0 -38
- package/util/dedupeJSONStringify.js.flow +0 -156
- package/util/generateAbstractTypeRefinementKey.js.flow +0 -29
- package/util/getDefinitionNodeHash.js.flow +0 -24
- package/util/getModuleName.js.flow +0 -39
- package/util/joinArgumentDefinitions.js.flow +0 -105
- package/util/md5.js.flow +0 -19
- package/util/murmurHash.js.flow +0 -94
- package/util/nullthrowsOSS.js.flow +0 -25
- package/util/orList.js.flow +0 -37
- package/util/partitionArray.js.flow +0 -37
package/lib/core/Schema.js
DELETED
@@ -1,1877 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
3
|
-
*
|
4
|
-
* This source code is licensed under the MIT license found in the
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
6
|
-
*
|
7
|
-
*
|
8
|
-
* @format
|
9
|
-
* @emails oncall+relay
|
10
|
-
*/
|
11
|
-
// flowlint ambiguous-object-type:error
|
12
|
-
'use strict';
|
13
|
-
|
14
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
15
|
-
|
16
|
-
var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/createForOfIteratorHelper"));
|
17
|
-
|
18
|
-
var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
|
19
|
-
|
20
|
-
var _require = require('./CompilerError'),
|
21
|
-
createCompilerError = _require.createCompilerError;
|
22
|
-
|
23
|
-
var _require2 = require('./SchemaUtils'),
|
24
|
-
isSchemaDefinitionAST = _require2.isSchemaDefinitionAST;
|
25
|
-
|
26
|
-
var _require3 = require('graphql'),
|
27
|
-
GraphQLBoolean = _require3.GraphQLBoolean,
|
28
|
-
GraphQLFloat = _require3.GraphQLFloat,
|
29
|
-
GraphQLID = _require3.GraphQLID,
|
30
|
-
GraphQLInt = _require3.GraphQLInt,
|
31
|
-
GraphQLString = _require3.GraphQLString,
|
32
|
-
parse = _require3.parse,
|
33
|
-
parseType = _require3.parseType,
|
34
|
-
print = _require3.print,
|
35
|
-
valueFromASTUntyped = _require3.valueFromASTUntyped;
|
36
|
-
|
37
|
-
/**
|
38
|
-
* @private
|
39
|
-
*/
|
40
|
-
var Type = /*#__PURE__*/function () {
|
41
|
-
function Type(name, isClient) {
|
42
|
-
this.name = name;
|
43
|
-
this.isClient = isClient;
|
44
|
-
}
|
45
|
-
|
46
|
-
var _proto = Type.prototype;
|
47
|
-
|
48
|
-
_proto.toString = function toString() {
|
49
|
-
return this.name;
|
50
|
-
};
|
51
|
-
|
52
|
-
_proto.toJSON = function toJSON() {
|
53
|
-
return String(this);
|
54
|
-
};
|
55
|
-
|
56
|
-
return Type;
|
57
|
-
}();
|
58
|
-
/**
|
59
|
-
* @private
|
60
|
-
*/
|
61
|
-
|
62
|
-
|
63
|
-
var ScalarType = /*#__PURE__*/function (_Type) {
|
64
|
-
(0, _inheritsLoose2["default"])(ScalarType, _Type);
|
65
|
-
|
66
|
-
function ScalarType() {
|
67
|
-
return _Type.apply(this, arguments) || this;
|
68
|
-
}
|
69
|
-
|
70
|
-
return ScalarType;
|
71
|
-
}(Type);
|
72
|
-
/**
|
73
|
-
* @private
|
74
|
-
*/
|
75
|
-
|
76
|
-
|
77
|
-
var EnumType = /*#__PURE__*/function (_Type2) {
|
78
|
-
(0, _inheritsLoose2["default"])(EnumType, _Type2);
|
79
|
-
|
80
|
-
function EnumType(name, values, isClient) {
|
81
|
-
var _this;
|
82
|
-
|
83
|
-
_this = _Type2.call(this, name, isClient) || this;
|
84
|
-
_this.values = values;
|
85
|
-
return _this;
|
86
|
-
}
|
87
|
-
|
88
|
-
return EnumType;
|
89
|
-
}(Type);
|
90
|
-
/**
|
91
|
-
* @private
|
92
|
-
*/
|
93
|
-
|
94
|
-
|
95
|
-
var UnionType = /*#__PURE__*/function (_Type3) {
|
96
|
-
(0, _inheritsLoose2["default"])(UnionType, _Type3);
|
97
|
-
|
98
|
-
function UnionType() {
|
99
|
-
return _Type3.apply(this, arguments) || this;
|
100
|
-
}
|
101
|
-
|
102
|
-
return UnionType;
|
103
|
-
}(Type);
|
104
|
-
/**
|
105
|
-
* @private
|
106
|
-
*/
|
107
|
-
|
108
|
-
|
109
|
-
var ObjectType = /*#__PURE__*/function (_Type4) {
|
110
|
-
(0, _inheritsLoose2["default"])(ObjectType, _Type4);
|
111
|
-
|
112
|
-
function ObjectType() {
|
113
|
-
return _Type4.apply(this, arguments) || this;
|
114
|
-
}
|
115
|
-
|
116
|
-
return ObjectType;
|
117
|
-
}(Type);
|
118
|
-
/**
|
119
|
-
* @private
|
120
|
-
*/
|
121
|
-
|
122
|
-
|
123
|
-
var InputObjectType = /*#__PURE__*/function (_Type5) {
|
124
|
-
(0, _inheritsLoose2["default"])(InputObjectType, _Type5);
|
125
|
-
|
126
|
-
function InputObjectType() {
|
127
|
-
return _Type5.apply(this, arguments) || this;
|
128
|
-
}
|
129
|
-
|
130
|
-
return InputObjectType;
|
131
|
-
}(Type);
|
132
|
-
/**
|
133
|
-
* @private
|
134
|
-
*/
|
135
|
-
|
136
|
-
|
137
|
-
var InterfaceType = /*#__PURE__*/function (_Type6) {
|
138
|
-
(0, _inheritsLoose2["default"])(InterfaceType, _Type6);
|
139
|
-
|
140
|
-
function InterfaceType() {
|
141
|
-
return _Type6.apply(this, arguments) || this;
|
142
|
-
}
|
143
|
-
|
144
|
-
return InterfaceType;
|
145
|
-
}(Type);
|
146
|
-
/**
|
147
|
-
* @private
|
148
|
-
*/
|
149
|
-
|
150
|
-
|
151
|
-
var List = /*#__PURE__*/function () {
|
152
|
-
function List(type) {
|
153
|
-
this.ofType = type;
|
154
|
-
this._typeString = "[".concat(String(this.ofType), "]");
|
155
|
-
}
|
156
|
-
|
157
|
-
var _proto2 = List.prototype;
|
158
|
-
|
159
|
-
_proto2.toString = function toString() {
|
160
|
-
return this._typeString;
|
161
|
-
};
|
162
|
-
|
163
|
-
_proto2.toJSON = function toJSON() {
|
164
|
-
return this.toString();
|
165
|
-
};
|
166
|
-
|
167
|
-
return List;
|
168
|
-
}();
|
169
|
-
/**
|
170
|
-
* @private
|
171
|
-
*/
|
172
|
-
|
173
|
-
|
174
|
-
var NonNull = /*#__PURE__*/function () {
|
175
|
-
function NonNull(type) {
|
176
|
-
this.ofType = type;
|
177
|
-
this._typeString = "".concat(String(this.ofType), "!");
|
178
|
-
}
|
179
|
-
|
180
|
-
var _proto3 = NonNull.prototype;
|
181
|
-
|
182
|
-
_proto3.toString = function toString() {
|
183
|
-
return this._typeString;
|
184
|
-
};
|
185
|
-
|
186
|
-
_proto3.toJSON = function toJSON() {
|
187
|
-
return this.toString();
|
188
|
-
};
|
189
|
-
|
190
|
-
return NonNull;
|
191
|
-
}();
|
192
|
-
/**
|
193
|
-
* @private
|
194
|
-
*/
|
195
|
-
|
196
|
-
|
197
|
-
var Field = function Field(schema, name, type, belongsTo, args, directives, isClient) {
|
198
|
-
this.name = name;
|
199
|
-
this.type = type;
|
200
|
-
this.belongsTo = belongsTo;
|
201
|
-
this.isClient = isClient;
|
202
|
-
this.args = parseInputArgumentDefinitionsMap(schema, args);
|
203
|
-
this.directives = directives;
|
204
|
-
};
|
205
|
-
/**
|
206
|
-
* @private
|
207
|
-
*/
|
208
|
-
|
209
|
-
|
210
|
-
function unwrap(type) {
|
211
|
-
if (type instanceof NonNull || type instanceof List) {
|
212
|
-
return unwrap(type.ofType);
|
213
|
-
}
|
214
|
-
|
215
|
-
return type;
|
216
|
-
}
|
217
|
-
/**
|
218
|
-
* @private
|
219
|
-
*/
|
220
|
-
|
221
|
-
|
222
|
-
function hasConcreteTypeThatImplements(schema, type, interfaceType) {
|
223
|
-
return _isAbstractType(type) && getConcreteTypes(schema, type).some(function (concreteType) {
|
224
|
-
return schema.implementsInterface(schema.assertCompositeType(concreteType), interfaceType);
|
225
|
-
});
|
226
|
-
}
|
227
|
-
/**
|
228
|
-
* @private
|
229
|
-
*/
|
230
|
-
|
231
|
-
|
232
|
-
function getConcreteTypes(schema, type) {
|
233
|
-
var concreteTypes = new Set();
|
234
|
-
schema.getPossibleTypes(type).forEach(function (possibleType) {
|
235
|
-
if (_isObject(possibleType)) {
|
236
|
-
concreteTypes.add(possibleType);
|
237
|
-
}
|
238
|
-
});
|
239
|
-
return Array.from(concreteTypes);
|
240
|
-
}
|
241
|
-
|
242
|
-
var TYPENAME_FIELD = '__typename';
|
243
|
-
var CLIENT_ID_FIELD = '__id';
|
244
|
-
var QUERY_TYPE_KEY = Symbol('Query');
|
245
|
-
var MUTATION_TYPE_KEY = Symbol('Mutation');
|
246
|
-
var SUBSCRIPTION_TYPE_KEY = Symbol('Subscription');
|
247
|
-
|
248
|
-
function _isScalar(type) {
|
249
|
-
return type instanceof ScalarType;
|
250
|
-
}
|
251
|
-
|
252
|
-
function _isObject(type) {
|
253
|
-
return type instanceof ObjectType;
|
254
|
-
}
|
255
|
-
|
256
|
-
function _isEnum(type) {
|
257
|
-
return type instanceof EnumType;
|
258
|
-
}
|
259
|
-
|
260
|
-
function _isUnion(type) {
|
261
|
-
return type instanceof UnionType;
|
262
|
-
}
|
263
|
-
|
264
|
-
function _isInputObject(type) {
|
265
|
-
return type instanceof InputObjectType;
|
266
|
-
}
|
267
|
-
|
268
|
-
function _isInterface(type) {
|
269
|
-
return type instanceof InterfaceType;
|
270
|
-
}
|
271
|
-
|
272
|
-
function _isWrapper(type) {
|
273
|
-
return type instanceof List || type instanceof NonNull;
|
274
|
-
}
|
275
|
-
|
276
|
-
function isBaseType(type) {
|
277
|
-
return type instanceof ScalarType || type instanceof ObjectType || type instanceof EnumType || type instanceof UnionType || type instanceof InputObjectType || type instanceof InterfaceType;
|
278
|
-
}
|
279
|
-
|
280
|
-
function _isAbstractType(type) {
|
281
|
-
return type instanceof UnionType || type instanceof InterfaceType;
|
282
|
-
}
|
283
|
-
|
284
|
-
function _isCompositeType(type) {
|
285
|
-
return type instanceof ObjectType || type instanceof UnionType || type instanceof InterfaceType;
|
286
|
-
}
|
287
|
-
|
288
|
-
function _isInputType(type) {
|
289
|
-
return type instanceof InputObjectType || type instanceof ScalarType || type instanceof EnumType;
|
290
|
-
}
|
291
|
-
|
292
|
-
var Schema = /*#__PURE__*/function () {
|
293
|
-
/**
|
294
|
-
* @private
|
295
|
-
*/
|
296
|
-
function Schema(typeMap) {
|
297
|
-
var _this2 = this;
|
298
|
-
|
299
|
-
this._typeMap = typeMap;
|
300
|
-
this._typeWrappersMap = new Map();
|
301
|
-
this._fieldsMap = new Map();
|
302
|
-
this._typeNameMap = new Map();
|
303
|
-
this._clientIdMap = new Map();
|
304
|
-
this._directiveMap = new Map(typeMap.getDirectives().map(function (directive) {
|
305
|
-
return [directive.name, {
|
306
|
-
locations: directive.locations,
|
307
|
-
args: parseInputArgumentDefinitions(_this2, directive.args),
|
308
|
-
name: directive.name,
|
309
|
-
isClient: directive.isClient
|
310
|
-
}];
|
311
|
-
}));
|
312
|
-
}
|
313
|
-
|
314
|
-
var _proto4 = Schema.prototype;
|
315
|
-
|
316
|
-
_proto4.getTypes = function getTypes() {
|
317
|
-
return this._typeMap.getTypes();
|
318
|
-
};
|
319
|
-
|
320
|
-
_proto4.getTypeFromAST = function getTypeFromAST(typeNode) {
|
321
|
-
if (typeNode.kind === 'NonNullType') {
|
322
|
-
var innerType = this.getTypeFromAST(typeNode.type);
|
323
|
-
|
324
|
-
if (!innerType) {
|
325
|
-
return;
|
326
|
-
}
|
327
|
-
|
328
|
-
if (innerType instanceof NonNull) {
|
329
|
-
throw createCompilerError('Unable to wrap non-nullable type with non-null wrapper.');
|
330
|
-
}
|
331
|
-
|
332
|
-
var cacheKey = "".concat(this.getTypeString(innerType), "!");
|
333
|
-
|
334
|
-
var type = this._typeWrappersMap.get(cacheKey);
|
335
|
-
|
336
|
-
if (type) {
|
337
|
-
return type;
|
338
|
-
}
|
339
|
-
|
340
|
-
type = new NonNull(innerType);
|
341
|
-
|
342
|
-
this._typeWrappersMap.set(cacheKey, type);
|
343
|
-
|
344
|
-
return type;
|
345
|
-
} else if (typeNode.kind === 'ListType') {
|
346
|
-
var _innerType = this.getTypeFromAST(typeNode.type);
|
347
|
-
|
348
|
-
if (!_innerType) {
|
349
|
-
return;
|
350
|
-
}
|
351
|
-
|
352
|
-
var _cacheKey = "[".concat(this.getTypeString(_innerType), "]");
|
353
|
-
|
354
|
-
var _type = this._typeWrappersMap.get(_cacheKey);
|
355
|
-
|
356
|
-
if (_type) {
|
357
|
-
return _type;
|
358
|
-
}
|
359
|
-
|
360
|
-
_type = new List(_innerType);
|
361
|
-
|
362
|
-
this._typeWrappersMap.set(_cacheKey, _type);
|
363
|
-
|
364
|
-
return _type;
|
365
|
-
}
|
366
|
-
|
367
|
-
return this._typeMap.getTypeByName(typeNode.name.value);
|
368
|
-
};
|
369
|
-
|
370
|
-
_proto4._getRawType = function _getRawType(typeName) {
|
371
|
-
var type = this._typeWrappersMap.get(typeName);
|
372
|
-
|
373
|
-
if (type) {
|
374
|
-
return type;
|
375
|
-
}
|
376
|
-
|
377
|
-
if (typeof typeName === 'string') {
|
378
|
-
return this.getTypeFromAST(parseType(typeName));
|
379
|
-
} else {
|
380
|
-
var operationType;
|
381
|
-
|
382
|
-
if (typeName === QUERY_TYPE_KEY) {
|
383
|
-
operationType = this._typeMap.getQueryType();
|
384
|
-
} else if (typeName === MUTATION_TYPE_KEY) {
|
385
|
-
operationType = this._typeMap.getMutationType();
|
386
|
-
} else if (typeName === SUBSCRIPTION_TYPE_KEY) {
|
387
|
-
operationType = this._typeMap.getSubscriptionType();
|
388
|
-
}
|
389
|
-
|
390
|
-
if (operationType instanceof ObjectType) {
|
391
|
-
return operationType;
|
392
|
-
}
|
393
|
-
}
|
394
|
-
};
|
395
|
-
|
396
|
-
_proto4.getTypeFromString = function getTypeFromString(typeName) {
|
397
|
-
return this._getRawType(typeName);
|
398
|
-
};
|
399
|
-
|
400
|
-
_proto4.expectTypeFromString = function expectTypeFromString(typeName) {
|
401
|
-
var type = this.getTypeFromString(typeName);
|
402
|
-
|
403
|
-
if (type == null) {
|
404
|
-
throw createCompilerError("Unknown type: '".concat(typeName, "'."));
|
405
|
-
}
|
406
|
-
|
407
|
-
return type;
|
408
|
-
};
|
409
|
-
|
410
|
-
_proto4.expectTypeFromAST = function expectTypeFromAST(ast) {
|
411
|
-
var type = this.getTypeFromAST(ast);
|
412
|
-
|
413
|
-
if (type == null) {
|
414
|
-
throw createCompilerError("Unknown type: '".concat(print(ast), "'."), null, [ast]);
|
415
|
-
}
|
416
|
-
|
417
|
-
return type;
|
418
|
-
};
|
419
|
-
|
420
|
-
_proto4.getNonNullType = function getNonNullType(type) {
|
421
|
-
if (type instanceof NonNull) {
|
422
|
-
return type;
|
423
|
-
}
|
424
|
-
|
425
|
-
var cacheKey = "".concat(String(type), "!");
|
426
|
-
|
427
|
-
var nonNullType = this._typeWrappersMap.get(cacheKey);
|
428
|
-
|
429
|
-
if (nonNullType) {
|
430
|
-
return nonNullType;
|
431
|
-
}
|
432
|
-
|
433
|
-
nonNullType = new NonNull(type);
|
434
|
-
|
435
|
-
this._typeWrappersMap.set(cacheKey, nonNullType);
|
436
|
-
|
437
|
-
return nonNullType;
|
438
|
-
};
|
439
|
-
|
440
|
-
_proto4.getRawType = function getRawType(type) {
|
441
|
-
return unwrap(type);
|
442
|
-
};
|
443
|
-
|
444
|
-
_proto4.getNullableType = function getNullableType(type) {
|
445
|
-
if (type instanceof NonNull) {
|
446
|
-
return type.ofType;
|
447
|
-
}
|
448
|
-
|
449
|
-
return type;
|
450
|
-
};
|
451
|
-
|
452
|
-
_proto4.getListItemType = function getListItemType(type) {
|
453
|
-
if (type instanceof List) {
|
454
|
-
return type.ofType;
|
455
|
-
}
|
456
|
-
|
457
|
-
return type;
|
458
|
-
};
|
459
|
-
|
460
|
-
_proto4.mapListItemType = function mapListItemType(type, mapper) {
|
461
|
-
if (!(type instanceof List)) {
|
462
|
-
throw createCompilerError('Expected List type');
|
463
|
-
}
|
464
|
-
|
465
|
-
var innerType = mapper(type.ofType);
|
466
|
-
var cacheKey = "[".concat(this.getTypeString(innerType), "]");
|
467
|
-
|
468
|
-
var newType = this._typeWrappersMap.get(cacheKey);
|
469
|
-
|
470
|
-
if (newType) {
|
471
|
-
return newType;
|
472
|
-
}
|
473
|
-
|
474
|
-
newType = new List(innerType);
|
475
|
-
|
476
|
-
this._typeWrappersMap.set(cacheKey, newType);
|
477
|
-
|
478
|
-
return newType;
|
479
|
-
};
|
480
|
-
|
481
|
-
_proto4.areEqualTypes = function areEqualTypes(typeA, typeB) {
|
482
|
-
if (typeA === typeB) {
|
483
|
-
return true;
|
484
|
-
}
|
485
|
-
|
486
|
-
if (typeA instanceof NonNull && typeB instanceof NonNull) {
|
487
|
-
return this.areEqualTypes(typeA.ofType, typeB.ofType);
|
488
|
-
}
|
489
|
-
|
490
|
-
if (typeA instanceof List && typeB instanceof List) {
|
491
|
-
return this.areEqualTypes(typeA.ofType, typeB.ofType);
|
492
|
-
}
|
493
|
-
|
494
|
-
if (isBaseType(typeA) && isBaseType(typeB)) {
|
495
|
-
return typeA.name === typeB.name;
|
496
|
-
}
|
497
|
-
|
498
|
-
return false;
|
499
|
-
}
|
500
|
-
/**
|
501
|
-
* Determine if the given type may implement the named type:
|
502
|
-
* - it is the named type
|
503
|
-
* - it implements the named interface
|
504
|
-
* - it is an abstract type and *some* of its concrete types may
|
505
|
-
* implement the named type
|
506
|
-
*/
|
507
|
-
;
|
508
|
-
|
509
|
-
_proto4.mayImplement = function mayImplement(type, interfaceType) {
|
510
|
-
return this.areEqualTypes(type, interfaceType) || this.implementsInterface(type, interfaceType) || this.isAbstractType(type) && hasConcreteTypeThatImplements(this, type, interfaceType);
|
511
|
-
};
|
512
|
-
|
513
|
-
_proto4.implementsInterface = function implementsInterface(type, interfaceType) {
|
514
|
-
var _this3 = this;
|
515
|
-
|
516
|
-
return this.getInterfaces(type).some(function (typeInterface) {
|
517
|
-
return _this3.areEqualTypes(typeInterface, interfaceType);
|
518
|
-
});
|
519
|
-
};
|
520
|
-
|
521
|
-
_proto4.canHaveSelections = function canHaveSelections(type) {
|
522
|
-
return this.isObject(type) || this.isInterface(type);
|
523
|
-
};
|
524
|
-
|
525
|
-
_proto4.getTypeString = function getTypeString(type) {
|
526
|
-
return type.toString();
|
527
|
-
};
|
528
|
-
|
529
|
-
_proto4.isTypeSubTypeOf = function isTypeSubTypeOf(maybeSubType, superType) {
|
530
|
-
// Equivalent type is a valid subtype
|
531
|
-
if (maybeSubType === superType) {
|
532
|
-
return true;
|
533
|
-
} // If superType is non-null, maybeSubType must also be non-null.
|
534
|
-
|
535
|
-
|
536
|
-
if (superType instanceof NonNull) {
|
537
|
-
if (maybeSubType instanceof NonNull) {
|
538
|
-
return this.isTypeSubTypeOf(maybeSubType.ofType, superType.ofType);
|
539
|
-
}
|
540
|
-
|
541
|
-
return false;
|
542
|
-
}
|
543
|
-
|
544
|
-
if (maybeSubType instanceof NonNull) {
|
545
|
-
// If superType is nullable, maybeSubType may be non-null or nullable.
|
546
|
-
return this.isTypeSubTypeOf(maybeSubType.ofType, superType);
|
547
|
-
} // If superType type is a list, maybeSubType type must also be a list.
|
548
|
-
|
549
|
-
|
550
|
-
if (superType instanceof List) {
|
551
|
-
if (maybeSubType instanceof List) {
|
552
|
-
return this.isTypeSubTypeOf(maybeSubType.ofType, superType.ofType);
|
553
|
-
}
|
554
|
-
|
555
|
-
return false;
|
556
|
-
}
|
557
|
-
|
558
|
-
if (maybeSubType instanceof List) {
|
559
|
-
// If superType is not a list, maybeSubType must also be not a list.
|
560
|
-
return false;
|
561
|
-
} // If superType type is an abstract type, maybeSubType type may be a currently
|
562
|
-
// possible object type.
|
563
|
-
|
564
|
-
|
565
|
-
if (this.isAbstractType(superType) && this.isObject(maybeSubType) && this.isPossibleType(this.assertAbstractType(superType), this.assertObjectType(maybeSubType))) {
|
566
|
-
return true;
|
567
|
-
} // Otherwise, maybeSubType is not a valid subtype of the superType.
|
568
|
-
|
569
|
-
|
570
|
-
return false;
|
571
|
-
}
|
572
|
-
/**
|
573
|
-
* Provided two composite types, determine if they "overlap". Two composite
|
574
|
-
* types overlap when the Sets of possible concrete types for each intersect.
|
575
|
-
*
|
576
|
-
* This is often used to determine if a fragment of a given type could possibly
|
577
|
-
* be visited in a context of another type.
|
578
|
-
*
|
579
|
-
* This function is commutative.
|
580
|
-
*/
|
581
|
-
;
|
582
|
-
|
583
|
-
_proto4.doTypesOverlap = function doTypesOverlap(typeA, typeB) {
|
584
|
-
var _this4 = this;
|
585
|
-
|
586
|
-
// Equivalent types overlap
|
587
|
-
if (typeA === typeB) {
|
588
|
-
return true;
|
589
|
-
}
|
590
|
-
|
591
|
-
if (_isAbstractType(typeA)) {
|
592
|
-
if (_isAbstractType(typeB)) {
|
593
|
-
// If both types are abstract, then determine if there is any intersection
|
594
|
-
// between possible concrete types of each.
|
595
|
-
return Array.from(this.getPossibleTypes(typeA)).some(function (type) {
|
596
|
-
if (_isObject(type)) {
|
597
|
-
return _this4.isPossibleType(typeB, type);
|
598
|
-
}
|
599
|
-
});
|
600
|
-
} // Determine if the latter type is a possible concrete type of the former.
|
601
|
-
|
602
|
-
|
603
|
-
return this.isPossibleType(typeA, typeB);
|
604
|
-
}
|
605
|
-
|
606
|
-
if (_isAbstractType(typeB)) {
|
607
|
-
// Determine if the former type is a possible concrete type of the latter.
|
608
|
-
return this.isPossibleType(typeB, typeA);
|
609
|
-
} // Otherwise the types do not overlap.
|
610
|
-
|
611
|
-
|
612
|
-
return false;
|
613
|
-
};
|
614
|
-
|
615
|
-
_proto4.isPossibleType = function isPossibleType(superType, maybeSubType) {
|
616
|
-
return this._typeMap.getPossibleTypeSet(superType).has(maybeSubType);
|
617
|
-
};
|
618
|
-
|
619
|
-
_proto4.assertScalarFieldType = function assertScalarFieldType(type) {
|
620
|
-
// Scalar type fields can be wrappers / or can be scalars/enums
|
621
|
-
if (_isWrapper(type) && !_isScalar(unwrap(type)) && !_isEnum(unwrap(type)) || !_isWrapper(type) && !_isScalar(type) && !_isEnum(type)) {
|
622
|
-
throw createCompilerError("Expected ".concat(String(type), " to be a Scalar or Enum type."));
|
623
|
-
}
|
624
|
-
|
625
|
-
return type;
|
626
|
-
};
|
627
|
-
|
628
|
-
_proto4.assertLinkedFieldType = function assertLinkedFieldType(type) {
|
629
|
-
// Linked Field types can be wrappers / or can be composite types
|
630
|
-
if (_isWrapper(type) && !_isCompositeType(unwrap(type)) || !_isWrapper(type) && !_isCompositeType(type)) {
|
631
|
-
throw createCompilerError("Expected ".concat(String(type), " to be a Object, Interface or a Union Type."));
|
632
|
-
}
|
633
|
-
|
634
|
-
return type;
|
635
|
-
};
|
636
|
-
|
637
|
-
_proto4.assertInputType = function assertInputType(type) {
|
638
|
-
// Input type fields can be wrappers / or can be scalars/enums
|
639
|
-
if (_isWrapper(type) && !_isInputType(unwrap(type)) || !_isWrapper(type) && !_isInputType(type)) {
|
640
|
-
throw createCompilerError("Expected ".concat(String(type), " to be a Input, Scalar or Enum type."));
|
641
|
-
}
|
642
|
-
|
643
|
-
return type;
|
644
|
-
};
|
645
|
-
|
646
|
-
_proto4.asCompositeType = function asCompositeType(type) {
|
647
|
-
if (_isCompositeType(type)) {
|
648
|
-
return type;
|
649
|
-
}
|
650
|
-
};
|
651
|
-
|
652
|
-
_proto4.asInputType = function asInputType(type) {
|
653
|
-
if (_isWrapper(type) && _isInputType(unwrap(type)) || !_isWrapper(type) && _isInputType(type)) {
|
654
|
-
return type;
|
655
|
-
}
|
656
|
-
};
|
657
|
-
|
658
|
-
_proto4.asScalarFieldType = function asScalarFieldType(type) {
|
659
|
-
if (_isScalar(type) || _isEnum(type)) {
|
660
|
-
return type;
|
661
|
-
}
|
662
|
-
};
|
663
|
-
|
664
|
-
_proto4.assertScalarType = function assertScalarType(type) {
|
665
|
-
if (!_isScalar(type)) {
|
666
|
-
throw createCompilerError("Expected ".concat(this.getTypeString(type), " to be a scalar type, got ").concat(this.getTypeString(type), "."));
|
667
|
-
}
|
668
|
-
|
669
|
-
return type;
|
670
|
-
};
|
671
|
-
|
672
|
-
_proto4.assertObjectType = function assertObjectType(type) {
|
673
|
-
if (!_isObject(type)) {
|
674
|
-
throw createCompilerError("Expected ".concat(this.getTypeString(type), " to be an object type."));
|
675
|
-
}
|
676
|
-
|
677
|
-
return type;
|
678
|
-
};
|
679
|
-
|
680
|
-
_proto4.assertInputObjectType = function assertInputObjectType(type) {
|
681
|
-
if (!_isInputObject(type)) {
|
682
|
-
throw createCompilerError("Expected ".concat(this.getTypeString(type), " to be an input type."));
|
683
|
-
}
|
684
|
-
|
685
|
-
return type;
|
686
|
-
};
|
687
|
-
|
688
|
-
_proto4.asInputObjectType = function asInputObjectType(type) {
|
689
|
-
if (!_isInputObject(type)) {
|
690
|
-
return null;
|
691
|
-
}
|
692
|
-
|
693
|
-
return type;
|
694
|
-
};
|
695
|
-
|
696
|
-
_proto4.assertInterfaceType = function assertInterfaceType(type) {
|
697
|
-
if (!_isInterface(type)) {
|
698
|
-
throw createCompilerError("Expected ".concat(this.getTypeString(type), " to be an interface type."));
|
699
|
-
}
|
700
|
-
|
701
|
-
return type;
|
702
|
-
};
|
703
|
-
|
704
|
-
_proto4.assertCompositeType = function assertCompositeType(type) {
|
705
|
-
if (!_isCompositeType(type)) {
|
706
|
-
throw createCompilerError("Expected ".concat(this.getTypeString(type), " to be a composite type."));
|
707
|
-
}
|
708
|
-
|
709
|
-
return type;
|
710
|
-
};
|
711
|
-
|
712
|
-
_proto4.assertAbstractType = function assertAbstractType(type) {
|
713
|
-
if (!_isAbstractType(type)) {
|
714
|
-
throw createCompilerError("Expected ".concat(this.getTypeString(type), " to be an abstract type."));
|
715
|
-
}
|
716
|
-
|
717
|
-
return type;
|
718
|
-
};
|
719
|
-
|
720
|
-
_proto4.assertLeafType = function assertLeafType(type) {
|
721
|
-
if (!this.isLeafType(type)) {
|
722
|
-
throw createCompilerError("Expected ".concat(this.getTypeString(type), " to be a leaf type."));
|
723
|
-
}
|
724
|
-
|
725
|
-
return type;
|
726
|
-
};
|
727
|
-
|
728
|
-
_proto4.assertUnionType = function assertUnionType(type) {
|
729
|
-
if (!_isUnion(type)) {
|
730
|
-
throw createCompilerError("Expected ".concat(this.getTypeString(type), " to be a union type."));
|
731
|
-
}
|
732
|
-
|
733
|
-
return type;
|
734
|
-
};
|
735
|
-
|
736
|
-
_proto4.assertEnumType = function assertEnumType(type) {
|
737
|
-
if (!_isEnum(type)) {
|
738
|
-
throw createCompilerError("Expected ".concat(String(type), " to be an enum type."));
|
739
|
-
}
|
740
|
-
|
741
|
-
return type;
|
742
|
-
};
|
743
|
-
|
744
|
-
_proto4.assertIntType = function assertIntType(type) {
|
745
|
-
if (!_isScalar(type) || !this.isInt(type)) {
|
746
|
-
throw createCompilerError("Expected ".concat(String(type), " to be an 'Int' type."));
|
747
|
-
}
|
748
|
-
|
749
|
-
return type;
|
750
|
-
};
|
751
|
-
|
752
|
-
_proto4.assertFloatType = function assertFloatType(type) {
|
753
|
-
if (!_isScalar(type) || !this.isFloat(type)) {
|
754
|
-
throw createCompilerError("Expected ".concat(this.getTypeString(type), " to be a 'Float' type."));
|
755
|
-
}
|
756
|
-
|
757
|
-
return type;
|
758
|
-
};
|
759
|
-
|
760
|
-
_proto4.assertBooleanType = function assertBooleanType(type) {
|
761
|
-
if (!_isScalar(type) || !this.isBoolean(type)) {
|
762
|
-
throw createCompilerError("Expected ".concat(this.getTypeString(type), " to be a 'Boolean' type."));
|
763
|
-
}
|
764
|
-
|
765
|
-
return type;
|
766
|
-
};
|
767
|
-
|
768
|
-
_proto4.assertStringType = function assertStringType(type) {
|
769
|
-
if (!_isScalar(type) || !this.isString(type)) {
|
770
|
-
throw createCompilerError("Expected ".concat(this.getTypeString(type), " to be a 'String' type."));
|
771
|
-
}
|
772
|
-
|
773
|
-
return type;
|
774
|
-
};
|
775
|
-
|
776
|
-
_proto4.assertIdType = function assertIdType(type) {
|
777
|
-
if (!_isScalar(type) || !this.isId(type)) {
|
778
|
-
throw createCompilerError("Expected ".concat(this.getTypeString(type), " to be an ID type."));
|
779
|
-
}
|
780
|
-
|
781
|
-
return type;
|
782
|
-
};
|
783
|
-
|
784
|
-
_proto4.expectBooleanType = function expectBooleanType() {
|
785
|
-
return this.assertScalarType(this.expectTypeFromString('Boolean'));
|
786
|
-
};
|
787
|
-
|
788
|
-
_proto4.expectIntType = function expectIntType() {
|
789
|
-
return this.assertScalarType(this.expectTypeFromString('Int'));
|
790
|
-
};
|
791
|
-
|
792
|
-
_proto4.expectFloatType = function expectFloatType() {
|
793
|
-
return this.assertScalarType(this.expectTypeFromString('Float'));
|
794
|
-
};
|
795
|
-
|
796
|
-
_proto4.expectStringType = function expectStringType() {
|
797
|
-
return this.assertScalarType(this.expectTypeFromString('String'));
|
798
|
-
};
|
799
|
-
|
800
|
-
_proto4.expectIdType = function expectIdType() {
|
801
|
-
return this.assertScalarType(this.expectTypeFromString('ID'));
|
802
|
-
};
|
803
|
-
|
804
|
-
_proto4.getQueryType = function getQueryType() {
|
805
|
-
var queryType = this._getRawType(QUERY_TYPE_KEY);
|
806
|
-
|
807
|
-
if (queryType && _isObject(queryType)) {
|
808
|
-
return queryType;
|
809
|
-
}
|
810
|
-
};
|
811
|
-
|
812
|
-
_proto4.getMutationType = function getMutationType() {
|
813
|
-
var mutationType = this._getRawType(MUTATION_TYPE_KEY);
|
814
|
-
|
815
|
-
if (mutationType && _isObject(mutationType)) {
|
816
|
-
return mutationType;
|
817
|
-
}
|
818
|
-
};
|
819
|
-
|
820
|
-
_proto4.getSubscriptionType = function getSubscriptionType() {
|
821
|
-
var subscriptionType = this._getRawType(SUBSCRIPTION_TYPE_KEY);
|
822
|
-
|
823
|
-
if (subscriptionType && _isObject(subscriptionType)) {
|
824
|
-
return subscriptionType;
|
825
|
-
}
|
826
|
-
};
|
827
|
-
|
828
|
-
_proto4.expectQueryType = function expectQueryType() {
|
829
|
-
var queryType = this.getQueryType();
|
830
|
-
|
831
|
-
if (queryType == null) {
|
832
|
-
throw createCompilerError('Query type is not defined on the Schema');
|
833
|
-
}
|
834
|
-
|
835
|
-
return queryType;
|
836
|
-
};
|
837
|
-
|
838
|
-
_proto4.expectMutationType = function expectMutationType() {
|
839
|
-
var mutationType = this.getMutationType();
|
840
|
-
|
841
|
-
if (mutationType == null) {
|
842
|
-
throw createCompilerError('Mutation type is not defined the Schema');
|
843
|
-
}
|
844
|
-
|
845
|
-
return mutationType;
|
846
|
-
};
|
847
|
-
|
848
|
-
_proto4.expectSubscriptionType = function expectSubscriptionType() {
|
849
|
-
var subscriptionType = this.getSubscriptionType();
|
850
|
-
|
851
|
-
if (subscriptionType == null) {
|
852
|
-
throw createCompilerError('Subscription type is not defined the Schema');
|
853
|
-
}
|
854
|
-
|
855
|
-
return subscriptionType;
|
856
|
-
};
|
857
|
-
|
858
|
-
_proto4.isNonNull = function isNonNull(type) {
|
859
|
-
return type instanceof NonNull;
|
860
|
-
};
|
861
|
-
|
862
|
-
_proto4.isList = function isList(type) {
|
863
|
-
return type instanceof List;
|
864
|
-
};
|
865
|
-
|
866
|
-
_proto4.isWrapper = function isWrapper(type) {
|
867
|
-
return _isWrapper(type);
|
868
|
-
};
|
869
|
-
|
870
|
-
_proto4.isScalar = function isScalar(type) {
|
871
|
-
return _isScalar(type);
|
872
|
-
};
|
873
|
-
|
874
|
-
_proto4.isObject = function isObject(type) {
|
875
|
-
return _isObject(type);
|
876
|
-
};
|
877
|
-
|
878
|
-
_proto4.isEnum = function isEnum(type) {
|
879
|
-
return _isEnum(type);
|
880
|
-
};
|
881
|
-
|
882
|
-
_proto4.isUnion = function isUnion(type) {
|
883
|
-
return _isUnion(type);
|
884
|
-
};
|
885
|
-
|
886
|
-
_proto4.isInputObject = function isInputObject(type) {
|
887
|
-
return _isInputObject(type);
|
888
|
-
};
|
889
|
-
|
890
|
-
_proto4.isInterface = function isInterface(type) {
|
891
|
-
return _isInterface(type);
|
892
|
-
};
|
893
|
-
|
894
|
-
_proto4.isInputType = function isInputType(type) {
|
895
|
-
// Wrappers can be input types (so it's save to check unwrapped type here)
|
896
|
-
return _isInputType(type) || _isWrapper(type) && _isInputType(unwrap(type));
|
897
|
-
};
|
898
|
-
|
899
|
-
_proto4.isCompositeType = function isCompositeType(type) {
|
900
|
-
return _isCompositeType(type);
|
901
|
-
};
|
902
|
-
|
903
|
-
_proto4.isAbstractType = function isAbstractType(type) {
|
904
|
-
return _isAbstractType(type);
|
905
|
-
};
|
906
|
-
|
907
|
-
_proto4.isLeafType = function isLeafType(type) {
|
908
|
-
return this.isScalar(type) || this.isEnum(type);
|
909
|
-
};
|
910
|
-
|
911
|
-
_proto4.isId = function isId(type) {
|
912
|
-
if (type instanceof ScalarType) {
|
913
|
-
return type.name === 'ID';
|
914
|
-
}
|
915
|
-
|
916
|
-
return false;
|
917
|
-
};
|
918
|
-
|
919
|
-
_proto4.isInt = function isInt(type) {
|
920
|
-
if (type instanceof ScalarType) {
|
921
|
-
return type.name === 'Int';
|
922
|
-
}
|
923
|
-
|
924
|
-
return false;
|
925
|
-
};
|
926
|
-
|
927
|
-
_proto4.isFloat = function isFloat(type) {
|
928
|
-
if (type instanceof ScalarType) {
|
929
|
-
return type.name === 'Float';
|
930
|
-
}
|
931
|
-
|
932
|
-
return false;
|
933
|
-
};
|
934
|
-
|
935
|
-
_proto4.isBoolean = function isBoolean(type) {
|
936
|
-
if (type instanceof ScalarType) {
|
937
|
-
return type.name === 'Boolean';
|
938
|
-
}
|
939
|
-
|
940
|
-
return false;
|
941
|
-
};
|
942
|
-
|
943
|
-
_proto4.isString = function isString(type) {
|
944
|
-
if (type instanceof ScalarType) {
|
945
|
-
return type.name === 'String';
|
946
|
-
}
|
947
|
-
|
948
|
-
return false;
|
949
|
-
};
|
950
|
-
|
951
|
-
_proto4.hasField = function hasField(type, fieldName) {
|
952
|
-
var canHaveTypename = this.isObject(type) || this.isAbstractType(type); // Special case for __typename field
|
953
|
-
|
954
|
-
if (canHaveTypename && (fieldName === TYPENAME_FIELD || fieldName === CLIENT_ID_FIELD)) {
|
955
|
-
return true;
|
956
|
-
}
|
957
|
-
|
958
|
-
if (type instanceof ObjectType || type instanceof InterfaceType) {
|
959
|
-
return this._typeMap.getField(type, fieldName) != null;
|
960
|
-
} else if (type instanceof InputObjectType) {
|
961
|
-
return this._typeMap.getInputField(type, fieldName) != null;
|
962
|
-
}
|
963
|
-
|
964
|
-
return false;
|
965
|
-
};
|
966
|
-
|
967
|
-
_proto4.hasId = function hasId(type) {
|
968
|
-
if (!this.hasField(type, 'id')) {
|
969
|
-
return false;
|
970
|
-
}
|
971
|
-
|
972
|
-
var idField = this.expectField(type, 'id');
|
973
|
-
return this.areEqualTypes(this.getNullableType(this.getFieldType(idField)), this.expectIdType());
|
974
|
-
};
|
975
|
-
|
976
|
-
_proto4.getFields = function getFields(type) {
|
977
|
-
var fieldsMap = this._getFieldsMap(type);
|
978
|
-
|
979
|
-
return Array.from(fieldsMap.values());
|
980
|
-
};
|
981
|
-
|
982
|
-
_proto4._getFieldsMap = function _getFieldsMap(type) {
|
983
|
-
var cachedMap = this._fieldsMap.get(type);
|
984
|
-
|
985
|
-
if (cachedMap != null) {
|
986
|
-
return cachedMap;
|
987
|
-
}
|
988
|
-
|
989
|
-
var fieldsMap = new Map();
|
990
|
-
|
991
|
-
if (type instanceof ObjectType || type instanceof InterfaceType) {
|
992
|
-
var fields = this._typeMap.getFieldMap(type);
|
993
|
-
|
994
|
-
if (fields) {
|
995
|
-
var _iterator = (0, _createForOfIteratorHelper2["default"])(fields),
|
996
|
-
_step;
|
997
|
-
|
998
|
-
try {
|
999
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
1000
|
-
var _step$value = _step.value,
|
1001
|
-
fieldName = _step$value[0],
|
1002
|
-
fieldDefinition = _step$value[1];
|
1003
|
-
var fieldType = this.expectTypeFromAST(fieldDefinition.type);
|
1004
|
-
fieldsMap.set(fieldName, new Field(this, fieldName, fieldType, this.assertCompositeType(type), fieldDefinition.arguments, fieldDefinition.directives, fieldDefinition.isClient));
|
1005
|
-
}
|
1006
|
-
} catch (err) {
|
1007
|
-
_iterator.e(err);
|
1008
|
-
} finally {
|
1009
|
-
_iterator.f();
|
1010
|
-
}
|
1011
|
-
}
|
1012
|
-
} else if (type instanceof InputObjectType) {
|
1013
|
-
var _fields = this._typeMap.getInputFieldMap(type);
|
1014
|
-
|
1015
|
-
if (_fields) {
|
1016
|
-
var _iterator2 = (0, _createForOfIteratorHelper2["default"])(_fields),
|
1017
|
-
_step2;
|
1018
|
-
|
1019
|
-
try {
|
1020
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
1021
|
-
var _step2$value = _step2.value,
|
1022
|
-
_fieldName = _step2$value[0],
|
1023
|
-
typeNode = _step2$value[1];
|
1024
|
-
|
1025
|
-
var _fieldType = this.expectTypeFromAST(typeNode);
|
1026
|
-
|
1027
|
-
fieldsMap.set(_fieldName, new Field(this, _fieldName, _fieldType, type, [], null, false));
|
1028
|
-
}
|
1029
|
-
} catch (err) {
|
1030
|
-
_iterator2.e(err);
|
1031
|
-
} finally {
|
1032
|
-
_iterator2.f();
|
1033
|
-
}
|
1034
|
-
}
|
1035
|
-
}
|
1036
|
-
|
1037
|
-
if (fieldsMap.size === 0) {
|
1038
|
-
throw createCompilerError("_getFieldsMap: Type '".concat(type.name, "' should have fields."));
|
1039
|
-
}
|
1040
|
-
|
1041
|
-
this._fieldsMap.set(type, fieldsMap);
|
1042
|
-
|
1043
|
-
return fieldsMap;
|
1044
|
-
};
|
1045
|
-
|
1046
|
-
_proto4.getFieldByName = function getFieldByName(type, fieldName) {
|
1047
|
-
if (!this.hasField(type, fieldName)) {
|
1048
|
-
return;
|
1049
|
-
} // A "special" case for __typename and __id fields - which should
|
1050
|
-
// not be in the list of type fields, but should be fine to select
|
1051
|
-
|
1052
|
-
|
1053
|
-
if (fieldName === TYPENAME_FIELD) {
|
1054
|
-
var typename = this._typeNameMap.get(type);
|
1055
|
-
|
1056
|
-
if (!typename) {
|
1057
|
-
typename = new Field(this, TYPENAME_FIELD, this.getNonNullType(this.expectStringType()), type, [], null, false);
|
1058
|
-
|
1059
|
-
this._typeNameMap.set(type, typename);
|
1060
|
-
}
|
1061
|
-
|
1062
|
-
return typename;
|
1063
|
-
}
|
1064
|
-
|
1065
|
-
if (fieldName === CLIENT_ID_FIELD) {
|
1066
|
-
var clientId = this._clientIdMap.get(type);
|
1067
|
-
|
1068
|
-
if (!clientId) {
|
1069
|
-
clientId = new Field(this, CLIENT_ID_FIELD, this.getNonNullType(this.expectIdType()), type, [], null, true);
|
1070
|
-
|
1071
|
-
this._clientIdMap.set(type, clientId);
|
1072
|
-
}
|
1073
|
-
|
1074
|
-
return clientId;
|
1075
|
-
}
|
1076
|
-
|
1077
|
-
if (_isUnion(type)) {
|
1078
|
-
throw createCompilerError("Unexpected union type '".concat(this.getTypeString(type), "' in the 'getFieldByName(...)'. Expected type with fields"));
|
1079
|
-
}
|
1080
|
-
|
1081
|
-
var fieldsMap = this._getFieldsMap(type);
|
1082
|
-
|
1083
|
-
return fieldsMap.get(fieldName);
|
1084
|
-
};
|
1085
|
-
|
1086
|
-
_proto4.expectField = function expectField(type, fieldName) {
|
1087
|
-
var field = this.getFieldByName(type, fieldName);
|
1088
|
-
|
1089
|
-
if (!field) {
|
1090
|
-
throw createCompilerError("Unknown field '".concat(fieldName, "' on type '").concat(this.getTypeString(type), "'."));
|
1091
|
-
}
|
1092
|
-
|
1093
|
-
return field;
|
1094
|
-
};
|
1095
|
-
|
1096
|
-
_proto4.getFieldConfig = function getFieldConfig(field) {
|
1097
|
-
return {
|
1098
|
-
type: field.type,
|
1099
|
-
args: Array.from(field.args.values())
|
1100
|
-
};
|
1101
|
-
};
|
1102
|
-
|
1103
|
-
_proto4.getFieldName = function getFieldName(field) {
|
1104
|
-
return field.name;
|
1105
|
-
};
|
1106
|
-
|
1107
|
-
_proto4.getFieldType = function getFieldType(field) {
|
1108
|
-
return field.type;
|
1109
|
-
};
|
1110
|
-
|
1111
|
-
_proto4.getFieldParentType = function getFieldParentType(field) {
|
1112
|
-
return field.belongsTo;
|
1113
|
-
};
|
1114
|
-
|
1115
|
-
_proto4.getFieldArgs = function getFieldArgs(field) {
|
1116
|
-
return Array.from(field.args.values());
|
1117
|
-
};
|
1118
|
-
|
1119
|
-
_proto4.getFieldArgByName = function getFieldArgByName(field, argName) {
|
1120
|
-
return field.args.get(argName);
|
1121
|
-
};
|
1122
|
-
|
1123
|
-
_proto4.getEnumValues = function getEnumValues(type) {
|
1124
|
-
return type.values;
|
1125
|
-
};
|
1126
|
-
|
1127
|
-
_proto4.getUnionTypes = function getUnionTypes(type) {
|
1128
|
-
return Array.from(this._typeMap.getPossibleTypeSet(type));
|
1129
|
-
};
|
1130
|
-
|
1131
|
-
_proto4.getInterfaces = function getInterfaces(type) {
|
1132
|
-
if (type instanceof ObjectType) {
|
1133
|
-
return this._typeMap.getInterfaces(type);
|
1134
|
-
}
|
1135
|
-
|
1136
|
-
return [];
|
1137
|
-
};
|
1138
|
-
|
1139
|
-
_proto4.getPossibleTypes = function getPossibleTypes(type) {
|
1140
|
-
return this._typeMap.getPossibleTypeSet(type);
|
1141
|
-
};
|
1142
|
-
|
1143
|
-
_proto4.getFetchableFieldName = function getFetchableFieldName(type) {
|
1144
|
-
return this._typeMap.getFetchableFieldName(type);
|
1145
|
-
};
|
1146
|
-
|
1147
|
-
_proto4.parseLiteral = function parseLiteral(type, valueNode) {
|
1148
|
-
if (type instanceof EnumType && valueNode.kind === 'EnumValue') {
|
1149
|
-
return this.parseValue(type, valueNode.value);
|
1150
|
-
} else if (type instanceof ScalarType) {
|
1151
|
-
if (valueNode.kind === 'BooleanValue' && type.name === 'Boolean') {
|
1152
|
-
return GraphQLBoolean.parseLiteral(valueNode);
|
1153
|
-
} else if (valueNode.kind === 'FloatValue' && type.name === 'Float') {
|
1154
|
-
return GraphQLFloat.parseLiteral(valueNode);
|
1155
|
-
} else if (valueNode.kind === 'IntValue' && (type.name === 'Int' || type.name === 'ID' || type.name === 'Float')) {
|
1156
|
-
return GraphQLInt.parseLiteral(valueNode);
|
1157
|
-
} else if (valueNode.kind === 'StringValue' && (type.name === 'String' || type.name === 'ID')) {
|
1158
|
-
return GraphQLString.parseLiteral(valueNode);
|
1159
|
-
} else if (!isDefaultScalar(type.name)) {
|
1160
|
-
return valueFromASTUntyped(valueNode);
|
1161
|
-
}
|
1162
|
-
}
|
1163
|
-
};
|
1164
|
-
|
1165
|
-
_proto4.parseValue = function parseValue(type, value) {
|
1166
|
-
if (type instanceof EnumType) {
|
1167
|
-
return type.values.includes(value) ? value : undefined;
|
1168
|
-
} else if (type instanceof ScalarType) {
|
1169
|
-
switch (type.name) {
|
1170
|
-
case 'Boolean':
|
1171
|
-
return GraphQLBoolean.parseValue(value);
|
1172
|
-
|
1173
|
-
case 'Float':
|
1174
|
-
return GraphQLFloat.parseValue(value);
|
1175
|
-
|
1176
|
-
case 'Int':
|
1177
|
-
return GraphQLInt.parseValue(value);
|
1178
|
-
|
1179
|
-
case 'String':
|
1180
|
-
return GraphQLString.parseValue(value);
|
1181
|
-
|
1182
|
-
case 'ID':
|
1183
|
-
return GraphQLID.parseValue(value);
|
1184
|
-
|
1185
|
-
default:
|
1186
|
-
return value;
|
1187
|
-
}
|
1188
|
-
}
|
1189
|
-
};
|
1190
|
-
|
1191
|
-
_proto4.serialize = function serialize(type, value) {
|
1192
|
-
if (type instanceof EnumType) {
|
1193
|
-
return type.values.includes(value) ? value : undefined;
|
1194
|
-
} else if (type instanceof ScalarType) {
|
1195
|
-
switch (type.name) {
|
1196
|
-
case 'Boolean':
|
1197
|
-
return GraphQLBoolean.serialize(value);
|
1198
|
-
|
1199
|
-
case 'Float':
|
1200
|
-
return GraphQLFloat.serialize(value);
|
1201
|
-
|
1202
|
-
case 'Int':
|
1203
|
-
return GraphQLInt.serialize(value);
|
1204
|
-
|
1205
|
-
case 'String':
|
1206
|
-
return GraphQLString.serialize(value);
|
1207
|
-
|
1208
|
-
case 'ID':
|
1209
|
-
return GraphQLID.serialize(value);
|
1210
|
-
|
1211
|
-
default:
|
1212
|
-
return value;
|
1213
|
-
}
|
1214
|
-
}
|
1215
|
-
};
|
1216
|
-
|
1217
|
-
_proto4.getDirectives = function getDirectives() {
|
1218
|
-
return Array.from(this._directiveMap.values());
|
1219
|
-
};
|
1220
|
-
|
1221
|
-
_proto4.getDirective = function getDirective(directiveName) {
|
1222
|
-
return this._directiveMap.get(directiveName);
|
1223
|
-
};
|
1224
|
-
|
1225
|
-
_proto4.isServerType = function isServerType(type) {
|
1226
|
-
var unwrapped = unwrap(type);
|
1227
|
-
return unwrapped.isClient === false;
|
1228
|
-
};
|
1229
|
-
|
1230
|
-
_proto4.isServerField = function isServerField(field) {
|
1231
|
-
return field.isClient === false;
|
1232
|
-
};
|
1233
|
-
|
1234
|
-
_proto4.isServerDirective = function isServerDirective(directiveName) {
|
1235
|
-
var directive = this._directiveMap.get(directiveName);
|
1236
|
-
|
1237
|
-
return (directive === null || directive === void 0 ? void 0 : directive.isClient) === false;
|
1238
|
-
};
|
1239
|
-
|
1240
|
-
_proto4.isServerDefinedField = function isServerDefinedField(type, field) {
|
1241
|
-
return this.isAbstractType(type) && field.directives.some(function (_ref) {
|
1242
|
-
var name = _ref.name;
|
1243
|
-
return name === 'fixme_fat_interface';
|
1244
|
-
}) || this.hasField(type, field.name) && this.isServerField(this.expectField(type, field.name));
|
1245
|
-
};
|
1246
|
-
|
1247
|
-
_proto4.isClientDefinedField = function isClientDefinedField(type, field) {
|
1248
|
-
return !this.isServerDefinedField(type, field);
|
1249
|
-
};
|
1250
|
-
|
1251
|
-
_proto4.extend = function extend(extensions) {
|
1252
|
-
var doc = Array.isArray(extensions) ? parse(extensions.join('\n')) : extensions;
|
1253
|
-
var schemaExtensions = [];
|
1254
|
-
doc.definitions.forEach(function (definition) {
|
1255
|
-
if (isSchemaDefinitionAST(definition)) {
|
1256
|
-
schemaExtensions.push(definition);
|
1257
|
-
}
|
1258
|
-
});
|
1259
|
-
|
1260
|
-
if (schemaExtensions.length > 0) {
|
1261
|
-
return new Schema(this._typeMap.extend(schemaExtensions));
|
1262
|
-
}
|
1263
|
-
|
1264
|
-
return this;
|
1265
|
-
};
|
1266
|
-
|
1267
|
-
return Schema;
|
1268
|
-
}();
|
1269
|
-
|
1270
|
-
var TypeMap = /*#__PURE__*/function () {
|
1271
|
-
function TypeMap(source, extensions) {
|
1272
|
-
this._types = new Map([['ID', new ScalarType('ID', false)], ['String', new ScalarType('String', false)], ['Boolean', new ScalarType('Boolean', false)], ['Float', new ScalarType('Float', false)], ['Int', new ScalarType('Int', false)]]);
|
1273
|
-
this._typeInterfaces = new Map();
|
1274
|
-
this._unionTypes = new Map();
|
1275
|
-
this._interfaceImplementations = new Map();
|
1276
|
-
this._fields = new Map();
|
1277
|
-
this._inputFields = new Map();
|
1278
|
-
this._directives = new Map([['include', {
|
1279
|
-
name: 'include',
|
1280
|
-
isClient: false,
|
1281
|
-
locations: ['FIELD', 'FRAGMENT_SPREAD', 'INLINE_FRAGMENT'],
|
1282
|
-
args: [{
|
1283
|
-
name: 'if',
|
1284
|
-
typeNode: parseType('Boolean!'),
|
1285
|
-
defaultValue: undefined
|
1286
|
-
}]
|
1287
|
-
}], ['skip', {
|
1288
|
-
name: 'skip',
|
1289
|
-
isClient: false,
|
1290
|
-
locations: ['FIELD', 'FRAGMENT_SPREAD', 'INLINE_FRAGMENT'],
|
1291
|
-
args: [{
|
1292
|
-
name: 'if',
|
1293
|
-
typeNode: parseType('Boolean!'),
|
1294
|
-
defaultValue: undefined
|
1295
|
-
}]
|
1296
|
-
}], ['deprecated', {
|
1297
|
-
name: 'deprecated',
|
1298
|
-
isClient: false,
|
1299
|
-
locations: ['FIELD_DEFINITION', 'ENUM_VALUE'],
|
1300
|
-
args: [{
|
1301
|
-
name: 'reason',
|
1302
|
-
typeNode: parseType('String'),
|
1303
|
-
defaultValue: {
|
1304
|
-
kind: 'StringValue',
|
1305
|
-
value: 'No longer supported'
|
1306
|
-
}
|
1307
|
-
}]
|
1308
|
-
}]]);
|
1309
|
-
this._queryTypeName = 'Query';
|
1310
|
-
this._mutationTypeName = 'Mutation';
|
1311
|
-
this._subscriptionTypeName = 'Subscription';
|
1312
|
-
this._source = source;
|
1313
|
-
this._extensions = extensions;
|
1314
|
-
this._fetchable = new Map();
|
1315
|
-
|
1316
|
-
this._parse(source);
|
1317
|
-
|
1318
|
-
this._extend(extensions);
|
1319
|
-
}
|
1320
|
-
|
1321
|
-
var _proto5 = TypeMap.prototype;
|
1322
|
-
|
1323
|
-
_proto5._parse = function _parse(source) {
|
1324
|
-
var _this5 = this;
|
1325
|
-
|
1326
|
-
var document = parse(source, {
|
1327
|
-
noLocation: true
|
1328
|
-
});
|
1329
|
-
document.definitions.forEach(function (definition) {
|
1330
|
-
switch (definition.kind) {
|
1331
|
-
case 'SchemaDefinition':
|
1332
|
-
{
|
1333
|
-
_this5._parseSchemaDefinition(definition);
|
1334
|
-
|
1335
|
-
break;
|
1336
|
-
}
|
1337
|
-
|
1338
|
-
case 'ScalarTypeDefinition':
|
1339
|
-
{
|
1340
|
-
_this5._parseScalarNode(definition, false);
|
1341
|
-
|
1342
|
-
break;
|
1343
|
-
}
|
1344
|
-
|
1345
|
-
case 'EnumTypeDefinition':
|
1346
|
-
{
|
1347
|
-
_this5._parseEnumNode(definition, false);
|
1348
|
-
|
1349
|
-
break;
|
1350
|
-
}
|
1351
|
-
|
1352
|
-
case 'ObjectTypeDefinition':
|
1353
|
-
{
|
1354
|
-
_this5._parseObjectTypeNode(definition, false);
|
1355
|
-
|
1356
|
-
break;
|
1357
|
-
}
|
1358
|
-
|
1359
|
-
case 'InputObjectTypeDefinition':
|
1360
|
-
{
|
1361
|
-
_this5._parseInputObjectTypeNode(definition, false);
|
1362
|
-
|
1363
|
-
break;
|
1364
|
-
}
|
1365
|
-
|
1366
|
-
case 'UnionTypeDefinition':
|
1367
|
-
{
|
1368
|
-
_this5._parseUnionNode(definition, false);
|
1369
|
-
|
1370
|
-
break;
|
1371
|
-
}
|
1372
|
-
|
1373
|
-
case 'InterfaceTypeDefinition':
|
1374
|
-
{
|
1375
|
-
_this5._parseInterfaceNode(definition, false);
|
1376
|
-
|
1377
|
-
break;
|
1378
|
-
}
|
1379
|
-
|
1380
|
-
case 'DirectiveDefinition':
|
1381
|
-
{
|
1382
|
-
_this5._parseDirective(definition, false);
|
1383
|
-
|
1384
|
-
break;
|
1385
|
-
}
|
1386
|
-
}
|
1387
|
-
});
|
1388
|
-
};
|
1389
|
-
|
1390
|
-
_proto5._parseSchemaDefinition = function _parseSchemaDefinition(node) {
|
1391
|
-
var _this6 = this;
|
1392
|
-
|
1393
|
-
node.operationTypes.forEach(function (operationType) {
|
1394
|
-
switch (operationType.operation) {
|
1395
|
-
case 'query':
|
1396
|
-
_this6._queryTypeName = operationType.type.name.value;
|
1397
|
-
break;
|
1398
|
-
|
1399
|
-
case 'mutation':
|
1400
|
-
_this6._mutationTypeName = operationType.type.name.value;
|
1401
|
-
break;
|
1402
|
-
|
1403
|
-
case 'subscription':
|
1404
|
-
_this6._subscriptionTypeName = operationType.type.name.value;
|
1405
|
-
break;
|
1406
|
-
}
|
1407
|
-
});
|
1408
|
-
};
|
1409
|
-
|
1410
|
-
_proto5._parseScalarNode = function _parseScalarNode(node, isClient) {
|
1411
|
-
var name = node.name.value;
|
1412
|
-
|
1413
|
-
if (!isDefaultScalar(name) && this._types.has(name)) {
|
1414
|
-
throw createCompilerError("_parseScalarNode: Duplicate definition for type ".concat(name, "."), null, [node]);
|
1415
|
-
}
|
1416
|
-
|
1417
|
-
this._types.set(name, new ScalarType(name, isClient));
|
1418
|
-
};
|
1419
|
-
|
1420
|
-
_proto5._parseEnumNode = function _parseEnumNode(node, isClient) {
|
1421
|
-
var name = node.name.value;
|
1422
|
-
|
1423
|
-
if (this._types.has(name)) {
|
1424
|
-
throw createCompilerError("_parseEnumNode: Duplicate definition for type ".concat(name, "."), null, [node]);
|
1425
|
-
} // SDL doesn't have information about the actual ENUM values
|
1426
|
-
|
1427
|
-
|
1428
|
-
var values = node.values ? node.values.map(function (value) {
|
1429
|
-
return value.name.value;
|
1430
|
-
}) : [];
|
1431
|
-
|
1432
|
-
this._types.set(name, new EnumType(name, values, isClient));
|
1433
|
-
};
|
1434
|
-
|
1435
|
-
_proto5._parseObjectTypeNode = function _parseObjectTypeNode(node, isClient) {
|
1436
|
-
var _this7 = this;
|
1437
|
-
|
1438
|
-
var _this$_types$get;
|
1439
|
-
|
1440
|
-
var name = node.name.value; // Objects may be created by _parseUnionNode
|
1441
|
-
|
1442
|
-
var type = (_this$_types$get = this._types.get(name)) !== null && _this$_types$get !== void 0 ? _this$_types$get : new ObjectType(name, isClient);
|
1443
|
-
|
1444
|
-
if (!(type instanceof ObjectType)) {
|
1445
|
-
throw createCompilerError("_parseObjectTypeNode: Expected object type, got ".concat(String(type)), null, [node]);
|
1446
|
-
}
|
1447
|
-
|
1448
|
-
if (type.isClient !== isClient) {
|
1449
|
-
throw createCompilerError("_parseObjectTypeNode: Cannot create object type '".concat(name, "' defined as a client type."), null, [node]);
|
1450
|
-
}
|
1451
|
-
|
1452
|
-
var typeInterfaces = [];
|
1453
|
-
node.interfaces && node.interfaces.forEach(function (interfaceTypeNode) {
|
1454
|
-
var _this$_interfaceImple;
|
1455
|
-
|
1456
|
-
var interfaceName = interfaceTypeNode.name.value;
|
1457
|
-
|
1458
|
-
var interfaceType = _this7._types.get(interfaceName);
|
1459
|
-
|
1460
|
-
if (!interfaceType) {
|
1461
|
-
interfaceType = new InterfaceType(interfaceName, isClient);
|
1462
|
-
|
1463
|
-
_this7._types.set(interfaceName, interfaceType);
|
1464
|
-
}
|
1465
|
-
|
1466
|
-
if (!(interfaceType instanceof InterfaceType)) {
|
1467
|
-
throw createCompilerError('_parseObjectTypeNode: Expected interface type', null, [interfaceTypeNode]);
|
1468
|
-
}
|
1469
|
-
|
1470
|
-
var implementations = (_this$_interfaceImple = _this7._interfaceImplementations.get(interfaceType)) !== null && _this$_interfaceImple !== void 0 ? _this$_interfaceImple : new Set();
|
1471
|
-
implementations.add(type);
|
1472
|
-
|
1473
|
-
_this7._interfaceImplementations.set(interfaceType, implementations);
|
1474
|
-
|
1475
|
-
typeInterfaces.push(interfaceType);
|
1476
|
-
});
|
1477
|
-
var fetchable = null;
|
1478
|
-
node.directives && node.directives.forEach(function (directiveNode) {
|
1479
|
-
if (directiveNode.name.value === 'fetchable') {
|
1480
|
-
var field_name_arg = directiveNode.arguments && directiveNode.arguments.find(function (arg) {
|
1481
|
-
return arg.name.value === 'field_name';
|
1482
|
-
});
|
1483
|
-
|
1484
|
-
if (field_name_arg != null && field_name_arg.value.kind === 'StringValue') {
|
1485
|
-
fetchable = {
|
1486
|
-
field_name: field_name_arg.value.value
|
1487
|
-
};
|
1488
|
-
}
|
1489
|
-
}
|
1490
|
-
});
|
1491
|
-
|
1492
|
-
this._typeInterfaces.set(type, typeInterfaces);
|
1493
|
-
|
1494
|
-
this._types.set(name, type);
|
1495
|
-
|
1496
|
-
if (fetchable != null) {
|
1497
|
-
this._fetchable.set(type, fetchable);
|
1498
|
-
}
|
1499
|
-
|
1500
|
-
node.fields && this._handleTypeFieldsStrict(type, node.fields, isClient);
|
1501
|
-
};
|
1502
|
-
|
1503
|
-
_proto5._parseInputObjectTypeNode = function _parseInputObjectTypeNode(node, isClient) {
|
1504
|
-
var name = node.name.value;
|
1505
|
-
|
1506
|
-
if (this._types.has(name)) {
|
1507
|
-
throw createCompilerError('_parseInputObjectTypeNode: Unable to parse schema file. Duplicate definition for object type', null, [node]);
|
1508
|
-
}
|
1509
|
-
|
1510
|
-
var type = new InputObjectType(name, isClient);
|
1511
|
-
|
1512
|
-
this._types.set(name, type);
|
1513
|
-
|
1514
|
-
this._parseInputObjectFields(type, node);
|
1515
|
-
};
|
1516
|
-
|
1517
|
-
_proto5._parseUnionNode = function _parseUnionNode(node, isClient) {
|
1518
|
-
var _this8 = this;
|
1519
|
-
|
1520
|
-
var name = node.name.value;
|
1521
|
-
|
1522
|
-
if (this._types.has(name)) {
|
1523
|
-
throw createCompilerError('_parseUnionNode: Unable to parse schema file. Duplicate definition for object type', null, [node]);
|
1524
|
-
}
|
1525
|
-
|
1526
|
-
var union = new UnionType(name, isClient);
|
1527
|
-
|
1528
|
-
this._types.set(name, union);
|
1529
|
-
|
1530
|
-
this._unionTypes.set(union, new Set(node.types ? node.types.map(function (typeInUnion) {
|
1531
|
-
var _this$_types$get2;
|
1532
|
-
|
1533
|
-
var typeInUnionName = typeInUnion.name.value;
|
1534
|
-
var object = (_this$_types$get2 = _this8._types.get(typeInUnionName)) !== null && _this$_types$get2 !== void 0 ? _this$_types$get2 : new ObjectType(typeInUnionName, false);
|
1535
|
-
|
1536
|
-
if (!(object instanceof ObjectType)) {
|
1537
|
-
throw createCompilerError('_parseUnionNode: Expected object type', null, [typeInUnion]);
|
1538
|
-
}
|
1539
|
-
|
1540
|
-
_this8._types.set(typeInUnionName, object);
|
1541
|
-
|
1542
|
-
return object;
|
1543
|
-
}) : []));
|
1544
|
-
};
|
1545
|
-
|
1546
|
-
_proto5._parseInterfaceNode = function _parseInterfaceNode(node, isClient) {
|
1547
|
-
var name = node.name.value;
|
1548
|
-
|
1549
|
-
var type = this._types.get(name);
|
1550
|
-
|
1551
|
-
if (!type) {
|
1552
|
-
type = new InterfaceType(name, isClient);
|
1553
|
-
|
1554
|
-
this._types.set(name, type);
|
1555
|
-
}
|
1556
|
-
|
1557
|
-
if (!(type instanceof InterfaceType)) {
|
1558
|
-
throw createCompilerError("_parseInterfaceNode: Expected interface type. Got ".concat(String(type)), null, [node]);
|
1559
|
-
}
|
1560
|
-
|
1561
|
-
if (type.isClient !== isClient) {
|
1562
|
-
throw createCompilerError("_parseInterfaceNode: Cannot create interface '".concat(name, "' defined as a client interface"), null, [node]);
|
1563
|
-
}
|
1564
|
-
|
1565
|
-
node.fields && this._handleTypeFieldsStrict(type, node.fields, isClient);
|
1566
|
-
};
|
1567
|
-
|
1568
|
-
_proto5._handleTypeFieldsStrict = function _handleTypeFieldsStrict(type, fields, isClient) {
|
1569
|
-
if (this._fields.has(type)) {
|
1570
|
-
throw createCompilerError('_handleTypeFieldsStrict: Unable to parse schema file. Duplicate definition for object type');
|
1571
|
-
}
|
1572
|
-
|
1573
|
-
this._handleTypeFields(type, fields, isClient);
|
1574
|
-
};
|
1575
|
-
|
1576
|
-
_proto5._handleTypeFields = function _handleTypeFields(type, fields, isClient) {
|
1577
|
-
var _this$_fields$get;
|
1578
|
-
|
1579
|
-
var fieldsMap = (_this$_fields$get = this._fields.get(type)) !== null && _this$_fields$get !== void 0 ? _this$_fields$get : new Map();
|
1580
|
-
fields.forEach(function (fieldNode) {
|
1581
|
-
var fieldName = fieldNode.name.value;
|
1582
|
-
|
1583
|
-
if (fieldsMap.has(fieldName)) {
|
1584
|
-
throw createCompilerError("_handleTypeFields: Duplicate definition for field '".concat(fieldName, "'."));
|
1585
|
-
}
|
1586
|
-
|
1587
|
-
fieldsMap.set(fieldName, {
|
1588
|
-
arguments: fieldNode.arguments ? fieldNode.arguments.map(function (arg) {
|
1589
|
-
return {
|
1590
|
-
name: arg.name.value,
|
1591
|
-
typeNode: arg.type,
|
1592
|
-
defaultValue: arg.defaultValue
|
1593
|
-
};
|
1594
|
-
}) : [],
|
1595
|
-
directives: fieldNode.directives ? fieldNode.directives.map(function (directive) {
|
1596
|
-
return {
|
1597
|
-
name: directive.name.value,
|
1598
|
-
args: directive.arguments ? directive.arguments.map(function (arg) {
|
1599
|
-
return {
|
1600
|
-
name: arg.name.value,
|
1601
|
-
value: arg.value
|
1602
|
-
};
|
1603
|
-
}) : []
|
1604
|
-
};
|
1605
|
-
}) : null,
|
1606
|
-
type: fieldNode.type,
|
1607
|
-
isClient: isClient
|
1608
|
-
});
|
1609
|
-
});
|
1610
|
-
|
1611
|
-
this._fields.set(type, fieldsMap);
|
1612
|
-
};
|
1613
|
-
|
1614
|
-
_proto5._parseInputObjectFields = function _parseInputObjectFields(type, node) {
|
1615
|
-
if (this._inputFields.has(type)) {
|
1616
|
-
throw createCompilerError('_parseInputObjectFields: Unable to parse schema file. Duplicate definition for type', null, [node]);
|
1617
|
-
}
|
1618
|
-
|
1619
|
-
var fields = new Map();
|
1620
|
-
|
1621
|
-
if (node.fields) {
|
1622
|
-
node.fields.forEach(function (fieldNode) {
|
1623
|
-
fields.set(fieldNode.name.value, fieldNode.type);
|
1624
|
-
});
|
1625
|
-
}
|
1626
|
-
|
1627
|
-
this._inputFields.set(type, fields);
|
1628
|
-
};
|
1629
|
-
|
1630
|
-
_proto5._parseDirective = function _parseDirective(node, isClient) {
|
1631
|
-
var name = node.name.value;
|
1632
|
-
|
1633
|
-
this._directives.set(name, {
|
1634
|
-
name: name,
|
1635
|
-
args: node.arguments ? node.arguments.map(function (arg) {
|
1636
|
-
return {
|
1637
|
-
name: arg.name.value,
|
1638
|
-
typeNode: arg.type,
|
1639
|
-
defaultValue: arg.defaultValue
|
1640
|
-
};
|
1641
|
-
}) : [],
|
1642
|
-
locations: node.locations.map(function (location) {
|
1643
|
-
switch (location.value) {
|
1644
|
-
case 'QUERY':
|
1645
|
-
case 'MUTATION':
|
1646
|
-
case 'SUBSCRIPTION':
|
1647
|
-
case 'FIELD':
|
1648
|
-
case 'FRAGMENT_DEFINITION':
|
1649
|
-
case 'FRAGMENT_SPREAD':
|
1650
|
-
case 'INLINE_FRAGMENT':
|
1651
|
-
case 'VARIABLE_DEFINITION':
|
1652
|
-
case 'SCHEMA':
|
1653
|
-
case 'SCALAR':
|
1654
|
-
case 'OBJECT':
|
1655
|
-
case 'FIELD_DEFINITION':
|
1656
|
-
case 'ARGUMENT_DEFINITION':
|
1657
|
-
case 'INTERFACE':
|
1658
|
-
case 'UNION':
|
1659
|
-
case 'ENUM':
|
1660
|
-
case 'ENUM_VALUE':
|
1661
|
-
case 'INPUT_OBJECT':
|
1662
|
-
case 'INPUT_FIELD_DEFINITION':
|
1663
|
-
return location.value;
|
1664
|
-
|
1665
|
-
default:
|
1666
|
-
throw createCompilerError('Invalid directive location');
|
1667
|
-
}
|
1668
|
-
}),
|
1669
|
-
isClient: isClient
|
1670
|
-
});
|
1671
|
-
};
|
1672
|
-
|
1673
|
-
_proto5._parseObjectTypeExtension = function _parseObjectTypeExtension(node) {
|
1674
|
-
var type = this._types.get(node.name.value);
|
1675
|
-
|
1676
|
-
if (!(type instanceof ObjectType)) {
|
1677
|
-
throw createCompilerError("_parseObjectTypeExtension: Expected to find type with the name '".concat(node.name.value, "'"), null, [node]);
|
1678
|
-
}
|
1679
|
-
|
1680
|
-
node.fields && this._handleTypeFields(type, node.fields, true
|
1681
|
-
/** client fields */
|
1682
|
-
);
|
1683
|
-
};
|
1684
|
-
|
1685
|
-
_proto5._parseInterfaceTypeExtension = function _parseInterfaceTypeExtension(node) {
|
1686
|
-
var type = this._types.get(node.name.value);
|
1687
|
-
|
1688
|
-
if (!(type instanceof InterfaceType)) {
|
1689
|
-
throw createCompilerError('_parseInterfaceTypeExtension: Expected to have an interface type');
|
1690
|
-
}
|
1691
|
-
|
1692
|
-
node.fields && this._handleTypeFields(type, node.fields, true);
|
1693
|
-
};
|
1694
|
-
|
1695
|
-
_proto5._extend = function _extend(extensions) {
|
1696
|
-
var _this9 = this;
|
1697
|
-
|
1698
|
-
extensions.forEach(function (definition) {
|
1699
|
-
if (definition.kind === 'ObjectTypeDefinition') {
|
1700
|
-
_this9._parseObjectTypeNode(definition, true);
|
1701
|
-
} else if (definition.kind === 'InterfaceTypeDefinition') {
|
1702
|
-
_this9._parseInterfaceNode(definition, true);
|
1703
|
-
} else if (definition.kind === 'ScalarTypeDefinition') {
|
1704
|
-
_this9._parseScalarNode(definition, true);
|
1705
|
-
} else if (definition.kind === 'EnumTypeDefinition') {
|
1706
|
-
_this9._parseEnumNode(definition, true);
|
1707
|
-
} else if (definition.kind === 'InterfaceTypeExtension') {
|
1708
|
-
_this9._parseInterfaceTypeExtension(definition);
|
1709
|
-
} else if (definition.kind === 'ObjectTypeExtension') {
|
1710
|
-
_this9._parseObjectTypeExtension(definition);
|
1711
|
-
} else if (definition.kind === 'DirectiveDefinition') {
|
1712
|
-
_this9._parseDirective(definition, true
|
1713
|
-
/* client directive */
|
1714
|
-
);
|
1715
|
-
} else {
|
1716
|
-
throw createCompilerError("Unexpected extension kind: '".concat(definition.kind, "'"), null, [definition]);
|
1717
|
-
}
|
1718
|
-
});
|
1719
|
-
};
|
1720
|
-
|
1721
|
-
_proto5.getTypes = function getTypes() {
|
1722
|
-
return Array.from(this._types.values());
|
1723
|
-
};
|
1724
|
-
|
1725
|
-
_proto5.getTypeByName = function getTypeByName(typename) {
|
1726
|
-
return this._types.get(typename);
|
1727
|
-
};
|
1728
|
-
|
1729
|
-
_proto5.getInterfaces = function getInterfaces(type) {
|
1730
|
-
var _this$_typeInterfaces;
|
1731
|
-
|
1732
|
-
return (_this$_typeInterfaces = this._typeInterfaces.get(type)) !== null && _this$_typeInterfaces !== void 0 ? _this$_typeInterfaces : [];
|
1733
|
-
};
|
1734
|
-
|
1735
|
-
_proto5.getPossibleTypeSet = function getPossibleTypeSet(type) {
|
1736
|
-
var set;
|
1737
|
-
|
1738
|
-
if (type instanceof InterfaceType) {
|
1739
|
-
var _this$_interfaceImple2;
|
1740
|
-
|
1741
|
-
set = (_this$_interfaceImple2 = this._interfaceImplementations.get(type)) !== null && _this$_interfaceImple2 !== void 0 ? _this$_interfaceImple2 : new Set();
|
1742
|
-
} else if (type instanceof UnionType) {
|
1743
|
-
var _this$_unionTypes$get;
|
1744
|
-
|
1745
|
-
set = (_this$_unionTypes$get = this._unionTypes.get(type)) !== null && _this$_unionTypes$get !== void 0 ? _this$_unionTypes$get : new Set();
|
1746
|
-
} else {
|
1747
|
-
throw createCompilerError('Invalid type supplied to "getPossibleTypeSet"');
|
1748
|
-
}
|
1749
|
-
|
1750
|
-
if (!set) {
|
1751
|
-
throw createCompilerError("Unable to find possible types for ".concat(type.name));
|
1752
|
-
}
|
1753
|
-
|
1754
|
-
return set;
|
1755
|
-
};
|
1756
|
-
|
1757
|
-
_proto5.getFetchableFieldName = function getFetchableFieldName(type) {
|
1758
|
-
var _this$_fetchable$get$, _this$_fetchable$get;
|
1759
|
-
|
1760
|
-
return (_this$_fetchable$get$ = (_this$_fetchable$get = this._fetchable.get(type)) === null || _this$_fetchable$get === void 0 ? void 0 : _this$_fetchable$get.field_name) !== null && _this$_fetchable$get$ !== void 0 ? _this$_fetchable$get$ : null;
|
1761
|
-
};
|
1762
|
-
|
1763
|
-
_proto5.getQueryType = function getQueryType() {
|
1764
|
-
return this._types.get(this._queryTypeName);
|
1765
|
-
};
|
1766
|
-
|
1767
|
-
_proto5.getMutationType = function getMutationType() {
|
1768
|
-
return this._types.get(this._mutationTypeName);
|
1769
|
-
};
|
1770
|
-
|
1771
|
-
_proto5.getSubscriptionType = function getSubscriptionType() {
|
1772
|
-
return this._types.get(this._subscriptionTypeName);
|
1773
|
-
};
|
1774
|
-
|
1775
|
-
_proto5.getField = function getField(type, fieldName) {
|
1776
|
-
var fields = this._fields.get(type);
|
1777
|
-
|
1778
|
-
if (fields) {
|
1779
|
-
return fields.get(fieldName);
|
1780
|
-
}
|
1781
|
-
};
|
1782
|
-
|
1783
|
-
_proto5.getFieldMap = function getFieldMap(type) {
|
1784
|
-
return this._fields.get(type);
|
1785
|
-
};
|
1786
|
-
|
1787
|
-
_proto5.getInputField = function getInputField(type, fieldName) {
|
1788
|
-
var inputFields = this._inputFields.get(type);
|
1789
|
-
|
1790
|
-
if (inputFields) {
|
1791
|
-
return inputFields.get(fieldName);
|
1792
|
-
}
|
1793
|
-
};
|
1794
|
-
|
1795
|
-
_proto5.getInputFieldMap = function getInputFieldMap(type) {
|
1796
|
-
return this._inputFields.get(type);
|
1797
|
-
};
|
1798
|
-
|
1799
|
-
_proto5.getDirectives = function getDirectives() {
|
1800
|
-
return Array.from(this._directives.values());
|
1801
|
-
};
|
1802
|
-
|
1803
|
-
_proto5.extend = function extend(extensions) {
|
1804
|
-
return new TypeMap(this._source, this._extensions.concat(extensions));
|
1805
|
-
};
|
1806
|
-
|
1807
|
-
return TypeMap;
|
1808
|
-
}();
|
1809
|
-
|
1810
|
-
function create(baseSchema, schemaExtensionDocuments, schemaExtensions) {
|
1811
|
-
var extensions = [];
|
1812
|
-
schemaExtensions && schemaExtensions.forEach(function (source) {
|
1813
|
-
var doc = parse(source, {
|
1814
|
-
noLocation: true
|
1815
|
-
});
|
1816
|
-
doc.definitions.forEach(function (definition) {
|
1817
|
-
if (isSchemaDefinitionAST(definition)) {
|
1818
|
-
extensions.push(definition);
|
1819
|
-
}
|
1820
|
-
});
|
1821
|
-
});
|
1822
|
-
schemaExtensionDocuments && schemaExtensionDocuments.forEach(function (doc) {
|
1823
|
-
doc.definitions.forEach(function (definition) {
|
1824
|
-
if (isSchemaDefinitionAST(definition)) {
|
1825
|
-
extensions.push(definition);
|
1826
|
-
}
|
1827
|
-
});
|
1828
|
-
});
|
1829
|
-
return new Schema(new TypeMap(baseSchema, extensions));
|
1830
|
-
}
|
1831
|
-
|
1832
|
-
function parseInputArgumentDefinitions(schema, args) {
|
1833
|
-
return args.map(function (arg) {
|
1834
|
-
var argType = schema.assertInputType(schema.expectTypeFromAST(arg.typeNode));
|
1835
|
-
var defaultValue;
|
1836
|
-
var defaultValueNode = arg.defaultValue;
|
1837
|
-
|
1838
|
-
if (defaultValueNode != null) {
|
1839
|
-
var nullableType = schema.getNullableType(argType);
|
1840
|
-
var isNullable = schema.isNonNull(argType) === false;
|
1841
|
-
|
1842
|
-
if (isNullable && defaultValueNode.kind === 'NullValue') {
|
1843
|
-
defaultValue = null;
|
1844
|
-
} else {
|
1845
|
-
if (nullableType instanceof ScalarType || nullableType instanceof EnumType) {
|
1846
|
-
defaultValue = schema.parseLiteral(nullableType, defaultValueNode);
|
1847
|
-
} else if (nullableType instanceof List && defaultValueNode.kind === 'ListValue' || nullableType instanceof InputObjectType && defaultValueNode.kind === 'ObjectValue') {
|
1848
|
-
defaultValue = valueFromASTUntyped(defaultValueNode);
|
1849
|
-
}
|
1850
|
-
}
|
1851
|
-
|
1852
|
-
if (defaultValue === undefined) {
|
1853
|
-
throw createCompilerError("parseInputArgumentDefinitions: Unexpected default value: ".concat(String(defaultValueNode), ". Expected to have a value of type ").concat(String(nullableType), "."));
|
1854
|
-
}
|
1855
|
-
}
|
1856
|
-
|
1857
|
-
return {
|
1858
|
-
name: arg.name,
|
1859
|
-
type: argType,
|
1860
|
-
defaultValue: defaultValue
|
1861
|
-
};
|
1862
|
-
});
|
1863
|
-
}
|
1864
|
-
|
1865
|
-
function parseInputArgumentDefinitionsMap(schema, args) {
|
1866
|
-
return new Map(parseInputArgumentDefinitions(schema, args).map(function (arg) {
|
1867
|
-
return [arg.name, arg];
|
1868
|
-
}));
|
1869
|
-
}
|
1870
|
-
|
1871
|
-
function isDefaultScalar(name) {
|
1872
|
-
return new Set(['ID', 'String', 'Boolean', 'Int', 'Float']).has(name);
|
1873
|
-
}
|
1874
|
-
|
1875
|
-
module.exports = {
|
1876
|
-
create: create
|
1877
|
-
};
|