relay-compiler 1.3.0 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE +16 -26
- package/bin/relay-compiler +7348 -5939
- package/index.js +3 -6
- package/lib/{FileParser.js → ASTCache.js} +17 -14
- package/lib/ASTConvert.js +84 -70
- package/lib/CodegenDirectory.js +122 -28
- package/lib/{RelayCodegenRunner.js → CodegenRunner.js} +110 -186
- package/lib/CodegenTypes.js +12 -0
- package/lib/{RelayCodegenWatcher.js → CodegenWatcher.js} +53 -43
- package/lib/DefaultHandleKey.js +2 -4
- package/lib/DotGraphQLParser.js +27 -0
- package/lib/FilterDirectivesTransform.js +11 -11
- package/lib/FindGraphQLTags.js +33 -52
- package/lib/FlattenTransform.js +197 -0
- package/lib/GraphQLCompilerContext.js +158 -0
- package/lib/GraphQLCompilerProfiler.js +271 -0
- package/lib/GraphQLCompilerPublic.js +27 -22
- package/lib/GraphQLCompilerUserError.js +26 -0
- package/lib/GraphQLConsoleReporter.js +58 -0
- package/lib/GraphQLIR.js +12 -0
- package/lib/{RelayPrinter.js → GraphQLIRPrinter.js} +42 -38
- package/lib/{RelayIRTransformer.js → GraphQLIRTransformer.js} +47 -38
- package/lib/GraphQLIRTransforms.js +6 -15
- package/lib/{RelayIRVisitor.js → GraphQLIRVisitor.js} +7 -6
- package/lib/GraphQLMultiReporter.js +50 -0
- package/lib/GraphQLParser.js +743 -0
- package/lib/GraphQLReporter.js +12 -0
- package/lib/GraphQLSchemaUtils.js +10 -36
- package/lib/GraphQLValidator.js +13 -15
- package/lib/{RelayWatchmanClient.js → GraphQLWatchmanClient.js} +15 -17
- package/lib/InlineFragmentsTransform.js +48 -0
- package/lib/PatchedBabelGenerator.js +58 -0
- package/lib/RelayApplyFragmentArgumentTransform.js +37 -18
- package/lib/RelayCodeGenerator.js +130 -60
- package/lib/RelayCompilerBin.js +80 -35
- package/lib/RelayCompilerCache.js +18 -11
- package/lib/RelayCompilerPublic.js +24 -10
- package/lib/RelayCompilerScope.js +2 -4
- package/lib/RelayConcreteNode.js +31 -14
- package/lib/RelayConnectionConstants.js +2 -4
- package/lib/RelayConnectionTransform.js +34 -38
- package/lib/RelayDefaultHandleKey.js +2 -4
- package/lib/RelayDeferrableFragmentTransform.js +464 -0
- package/lib/RelayError.js +2 -6
- package/lib/RelayFieldHandleTransform.js +15 -11
- package/lib/RelayFileWriter.js +119 -98
- package/lib/RelayFlowBabelFactories.js +113 -0
- package/lib/RelayFlowGenerator.js +180 -200
- package/lib/RelayFlowTypeTransformers.js +109 -0
- package/lib/RelayGenerateIDFieldTransform.js +131 -0
- package/lib/RelayGenerateTypeNameTransform.js +75 -0
- package/lib/RelayGraphQLEnumsGenerator.js +65 -0
- package/lib/RelayIRTransforms.js +19 -23
- package/lib/RelayInternalTypes.js +2 -5
- package/lib/RelayInternals.js +2 -5
- package/lib/RelayJSModuleParser.js +64 -0
- package/lib/RelayMaskTransform.js +129 -0
- package/lib/RelayMetricsRecorder.js +9 -9
- package/lib/RelayMockRenderer.js +3 -8
- package/lib/RelayNetworkDebug.js +4 -7
- package/lib/RelayParser.js +28 -645
- package/lib/RelayProfiler.js +7 -7
- package/lib/RelayQueryCaching.js +2 -5
- package/lib/RelayRelayDirectiveTransform.js +47 -33
- package/lib/RelayRuntimeTypes.js +22 -0
- package/lib/RelayShallowMock.js +4 -7
- package/lib/RelaySkipHandleFieldTransform.js +13 -11
- package/lib/RelayTaskQueue.js +2 -5
- package/lib/RelayTransformUtils.js +20 -0
- package/lib/RelayTypes.js +2 -5
- package/lib/RelayValidator.js +9 -8
- package/lib/RelayViewerHandleTransform.js +22 -18
- package/lib/SkipClientFieldTransform.js +36 -53
- package/lib/SkipRedundantNodesTransform.js +22 -29
- package/lib/SkipUnreachableNodeTransform.js +57 -36
- package/lib/SourceControl.js +61 -0
- package/lib/StripUnusedVariablesTransform.js +86 -41
- package/lib/areEqualOSS.js +2 -4
- package/lib/compileRelayArtifacts.js +72 -0
- package/lib/dedent.js +2 -5
- package/lib/dedupeJSONStringify.js +132 -0
- package/lib/deepFreeze.js +3 -5
- package/lib/deepMergeAssignments.js +68 -0
- package/lib/filterContextForNode.js +5 -7
- package/lib/formatGeneratedModule.js +5 -9
- package/lib/{getIdentifierForRelayArgumentValue.js → getIdentifierForArgumentValue.js} +8 -10
- package/lib/getIdentifierForSelection.js +37 -0
- package/lib/getLiteralArgumentValues.js +26 -0
- package/lib/getModuleName.js +2 -4
- package/lib/getRelayHandleKey.js +2 -4
- package/lib/isCompatibleRelayFragmentType.js +2 -5
- package/lib/isEquivalentType.js +55 -0
- package/lib/isPromise.js +2 -5
- package/lib/isScalarAndEqual.js +3 -5
- package/lib/murmurHash.js +2 -4
- package/lib/nullthrowsOSS.js +7 -5
- package/lib/recycleNodesInto.js +2 -4
- package/lib/relayUnstableBatchedUpdates.js +2 -5
- package/lib/relayUnstableBatchedUpdates.native.js +2 -5
- package/lib/requestsForOperation.js +75 -0
- package/lib/simpleClone.js +2 -4
- package/lib/stableCopy.js +35 -0
- package/lib/testEditDistance.js +2 -5
- package/lib/throwFailedPromise.js +2 -5
- package/lib/writeRelayGeneratedFile.js +84 -50
- package/package.json +16 -15
- package/relay-compiler.js +7208 -5872
- package/relay-compiler.min.js +7200 -5867
- package/ARCHITECTURE.md +0 -94
- package/PATENTS +0 -33
- package/lib/AutoAliasTransform.js +0 -80
- package/lib/GraphQLFileParser.js +0 -27
- package/lib/GraphQLTextParser.js +0 -46
- package/lib/RelayCodegenTypes.js +0 -14
- package/lib/RelayCompiledTypes.js +0 -13
- package/lib/RelayCompiler.js +0 -144
- package/lib/RelayCompilerContext.js +0 -133
- package/lib/RelayCompilerUserError.js +0 -30
- package/lib/RelayConsoleReporter.js +0 -40
- package/lib/RelayFileIRParser.js +0 -66
- package/lib/RelayFlattenTransform.js +0 -278
- package/lib/RelayFlowParser.js +0 -188
- package/lib/RelayGenerateRequisiteFieldsTransform.js +0 -189
- package/lib/RelayIR.js +0 -14
- package/lib/RelayMultiReporter.js +0 -40
- package/lib/RelayReporter.js +0 -14
- package/lib/RelayTestSchema.js +0 -21
- package/lib/formatStorageKey.js +0 -37
- package/lib/getIdentifierForRelaySelection.js +0 -54
- package/lib/getRelayLiteralArgumentValues.js +0 -28
- package/lib/parseGraphQLText.js +0 -33
- package/lib/prettyStringify.js +0 -35
- package/lib/printFlowTypes.js +0 -282
- package/lib/stableJSONStringify.js +0 -45
- package/lib/stableJSONStringifyOSS.js +0 -44
- package/lib/transformInputObjectToIR.js +0 -85
- package/lib/writeLegacyFlowFile.js +0 -24
@@ -0,0 +1,743 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) 2013-present, Facebook, Inc.
|
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
|
+
* @providesModule GraphQLParser
|
8
|
+
*
|
9
|
+
* @format
|
10
|
+
*/
|
11
|
+
|
12
|
+
'use strict';
|
13
|
+
|
14
|
+
var _extends3 = _interopRequireDefault(require('babel-runtime/helpers/extends'));
|
15
|
+
|
16
|
+
var _classCallCheck3 = _interopRequireDefault(require('babel-runtime/helpers/classCallCheck'));
|
17
|
+
|
18
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
19
|
+
|
20
|
+
var _require = require('./DefaultHandleKey'),
|
21
|
+
DEFAULT_HANDLE_KEY = _require.DEFAULT_HANDLE_KEY;
|
22
|
+
|
23
|
+
var _require2 = require('./GraphQLSchemaUtils'),
|
24
|
+
getNullableType = _require2.getNullableType,
|
25
|
+
getRawType = _require2.getRawType,
|
26
|
+
getTypeFromAST = _require2.getTypeFromAST,
|
27
|
+
isExecutableDefinitionAST = _require2.isExecutableDefinitionAST;
|
28
|
+
|
29
|
+
var _require3 = require('graphql'),
|
30
|
+
assertCompositeType = _require3.assertCompositeType,
|
31
|
+
assertInputType = _require3.assertInputType,
|
32
|
+
assertOutputType = _require3.assertOutputType,
|
33
|
+
extendSchema = _require3.extendSchema,
|
34
|
+
getNamedType = _require3.getNamedType,
|
35
|
+
GraphQLEnumType = _require3.GraphQLEnumType,
|
36
|
+
GraphQLInputObjectType = _require3.GraphQLInputObjectType,
|
37
|
+
GraphQLInterfaceType = _require3.GraphQLInterfaceType,
|
38
|
+
GraphQLList = _require3.GraphQLList,
|
39
|
+
GraphQLObjectType = _require3.GraphQLObjectType,
|
40
|
+
GraphQLScalarType = _require3.GraphQLScalarType,
|
41
|
+
GraphQLUnionType = _require3.GraphQLUnionType,
|
42
|
+
isLeafType = _require3.isLeafType,
|
43
|
+
isTypeSubTypeOf = _require3.isTypeSubTypeOf,
|
44
|
+
_parse = _require3.parse,
|
45
|
+
parseType = _require3.parseType,
|
46
|
+
SchemaMetaFieldDef = _require3.SchemaMetaFieldDef,
|
47
|
+
Source = _require3.Source,
|
48
|
+
TypeMetaFieldDef = _require3.TypeMetaFieldDef,
|
49
|
+
TypeNameMetaFieldDef = _require3.TypeNameMetaFieldDef;
|
50
|
+
|
51
|
+
var ARGUMENT_DEFINITIONS = 'argumentDefinitions';
|
52
|
+
var ARGUMENTS = 'arguments';
|
53
|
+
|
54
|
+
/**
|
55
|
+
* @internal
|
56
|
+
*
|
57
|
+
* This directive is not intended for use by developers directly. To set a field
|
58
|
+
* handle in product code use a compiler plugin.
|
59
|
+
*/
|
60
|
+
var CLIENT_FIELD = '__clientField';
|
61
|
+
var CLIENT_FIELD_HANDLE = 'handle';
|
62
|
+
var CLIENT_FIELD_KEY = 'key';
|
63
|
+
var CLIENT_FIELD_FILTERS = 'filters';
|
64
|
+
|
65
|
+
var INCLUDE = 'include';
|
66
|
+
var SKIP = 'skip';
|
67
|
+
var IF = 'if';
|
68
|
+
|
69
|
+
var GraphQLParser = function () {
|
70
|
+
GraphQLParser.parse = function parse(schema, text, filename) {
|
71
|
+
var _this = this;
|
72
|
+
|
73
|
+
var ast = _parse(new Source(text, filename));
|
74
|
+
var nodes = [];
|
75
|
+
// TODO T24511737 figure out if this is dangerous
|
76
|
+
schema = extendSchema(schema, ast, { assumeValid: true });
|
77
|
+
ast.definitions.forEach(function (definition) {
|
78
|
+
if (isExecutableDefinitionAST(definition)) {
|
79
|
+
nodes.push(_this.transform(schema, definition));
|
80
|
+
}
|
81
|
+
}, this);
|
82
|
+
return nodes;
|
83
|
+
};
|
84
|
+
|
85
|
+
/**
|
86
|
+
* Transforms a raw GraphQL AST into a simpler representation with type
|
87
|
+
* information.
|
88
|
+
*/
|
89
|
+
|
90
|
+
|
91
|
+
GraphQLParser.transform = function transform(schema, definition) {
|
92
|
+
var _this2 = this;
|
93
|
+
|
94
|
+
return require('./GraphQLCompilerProfiler').run('GraphQLParser.transform', function () {
|
95
|
+
var parser = new _this2(schema, definition);
|
96
|
+
return parser.transform();
|
97
|
+
});
|
98
|
+
};
|
99
|
+
|
100
|
+
function GraphQLParser(schema, definition) {
|
101
|
+
(0, _classCallCheck3['default'])(this, GraphQLParser);
|
102
|
+
|
103
|
+
this._definition = definition;
|
104
|
+
this._referencedVariableTypesByName = {};
|
105
|
+
this._schema = schema;
|
106
|
+
}
|
107
|
+
|
108
|
+
/**
|
109
|
+
* Find the definition of a field of the specified type.
|
110
|
+
*/
|
111
|
+
|
112
|
+
|
113
|
+
GraphQLParser.prototype.getFieldDefinition = function getFieldDefinition(parentType, fieldName, fieldAST) {
|
114
|
+
var type = getRawType(parentType);
|
115
|
+
var isQueryType = type === this._schema.getQueryType();
|
116
|
+
var hasTypeName = type instanceof GraphQLObjectType || type instanceof GraphQLInterfaceType || type instanceof GraphQLUnionType;
|
117
|
+
|
118
|
+
var schemaFieldDef = void 0;
|
119
|
+
if (isQueryType && fieldName === SchemaMetaFieldDef.name) {
|
120
|
+
schemaFieldDef = SchemaMetaFieldDef;
|
121
|
+
} else if (isQueryType && fieldName === TypeMetaFieldDef.name) {
|
122
|
+
schemaFieldDef = TypeMetaFieldDef;
|
123
|
+
} else if (hasTypeName && fieldName === TypeNameMetaFieldDef.name) {
|
124
|
+
schemaFieldDef = TypeNameMetaFieldDef;
|
125
|
+
} else if (type instanceof GraphQLInterfaceType || type instanceof GraphQLObjectType) {
|
126
|
+
schemaFieldDef = type.getFields()[fieldName];
|
127
|
+
}
|
128
|
+
return schemaFieldDef;
|
129
|
+
};
|
130
|
+
|
131
|
+
GraphQLParser.prototype._getErrorContext = function _getErrorContext() {
|
132
|
+
var message = 'document `' + getName(this._definition) + '`';
|
133
|
+
if (this._definition.loc && this._definition.loc.source) {
|
134
|
+
message += ' file: `' + this._definition.loc.source.name + '`';
|
135
|
+
}
|
136
|
+
return message;
|
137
|
+
};
|
138
|
+
|
139
|
+
GraphQLParser.prototype._recordAndVerifyVariableReference = function _recordAndVerifyVariableReference(name, usedAsType) {
|
140
|
+
var previousType = this._referencedVariableTypesByName[name];
|
141
|
+
|
142
|
+
if (!previousType) {
|
143
|
+
// No previous usage, current type is strongest
|
144
|
+
this._referencedVariableTypesByName[name] = usedAsType;
|
145
|
+
} else if (usedAsType) {
|
146
|
+
require('fbjs/lib/invariant')(isTypeSubTypeOf(this._schema, usedAsType, previousType) || isTypeSubTypeOf(this._schema, previousType, usedAsType), 'GraphQLParser: Variable `$%s` was used in locations expecting ' + 'the conflicting types `%s` and `%s`. Source: %s.', name, previousType, usedAsType, this._getErrorContext());
|
147
|
+
|
148
|
+
// If the new used type has stronger requirements, use that type as reference,
|
149
|
+
// otherwise keep referencing the previous type
|
150
|
+
this._referencedVariableTypesByName[name] = isTypeSubTypeOf(this._schema, usedAsType, previousType) ? usedAsType : previousType;
|
151
|
+
}
|
152
|
+
};
|
153
|
+
|
154
|
+
GraphQLParser.prototype.transform = function transform() {
|
155
|
+
switch (this._definition.kind) {
|
156
|
+
case 'OperationDefinition':
|
157
|
+
return this._transformOperation(this._definition);
|
158
|
+
case 'FragmentDefinition':
|
159
|
+
return this._transformFragment(this._definition);
|
160
|
+
default:
|
161
|
+
require('fbjs/lib/invariant')(false, 'GraphQLParser: Unknown AST kind `%s`. Source: %s.', this._definition.kind, this._getErrorContext());
|
162
|
+
}
|
163
|
+
};
|
164
|
+
|
165
|
+
GraphQLParser.prototype._transformFragment = function _transformFragment(fragment) {
|
166
|
+
var _this3 = this;
|
167
|
+
|
168
|
+
var argumentDefinitions = this._buildArgumentDefinitions(fragment);
|
169
|
+
var directives = this._transformDirectives((fragment.directives || []).filter(function (directive) {
|
170
|
+
return getName(directive) !== ARGUMENT_DEFINITIONS;
|
171
|
+
}));
|
172
|
+
var type = assertCompositeType(getTypeFromAST(this._schema, fragment.typeCondition));
|
173
|
+
var selections = this._transformSelections(fragment.selectionSet, type);
|
174
|
+
|
175
|
+
var _loop = function _loop(_name) {
|
176
|
+
if (_this3._referencedVariableTypesByName.hasOwnProperty(_name)) {
|
177
|
+
var variableType = _this3._referencedVariableTypesByName[_name];
|
178
|
+
var localArgument = argumentDefinitions.find(function (argDef) {
|
179
|
+
return argDef.name === _name;
|
180
|
+
});
|
181
|
+
if (localArgument) {
|
182
|
+
require('fbjs/lib/invariant')(variableType == null || isTypeSubTypeOf(_this3._schema, localArgument.type, variableType), 'GraphQLParser: Variable `$%s` was defined as type `%s`, but used ' + 'in a location that expects type `%s`. Source: %s.', _name, localArgument.type, variableType, _this3._getErrorContext());
|
183
|
+
} else {
|
184
|
+
argumentDefinitions.push({
|
185
|
+
kind: 'RootArgumentDefinition',
|
186
|
+
metadata: null,
|
187
|
+
name: _name,
|
188
|
+
// $FlowFixMe - could be null
|
189
|
+
type: variableType
|
190
|
+
});
|
191
|
+
}
|
192
|
+
}
|
193
|
+
};
|
194
|
+
|
195
|
+
for (var _name in this._referencedVariableTypesByName) {
|
196
|
+
_loop(_name);
|
197
|
+
}
|
198
|
+
return {
|
199
|
+
kind: 'Fragment',
|
200
|
+
directives: directives,
|
201
|
+
metadata: null,
|
202
|
+
name: getName(fragment),
|
203
|
+
selections: selections,
|
204
|
+
type: type,
|
205
|
+
argumentDefinitions: argumentDefinitions
|
206
|
+
};
|
207
|
+
};
|
208
|
+
|
209
|
+
/**
|
210
|
+
* Polyfills suport for fragment variable definitions via the
|
211
|
+
* @argumentDefinitions directive. Returns the equivalent AST
|
212
|
+
* to the `argumentDefinitions` property on queries/mutations/etc.
|
213
|
+
*/
|
214
|
+
|
215
|
+
|
216
|
+
GraphQLParser.prototype._buildArgumentDefinitions = function _buildArgumentDefinitions(fragment) {
|
217
|
+
var _this4 = this;
|
218
|
+
|
219
|
+
var variableDirectives = (fragment.directives || []).filter(function (directive) {
|
220
|
+
return getName(directive) === ARGUMENT_DEFINITIONS;
|
221
|
+
});
|
222
|
+
if (!variableDirectives.length) {
|
223
|
+
return [];
|
224
|
+
}
|
225
|
+
require('fbjs/lib/invariant')(variableDirectives.length === 1, 'GraphQLParser: Directive %s may be defined at most once on fragment ' + '`%s`. Source: %s.', ARGUMENT_DEFINITIONS, getName(fragment), this._getErrorContext());
|
226
|
+
var variableDirective = variableDirectives[0];
|
227
|
+
// $FlowIssue: refining directly on `variableDirective.arguments` doesn't
|
228
|
+
// work, below accesses all report arguments could still be null/undefined.
|
229
|
+
var args = variableDirective.arguments;
|
230
|
+
if (variableDirective == null || !Array.isArray(args)) {
|
231
|
+
return [];
|
232
|
+
}
|
233
|
+
require('fbjs/lib/invariant')(args.length, 'GraphQLParser: Directive %s requires arguments: remove the directive ' + 'to skip defining local variables for this fragment `%s`. Source: %s.', ARGUMENT_DEFINITIONS, getName(fragment), this._getErrorContext());
|
234
|
+
return args.map(function (arg) {
|
235
|
+
var argName = getName(arg);
|
236
|
+
var argValue = _this4._transformValue(arg.value);
|
237
|
+
require('fbjs/lib/invariant')(argValue.kind === 'Literal', 'GraphQLParser: Expected definition for variable `%s` to be an ' + 'object with the following shape: `{type: string, defaultValue?: ' + 'mixed}`, got `%s`. Source: %s.', argValue, _this4._getErrorContext());
|
238
|
+
var value = argValue.value;
|
239
|
+
require('fbjs/lib/invariant')(!Array.isArray(value) && typeof value === 'object' && value !== null && typeof value.type === 'string', 'GraphQLParser: Expected definition for variable `%s` to be an ' + 'object with the following shape: `{type: string, defaultValue?: ' + 'mixed, nonNull?: boolean, list?: boolean}`, got `%s`. Source: %s.', argName, argValue, _this4._getErrorContext());
|
240
|
+
|
241
|
+
var valueType = value.type;
|
242
|
+
|
243
|
+
var unknownKeys = Object.keys(value).filter(function (key) {
|
244
|
+
return key !== 'type' && key !== 'defaultValue' && key !== 'nonNull' && key !== 'list';
|
245
|
+
});
|
246
|
+
require('fbjs/lib/invariant')(unknownKeys.length === 0, 'GraphQLParser: Expected definition for variable `%s` to be an ' + 'object with the following shape: `{type: string, defaultValue?: ' + 'mixed, nonNull?: boolean, list?: boolean}`, got unknown key(s) ' + '`%s`. Source: %s.', argName, unknownKeys.join('`, `'), _this4._getErrorContext());
|
247
|
+
|
248
|
+
var typeAST = parseType(valueType);
|
249
|
+
var type = assertInputType(getTypeFromAST(_this4._schema, typeAST));
|
250
|
+
return {
|
251
|
+
kind: 'LocalArgumentDefinition',
|
252
|
+
defaultValue: value.defaultValue != null ? value.defaultValue : null,
|
253
|
+
metadata: null,
|
254
|
+
name: argName,
|
255
|
+
type: type
|
256
|
+
};
|
257
|
+
});
|
258
|
+
};
|
259
|
+
|
260
|
+
GraphQLParser.prototype._transformOperation = function _transformOperation(definition) {
|
261
|
+
var name = getName(definition);
|
262
|
+
var argumentDefinitions = this._transformArgumentDefinitions(definition.variableDefinitions || []);
|
263
|
+
var directives = this._transformDirectives(definition.directives || []);
|
264
|
+
var type = void 0;
|
265
|
+
var operation = void 0;
|
266
|
+
switch (definition.operation) {
|
267
|
+
case 'query':
|
268
|
+
operation = 'query';
|
269
|
+
type = assertCompositeType(this._schema.getQueryType());
|
270
|
+
break;
|
271
|
+
case 'mutation':
|
272
|
+
operation = 'mutation';
|
273
|
+
type = assertCompositeType(this._schema.getMutationType());
|
274
|
+
break;
|
275
|
+
case 'subscription':
|
276
|
+
operation = 'subscription';
|
277
|
+
type = assertCompositeType(this._schema.getSubscriptionType());
|
278
|
+
break;
|
279
|
+
default:
|
280
|
+
require('fbjs/lib/invariant')(false, 'GraphQLParser: Unknown AST kind `%s`. Source: %s.', definition.operation, this._getErrorContext());
|
281
|
+
}
|
282
|
+
require('fbjs/lib/invariant')(definition.selectionSet, 'GraphQLParser: Expected %s `%s` to have selections. Source: %s.', operation, name, this._getErrorContext());
|
283
|
+
var selections = this._transformSelections(definition.selectionSet, type);
|
284
|
+
return {
|
285
|
+
kind: 'Root',
|
286
|
+
operation: operation,
|
287
|
+
metadata: null,
|
288
|
+
name: name,
|
289
|
+
dependentRequests: [],
|
290
|
+
argumentDefinitions: argumentDefinitions,
|
291
|
+
directives: directives,
|
292
|
+
selections: selections,
|
293
|
+
type: type
|
294
|
+
};
|
295
|
+
};
|
296
|
+
|
297
|
+
GraphQLParser.prototype._transformArgumentDefinitions = function _transformArgumentDefinitions(argumentDefinitions) {
|
298
|
+
var _this5 = this;
|
299
|
+
|
300
|
+
return argumentDefinitions.map(function (def) {
|
301
|
+
var name = getName(def.variable);
|
302
|
+
var type = assertInputType(getTypeFromAST(_this5._schema, def.type));
|
303
|
+
var defaultLiteral = def.defaultValue ? _this5._transformValue(def.defaultValue) : null;
|
304
|
+
if (_this5._referencedVariableTypesByName.hasOwnProperty(name)) {
|
305
|
+
var variableType = _this5._referencedVariableTypesByName[name];
|
306
|
+
require('fbjs/lib/invariant')(variableType == null || isTypeSubTypeOf(_this5._schema, type, variableType), 'GraphQLParser: Variable `$%s` was defined as type `%s`, but used ' + 'in a location that expects type `%s`. Source: %s.', name, type, variableType, _this5._getErrorContext());
|
307
|
+
}
|
308
|
+
require('fbjs/lib/invariant')(defaultLiteral === null || defaultLiteral.kind === 'Literal', 'GraphQLParser: Expected null or Literal default value, got: `%s`. ' + 'Source: %s.', defaultLiteral && defaultLiteral.kind, _this5._getErrorContext());
|
309
|
+
return {
|
310
|
+
kind: 'LocalArgumentDefinition',
|
311
|
+
metadata: null,
|
312
|
+
name: name,
|
313
|
+
defaultValue: defaultLiteral ? defaultLiteral.value : null,
|
314
|
+
type: type
|
315
|
+
};
|
316
|
+
});
|
317
|
+
};
|
318
|
+
|
319
|
+
GraphQLParser.prototype._transformSelections = function _transformSelections(selectionSet, parentType) {
|
320
|
+
var _this6 = this;
|
321
|
+
|
322
|
+
return selectionSet.selections.map(function (selection) {
|
323
|
+
var node = void 0;
|
324
|
+
if (selection.kind === 'Field') {
|
325
|
+
node = _this6._transformField(selection, parentType);
|
326
|
+
} else if (selection.kind === 'FragmentSpread') {
|
327
|
+
node = _this6._transformFragmentSpread(selection, parentType);
|
328
|
+
} else if (selection.kind === 'InlineFragment') {
|
329
|
+
node = _this6._transformInlineFragment(selection, parentType);
|
330
|
+
} else {
|
331
|
+
require('fbjs/lib/invariant')(false, 'GraphQLParser: Unexpected AST kind `%s`. Source: %s.', selection.kind, _this6._getErrorContext());
|
332
|
+
}
|
333
|
+
|
334
|
+
var _splitConditions2 = _this6._splitConditions(node.directives),
|
335
|
+
conditions = _splitConditions2[0],
|
336
|
+
directives = _splitConditions2[1];
|
337
|
+
|
338
|
+
var conditionalNodes = applyConditions(conditions,
|
339
|
+
// $FlowFixMe(>=0.28.0)
|
340
|
+
[(0, _extends3['default'])({}, node, { directives: directives })]);
|
341
|
+
require('fbjs/lib/invariant')(conditionalNodes.length === 1, 'GraphQLParser: Expected exactly one conditional node, got `%s`. ' + 'Source: %s.', conditionalNodes.length, _this6._getErrorContext());
|
342
|
+
return conditionalNodes[0];
|
343
|
+
});
|
344
|
+
};
|
345
|
+
|
346
|
+
GraphQLParser.prototype._transformInlineFragment = function _transformInlineFragment(fragment, parentType) {
|
347
|
+
var typeCondition = assertCompositeType(fragment.typeCondition ? getTypeFromAST(this._schema, fragment.typeCondition) : parentType);
|
348
|
+
var directives = this._transformDirectives(fragment.directives || []);
|
349
|
+
var selections = this._transformSelections(fragment.selectionSet, typeCondition);
|
350
|
+
return {
|
351
|
+
kind: 'InlineFragment',
|
352
|
+
directives: directives,
|
353
|
+
metadata: null,
|
354
|
+
selections: selections,
|
355
|
+
typeCondition: typeCondition
|
356
|
+
};
|
357
|
+
};
|
358
|
+
|
359
|
+
GraphQLParser.prototype._transformFragmentSpread = function _transformFragmentSpread(fragment, parentType) {
|
360
|
+
var _this7 = this;
|
361
|
+
|
362
|
+
var fragmentName = getName(fragment);
|
363
|
+
|
364
|
+
var _partitionArray = partitionArray(fragment.directives || [], function (directive) {
|
365
|
+
return getName(directive) !== ARGUMENTS;
|
366
|
+
}),
|
367
|
+
otherDirectives = _partitionArray[0],
|
368
|
+
argumentDirectives = _partitionArray[1];
|
369
|
+
|
370
|
+
require('fbjs/lib/invariant')(argumentDirectives.length <= 1, 'GraphQLParser: Directive %s may be used at most once in fragment ' + 'spread `...%s`. Source: %s.', ARGUMENTS, fragmentName, this._getErrorContext());
|
371
|
+
var args = void 0;
|
372
|
+
if (argumentDirectives.length) {
|
373
|
+
args = (argumentDirectives[0].arguments || []).map(function (arg) {
|
374
|
+
var argValue = arg.value;
|
375
|
+
require('fbjs/lib/invariant')(argValue.kind === 'Variable', 'GraphQLParser: All @arguments() args must be variables, got %s. ' + 'Source: %s.', argValue.kind, _this7._getErrorContext());
|
376
|
+
|
377
|
+
return {
|
378
|
+
kind: 'Argument',
|
379
|
+
metadata: null,
|
380
|
+
name: getName(arg),
|
381
|
+
value: _this7._transformVariable(argValue),
|
382
|
+
type: null // TODO: can't get type until referenced fragment is defined
|
383
|
+
};
|
384
|
+
});
|
385
|
+
}
|
386
|
+
var directives = this._transformDirectives(otherDirectives);
|
387
|
+
return {
|
388
|
+
kind: 'FragmentSpread',
|
389
|
+
args: args || [],
|
390
|
+
metadata: null,
|
391
|
+
name: fragmentName,
|
392
|
+
directives: directives
|
393
|
+
};
|
394
|
+
};
|
395
|
+
|
396
|
+
GraphQLParser.prototype._transformField = function _transformField(field, parentType) {
|
397
|
+
var name = getName(field);
|
398
|
+
var fieldDef = this.getFieldDefinition(parentType, name, field);
|
399
|
+
|
400
|
+
require('fbjs/lib/invariant')(fieldDef, 'GraphQLParser: Unknown field `%s` on type `%s`. Source: %s.', name, parentType, this._getErrorContext());
|
401
|
+
var alias = field.alias ? field.alias.value : null;
|
402
|
+
var args = this._transformArguments(field.arguments || [], fieldDef.args);
|
403
|
+
|
404
|
+
var _partitionArray2 = partitionArray(field.directives || [], function (directive) {
|
405
|
+
return getName(directive) !== CLIENT_FIELD;
|
406
|
+
}),
|
407
|
+
otherDirectives = _partitionArray2[0],
|
408
|
+
clientFieldDirectives = _partitionArray2[1];
|
409
|
+
|
410
|
+
var directives = this._transformDirectives(otherDirectives);
|
411
|
+
var type = assertOutputType(fieldDef.type);
|
412
|
+
var handles = this._transformHandle(name, args, clientFieldDirectives);
|
413
|
+
if (isLeafType(getNamedType(type))) {
|
414
|
+
require('fbjs/lib/invariant')(!field.selectionSet || !field.selectionSet.selections || !field.selectionSet.selections.length, 'GraphQLParser: Expected no selections for scalar field `%s` on type ' + '`%s`. Source: %s.', name, this._getErrorContext());
|
415
|
+
return {
|
416
|
+
kind: 'ScalarField',
|
417
|
+
alias: alias,
|
418
|
+
args: args,
|
419
|
+
directives: directives,
|
420
|
+
handles: handles,
|
421
|
+
metadata: null,
|
422
|
+
name: name,
|
423
|
+
type: assertScalarFieldType(type)
|
424
|
+
};
|
425
|
+
} else {
|
426
|
+
var selections = field.selectionSet ? this._transformSelections(field.selectionSet, type) : null;
|
427
|
+
require('fbjs/lib/invariant')(selections && selections.length, 'GraphQLParser: Expected at least one selection for non-scalar field ' + '`%s` on type `%s`. Source: %s.', name, type, this._getErrorContext());
|
428
|
+
return {
|
429
|
+
kind: 'LinkedField',
|
430
|
+
alias: alias,
|
431
|
+
args: args,
|
432
|
+
directives: directives,
|
433
|
+
handles: handles,
|
434
|
+
metadata: null,
|
435
|
+
name: name,
|
436
|
+
selections: selections,
|
437
|
+
type: type
|
438
|
+
};
|
439
|
+
}
|
440
|
+
};
|
441
|
+
|
442
|
+
GraphQLParser.prototype._transformHandle = function _transformHandle(fieldName, fieldArgs, clientFieldDirectives) {
|
443
|
+
var _this8 = this;
|
444
|
+
|
445
|
+
var handles = void 0;
|
446
|
+
clientFieldDirectives.forEach(function (clientFieldDirective) {
|
447
|
+
var handleArgument = (clientFieldDirective.arguments || []).find(function (arg) {
|
448
|
+
return getName(arg) === CLIENT_FIELD_HANDLE;
|
449
|
+
});
|
450
|
+
if (handleArgument) {
|
451
|
+
var _name2 = null;
|
452
|
+
var key = DEFAULT_HANDLE_KEY;
|
453
|
+
var filters = null;
|
454
|
+
var maybeHandle = _this8._transformValue(handleArgument.value);
|
455
|
+
require('fbjs/lib/invariant')(maybeHandle.kind === 'Literal' && typeof maybeHandle.value === 'string', 'GraphQLParser: Expected the %s argument to @%s to be a literal ' + 'string, got `%s` on field `%s`. Source: %s.', CLIENT_FIELD_HANDLE, CLIENT_FIELD, maybeHandle, fieldName, _this8._getErrorContext());
|
456
|
+
_name2 = maybeHandle.value;
|
457
|
+
|
458
|
+
var keyArgument = (clientFieldDirective.arguments || []).find(function (arg) {
|
459
|
+
return getName(arg) === CLIENT_FIELD_KEY;
|
460
|
+
});
|
461
|
+
if (keyArgument) {
|
462
|
+
var maybeKey = _this8._transformValue(keyArgument.value);
|
463
|
+
require('fbjs/lib/invariant')(maybeKey.kind === 'Literal' && typeof maybeKey.value === 'string', 'GraphQLParser: Expected %s argument to @%s to be a literal ' + 'string, got `%s` on field `%s`. Source: %s.', CLIENT_FIELD_KEY, CLIENT_FIELD, maybeKey, fieldName, _this8._getErrorContext());
|
464
|
+
key = maybeKey.value;
|
465
|
+
}
|
466
|
+
var filtersArgument = (clientFieldDirective.arguments || []).find(function (arg) {
|
467
|
+
return getName(arg) === CLIENT_FIELD_FILTERS;
|
468
|
+
});
|
469
|
+
if (filtersArgument) {
|
470
|
+
var maybeFilters = _this8._transformValue(filtersArgument.value);
|
471
|
+
require('fbjs/lib/invariant')(maybeFilters.kind === 'Literal' && Array.isArray(maybeFilters.value) && maybeFilters.value.every(function (filter) {
|
472
|
+
return fieldArgs.some(function (fieldArg) {
|
473
|
+
return fieldArg.name === filter;
|
474
|
+
});
|
475
|
+
}), 'GraphQLParser: Expected %s argument to @%s to be an array of ' + 'argument names on field `%s`, but get %s. Source: %s.', CLIENT_FIELD_FILTERS, CLIENT_FIELD, fieldName, maybeFilters, _this8._getErrorContext());
|
476
|
+
// $FlowFixMe
|
477
|
+
filters = maybeFilters.value;
|
478
|
+
}
|
479
|
+
handles = handles || [];
|
480
|
+
handles.push({ name: _name2, key: key, filters: filters });
|
481
|
+
}
|
482
|
+
});
|
483
|
+
return handles;
|
484
|
+
};
|
485
|
+
|
486
|
+
GraphQLParser.prototype._transformDirectives = function _transformDirectives(directives) {
|
487
|
+
var _this9 = this;
|
488
|
+
|
489
|
+
return directives.map(function (directive) {
|
490
|
+
var name = getName(directive);
|
491
|
+
var directiveDef = _this9._schema.getDirective(name);
|
492
|
+
require('fbjs/lib/invariant')(directiveDef, 'GraphQLParser: Unknown directive `@%s`. Source: %s.', name, _this9._getErrorContext());
|
493
|
+
var args = _this9._transformArguments(directive.arguments || [], directiveDef.args);
|
494
|
+
return {
|
495
|
+
kind: 'Directive',
|
496
|
+
metadata: null,
|
497
|
+
name: name,
|
498
|
+
args: args
|
499
|
+
};
|
500
|
+
});
|
501
|
+
};
|
502
|
+
|
503
|
+
GraphQLParser.prototype._transformArguments = function _transformArguments(args, argumentDefinitions) {
|
504
|
+
var _this10 = this;
|
505
|
+
|
506
|
+
return args.map(function (arg) {
|
507
|
+
var argName = getName(arg);
|
508
|
+
var argDef = argumentDefinitions.find(function (def) {
|
509
|
+
return def.name === argName;
|
510
|
+
});
|
511
|
+
require('fbjs/lib/invariant')(argDef, 'GraphQLParser: Unknown argument `%s`. Source: %s.', argName, _this10._getErrorContext());
|
512
|
+
var value = _this10._transformValue(arg.value, argDef.type);
|
513
|
+
return {
|
514
|
+
kind: 'Argument',
|
515
|
+
metadata: null,
|
516
|
+
name: argName,
|
517
|
+
value: value,
|
518
|
+
type: argDef.type
|
519
|
+
};
|
520
|
+
});
|
521
|
+
};
|
522
|
+
|
523
|
+
GraphQLParser.prototype._splitConditions = function _splitConditions(mixedDirectives) {
|
524
|
+
var _this11 = this;
|
525
|
+
|
526
|
+
var conditions = [];
|
527
|
+
var directives = [];
|
528
|
+
mixedDirectives.forEach(function (directive) {
|
529
|
+
if (directive.name === INCLUDE || directive.name === SKIP) {
|
530
|
+
var passingValue = directive.name === INCLUDE;
|
531
|
+
var arg = directive.args[0];
|
532
|
+
require('fbjs/lib/invariant')(arg && arg.name === IF, 'GraphQLParser: Expected an `if` argument to @%s. Source: %s.', directive.name, _this11._getErrorContext());
|
533
|
+
require('fbjs/lib/invariant')(arg.value.kind === 'Variable' || arg.value.kind === 'Literal', 'GraphQLParser: Expected the `if` argument to @%s to be a variable. ' + 'Source: %s.', directive.name, _this11._getErrorContext());
|
534
|
+
conditions.push({
|
535
|
+
kind: 'Condition',
|
536
|
+
condition: arg.value,
|
537
|
+
metadata: null,
|
538
|
+
passingValue: passingValue,
|
539
|
+
selections: []
|
540
|
+
});
|
541
|
+
} else {
|
542
|
+
directives.push(directive);
|
543
|
+
}
|
544
|
+
});
|
545
|
+
var sortedConditions = [].concat(conditions).sort(function (a, b) {
|
546
|
+
if (a.condition.kind === 'Variable' && b.condition.kind === 'Variable') {
|
547
|
+
return a.condition.variableName < b.condition.variableName ? -1 : a.condition.variableName > b.condition.variableName ? 1 : 0;
|
548
|
+
} else {
|
549
|
+
// sort literals earlier, variables later
|
550
|
+
return a.condition.kind === 'Variable' ? 1 : b.condition.kind === 'Variable' ? -1 : 0;
|
551
|
+
}
|
552
|
+
});
|
553
|
+
return [sortedConditions, directives];
|
554
|
+
};
|
555
|
+
|
556
|
+
GraphQLParser.prototype._transformVariable = function _transformVariable(ast, type) {
|
557
|
+
var variableName = getName(ast);
|
558
|
+
this._recordAndVerifyVariableReference(variableName, type);
|
559
|
+
return {
|
560
|
+
kind: 'Variable',
|
561
|
+
metadata: null,
|
562
|
+
variableName: variableName,
|
563
|
+
type: type
|
564
|
+
};
|
565
|
+
};
|
566
|
+
|
567
|
+
/**
|
568
|
+
* Transforms AST values into IR values, extracting the literal JS values of any
|
569
|
+
* subtree of the AST that does not contain a variable.
|
570
|
+
*/
|
571
|
+
|
572
|
+
|
573
|
+
GraphQLParser.prototype._transformValue = function _transformValue(ast, type) {
|
574
|
+
var _this12 = this;
|
575
|
+
|
576
|
+
switch (ast.kind) {
|
577
|
+
case 'IntValue':
|
578
|
+
return {
|
579
|
+
kind: 'Literal',
|
580
|
+
metadata: null,
|
581
|
+
value: parseInt(ast.value, 10)
|
582
|
+
};
|
583
|
+
case 'FloatValue':
|
584
|
+
return {
|
585
|
+
kind: 'Literal',
|
586
|
+
metadata: null,
|
587
|
+
value: parseFloat(ast.value)
|
588
|
+
};
|
589
|
+
case 'StringValue':
|
590
|
+
return {
|
591
|
+
kind: 'Literal',
|
592
|
+
metadata: null,
|
593
|
+
value: ast.value
|
594
|
+
};
|
595
|
+
case 'BooleanValue':
|
596
|
+
// Note: duplicated because Flow does not understand fall-through cases
|
597
|
+
return {
|
598
|
+
kind: 'Literal',
|
599
|
+
metadata: null,
|
600
|
+
value: ast.value
|
601
|
+
};
|
602
|
+
case 'EnumValue':
|
603
|
+
// Note: duplicated because Flow does not understand fall-through cases
|
604
|
+
return {
|
605
|
+
kind: 'Literal',
|
606
|
+
metadata: null,
|
607
|
+
value: ast.value
|
608
|
+
};
|
609
|
+
case 'ListValue':
|
610
|
+
var itemType = void 0;
|
611
|
+
if (type) {
|
612
|
+
var listType = getNullableType(type);
|
613
|
+
// The user entered a list, a `type` was expected; this is only valid
|
614
|
+
// if `type` is a List.
|
615
|
+
require('fbjs/lib/invariant')(listType instanceof GraphQLList, 'GraphQLParser: Expected a value matching type `%s`, but ' + 'got a list value. Source: %s.', type, this._getErrorContext());
|
616
|
+
itemType = assertInputType(listType.ofType);
|
617
|
+
}
|
618
|
+
var literalList = [];
|
619
|
+
var items = [];
|
620
|
+
var areAllItemsScalar = true;
|
621
|
+
ast.values.forEach(function (item) {
|
622
|
+
var itemValue = _this12._transformValue(item, itemType);
|
623
|
+
if (itemValue.kind === 'Literal') {
|
624
|
+
literalList.push(itemValue.value);
|
625
|
+
}
|
626
|
+
items.push(itemValue);
|
627
|
+
areAllItemsScalar = areAllItemsScalar && itemValue.kind === 'Literal';
|
628
|
+
});
|
629
|
+
if (areAllItemsScalar) {
|
630
|
+
return {
|
631
|
+
kind: 'Literal',
|
632
|
+
metadata: null,
|
633
|
+
value: literalList
|
634
|
+
};
|
635
|
+
} else {
|
636
|
+
return {
|
637
|
+
kind: 'ListValue',
|
638
|
+
metadata: null,
|
639
|
+
items: items
|
640
|
+
};
|
641
|
+
}
|
642
|
+
case 'NullValue':
|
643
|
+
return {
|
644
|
+
kind: 'Literal',
|
645
|
+
metadata: null,
|
646
|
+
value: null
|
647
|
+
};
|
648
|
+
case 'ObjectValue':
|
649
|
+
var literalObject = {};
|
650
|
+
var fields = [];
|
651
|
+
var areAllFieldsScalar = true;
|
652
|
+
ast.fields.forEach(function (field) {
|
653
|
+
var fieldName = getName(field);
|
654
|
+
var fieldType = void 0;
|
655
|
+
if (type) {
|
656
|
+
var objectType = getNullableType(type);
|
657
|
+
// The user entered an object, a `type` was expected; this is only
|
658
|
+
// valid if `type` is an Object.
|
659
|
+
require('fbjs/lib/invariant')(objectType instanceof GraphQLInputObjectType, 'GraphQLParser: Expected a value matching type `%s`, but ' + 'got an object value. Source: %s.', type, _this12._getErrorContext());
|
660
|
+
var fieldConfig = objectType.getFields()[fieldName];
|
661
|
+
require('fbjs/lib/invariant')(fieldConfig, 'GraphQLParser: Unknown field `%s` on type `%s`. Source: %s.', fieldName, type, _this12._getErrorContext());
|
662
|
+
fieldType = assertInputType(fieldConfig.type);
|
663
|
+
}
|
664
|
+
var fieldValue = _this12._transformValue(field.value, fieldType);
|
665
|
+
if (fieldValue.kind === 'Literal') {
|
666
|
+
literalObject[field.name.value] = fieldValue.value;
|
667
|
+
}
|
668
|
+
fields.push({
|
669
|
+
kind: 'ObjectFieldValue',
|
670
|
+
metadata: null,
|
671
|
+
name: fieldName,
|
672
|
+
value: fieldValue
|
673
|
+
});
|
674
|
+
areAllFieldsScalar = areAllFieldsScalar && fieldValue.kind === 'Literal';
|
675
|
+
});
|
676
|
+
if (areAllFieldsScalar) {
|
677
|
+
return {
|
678
|
+
kind: 'Literal',
|
679
|
+
metadata: null,
|
680
|
+
value: literalObject
|
681
|
+
};
|
682
|
+
} else {
|
683
|
+
return {
|
684
|
+
kind: 'ObjectValue',
|
685
|
+
metadata: null,
|
686
|
+
fields: fields
|
687
|
+
};
|
688
|
+
}
|
689
|
+
case 'Variable':
|
690
|
+
return this._transformVariable(ast, type);
|
691
|
+
default:
|
692
|
+
require('fbjs/lib/invariant')(false, 'GraphQLParser: Unknown ast kind: %s. Source: %s.', ast.kind, this._getErrorContext());
|
693
|
+
}
|
694
|
+
};
|
695
|
+
|
696
|
+
return GraphQLParser;
|
697
|
+
}();
|
698
|
+
|
699
|
+
function isScalarFieldType(type) {
|
700
|
+
var namedType = getNamedType(type);
|
701
|
+
return namedType instanceof GraphQLScalarType || namedType instanceof GraphQLEnumType;
|
702
|
+
}
|
703
|
+
|
704
|
+
function assertScalarFieldType(type) {
|
705
|
+
require('fbjs/lib/invariant')(isScalarFieldType(type), 'Expected %s to be a Scalar Field type.', type);
|
706
|
+
return type;
|
707
|
+
}
|
708
|
+
|
709
|
+
function applyConditions(conditions, selections) {
|
710
|
+
var nextSelections = selections;
|
711
|
+
conditions.forEach(function (condition) {
|
712
|
+
nextSelections = [(0, _extends3['default'])({}, condition, {
|
713
|
+
selections: nextSelections
|
714
|
+
})];
|
715
|
+
});
|
716
|
+
return nextSelections;
|
717
|
+
}
|
718
|
+
|
719
|
+
function getName(ast) {
|
720
|
+
var name = ast.name ? ast.name.value : null;
|
721
|
+
require('fbjs/lib/invariant')(typeof name === 'string', 'GraphQLParser: Expected ast node `%s` to have a name.', ast);
|
722
|
+
return name;
|
723
|
+
}
|
724
|
+
|
725
|
+
/**
|
726
|
+
* Partitions an array given a predicate. All elements satisfying the predicate
|
727
|
+
* are part of the first returned array, and all elements that don't are in the
|
728
|
+
* second.
|
729
|
+
*/
|
730
|
+
function partitionArray(array, predicate, context) {
|
731
|
+
var first = [];
|
732
|
+
var second = [];
|
733
|
+
array.forEach(function (element, index) {
|
734
|
+
if (predicate.call(context, element, index, array)) {
|
735
|
+
first.push(element);
|
736
|
+
} else {
|
737
|
+
second.push(element);
|
738
|
+
}
|
739
|
+
});
|
740
|
+
return [first, second];
|
741
|
+
}
|
742
|
+
|
743
|
+
module.exports = GraphQLParser;
|