UNPKG

1.19 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 *
8 * @format
9 */
10// flowlint ambiguous-object-type:error
11'use strict';
12
13var invariant = require("fbjs/lib/invariant");
14
15var isRelayEnvironment = require('./isRelayEnvironment');
16
17/**
18 * Asserts that the input is a matches the `RelayContext` type defined in
19 * `RelayEnvironmentTypes` and returns it as that type.
20 */
21function assertRelayContext(relay) {
22 !isRelayContext(relay) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayContext: Expected `context.relay` to be an object conforming to ' + 'the `RelayContext` interface, got `%s`.', relay) : invariant(false) : void 0;
23 return relay;
24}
25/**
26 * Determine if the input is a plain object that matches the `RelayContext`
27 * type defined in `RelayEnvironmentTypes`.
28 */
29
30
31function isRelayContext(context) {
32 return typeof context === 'object' && context !== null && !Array.isArray(context) && isRelayEnvironment(context.environment);
33}
34
35module.exports = {
36 assertRelayContext: assertRelayContext,
37 isRelayContext: isRelayContext
38};
\No newline at end of file