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
package/lib/printFlowTypes.js
DELETED
@@ -1,282 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Copyright (c) 2013-present, Facebook, Inc.
|
3
|
-
* All rights reserved.
|
4
|
-
*
|
5
|
-
* This source code is licensed under the BSD-style license found in the
|
6
|
-
* LICENSE file in the root directory of this source tree. An additional grant
|
7
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
8
|
-
*
|
9
|
-
*
|
10
|
-
* @providesModule printFlowTypes
|
11
|
-
* @format
|
12
|
-
*/
|
13
|
-
|
14
|
-
'use strict';
|
15
|
-
|
16
|
-
var generate = require('babel-generator')['default'];
|
17
|
-
|
18
|
-
var traverse = require('babel-traverse')['default'];
|
19
|
-
|
20
|
-
var _require = require('./RelayFlowParser'),
|
21
|
-
RELAY_CLASSIC_MUTATION = _require.RELAY_CLASSIC_MUTATION;
|
22
|
-
|
23
|
-
var _require2 = require('./GraphQLSchemaUtils'),
|
24
|
-
getRawType = _require2.getRawType;
|
25
|
-
|
26
|
-
var _require3 = require('graphql'),
|
27
|
-
GraphQLEnumType = _require3.GraphQLEnumType,
|
28
|
-
GraphQLList = _require3.GraphQLList,
|
29
|
-
GraphQLNonNull = _require3.GraphQLNonNull,
|
30
|
-
GraphQLScalarType = _require3.GraphQLScalarType;
|
31
|
-
|
32
|
-
var FIELD_BLACKLIST = ['clientMutationId', 'client_mutation_id'];
|
33
|
-
|
34
|
-
/**
|
35
|
-
* Prints a given Root or Fragment into a Flow type declaration.
|
36
|
-
*/
|
37
|
-
function printFlowTypes(node) {
|
38
|
-
if (node.kind === 'Root') {
|
39
|
-
// for now, only fragments and mutations have flow types
|
40
|
-
if (node.operation === 'mutation') {
|
41
|
-
var selection = node.selections[0];
|
42
|
-
if (selection.kind === 'LinkedField') {
|
43
|
-
var argument = selection.args[0];
|
44
|
-
var inputIR = require('./transformInputObjectToIR')(argument);
|
45
|
-
|
46
|
-
var response = [];
|
47
|
-
if (node.name !== RELAY_CLASSIC_MUTATION) {
|
48
|
-
selection.name = node.name + 'Response';
|
49
|
-
response = normalize(transform(selection));
|
50
|
-
}
|
51
|
-
return normalize(transform(inputIR)).concat(response).map(function (n) {
|
52
|
-
return generate(n, { flowCommaSeparator: true }).code;
|
53
|
-
}).join('\n\n');
|
54
|
-
}
|
55
|
-
}
|
56
|
-
} else if (node.kind === 'Fragment') {
|
57
|
-
return normalize(transform(node)).map(function (n) {
|
58
|
-
return generate(n, { flowCommaSeparator: true }).code;
|
59
|
-
}).join('\n\n');
|
60
|
-
}
|
61
|
-
}
|
62
|
-
|
63
|
-
/**
|
64
|
-
* Transforms a "root" type (Fragment or LinkedField) into a Flow export type
|
65
|
-
* statement.
|
66
|
-
*/
|
67
|
-
function transform(node) {
|
68
|
-
return require('babel-types').exportNamedDeclaration(require('babel-types').typeAlias(require('babel-types').identifier(node.name), null, require('babel-types').objectTypeAnnotation(node.selections.map(function (selection) {
|
69
|
-
return transformSelection(selection);
|
70
|
-
}).reduce(function (prev, curr) {
|
71
|
-
if (!curr) {
|
72
|
-
return prev;
|
73
|
-
}
|
74
|
-
return prev.concat(curr);
|
75
|
-
}, []), null, null)), [], null);
|
76
|
-
}
|
77
|
-
|
78
|
-
function normalize(ast) {
|
79
|
-
var normalizedRoots = [ast];
|
80
|
-
|
81
|
-
var findObjectTypeProperty = {
|
82
|
-
enter: function enter(path) {
|
83
|
-
if (require('babel-types').isObjectTypeProperty(path)) {
|
84
|
-
// Ignore object types that are direct children of the root Flow type
|
85
|
-
if (require('babel-types').isTypeAlias(path.parent)) {
|
86
|
-
return;
|
87
|
-
}
|
88
|
-
var name = path.node.key.name;
|
89
|
-
|
90
|
-
path.traverse(findObjectTypeAnnotation, {
|
91
|
-
name: this.prevName + '_' + name
|
92
|
-
});
|
93
|
-
}
|
94
|
-
},
|
95
|
-
|
96
|
-
noScope: true
|
97
|
-
};
|
98
|
-
var findObjectTypeAnnotation = {
|
99
|
-
enter: function enter(path) {
|
100
|
-
if (require('babel-types').isObjectTypeAnnotation(path)) {
|
101
|
-
// This has side effects on the path
|
102
|
-
path.traverse(findObjectTypeProperty, { prevName: this.name });
|
103
|
-
|
104
|
-
// Add the node of that transformed path to the array
|
105
|
-
normalizedRoots.push(require('babel-types').exportNamedDeclaration(require('babel-types').typeAlias(require('babel-types').identifier(this.name), null, path.node), [], null));
|
106
|
-
|
107
|
-
// Replace that path with a reference to the extracted type
|
108
|
-
path.replaceWith(require('babel-types').genericTypeAnnotation(require('babel-types').identifier(this.name), null));
|
109
|
-
}
|
110
|
-
},
|
111
|
-
|
112
|
-
noScope: true
|
113
|
-
};
|
114
|
-
|
115
|
-
traverse(ast, findObjectTypeProperty, {}, { prevName: ast.declaration.id.name });
|
116
|
-
|
117
|
-
return normalizedRoots;
|
118
|
-
}
|
119
|
-
|
120
|
-
/**
|
121
|
-
* Transforms a ScalarField or LinkedField to a Flow objectTypeProperty.
|
122
|
-
* If `forceNull` is true, the selection will *always* be a nullable field.
|
123
|
-
*/
|
124
|
-
function transformSelection(node) {
|
125
|
-
var forceNull = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
126
|
-
|
127
|
-
if (node.name && FIELD_BLACKLIST.indexOf(node.name) !== -1) {
|
128
|
-
return;
|
129
|
-
}
|
130
|
-
|
131
|
-
var name = node.alias || node.name && node.name;
|
132
|
-
var annotation = void 0;
|
133
|
-
var body = void 0;
|
134
|
-
switch (node.kind) {
|
135
|
-
case 'ScalarField':
|
136
|
-
body = wrapNullOrArray(node.type, transformScalarField(getRawType(node.type)));
|
137
|
-
if (body.type !== 'NullableTypeAnnotation' && forceNull) {
|
138
|
-
body = require('babel-types').nullableTypeAnnotation(body);
|
139
|
-
}
|
140
|
-
annotation = require('babel-types').objectTypeProperty(require('babel-types').identifier(name), body);
|
141
|
-
break;
|
142
|
-
case 'LinkedField':
|
143
|
-
body = wrapNullOrArray(node.type, transformLinkedField(node));
|
144
|
-
if (body.type !== 'NullableTypeAnnotation' && forceNull) {
|
145
|
-
body = require('babel-types').nullableTypeAnnotation(body);
|
146
|
-
}
|
147
|
-
annotation = require('babel-types').objectTypeProperty(require('babel-types').identifier(name), body);
|
148
|
-
break;
|
149
|
-
case 'Condition':
|
150
|
-
annotation = node.selections.map(function (s) {
|
151
|
-
return transformSelection(s, true);
|
152
|
-
}).reduce(function (prev, curr) {
|
153
|
-
if (!curr) {
|
154
|
-
return prev;
|
155
|
-
}
|
156
|
-
return prev.concat(curr);
|
157
|
-
}, []);
|
158
|
-
break;
|
159
|
-
case 'FragmentSpread':
|
160
|
-
return; // noop
|
161
|
-
case 'InlineFragment':
|
162
|
-
return node.selections.map(function (s) {
|
163
|
-
return transformSelection(s);
|
164
|
-
}).reduce(function (prev, curr) {
|
165
|
-
if (!curr) {
|
166
|
-
return prev;
|
167
|
-
}
|
168
|
-
return prev.concat(curr);
|
169
|
-
}, []).map(function (s) {
|
170
|
-
s.optional = true;
|
171
|
-
return s;
|
172
|
-
});
|
173
|
-
default:
|
174
|
-
throw new Error('Unknown Selection type: ' + node.kind);
|
175
|
-
}
|
176
|
-
|
177
|
-
if (Array.isArray(annotation)) {
|
178
|
-
return annotation.map(function (a) {
|
179
|
-
if (!(node.type instanceof GraphQLNonNull)) {
|
180
|
-
a.optional = true;
|
181
|
-
}
|
182
|
-
return a;
|
183
|
-
});
|
184
|
-
}
|
185
|
-
|
186
|
-
if (!(node.type instanceof GraphQLNonNull)) {
|
187
|
-
annotation.optional = true;
|
188
|
-
}
|
189
|
-
return [annotation];
|
190
|
-
}
|
191
|
-
|
192
|
-
/**
|
193
|
-
* Wraps the given type annotation as a Flow Array.
|
194
|
-
*/
|
195
|
-
function getArrayTypeAnnotation(typeAnnotation) {
|
196
|
-
return require('babel-types').genericTypeAnnotation(require('babel-types').identifier('Array'), require('babel-types').typeParameterInstantiation([typeAnnotation]));
|
197
|
-
}
|
198
|
-
|
199
|
-
/**
|
200
|
-
* Recursively wraps the given type with Array or NonNullable nodes until it
|
201
|
-
* reaches the root type.
|
202
|
-
*/
|
203
|
-
function wrapNullOrArray(type, child) {
|
204
|
-
var nullable = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
205
|
-
|
206
|
-
if (!type) {
|
207
|
-
return child;
|
208
|
-
}
|
209
|
-
|
210
|
-
var annotation = void 0;
|
211
|
-
if (type instanceof GraphQLNonNull) {
|
212
|
-
return wrapNullOrArray(type.ofType, child, false);
|
213
|
-
} else if (type instanceof GraphQLList) {
|
214
|
-
annotation = getArrayTypeAnnotation(wrapNullOrArray(type.ofType, child));
|
215
|
-
} else {
|
216
|
-
annotation = child;
|
217
|
-
}
|
218
|
-
|
219
|
-
return nullable ? require('babel-types').nullableTypeAnnotation(annotation) : annotation;
|
220
|
-
}
|
221
|
-
|
222
|
-
/**
|
223
|
-
* Transforms a LinkedField into a Flow objectTypeAnnotation.
|
224
|
-
*/
|
225
|
-
function transformLinkedField(node) {
|
226
|
-
var selections = node.selections.map(function (selection) {
|
227
|
-
return transformSelection(selection);
|
228
|
-
}).reduce(function (prev, curr) {
|
229
|
-
if (!curr) {
|
230
|
-
return prev;
|
231
|
-
}
|
232
|
-
return prev.concat(curr);
|
233
|
-
}, []);
|
234
|
-
|
235
|
-
// If there are no selections, then we know the only child was a FragmentSpread
|
236
|
-
// so we should make this field an 'any' type. (The alternative is an empty
|
237
|
-
// object!)
|
238
|
-
if (selections.length) {
|
239
|
-
return require('babel-types').objectTypeAnnotation(selections, null, null);
|
240
|
-
} else {
|
241
|
-
return require('babel-types').anyTypeAnnotation();
|
242
|
-
}
|
243
|
-
}
|
244
|
-
|
245
|
-
/**
|
246
|
-
* Transforms a ScalarField type into its corresponding Flow AST node.
|
247
|
-
*/
|
248
|
-
function transformScalarField(type) {
|
249
|
-
if (type instanceof GraphQLScalarType) {
|
250
|
-
switch (type.name) {
|
251
|
-
case 'Color':
|
252
|
-
case 'File':
|
253
|
-
case 'ID':
|
254
|
-
case 'String':
|
255
|
-
case 'Url':
|
256
|
-
return require('babel-types').stringTypeAnnotation();
|
257
|
-
case 'Float':
|
258
|
-
case 'Int':
|
259
|
-
case 'Time':
|
260
|
-
return require('babel-types').numberTypeAnnotation();
|
261
|
-
case 'Boolean':
|
262
|
-
return require('babel-types').booleanTypeAnnotation();
|
263
|
-
default:
|
264
|
-
// Fallback to `any` for custom scalar types.
|
265
|
-
return require('babel-types').anyTypeAnnotation();
|
266
|
-
}
|
267
|
-
} else if (type instanceof GraphQLEnumType) {
|
268
|
-
var stringLiterals = type.getValues().map(function (_ref) {
|
269
|
-
var value = _ref.value;
|
270
|
-
|
271
|
-
var literal = require('babel-types').stringLiteralTypeAnnotation();
|
272
|
-
literal.value = value;
|
273
|
-
return literal;
|
274
|
-
});
|
275
|
-
|
276
|
-
return require('babel-types').unionTypeAnnotation(stringLiterals);
|
277
|
-
} else {
|
278
|
-
throw new Error('Could not convert from GraphQL type ' + type.toString());
|
279
|
-
}
|
280
|
-
}
|
281
|
-
|
282
|
-
module.exports = printFlowTypes;
|
@@ -1,45 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Copyright (c) 2013-present, Facebook, Inc.
|
3
|
-
* All rights reserved.
|
4
|
-
*
|
5
|
-
* This source code is licensed under the BSD-style license found in the
|
6
|
-
* LICENSE file in the root directory of this source tree. An additional grant
|
7
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
8
|
-
*
|
9
|
-
*
|
10
|
-
* @providesModule stableJSONStringify
|
11
|
-
* @format
|
12
|
-
*/
|
13
|
-
|
14
|
-
'use strict';
|
15
|
-
|
16
|
-
/**
|
17
|
-
* Simple recursive stringifier that produces a stable JSON string suitable for
|
18
|
-
* use as a cache key. Does not handle corner-cases such as circular references
|
19
|
-
* or exotic types.
|
20
|
-
*/
|
21
|
-
|
22
|
-
function stableJSONStringify(obj) {
|
23
|
-
if (Array.isArray(obj)) {
|
24
|
-
var result = [];
|
25
|
-
for (var ii = 0; ii < obj.length; ii++) {
|
26
|
-
var value = obj[ii] !== undefined ? obj[ii] : null;
|
27
|
-
result.push(stableJSONStringify(value));
|
28
|
-
}
|
29
|
-
return '[' + result.join(',') + ']';
|
30
|
-
} else if (typeof obj === 'object' && obj) {
|
31
|
-
var _result = [];
|
32
|
-
var keys = Object.keys(obj);
|
33
|
-
keys.sort();
|
34
|
-
for (var _ii = 0; _ii < keys.length; _ii++) {
|
35
|
-
var key = keys[_ii];
|
36
|
-
var _value = stableJSONStringify(obj[key]);
|
37
|
-
_result.push('"' + key + '":' + _value);
|
38
|
-
}
|
39
|
-
return '{' + _result.join(',') + '}';
|
40
|
-
} else {
|
41
|
-
return JSON.stringify(obj);
|
42
|
-
}
|
43
|
-
}
|
44
|
-
|
45
|
-
module.exports = stableJSONStringify;
|
@@ -1,44 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Copyright (c) 2013-present, Facebook, Inc.
|
3
|
-
* All rights reserved.
|
4
|
-
*
|
5
|
-
* This source code is licensed under the BSD-style license found in the
|
6
|
-
* LICENSE file in the root directory of this source tree. An additional grant
|
7
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
8
|
-
*
|
9
|
-
*
|
10
|
-
* @format
|
11
|
-
*/
|
12
|
-
|
13
|
-
'use strict';
|
14
|
-
|
15
|
-
/**
|
16
|
-
* Simple recursive stringifier that produces a stable JSON string suitable for
|
17
|
-
* use as a cache key. Does not handle corner-cases such as circular references
|
18
|
-
* or exotic types.
|
19
|
-
*/
|
20
|
-
|
21
|
-
function stableJSONStringifyOSS(obj) {
|
22
|
-
if (Array.isArray(obj)) {
|
23
|
-
var result = [];
|
24
|
-
for (var ii = 0; ii < obj.length; ii++) {
|
25
|
-
var value = obj[ii] !== undefined ? obj[ii] : null;
|
26
|
-
result.push(stableJSONStringifyOSS(value));
|
27
|
-
}
|
28
|
-
return '[' + result.join(',') + ']';
|
29
|
-
} else if (typeof obj === 'object' && obj) {
|
30
|
-
var _result = [];
|
31
|
-
var keys = Object.keys(obj);
|
32
|
-
keys.sort();
|
33
|
-
for (var _ii = 0; _ii < keys.length; _ii++) {
|
34
|
-
var key = keys[_ii];
|
35
|
-
var _value = stableJSONStringifyOSS(obj[key]);
|
36
|
-
_result.push('"' + key + '":' + _value);
|
37
|
-
}
|
38
|
-
return '{' + _result.join(',') + '}';
|
39
|
-
} else {
|
40
|
-
return JSON.stringify(obj);
|
41
|
-
}
|
42
|
-
}
|
43
|
-
|
44
|
-
module.exports = stableJSONStringifyOSS;
|
@@ -1,85 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Copyright (c) 2013-present, Facebook, Inc.
|
3
|
-
* All rights reserved.
|
4
|
-
*
|
5
|
-
* This source code is licensed under the BSD-style license found in the
|
6
|
-
* LICENSE file in the root directory of this source tree. An additional grant
|
7
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
8
|
-
*
|
9
|
-
* TODO @joesavona: enable flow
|
10
|
-
* @providesModule transformInputObjectToIR
|
11
|
-
* @format
|
12
|
-
*/
|
13
|
-
|
14
|
-
'use strict';
|
15
|
-
|
16
|
-
var _require = require('./GraphQLSchemaUtils'),
|
17
|
-
getRawType = _require.getRawType;
|
18
|
-
|
19
|
-
var _require2 = require('graphql'),
|
20
|
-
GraphQLEnumType = _require2.GraphQLEnumType,
|
21
|
-
GraphQLInputObjectType = _require2.GraphQLInputObjectType,
|
22
|
-
GraphQLNonNull = _require2.GraphQLNonNull,
|
23
|
-
GraphQLScalarType = _require2.GraphQLScalarType;
|
24
|
-
|
25
|
-
/**
|
26
|
-
* Transforms a GraphQLInputObjectType to a RelayIR LinkedField.
|
27
|
-
*/
|
28
|
-
function transformInputObjectToIR(node) {
|
29
|
-
var type = getRawType(node.type);
|
30
|
-
var fields = type.getFields();
|
31
|
-
// If the node is the root (an Argument), use the name of the type so it is
|
32
|
-
// named 'FooBarData' instead of 'input'
|
33
|
-
|
34
|
-
var _ref = node.kind === 'Argument' ? type : node,
|
35
|
-
name = _ref.name;
|
36
|
-
|
37
|
-
return {
|
38
|
-
alias: null,
|
39
|
-
args: [],
|
40
|
-
directives: [],
|
41
|
-
handles: null,
|
42
|
-
kind: 'LinkedField',
|
43
|
-
metadata: null,
|
44
|
-
name: name,
|
45
|
-
selections: Object.keys(fields).map(function (fieldKey) {
|
46
|
-
return transformFieldToIR(fields[fieldKey]);
|
47
|
-
}),
|
48
|
-
type: node.type
|
49
|
-
};
|
50
|
-
}
|
51
|
-
|
52
|
-
/**
|
53
|
-
* Transforms a field (GraphQLInputObjectType or GraphQLScalarType) to a
|
54
|
-
* RelayIR ScalarField or LinkedField.
|
55
|
-
*/
|
56
|
-
function transformFieldToIR(node) {
|
57
|
-
var type = getRawType(node.type);
|
58
|
-
if (type instanceof GraphQLInputObjectType) {
|
59
|
-
return transformInputObjectToIR(node);
|
60
|
-
}
|
61
|
-
|
62
|
-
if (type instanceof GraphQLEnumType || type instanceof GraphQLScalarType) {
|
63
|
-
return transformScalarToIR(node.name, type);
|
64
|
-
}
|
65
|
-
|
66
|
-
throw new Error('Unhandled node type');
|
67
|
-
}
|
68
|
-
|
69
|
-
/**
|
70
|
-
* Transforms a GraphQLScalarType to a RelayIR ScalarField
|
71
|
-
*/
|
72
|
-
function transformScalarToIR(name, type) {
|
73
|
-
return {
|
74
|
-
alias: null,
|
75
|
-
args: [],
|
76
|
-
directives: [],
|
77
|
-
handles: null,
|
78
|
-
kind: 'ScalarField',
|
79
|
-
metadata: null,
|
80
|
-
name: name,
|
81
|
-
type: type
|
82
|
-
};
|
83
|
-
}
|
84
|
-
|
85
|
-
module.exports = transformInputObjectToIR;
|
@@ -1,24 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Copyright (c) 2013-present, Facebook, Inc.
|
3
|
-
* All rights reserved.
|
4
|
-
*
|
5
|
-
* This source code is licensed under the BSD-style license found in the
|
6
|
-
* LICENSE file in the root directory of this source tree. An additional grant
|
7
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
8
|
-
*
|
9
|
-
* @providesModule writeLegacyFlowFile
|
10
|
-
*
|
11
|
-
* @format
|
12
|
-
*/
|
13
|
-
|
14
|
-
'use strict';
|
15
|
-
|
16
|
-
function writeLegacyFlowFile(outputDirectory, name, flowTypes, platform) {
|
17
|
-
var moduleName = name + '.legacyflow';
|
18
|
-
var header = '/**\n * Copyright 2004-present Facebook. All Rights Reserved.\n *\n * ' + '@' + 'providesModule ' + moduleName + '\n * ' + require('signedsource').getSigningToken() + '\n * ' + '@' + 'flow\n */\n\n\'use strict\';\n\n/**\n * NOTE:\n * These are legacy flow types that have issues in some edge cases. For example:\n *\n * fragment on Actor {\n * ... on User {\n * name\n * }\n * ... on Page {\n * name\n * }\n * }\n *\n * generates invalid output. Please use the flow types from the *.graphql.js\n * file instead.\n */\n\n';
|
19
|
-
|
20
|
-
var fileName = platform ? moduleName + '.' + platform : moduleName;
|
21
|
-
outputDirectory.writeFile(fileName + '.js', require('signedsource').signFile(header + flowTypes + '\n'));
|
22
|
-
}
|
23
|
-
|
24
|
-
module.exports = writeLegacyFlowFile;
|