UNPKG

2.02 kBJavaScriptView Raw
1/**
2 * Copyright (c) Facebook, Inc. and its affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 * @emails oncall+relay
8 *
9 * @format
10 */
11// flowlint ambiguous-object-type:error
12'use strict';
13
14var preloadQuery = require('./preloadQuery_DEPRECATED');
15
16function prepareEntryPoint(environmentProvider, entryPoint, entryPointParams) {
17 // Start loading the code for the entrypoint
18 if (entryPoint.root.getModuleIfRequired() == null) {
19 entryPoint.root.load();
20 }
21
22 var preloadProps = entryPoint.getPreloadProps(entryPointParams);
23 var queries = preloadProps.queries,
24 entryPoints = preloadProps.entryPoints;
25 var preloadedQueries = {};
26 var preloadedEntryPoints = {};
27
28 if (queries != null) {
29 var queriesPropNames = Object.keys(queries);
30 queriesPropNames.forEach(function (queryPropName) {
31 var _queries$queryPropNam = queries[queryPropName],
32 environmentProviderOptions = _queries$queryPropNam.environmentProviderOptions,
33 options = _queries$queryPropNam.options,
34 parameters = _queries$queryPropNam.parameters,
35 variables = _queries$queryPropNam.variables;
36 var environment = environmentProvider.getEnvironment(environmentProviderOptions);
37 preloadedQueries[queryPropName] = preloadQuery(environment, parameters, variables, options, environmentProviderOptions);
38 });
39 }
40
41 if (entryPoints != null) {
42 var entryPointPropNames = Object.keys(entryPoints);
43 entryPointPropNames.forEach(function (entryPointPropName) {
44 var entryPointDescription = entryPoints[entryPointPropName];
45
46 if (entryPointDescription == null) {
47 return;
48 }
49
50 var nestedEntryPoint = entryPointDescription.entryPoint,
51 nestedParams = entryPointDescription.entryPointParams;
52 preloadedEntryPoints[entryPointPropName] = prepareEntryPoint(environmentProvider, nestedEntryPoint, nestedParams);
53 });
54 }
55}
56
57module.exports = prepareEntryPoint;
\No newline at end of file