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,158 @@
|
|
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
|
+
*
|
8
|
+
* @providesModule GraphQLCompilerContext
|
9
|
+
* @format
|
10
|
+
*/
|
11
|
+
|
12
|
+
'use strict';
|
13
|
+
|
14
|
+
var _classCallCheck3 = _interopRequireDefault(require('babel-runtime/helpers/classCallCheck'));
|
15
|
+
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
17
|
+
|
18
|
+
var _require = require('./GraphQLCompilerUserError'),
|
19
|
+
createUserError = _require.createUserError;
|
20
|
+
|
21
|
+
var _require2 = require('immutable'),
|
22
|
+
ImmutableOrderedMap = _require2.OrderedMap;
|
23
|
+
|
24
|
+
/**
|
25
|
+
* An immutable representation of a corpus of documents being compiled together.
|
26
|
+
* For each document, the context stores the IR and any validation errors.
|
27
|
+
*/
|
28
|
+
var GraphQLCompilerContext = function () {
|
29
|
+
function GraphQLCompilerContext(serverSchema, clientSchema) {
|
30
|
+
(0, _classCallCheck3['default'])(this, GraphQLCompilerContext);
|
31
|
+
|
32
|
+
this._isMutable = false;
|
33
|
+
this._documents = new ImmutableOrderedMap();
|
34
|
+
this._withTransform = new WeakMap();
|
35
|
+
this.serverSchema = serverSchema;
|
36
|
+
// If a separate client schema doesn't exist, use the server schema.
|
37
|
+
this.clientSchema = clientSchema || serverSchema;
|
38
|
+
}
|
39
|
+
|
40
|
+
/**
|
41
|
+
* Returns the documents for the context in the order they were added.
|
42
|
+
*/
|
43
|
+
|
44
|
+
|
45
|
+
GraphQLCompilerContext.prototype.documents = function documents() {
|
46
|
+
return this._documents.toArray();
|
47
|
+
};
|
48
|
+
|
49
|
+
GraphQLCompilerContext.prototype.forEachDocument = function forEachDocument(fn) {
|
50
|
+
this._documents.forEach(fn);
|
51
|
+
};
|
52
|
+
|
53
|
+
GraphQLCompilerContext.prototype.replace = function replace(node) {
|
54
|
+
return this._update(this._documents.update(node.name, function (existing) {
|
55
|
+
require('fbjs/lib/invariant')(existing, 'GraphQLCompilerContext: Expected to replace existing node %s, but' + 'one was not found in the context.', node.name);
|
56
|
+
return node;
|
57
|
+
}));
|
58
|
+
};
|
59
|
+
|
60
|
+
GraphQLCompilerContext.prototype.add = function add(node) {
|
61
|
+
return this._update(this._documents.update(node.name, function (existing) {
|
62
|
+
require('fbjs/lib/invariant')(!existing, 'GraphQLCompilerContext: Duplicate document named `%s`. GraphQL ' + 'fragments and roots must have unique names.', node.name);
|
63
|
+
return node;
|
64
|
+
}));
|
65
|
+
};
|
66
|
+
|
67
|
+
GraphQLCompilerContext.prototype.addAll = function addAll(nodes) {
|
68
|
+
return this.withMutations(function (mutable) {
|
69
|
+
return nodes.reduce(function (ctx, definition) {
|
70
|
+
return ctx.add(definition);
|
71
|
+
}, mutable);
|
72
|
+
});
|
73
|
+
};
|
74
|
+
|
75
|
+
/**
|
76
|
+
* Apply a list of compiler transforms and return a new compiler context.
|
77
|
+
*/
|
78
|
+
|
79
|
+
|
80
|
+
GraphQLCompilerContext.prototype.applyTransforms = function applyTransforms(transforms, reporter) {
|
81
|
+
var _this = this;
|
82
|
+
|
83
|
+
return require('./GraphQLCompilerProfiler').run('applyTransforms', function () {
|
84
|
+
return transforms.reduce(function (ctx, transform) {
|
85
|
+
return ctx.applyTransform(transform, reporter);
|
86
|
+
}, _this);
|
87
|
+
});
|
88
|
+
};
|
89
|
+
|
90
|
+
/**
|
91
|
+
* Applies a transform to this context, returning a new context.
|
92
|
+
*
|
93
|
+
* This is memoized such that applying the same sequence of transforms will
|
94
|
+
* not result in duplicated work.
|
95
|
+
*/
|
96
|
+
|
97
|
+
|
98
|
+
GraphQLCompilerContext.prototype.applyTransform = function applyTransform(transform, reporter) {
|
99
|
+
var transformed = this._withTransform.get(transform);
|
100
|
+
if (!transformed) {
|
101
|
+
var start = process.hrtime();
|
102
|
+
transformed = require('./GraphQLCompilerProfiler').instrument(transform)(this);
|
103
|
+
var delta = process.hrtime(start);
|
104
|
+
var deltaMs = Math.round((delta[0] * 1e9 + delta[1]) / 1e6);
|
105
|
+
reporter && reporter.reportTime(transform.name, deltaMs);
|
106
|
+
this._withTransform.set(transform, transformed);
|
107
|
+
}
|
108
|
+
return transformed;
|
109
|
+
};
|
110
|
+
|
111
|
+
GraphQLCompilerContext.prototype.get = function get(name) {
|
112
|
+
return this._documents.get(name);
|
113
|
+
};
|
114
|
+
|
115
|
+
GraphQLCompilerContext.prototype.getFragment = function getFragment(name) {
|
116
|
+
var node = this._get(name);
|
117
|
+
if (node.kind !== 'Fragment') {
|
118
|
+
var childModule = name.substring(0, name.lastIndexOf('_'));
|
119
|
+
throw createUserError('GraphQLCompilerContext: Cannot find fragment `%s`.' + ' Please make sure the fragment exists in `%s`.', name, childModule);
|
120
|
+
}
|
121
|
+
return node;
|
122
|
+
};
|
123
|
+
|
124
|
+
GraphQLCompilerContext.prototype.getRoot = function getRoot(name) {
|
125
|
+
var node = this._get(name);
|
126
|
+
require('fbjs/lib/invariant')(node.kind === 'Root', 'GraphQLCompilerContext: Expected `%s` to be a root, got `%s`.', name, node.kind);
|
127
|
+
return node;
|
128
|
+
};
|
129
|
+
|
130
|
+
GraphQLCompilerContext.prototype.remove = function remove(name) {
|
131
|
+
return this._update(this._documents['delete'](name));
|
132
|
+
};
|
133
|
+
|
134
|
+
GraphQLCompilerContext.prototype.withMutations = function withMutations(fn) {
|
135
|
+
var mutableCopy = this._update(this._documents.asMutable());
|
136
|
+
mutableCopy._isMutable = true;
|
137
|
+
var result = fn(mutableCopy);
|
138
|
+
result._isMutable = false;
|
139
|
+
result._documents = result._documents.asImmutable();
|
140
|
+
return this._documents === result._documents ? this : result;
|
141
|
+
};
|
142
|
+
|
143
|
+
GraphQLCompilerContext.prototype._get = function _get(name) {
|
144
|
+
var document = this._documents.get(name);
|
145
|
+
require('fbjs/lib/invariant')(document, 'GraphQLCompilerContext: Unknown document `%s`.', name);
|
146
|
+
return document;
|
147
|
+
};
|
148
|
+
|
149
|
+
GraphQLCompilerContext.prototype._update = function _update(documents) {
|
150
|
+
var context = this._isMutable ? this : new GraphQLCompilerContext(this.serverSchema, this.clientSchema);
|
151
|
+
context._documents = documents;
|
152
|
+
return context;
|
153
|
+
};
|
154
|
+
|
155
|
+
return GraphQLCompilerContext;
|
156
|
+
}();
|
157
|
+
|
158
|
+
module.exports = GraphQLCompilerContext;
|
@@ -0,0 +1,271 @@
|
|
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
|
+
*
|
8
|
+
* @format
|
9
|
+
*/
|
10
|
+
|
11
|
+
'use strict';
|
12
|
+
|
13
|
+
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');
|
14
|
+
|
15
|
+
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
|
16
|
+
|
17
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
18
|
+
|
19
|
+
/**
|
20
|
+
* The compiler profiler builds a "call graph" of high level operations as a
|
21
|
+
* means of tracking time spent over the course of running the compiler.
|
22
|
+
*/
|
23
|
+
|
24
|
+
var enabled = false;
|
25
|
+
var traces = [{
|
26
|
+
ph: 'M',
|
27
|
+
pid: 0,
|
28
|
+
tid: 0,
|
29
|
+
name: 'process_name',
|
30
|
+
args: { name: 'relay-compiler' }
|
31
|
+
}, {
|
32
|
+
ph: 'M',
|
33
|
+
pid: 0,
|
34
|
+
tid: 0,
|
35
|
+
name: 'thread_name',
|
36
|
+
args: { name: 'relay-compiler' }
|
37
|
+
}];
|
38
|
+
var stack = [];
|
39
|
+
|
40
|
+
function enable() {
|
41
|
+
enabled = true;
|
42
|
+
}
|
43
|
+
|
44
|
+
function getTraces() {
|
45
|
+
return traces;
|
46
|
+
}
|
47
|
+
|
48
|
+
/**
|
49
|
+
* Run the provided function as part of a stack profile.
|
50
|
+
*/
|
51
|
+
function run(name, fn) {
|
52
|
+
return instrument(fn, name)();
|
53
|
+
}
|
54
|
+
|
55
|
+
/**
|
56
|
+
* Run the provided async function as part context in a stack profile.
|
57
|
+
* See instrumentAsyncContext() for limitations and usage notes.
|
58
|
+
*/
|
59
|
+
function asyncContext(name, fn) {
|
60
|
+
return instrumentAsyncContext(fn, name)();
|
61
|
+
}
|
62
|
+
|
63
|
+
/**
|
64
|
+
* Wait for the provided async operation as an async profile.
|
65
|
+
*/
|
66
|
+
function waitFor(name, fn) {
|
67
|
+
return instrumentWait(fn, name)();
|
68
|
+
}
|
69
|
+
|
70
|
+
/**
|
71
|
+
* Return a new instrumented sync function to be part of a stack profile.
|
72
|
+
*
|
73
|
+
* This instruments synchronous functions to be displayed in a stack
|
74
|
+
* visualization. To instrument async functions, see instrumentAsyncContext()
|
75
|
+
* and instrumentWait().
|
76
|
+
*/
|
77
|
+
function instrument(fn, name) {
|
78
|
+
if (!enabled) {
|
79
|
+
return fn;
|
80
|
+
}
|
81
|
+
var profileName = name || fn.displayName || fn.name;
|
82
|
+
var instrumented = function instrumented() {
|
83
|
+
var traceId = start(profileName);
|
84
|
+
try {
|
85
|
+
return fn.apply(this, arguments);
|
86
|
+
} finally {
|
87
|
+
end(traceId);
|
88
|
+
}
|
89
|
+
};
|
90
|
+
instrumented.displayName = profileName;
|
91
|
+
return instrumented;
|
92
|
+
}
|
93
|
+
|
94
|
+
/**
|
95
|
+
* Return a new instrumented async function which provides context for a stack.
|
96
|
+
*
|
97
|
+
* Because the resulting profiling information will be incorporated into a
|
98
|
+
* stack visualization, the instrumented function must represent a distinct
|
99
|
+
* region of time which does not overlap with any other async context.
|
100
|
+
*
|
101
|
+
* In other words, functions instrumented with instrumentAsyncContext must not
|
102
|
+
* run in parallel via Promise.all().
|
103
|
+
*
|
104
|
+
* To instrument functions which will run in parallel, use instrumentWait().
|
105
|
+
*/
|
106
|
+
function instrumentAsyncContext(fn, name) {
|
107
|
+
if (!enabled) {
|
108
|
+
return fn;
|
109
|
+
}
|
110
|
+
var profileName = name || fn.displayName || fn.name;
|
111
|
+
var instrumented = (() => {
|
112
|
+
var _ref = (0, _asyncToGenerator3.default)(function* () {
|
113
|
+
var traceId = start(profileName);
|
114
|
+
try {
|
115
|
+
return yield fn.apply(this, arguments);
|
116
|
+
} finally {
|
117
|
+
end(traceId);
|
118
|
+
}
|
119
|
+
});
|
120
|
+
|
121
|
+
function instrumented() {
|
122
|
+
return _ref.apply(this, arguments);
|
123
|
+
}
|
124
|
+
|
125
|
+
return instrumented;
|
126
|
+
})();
|
127
|
+
instrumented.displayName = profileName;
|
128
|
+
return instrumented;
|
129
|
+
}
|
130
|
+
|
131
|
+
/**
|
132
|
+
* Return a new instrumented function which performs an awaited async operation.
|
133
|
+
*
|
134
|
+
* The instrumented function is not included in the overall run time of the
|
135
|
+
* compiler, instead it captures the time waiting on some asynchronous external
|
136
|
+
* resource such as network or filesystem which are often run in parallel.
|
137
|
+
*/
|
138
|
+
function instrumentWait(fn, name) {
|
139
|
+
if (!enabled) {
|
140
|
+
return fn;
|
141
|
+
}
|
142
|
+
var profileName = name || fn.displayName || fn.name;
|
143
|
+
var instrumented = (() => {
|
144
|
+
var _ref2 = (0, _asyncToGenerator3.default)(function* () {
|
145
|
+
var traceId = startWait(profileName);
|
146
|
+
try {
|
147
|
+
return yield fn.apply(this, arguments);
|
148
|
+
} finally {
|
149
|
+
end(traceId);
|
150
|
+
}
|
151
|
+
});
|
152
|
+
|
153
|
+
function instrumented() {
|
154
|
+
return _ref2.apply(this, arguments);
|
155
|
+
}
|
156
|
+
|
157
|
+
return instrumented;
|
158
|
+
})();
|
159
|
+
instrumented.displayName = profileName;
|
160
|
+
return instrumented;
|
161
|
+
}
|
162
|
+
|
163
|
+
var T_ZERO = process.hrtime();
|
164
|
+
|
165
|
+
// Return a Uint32 of microtime duration since program start.
|
166
|
+
function microtime() {
|
167
|
+
var hrtime = process.hrtime(T_ZERO);
|
168
|
+
// eslint-disable-next-line no-bitwise
|
169
|
+
return 0 | hrtime[0] * 1e6 + Math.round(hrtime[1] / 1e3);
|
170
|
+
}
|
171
|
+
|
172
|
+
/**
|
173
|
+
* Start a stack profile with a particular name, returns an ID to pass to end().
|
174
|
+
*
|
175
|
+
* Other profiles may start before this one ends, which will be represented as
|
176
|
+
* nested operations, however all nested operations must end before this ends.
|
177
|
+
*
|
178
|
+
* In particular, be careful to end after errors.
|
179
|
+
*/
|
180
|
+
function start(name) {
|
181
|
+
var beginTrace = {
|
182
|
+
ph: 'B',
|
183
|
+
name: name,
|
184
|
+
pid: 0,
|
185
|
+
tid: 0,
|
186
|
+
ts: microtime()
|
187
|
+
};
|
188
|
+
traces.push(beginTrace);
|
189
|
+
stack.push(beginTrace);
|
190
|
+
return traces.length - 1;
|
191
|
+
}
|
192
|
+
|
193
|
+
var asyncID = 0;
|
194
|
+
|
195
|
+
/**
|
196
|
+
* Start an async wait profile with a particular name, returns an ID to pass
|
197
|
+
* to end().
|
198
|
+
*
|
199
|
+
* Other profiles may start before this one ends, which will be represented as
|
200
|
+
* nested operations, however all nested operations must end before this ends.
|
201
|
+
*
|
202
|
+
* In particular, be careful to end after errors.
|
203
|
+
*/
|
204
|
+
function startWait(name) {
|
205
|
+
traces.push({
|
206
|
+
ph: 'b',
|
207
|
+
name: name,
|
208
|
+
cat: 'wait',
|
209
|
+
id: asyncID++,
|
210
|
+
pid: 0,
|
211
|
+
tid: 0,
|
212
|
+
ts: microtime()
|
213
|
+
});
|
214
|
+
return traces.length - 1;
|
215
|
+
}
|
216
|
+
|
217
|
+
function end(traceIdx) {
|
218
|
+
var trace = traces[traceIdx];
|
219
|
+
|
220
|
+
if (trace.ph === 'b') {
|
221
|
+
traces.push({
|
222
|
+
ph: 'e',
|
223
|
+
cat: trace.cat,
|
224
|
+
name: trace.name,
|
225
|
+
id: trace.id,
|
226
|
+
pid: trace.pid,
|
227
|
+
tid: trace.tid,
|
228
|
+
ts: microtime()
|
229
|
+
});
|
230
|
+
return;
|
231
|
+
}
|
232
|
+
|
233
|
+
require('fbjs/lib/invariant')(trace.ph === 'B', 'Begin trace phase');
|
234
|
+
require('fbjs/lib/invariant')(stack.pop() === trace, 'GraphQLCompilerProfiler: The profile trace %s ended before nested traces. ' + 'If it is async, try using Profile.waitFor or Profile.profileWait.', trace.name);
|
235
|
+
|
236
|
+
var prevTrace = traces[traces.length - 1];
|
237
|
+
|
238
|
+
if (trace === prevTrace) {
|
239
|
+
traces[traceIdx] = {
|
240
|
+
ph: 'X',
|
241
|
+
name: trace.name,
|
242
|
+
pid: trace.pid,
|
243
|
+
tid: trace.tid,
|
244
|
+
ts: trace.ts,
|
245
|
+
dur: microtime() - trace.ts
|
246
|
+
};
|
247
|
+
return;
|
248
|
+
}
|
249
|
+
|
250
|
+
traces.push({
|
251
|
+
ph: 'E',
|
252
|
+
name: trace.name,
|
253
|
+
pid: trace.pid,
|
254
|
+
tid: trace.tid,
|
255
|
+
ts: microtime()
|
256
|
+
});
|
257
|
+
}
|
258
|
+
|
259
|
+
module.exports = {
|
260
|
+
enable: enable,
|
261
|
+
getTraces: getTraces,
|
262
|
+
run: run,
|
263
|
+
asyncContext: asyncContext,
|
264
|
+
waitFor: waitFor,
|
265
|
+
instrument: instrument,
|
266
|
+
instrumentAsyncContext: instrumentAsyncContext,
|
267
|
+
instrumentWait: instrumentWait,
|
268
|
+
start: start,
|
269
|
+
startWait: startWait,
|
270
|
+
end: end
|
271
|
+
};
|
@@ -1,10 +1,8 @@
|
|
1
1
|
/**
|
2
2
|
* Copyright (c) 2013-present, Facebook, Inc.
|
3
|
-
* All rights reserved.
|
4
3
|
*
|
5
|
-
* This source code is licensed under the
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
7
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
4
|
+
* This source code is licensed under the MIT license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
8
6
|
*
|
9
7
|
*
|
10
8
|
* @providesModule GraphQLCompilerPublic
|
@@ -13,30 +11,37 @@
|
|
13
11
|
|
14
12
|
'use strict';
|
15
13
|
|
14
|
+
var _require = require('./SourceControl'),
|
15
|
+
SourceControlMercurial = _require.SourceControlMercurial;
|
16
|
+
|
16
17
|
module.exports = {
|
17
18
|
ASTConvert: require('./ASTConvert'),
|
18
19
|
CodegenDirectory: require('./CodegenDirectory'),
|
19
|
-
CodegenRunner: require('./
|
20
|
-
|
21
|
-
CompilerContext: require('./
|
22
|
-
ConsoleReporter: require('./
|
23
|
-
|
20
|
+
CodegenRunner: require('./CodegenRunner'),
|
21
|
+
CodegenWatcher: require('./CodegenWatcher'),
|
22
|
+
CompilerContext: require('./GraphQLCompilerContext'),
|
23
|
+
ConsoleReporter: require('./GraphQLConsoleReporter'),
|
24
|
+
DotGraphQLParser: require('./DotGraphQLParser'),
|
25
|
+
ASTCache: require('./ASTCache'),
|
26
|
+
IRTransformer: require('./GraphQLIRTransformer'),
|
27
|
+
IRVisitor: require('./GraphQLIRVisitor'),
|
28
|
+
MultiReporter: require('./GraphQLMultiReporter'),
|
29
|
+
Parser: require('./GraphQLParser'),
|
30
|
+
Printer: require('./GraphQLIRPrinter'),
|
31
|
+
Profiler: require('./GraphQLCompilerProfiler'),
|
32
|
+
SchemaUtils: require('./GraphQLSchemaUtils'),
|
33
|
+
SourceControlMercurial: SourceControlMercurial,
|
34
|
+
Validator: require('./GraphQLValidator'),
|
35
|
+
WatchmanClient: require('./GraphQLWatchmanClient'),
|
24
36
|
filterContextForNode: require('./filterContextForNode'),
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
GraphQLTextParser: require('./GraphQLTextParser'),
|
30
|
-
GraphQLValidator: require('./GraphQLValidator'),
|
31
|
-
IRTransformer: require('./RelayIRTransformer'),
|
32
|
-
IRVisitor: require('./RelayIRVisitor'),
|
33
|
-
MultiReporter: require('./RelayMultiReporter'),
|
34
|
-
RelayParser: require('./RelayParser'),
|
35
|
-
Printer: require('./RelayPrinter'),
|
37
|
+
getIdentifierForArgumentValue: require('./getIdentifierForArgumentValue'),
|
38
|
+
getLiteralArgumentValues: require('./getLiteralArgumentValues'),
|
39
|
+
isEquivalentType: require('./isEquivalentType'),
|
40
|
+
nullthrows: require('./nullthrowsOSS'),
|
36
41
|
|
37
|
-
AutoAliasTransform: require('./AutoAliasTransform'),
|
38
42
|
FilterDirectivesTransform: require('./FilterDirectivesTransform'),
|
39
|
-
FlattenTransform: require('./
|
43
|
+
FlattenTransform: require('./FlattenTransform'),
|
44
|
+
InlineFragmentsTransform: require('./InlineFragmentsTransform'),
|
40
45
|
SkipClientFieldTransform: require('./SkipClientFieldTransform'),
|
41
46
|
SkipRedundantNodesTransform: require('./SkipRedundantNodesTransform'),
|
42
47
|
SkipUnreachableNodeTransform: require('./SkipUnreachableNodeTransform'),
|
@@ -0,0 +1,26 @@
|
|
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 GraphQLCompilerUserError
|
8
|
+
*
|
9
|
+
* @format
|
10
|
+
*/
|
11
|
+
|
12
|
+
'use strict';
|
13
|
+
|
14
|
+
var createUserError = function createUserError(format) {
|
15
|
+
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
16
|
+
args[_key - 1] = arguments[_key];
|
17
|
+
}
|
18
|
+
|
19
|
+
var index = 0;
|
20
|
+
var formatted = format.replace(/%s/g, function (match) {
|
21
|
+
return args[index++];
|
22
|
+
});
|
23
|
+
return new Error(formatted);
|
24
|
+
};
|
25
|
+
|
26
|
+
module.exports = { createUserError: createUserError };
|
@@ -0,0 +1,58 @@
|
|
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 GraphQLConsoleReporter
|
8
|
+
*
|
9
|
+
* @format
|
10
|
+
*/
|
11
|
+
|
12
|
+
'use strict';
|
13
|
+
|
14
|
+
var _classCallCheck3 = _interopRequireDefault(require('babel-runtime/helpers/classCallCheck'));
|
15
|
+
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
17
|
+
|
18
|
+
var GraphQLConsoleReporter = function () {
|
19
|
+
function GraphQLConsoleReporter(options) {
|
20
|
+
(0, _classCallCheck3['default'])(this, GraphQLConsoleReporter);
|
21
|
+
|
22
|
+
this._verbose = options.verbose;
|
23
|
+
this._quiet = options.quiet;
|
24
|
+
}
|
25
|
+
|
26
|
+
GraphQLConsoleReporter.prototype.reportMessage = function reportMessage(message) {
|
27
|
+
if (!this._quiet) {
|
28
|
+
process.stdout.write(message + '\n');
|
29
|
+
}
|
30
|
+
};
|
31
|
+
|
32
|
+
GraphQLConsoleReporter.prototype.reportTime = function reportTime(name, ms) {
|
33
|
+
if (this._verbose && !this.quiet) {
|
34
|
+
var time = ms === 0 ? require('chalk').gray(' <1ms') : ms < 1000 ? require('chalk').blue(leftPad(5, ms + 'ms')) : require('chalk').red(Math.floor(ms / 10) / 100 + 's');
|
35
|
+
process.stdout.write(' ' + time + ' ' + require('chalk').gray(name) + '\n');
|
36
|
+
}
|
37
|
+
};
|
38
|
+
|
39
|
+
GraphQLConsoleReporter.prototype.reportError = function reportError(caughtLocation, error) {
|
40
|
+
if (!this._quiet) {
|
41
|
+
process.stdout.write(require('chalk').red('ERROR:\n' + error.message + '\n'));
|
42
|
+
if (this._verbose) {
|
43
|
+
var frames = error.stack.match(/^ {4}at .*$/gm);
|
44
|
+
if (frames) {
|
45
|
+
process.stdout.write(require('chalk').gray('From: ' + caughtLocation + '\n' + frames.join('\n') + '\n'));
|
46
|
+
}
|
47
|
+
}
|
48
|
+
}
|
49
|
+
};
|
50
|
+
|
51
|
+
return GraphQLConsoleReporter;
|
52
|
+
}();
|
53
|
+
|
54
|
+
function leftPad(len, str) {
|
55
|
+
return new Array(len - str.length + 1).join(' ') + str;
|
56
|
+
}
|
57
|
+
|
58
|
+
module.exports = GraphQLConsoleReporter;
|
package/lib/GraphQLIR.js
ADDED
@@ -0,0 +1,12 @@
|
|
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 GraphQLIR
|
8
|
+
*
|
9
|
+
* @format
|
10
|
+
*/
|
11
|
+
|
12
|
+
'use strict';
|