react-relay
Version:
A framework for building data-driven React applications.
1,525 lines (1,305 loc) • 701 kB
JavaScript
/**
* Relay v0.2.0
*/
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory(require("React"));
else if(typeof define === 'function' && define.amd)
define(["React"], factory);
else if(typeof exports === 'object')
exports["Relay"] = factory(require("React"));
else
root["Relay"] = factory(root["React"]);
})(this, function(__WEBPACK_EXTERNAL_MODULE_51__) {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ((function(modules) {
// Check all modules for deduplicated modules
for(var i in modules) {
if(Object.prototype.hasOwnProperty.call(modules, i)) {
switch(typeof modules[i]) {
case "function": break;
case "object":
// Module can be created from a template
modules[i] = (function(_m) {
var args = _m.slice(1), fn = modules[_m[0]];
return function (a,b,c) {
fn.apply(this, [a,b,c].concat(args));
};
}(modules[i]));
break;
default:
// Module is a copy of another module
modules[i] = modules[modules[i]];
break;
}
}
}
return modules;
}([
/* 0 */
/***/ function(module, exports, __webpack_require__) {
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule Relay
* @typechecks
*
*/
'use strict';
var _extends = __webpack_require__(10)['default'];
var RelayDefaultNetworkLayer = __webpack_require__(139);
var RelayPublic = __webpack_require__(147);
// By default, assume that GraphQL is served at `/graphql` on the same domain.
RelayPublic.injectNetworkLayer(new RelayDefaultNetworkLayer('/graphql'));
module.exports = _extends({}, RelayPublic, {
// Expose the default network layer to allow convenient re-configuration.
DefaultNetworkLayer: RelayDefaultNetworkLayer
});
/***/ },
/* 1 */
/***/ function(module, exports, __webpack_require__) {
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule invariant
*/
"use strict";
/**
* Use invariant() to assert state which your program assumes to be true.
*
* Provide sprintf-style format (only %s is supported) and arguments
* to provide information about what broke and what you were
* expecting.
*
* The invariant message will be stripped in production, but the invariant
* will remain to ensure logic does not differ in production.
*/
var invariant = function invariant(condition, format, a, b, c, d, e, f) {
if (true) {
if (format === undefined) {
throw new Error('invariant requires an error message argument');
}
}
if (!condition) {
var error;
if (format === undefined) {
error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.');
} else {
var args = [a, b, c, d, e, f];
var argIndex = 0;
error = new Error('Invariant Violation: ' + format.replace(/%s/g, function () {
return args[argIndex++];
}));
}
error.framesToPop = 1; // we don't care about invariant's own frame
throw error;
}
};
module.exports = invariant;
/***/ },
/* 2 */
/***/ function(module, exports) {
"use strict";
exports["default"] = function (instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
};
exports.__esModule = true;
/***/ },
/* 3 */
/***/ function(module, exports, __webpack_require__) {
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule RelayQuery
*
* @typechecks
*/
'use strict';
var _classCallCheck = __webpack_require__(2)['default'];
var _inherits = __webpack_require__(7)['default'];
var _extends = __webpack_require__(10)['default'];
var GraphQL = __webpack_require__(17);
var RelayConnectionInterface = __webpack_require__(9);
var RelayFragmentReference = __webpack_require__(38);
var RelayMetaRoute = __webpack_require__(26);
var RelayRouteFragment = __webpack_require__(82);
var areEqual = __webpack_require__(109);
var callsFromGraphQL = __webpack_require__(58);
var callsToGraphQL = __webpack_require__(83);
var generateRQLFieldAlias = __webpack_require__(162);
var getWeakIdForObject = __webpack_require__(89);
var invariant = __webpack_require__(1);
var printRelayQueryCall = __webpack_require__(42);
var shallowEqual = __webpack_require__(72);
var stableStringify = __webpack_require__(94);
// TODO: replace once #6525923 is resolved
// conditional field calls/values
var IF = 'if';
var UNLESS = 'unless';
var TRUE = 'true';
var FALSE = 'false';
var QUERY_ID_PREFIX = 'q';
var REF_PARAM_PREFIX = 'ref_';
var _nextQueryID = 0;
var DEFAULT_FRAGMENT_METADATA = {
isDeferred: false,
isReferenceFragment: false,
isTypeConditional: false
};
/**
* @internal
*
* Queries in Relay are represented as trees. Possible nodes include the root,
* fields, and fragments. Fields can have children, or they can be leaf nodes.
* Root and fragment nodes must always have children.
*
* `RelayQueryNode` provides access to information such as the field name,
* generated alias, sub-fields, and call values.
*
* Nodes are immutable; query modification is supported via `clone`:
*
* ```
* var next = prev.clone(prev.getChildren().filter(f => ...));
* ```
*
* Note: Mediating access to actual query nodes is necessary so that we can
* replace the current mutable GraphQL nodes with an immutable query
* representation. This class *must not* mutate the underlying `concreteNode`.
* Instead, use an instance variable (see `clone()`).
*
* TODO (#6937314): RelayQueryNode support for toJSON/fromJSON
*/
var RelayQueryNode = (function () {
RelayQueryNode.create = function create(concreteNode, route, variables) {
var node = createNode(concreteNode, route, variables);
!(node instanceof RelayQueryNode) ? true ? invariant(false, 'RelayQueryNode.create(): Expected a node.') : invariant(false) : undefined;
return node;
};
/**
* Helper to construct a new root query with the given attributes and 'empty'
* route/variables.
*/
RelayQueryNode.buildRoot = function buildRoot(rootCall, rootCallValue, children, metadata, name) {
var nextChildren = children ? children.filter(function (child) {
return !!child;
}) : [];
var concreteRoot = new GraphQL.Query(rootCall, rootCallValue || null, null, null, metadata, name);
var root = new RelayQueryRoot(concreteRoot, RelayMetaRoute.get('$RelayQuery'), {});
root.__children__ = nextChildren;
return root;
};
/**
* Helper to construct a new fragment with the given attributes and 'empty'
* route/variables.
*/
RelayQueryNode.buildFragment = function buildFragment(name, type, children, metadata) {
var nextChildren = children ? children.filter(function (child) {
return !!child;
}) : [];
var concreteFragment = new GraphQL.QueryFragment(name, type, null, null, metadata);
var fragment = new RelayQueryFragment(concreteFragment, RelayMetaRoute.get('$RelayQuery'), {}, {
isDeferred: !!(metadata && metadata.isDeferred),
isReferenceFragment: !!(metadata && metadata.isReferenceFragment),
isTypeConditional: !!(metadata && metadata.isTypeConditional)
});
fragment.__children__ = nextChildren;
return fragment;
};
/**
* Helper to construct a new field with the given attributes and 'empty'
* route/variables.
*/
RelayQueryNode.buildField = function buildField(fieldName, calls, children, metadata, alias) {
var nextChildren = children ? children.filter(function (child) {
return !!child;
}) : [];
var concreteField = new GraphQL.Field(fieldName, null, null, calls ? callsToGraphQL(calls) : null, alias, null, metadata);
var field = new RelayQueryField(concreteField, RelayMetaRoute.get('$RelayQuery'), {});
field.__children__ = nextChildren;
return field;
};
/**
* Helper to construct a new mutation with the given attributes and 'empty'
* route/variables.
*/
RelayQueryNode.buildMutation = function buildMutation(mutationName, responseType, callName, callValue, children, metadata) {
var nextChildren = children ? children.filter(function (child) {
return !!child;
}) : [];
var concreteMutation = new GraphQL.Mutation(mutationName, responseType, new GraphQL.Callv(callName, new GraphQL.CallVariable('input')), null, null, metadata);
var mutation = new RelayQueryMutation(concreteMutation, RelayMetaRoute.get('$RelayQuery'), { input: callValue || '' });
mutation.__children__ = nextChildren;
return mutation;
};
RelayQueryNode.createFragment = function createFragment(concreteNode, route, variables, metadata) {
!GraphQL.isFragment(concreteNode) ? true ? invariant(false, 'RelayQuery.createQuery(): Expected a concrete query fragment, got: %s', concreteNode) : invariant(false) : undefined;
return createMemoizedFragment(concreteNode, route, variables, metadata || DEFAULT_FRAGMENT_METADATA);
};
RelayQueryNode.createQuery = function createQuery(concreteNode, route, variables) {
!GraphQL.isQuery(concreteNode) ? true ? invariant(false, 'RelayQuery.createQuery(): Expected a concrete query, got: %s', concreteNode) : invariant(false) : undefined;
return new RelayQueryRoot(concreteNode, route, variables);
};
/**
* @private
*
* Base class for all node types, must not be directly instantiated.
*/
function RelayQueryNode(concreteNode, route, variables) {
_classCallCheck(this, RelayQueryNode);
!(this.constructor.name !== 'RelayQueryNode') ? true ? invariant(false, 'RelayQueryNode: Abstract class cannot be instantiated.') : invariant(false) : undefined;
this.__concreteNode__ = concreteNode;
this.__route__ = route;
this.__variables__ = variables;
// lazily computed properties
this.__calls__ = null;
this.__children__ = null;
this.__fieldMap__ = null;
this.__hasDeferredDescendant__ = null;
this.__hasValidatedConnectionCalls__ = null;
this.__serializationKey__ = null;
this.__storageKey__ = null;
// TODO(#7161070) Remove this once `toGraphQL` is no longer needed.
this.__isConcreteNodeCached__ = false;
}
/**
* @internal
*
* Wraps access to query root nodes.
*/
RelayQueryNode.prototype.isGenerated = function isGenerated() {
return false;
};
RelayQueryNode.prototype.isRefQueryDependency = function isRefQueryDependency() {
return false;
};
RelayQueryNode.prototype.isScalar = function isScalar() {
return false;
};
RelayQueryNode.prototype.clone = function clone(children) {
if (this.isScalar()) {
// Compact new children *after* this check, for consistency.
!(children.length === 0) ? true ? invariant(false, 'RelayQueryNode: Cannot add children to scalar fields.') : invariant(false) : undefined;
return this;
}
var prevChildren = this.getChildren();
var nextChildren = cloneChildren(prevChildren, children);
if (!nextChildren.length) {
return null;
} else if (nextChildren === prevChildren) {
return this;
}
var clone = RelayQueryNode.create(this.__concreteNode__, this.__route__, this.__variables__);
clone.__children__ = nextChildren;
clone.__calls__ = this.__calls__;
clone.__serializationKey__ = this.__serializationKey__;
clone.__storageKey__ = this.__storageKey__;
return clone;
};
RelayQueryNode.prototype.getChildren = function getChildren() {
var _this = this;
var children = this.__children__;
if (!children) {
var nextChildren = [];
this.__concreteNode__.children.forEach(function (concreteChild) {
var node = createNode(concreteChild, _this.__route__, _this.__variables__);
if (node) {
nextChildren.push(node);
}
});
this.__children__ = nextChildren;
children = nextChildren;
}
return children;
};
RelayQueryNode.prototype.getField = function getField(field) {
return this.getFieldByStorageKey(field.getStorageKey());
};
RelayQueryNode.prototype.getFieldByStorageKey = function getFieldByStorageKey(storageKey) {
var fieldMap = this.__fieldMap__;
if (!fieldMap) {
fieldMap = {};
var child;
var children = this.getChildren();
for (var ii = 0; ii < children.length; ii++) {
child = children[ii];
if (child instanceof RelayQueryField) {
fieldMap[child.getStorageKey()] = child;
}
}
this.__fieldMap__ = fieldMap;
}
return fieldMap[storageKey];
};
RelayQueryNode.prototype.getRoute = function getRoute() {
return this.__route__;
};
RelayQueryNode.prototype.getVariables = function getVariables() {
return this.__variables__;
};
RelayQueryNode.prototype.hasDeferredDescendant = function hasDeferredDescendant() {
var hasDeferredDescendant = this.__hasDeferredDescendant__;
if (hasDeferredDescendant == null) {
hasDeferredDescendant = !this.isScalar() && this.getChildren().some(function (child) {
return child.hasDeferredDescendant();
});
this.__hasDeferredDescendant__ = hasDeferredDescendant;
}
return hasDeferredDescendant;
};
RelayQueryNode.prototype.isRequisite = function isRequisite() {
return false;
};
/**
* Determine if `this` and `that` are deeply equal.
*/
RelayQueryNode.prototype.equals = function equals(that) {
var thisChildren = this.getChildren();
var thatChildren = that.getChildren();
return thisChildren === thatChildren || thisChildren.length === thatChildren.length && thisChildren.every(function (c, ii) {
return c.equals(thatChildren[ii]);
});
};
/**
* Performs a fast comparison of whether `this` and `that` represent identical
* query nodes. Returns true only if the concrete nodes, routes, and variables
* are all the same.
*
* Note that it is possible that this method can return false in cases where
* `equals` would return true. This can happen when the concrete nodes are
* different but structurally identical, or when the route/variables are
* different but do not have an effect on the structure of the query.
*/
RelayQueryNode.prototype.isEquivalent = function isEquivalent(that) {
return this.__concreteNode__ === that.__concreteNode__ && this.__route__ === that.__route__ && shallowEqual(this.__variables__, that.__variables__);
};
RelayQueryNode.prototype.createNode = function createNode(concreteNode) {
return RelayQueryNode.create(concreteNode, this.__route__, this.__variables__);
};
RelayQueryNode.prototype.getConcreteQueryNode = function getConcreteQueryNode(onCacheMiss) {
if (!this.__isConcreteNodeCached__) {
this.__concreteNode__ = onCacheMiss();
this.__isConcreteNodeCached__ = true;
}
return this.__concreteNode__;
};
return RelayQueryNode;
})();
var RelayQueryRoot = (function (_RelayQueryNode) {
_inherits(RelayQueryRoot, _RelayQueryNode);
function RelayQueryRoot(concreteNode, route, variables) {
_classCallCheck(this, RelayQueryRoot);
_RelayQueryNode.call(this, concreteNode, route, variables);
this.__batchCall__ = undefined;
this.__deferredFragmentNames__ = undefined;
this.__id__ = undefined;
// Ensure IDs are generated in the order that queries are created
this.getID();
}
/**
* @internal
*
* Abstract base class for mutations and subscriptions.
*/
RelayQueryRoot.prototype.getName = function getName() {
var name = this.__concreteNode__.name;
if (!name) {
name = this.getID();
this.__concreteNode__.name = name;
}
return name;
};
RelayQueryRoot.prototype.getID = function getID() {
var id = this.__id__;
if (id == null) {
id = QUERY_ID_PREFIX + _nextQueryID++;
this.__id__ = id;
}
return id;
};
RelayQueryRoot.prototype.getBatchCall = function getBatchCall() {
var batchCall = this.__batchCall__;
if (batchCall === undefined) {
var concreteCalls = this.__concreteNode__.calls;
var callArg = concreteCalls[0].value;
if (GraphQL.isBatchCallVariable(callArg)) {
batchCall = {
refParamName: REF_PARAM_PREFIX + callArg.sourceQueryID,
sourceQueryID: callArg.sourceQueryID,
sourceQueryPath: callArg.jsonPath
};
} else {
batchCall = null;
}
this.__batchCall__ = batchCall;
}
return batchCall;
};
RelayQueryRoot.prototype.getRootCall = function getRootCall() {
var calls = this.__calls__;
if (!calls) {
var concreteCalls = this.__concreteNode__.calls;
calls = callsFromGraphQL(concreteCalls, this.__variables__);
this.__calls__ = calls;
}
return calls[0];
};
RelayQueryRoot.prototype.getCallType = function getCallType() {
if (this.__concreteNode__.calls.length > 0) {
return this.__concreteNode__.metadata.rootCallType;
}
};
RelayQueryRoot.prototype.getRootCallArgument = function getRootCallArgument() {
return this.__concreteNode__.metadata.rootArg;
};
RelayQueryRoot.prototype.hasDeferredDescendant = function hasDeferredDescendant() {
return this.isDeferred() || _RelayQueryNode.prototype.hasDeferredDescendant.call(this);
};
RelayQueryRoot.prototype.isDeferred = function isDeferred() {
return this.__concreteNode__.isDeferred;
};
RelayQueryRoot.prototype.getDeferredFragmentNames = function getDeferredFragmentNames() {
var fragmentNames = this.__deferredFragmentNames__;
if (!fragmentNames) {
fragmentNames = {};
getDeferredFragmentNamesForField(this, fragmentNames);
this.__deferredFragmentNames__ = fragmentNames;
}
return fragmentNames;
};
RelayQueryRoot.prototype.equals = function equals(that) {
if (this === that) {
return true;
}
if (!(that instanceof RelayQueryRoot)) {
return false;
}
if (!areEqual(this.getRootCall(), that.getRootCall())) {
return false;
}
if (!areEqual(this.getBatchCall(), that.getBatchCall())) {
return false;
}
if (this.getRootCallArgument() !== that.getRootCallArgument()) {
return false;
}
return _RelayQueryNode.prototype.equals.call(this, that);
};
return RelayQueryRoot;
})(RelayQueryNode);
var RelayQueryOperation = (function (_RelayQueryNode2) {
_inherits(RelayQueryOperation, _RelayQueryNode2);
function RelayQueryOperation(concreteNode, route, variables) {
_classCallCheck(this, RelayQueryOperation);
_RelayQueryNode2.call(this, concreteNode, route, variables);
!(this.constructor.name !== 'RelayQueryOperation') ? true ? invariant(false, 'RelayQueryOperation: Abstract class cannot be instantiated.') : invariant(false) : undefined;
}
/**
* @internal
*
* Represents a GraphQL mutation.
*/
RelayQueryOperation.prototype.getName = function getName() {
return this.__concreteNode__.name;
};
RelayQueryOperation.prototype.getResponseType = function getResponseType() {
return this.__concreteNode__.responseType;
};
RelayQueryOperation.prototype.getInputType = function getInputType() {
var inputType = this.__concreteNode__.metadata.inputType;
!inputType ? true ? invariant(false, 'RelayQuery: Expected operation `%s` to be annotated with the type of ' + 'its argument. Either the babel transform was configured incorrectly, ' + 'or the schema failed to define an argument for this mutation.', this.getCall().name) : invariant(false) : undefined;
return inputType;
};
RelayQueryOperation.prototype.getCall = function getCall() {
var calls = this.__calls__;
if (!calls) {
var concreteCalls = this.__concreteNode__.calls;
calls = callsFromGraphQL(concreteCalls, this.__variables__);
this.__calls__ = calls;
}
return calls[0];
};
RelayQueryOperation.prototype.getCallVariableName = function getCallVariableName() {
if (!this.__callVariableName__) {
var concreteCalls = this.__concreteNode__.calls;
var callArg = concreteCalls[0].value;
!GraphQL.isCallVariable(callArg) ? true ? invariant(false, 'RelayQuery: Expected mutation to have a single argument.') : invariant(false) : undefined;
this.__callVariableName__ = callArg.callVariableName;
}
return this.__callVariableName__;
};
return RelayQueryOperation;
})(RelayQueryNode);
var RelayQueryMutation = (function (_RelayQueryOperation) {
_inherits(RelayQueryMutation, _RelayQueryOperation);
function RelayQueryMutation() {
_classCallCheck(this, RelayQueryMutation);
_RelayQueryOperation.apply(this, arguments);
}
/**
* @internal
*
* Represents a GraphQL subscription.
*/
RelayQueryMutation.prototype.equals = function equals(that) {
if (this === that) {
return true;
}
if (!(that instanceof RelayQueryMutation)) {
return false;
}
if (!areEqual(this.getResponseType(), that.getResponseType())) {
return false;
}
if (!areEqual(this.getCall(), that.getCall())) {
return false;
}
return _RelayQueryOperation.prototype.equals.call(this, that);
};
return RelayQueryMutation;
})(RelayQueryOperation);
var RelayQuerySubscription = (function (_RelayQueryOperation2) {
_inherits(RelayQuerySubscription, _RelayQueryOperation2);
function RelayQuerySubscription() {
_classCallCheck(this, RelayQuerySubscription);
_RelayQueryOperation2.apply(this, arguments);
}
/**
* @internal
*
* Wraps access to query fragments.
*
* Note: place proxy methods for `GraphQL.QueryFragment` here.
*/
RelayQuerySubscription.prototype.getPublishedPayloadType = function getPublishedPayloadType() {
return this.getResponseType();
};
RelayQuerySubscription.prototype.equals = function equals(that) {
if (this === that) {
return true;
}
if (!(that instanceof RelayQuerySubscription)) {
return false;
}
if (!areEqual(this.getPublishedPayloadType(), that.getPublishedPayloadType())) {
return false;
}
if (!areEqual(this.getCall(), that.getCall())) {
return false;
}
return _RelayQueryOperation2.prototype.equals.call(this, that);
};
return RelayQuerySubscription;
})(RelayQueryOperation);
var RelayQueryFragment = (function (_RelayQueryNode3) {
_inherits(RelayQueryFragment, _RelayQueryNode3);
function RelayQueryFragment(concreteNode, route, variables, metadata) {
_classCallCheck(this, RelayQueryFragment);
_RelayQueryNode3.call(this, concreteNode, route, variables);
this.__fragmentID__ = null;
this.__metadata__ = metadata || DEFAULT_FRAGMENT_METADATA;
}
/**
* @internal
*
* Wraps access to query fields.
*
* Note: place proxy methods for `GraphQL.Field` here.
*/
RelayQueryFragment.prototype.getDebugName = function getDebugName() {
return this.__concreteNode__.name;
};
/**
* Returns the weak ID for the concrete fragment. Unlike `getFragmentID`,
* this value is identical for any `RelayQueryFragment` with the same concrete
* fragment, regardless of params/route.
*/
RelayQueryFragment.prototype.getConcreteFragmentID = function getConcreteFragmentID() {
return getWeakIdForObject(this.__concreteNode__);
};
/**
* Returns an identifier for a fragment that is unique for any combination of
* concrete fragment, route name, and variables.
*/
RelayQueryFragment.prototype.getFragmentID = function getFragmentID() {
var fragmentID = this.__fragmentID__;
if (!fragmentID) {
fragmentID = generateRQLFieldAlias(this.getConcreteFragmentID() + '.' + this.__route__.name + '.' + stableStringify(this.__variables__));
this.__fragmentID__ = fragmentID;
}
return fragmentID;
};
RelayQueryFragment.prototype.getType = function getType() {
return this.__concreteNode__.type;
};
RelayQueryFragment.prototype.isDeferred = function isDeferred() {
return this.__metadata__.isDeferred;
};
RelayQueryFragment.prototype.isPlural = function isPlural() {
return !!(this.__concreteNode__.isPlural || // RQLPrinter
this.__concreteNode__.metadata.plural);
};
// GraphQLPrinter
RelayQueryFragment.prototype.isReferenceFragment = function isReferenceFragment() {
return this.__metadata__.isReferenceFragment;
};
RelayQueryFragment.prototype.isTypeConditional = function isTypeConditional() {
return this.__metadata__.isTypeConditional;
};
RelayQueryFragment.prototype.hasDeferredDescendant = function hasDeferredDescendant() {
return this.isDeferred() || _RelayQueryNode3.prototype.hasDeferredDescendant.call(this);
};
RelayQueryFragment.prototype.clone = function clone(children) {
var clone = _RelayQueryNode3.prototype.clone.call(this, children);
if (clone instanceof RelayQueryFragment) {
clone.__metadata__ = _extends({}, this.__metadata__);
}
return clone;
};
RelayQueryFragment.prototype.equals = function equals(that) {
if (this === that) {
return true;
}
if (!(that instanceof RelayQueryFragment)) {
return false;
}
if (this.getType() !== that.getType()) {
return false;
}
return _RelayQueryNode3.prototype.equals.call(this, that);
};
return RelayQueryFragment;
})(RelayQueryNode);
var RelayQueryField = (function (_RelayQueryNode4) {
_inherits(RelayQueryField, _RelayQueryNode4);
function RelayQueryField(concreteNode, route, variables) {
_classCallCheck(this, RelayQueryField);
_RelayQueryNode4.call(this, concreteNode, route, variables);
this.__isRefQueryDependency__ = false;
}
RelayQueryField.prototype.isRequisite = function isRequisite() {
return this.__concreteNode__.metadata.isRequisite;
};
RelayQueryField.prototype.isFindable = function isFindable() {
return this.__concreteNode__.metadata.isFindable;
};
RelayQueryField.prototype.isGenerated = function isGenerated() {
return this.__concreteNode__.metadata.isGenerated;
};
RelayQueryField.prototype.isConnection = function isConnection() {
return this.__concreteNode__.metadata.isConnection;
};
RelayQueryField.prototype.isPlural = function isPlural() {
return this.__concreteNode__.metadata.isPlural;
};
RelayQueryField.prototype.isRefQueryDependency = function isRefQueryDependency() {
return this.__isRefQueryDependency__;
};
RelayQueryField.prototype.isScalar = function isScalar() {
return (!this.__children__ || this.__children__.length === 0) && this.__concreteNode__.children.length === 0;
};
RelayQueryField.prototype.isUnionOrInterface = function isUnionOrInterface() {
return this.__concreteNode__.metadata.isUnionOrInterface;
};
RelayQueryField.prototype.getParentType = function getParentType() {
var parentType = this.__concreteNode__.metadata.parentType;
!parentType ? true ? invariant(false, 'RelayQueryField(): Expected field `%s` to be annotated with the ' + 'type of the parent field.', this.getSchemaName()) : invariant(false) : undefined;
return parentType;
};
/**
* The canonical name for the referenced field in the schema.
*/
RelayQueryField.prototype.getSchemaName = function getSchemaName() {
return this.__concreteNode__.fieldName;
};
/**
* The name for the field when serializing the query or interpreting query
* responses from the server. The serialization key is derived from
* all calls/values and hashed for compactness.
*
* Given the graphql
* `news_feed.first(10).orderby(TOP_STORIES)`
*
* the serialization key is
* `generateRQLFieldAlias('news_feed.first(10).orderby(TOP_STORIES')`
*/
RelayQueryField.prototype.getSerializationKey = function getSerializationKey() {
var serializationKey = this.__serializationKey__;
if (!serializationKey) {
serializationKey = this.getSchemaName();
var calls = this.getCallsWithValues();
for (var ii = 0; ii < calls.length; ii++) {
serializationKey += printRelayQueryCall(calls[ii]);
}
serializationKey = generateRQLFieldAlias(serializationKey);
this.__serializationKey__ = serializationKey;
}
return serializationKey;
};
/**
* The name which Relay internals can use to reference this field, without
* collisions. The storage key is derived from arguments with the following
* exclusions:
*
* - Range calls such as `first` or `find` on connections.
* - Conditionals when the field is present.
*
* Given the graphql
* `news_feed.first(10).orderby(TOP_STORIES).if(true)`
*
* the storage key is
* `'news_feed.orderby(TOP_STORIES)'`
*/
RelayQueryField.prototype.getStorageKey = function getStorageKey() {
var storageKey = this.__storageKey__;
if (!storageKey) {
var isConnection = this.isConnection();
storageKey = this.getSchemaName();
var calls = this.getCallsWithValues();
for (var ii = 0; ii < calls.length; ii++) {
var call = calls[ii];
if (isConnection && RelayConnectionInterface.isConnectionCall(call)) {
continue;
} else if (call.name === IF && String(call.value) === TRUE || call.name === UNLESS && String(call.value) === FALSE) {
// `name.if(true)`, `name.unless(false)`, and `name` are all
// equivalent fields.
continue;
}
storageKey += printRelayQueryCall(call);
}
this.__storageKey__ = storageKey;
}
return storageKey;
};
/**
* The name by which this field's results should be made available to the
* application.
*/
RelayQueryField.prototype.getApplicationName = function getApplicationName() {
return this.__concreteNode__.alias || this.__concreteNode__.fieldName;
};
RelayQueryField.prototype.getInferredRootCallName = function getInferredRootCallName() {
return this.__concreteNode__.metadata.inferredRootCallName;
};
RelayQueryField.prototype.getInferredPrimaryKey = function getInferredPrimaryKey() {
return this.__concreteNode__.metadata.inferredPrimaryKey;
};
RelayQueryField.prototype.getCallsWithValues = function getCallsWithValues() {
var calls = this.__calls__;
if (!calls) {
var concreteCalls = this.__concreteNode__.calls;
calls = callsFromGraphQL(concreteCalls, this.__variables__);
this.__calls__ = calls;
}
return calls;
};
RelayQueryField.prototype.getCallType = function getCallType(callName) {
var concreteCall = this.__concreteNode__.calls.filter(function (call) {
return call.name === callName;
})[0];
if (concreteCall) {
return concreteCall.metadata.type;
}
};
RelayQueryField.prototype.equals = function equals(that) {
if (this === that) {
return true;
}
if (!(that instanceof RelayQueryField)) {
return false;
}
if (this.getSchemaName() !== that.getSchemaName() || this.getApplicationName() !== that.getApplicationName() || !areEqual(this.getCallsWithValues(), that.getCallsWithValues())) {
return false;
}
return _RelayQueryNode4.prototype.equals.call(this, that);
};
RelayQueryField.prototype.cloneAsRefQueryDependency = function cloneAsRefQueryDependency() {
var field = new RelayQueryField(this.__concreteNode__, this.__route__, this.__variables__);
field.__children__ = [];
field.__isRefQueryDependency__ = true;
return field;
};
RelayQueryField.prototype.cloneFieldWithCalls = function cloneFieldWithCalls(children, calls) {
if (this.isScalar()) {
// Compact new children *after* this check, for consistency.
!(children.length === 0) ? true ? invariant(false, 'RelayQueryField: Cannot add children to scalar fields.') : invariant(false) : undefined;
}
// use `clone()` if call values do not change
if (areEqual(this.getCallsWithValues(), calls)) {
var clone = this.clone(children);
return clone;
}
var nextChildren = cloneChildren(this.getChildren(), children);
if (!nextChildren.length) {
return null;
}
var field = new RelayQueryField(this.__concreteNode__, this.__route__, this.__variables__);
field.__children__ = nextChildren;
field.__calls__ = calls;
return field;
};
return RelayQueryField;
})(RelayQueryNode);
function createNode(_x, _x2, _x3) {
var _again = true;
_function: while (_again) {
var concreteNode = _x,
route = _x2,
variables = _x3;
type = routeFragment = fragment = fragmentVariables = undefined;
_again = false;
// unused default value keeps flow happy
var type = RelayQueryNode;
if (GraphQL.isField(concreteNode)) {
type = RelayQueryField;
} else if (GraphQL.isFragment(concreteNode)) {
type = RelayQueryFragment;
} else if (GraphQL.isQuery(concreteNode)) {
type = RelayQueryRoot;
} else if (GraphQL.isQueryWithValues(concreteNode)) {
concreteNode = concreteNode.query;
type = RelayQueryRoot;
} else if (GraphQL.isMutation(concreteNode)) {
type = RelayQueryMutation;
} else if (GraphQL.isSubscription(concreteNode)) {
type = RelayQuerySubscription;
} else if (concreteNode instanceof RelayRouteFragment) {
var routeFragment = concreteNode.getFragmentForRoute(route);
if (routeFragment) {
// may be null if no value was defined for this route.
_x = routeFragment;
_x2 = route;
_x3 = variables;
_again = true;
continue _function;
}
return null;
} else if (concreteNode instanceof RelayFragmentReference) {
var fragment = concreteNode.getFragment(variables);
var fragmentVariables = concreteNode.getVariables(route, variables);
if (fragment) {
// the fragment may be null when `if` or `unless` conditions are not met.
!GraphQL.isFragment(fragment) ? true ? invariant(false, 'RelayQuery: Invalid fragment reference, expected query fragment.') : invariant(false) : undefined;
return createMemoizedFragment(fragment, route, fragmentVariables, {
isDeferred: concreteNode.isDeferred(),
isReferenceFragment: true,
isTypeConditional: concreteNode.isTypeConditional()
});
}
return null;
} else {
true ? true ? invariant(false, 'RelayQueryNode: Invalid concrete node.') : invariant(false) : undefined;
}
return new type(concreteNode, route, variables);
}
}
/**
* Memoizes the `RelayQueryFragment` equivalent of a given `GraphQL` fragment
* for the given route, variables, and deferred status.
*/
function createMemoizedFragment(concreteFragment, route, variables, metadata) {
var cacheKey = route.name + ':' + stableStringify(variables) + ':' + stableStringify(metadata);
var fragment = concreteFragment.__cachedFragment__;
var fragmentCacheKey = concreteFragment.__cacheKey__;
if (!fragment || fragmentCacheKey !== cacheKey) {
fragment = new RelayQueryFragment(concreteFragment, route, variables, metadata);
concreteFragment.__cachedFragment__ = fragment;
concreteFragment.__cacheKey__ = cacheKey;
}
return fragment;
}
/**
* Compacts new children and compares them to the previous children.
* - If all items are equal, returns previous array
* - If any items differ, returns new array
*/
function cloneChildren(prevChildren, nextChildren) {
var children = [];
var isSameChildren = true;
var prevIndex = 0;
for (var ii = 0; ii < nextChildren.length; ii++) {
var child = nextChildren[ii];
if (child) {
children.push(child);
isSameChildren = isSameChildren && child === prevChildren[prevIndex++];
}
}
if (isSameChildren && children.length === prevChildren.length) {
return prevChildren;
} else {
return children;
}
}
/**
* Returns the names of the deferred fragments in the query. Does not return
* nested deferred fragment names.
*/
function getDeferredFragmentNamesForField(node, fragmentNames) {
if (node instanceof RelayQueryFragment && node.isDeferred()) {
var fragmentID = node.getFragmentID();
fragmentNames[fragmentID] = fragmentID;
return;
}
node.getChildren().forEach(function (child) {
return getDeferredFragmentNamesForField(child, fragmentNames);
});
}
module.exports = {
Field: RelayQueryField,
Fragment: RelayQueryFragment,
Mutation: RelayQueryMutation,
Node: RelayQueryNode,
Operation: RelayQueryOperation,
Root: RelayQueryRoot,
Subscription: RelayQuerySubscription
};
// for flow
// TODO(#7161070) Remove this once `toGraphQL` is no longer needed.
/***/ },
/* 4 */
/***/ function(module, exports, __webpack_require__) {
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule RelayProfiler
* @typechecks
*
*/
'use strict';
var emptyFunction = __webpack_require__(31);
var forEachObject = __webpack_require__(6);
var removeFromArray = __webpack_require__(222);
var aggregateHandlersByName = {};
var profileHandlersByName = {};
var NOT_INVOKED = {};
var defaultProfiler = { stop: emptyFunction };
var enableProfile = !!(("development") !== 'production');
/**
* @public
*
* Instruments methods to allow profiling various parts of Relay. Profiling code
* in Relay consists of three steps:
*
* - Instrument the function to be profiled.
* - Attach handlers to the instrumented function.
* - Run the code which triggers the handlers.
*
* Handlers attached to instrumented methods are called with an instrumentation
* name and a callback that must be synchronously executed:
*
* instrumentedMethod.attachHandler(function(name, callback) {
* var start = performance.now();
* callback();
* console.log('Duration', performance.now() - start);
* });
*
* Handlers for profiles consist of callbacks for `onStart` and `onStop`:
*
* var start;
* RelayProfiler.attachProfileHandler('profileName', {
* onStart: function(name, state) {
* start = performance.now();
* },
* onStop: function(name, state) {
* console.log('Duration', performance.now() - start);
* }
* });
*
*/
var RelayProfiler = {
/**
* This only controls whether `profile()`, `attachProfileHandler()` and
* `detachProfileHandler` is enabled, normal instrument methods cannot be
* enabled if they're not enabled at module require time.
*/
setEnableProfile: function setEnableProfile(isEnabled) {
enableProfile = isEnabled;
},
/**
* Instruments methods on a class or object. This re-assigns the method in
* order to preserve function names in stack traces (which are detected by
* modern debuggers via heuristics). Example usage:
*
* var RelayStore = { primeCache: function() {...} };
* RelayProfiler.instrumentMethods(RelayStore, {
* primeCache: 'RelayStore.primeCache'
* });
*
* RelayStore.primeCache.attachHandler(...);
*
* As a result, the methods will be replaced by wrappers that provide the
* `attachHandler` and `detachHandler` methods.
*/
instrumentMethods: function instrumentMethods(object, names) {
forEachObject(names, function (name, key) {
object[key] = RelayProfiler.instrument(name, object[key]);
});
},
/**
* Wraps the supplied function with one that provides the `attachHandler` and
* `detachHandler` methods. Example usage:
*
* var printRelayQuery =
* RelayProfiler.instrument('printRelayQuery', printRelayQuery);
*
* printRelayQuery.attachHandler(...);
*
*/
instrument: function instrument(name, originalFunction) {
if (true) {
var handlers = [];
var instrumentedCallback = function instrumentedCallback() {
var _this = this;
var originalReturn = NOT_INVOKED;
var boundArguments = arguments;
var invokeCallback = function invokeCallback() {
originalReturn = originalFunction.apply(_this, boundArguments);
};
var wrapCallback = function wrapCallback(handler) {
invokeCallback = handler.bind(_this, name, invokeCallback);
};
handlers.forEach(wrapCallback);
if (aggregateHandlersByName.hasOwnProperty(name)) {
aggregateHandlersByName[name].forEach(wrapCallback);
}
invokeCallback();
if (originalReturn === NOT_INVOKED) {
throw new Error('RelayProfiler: Handler did not invoke original function.');
}
return originalReturn;
};
instrumentedCallback.attachHandler = function (handler) {
handlers.push(handler);
};
instrumentedCallback.detachHandler = function (handler) {
removeFromArray(handlers, handler);
};
instrumentedCallback.displayName = '(instrumented ' + name + ')';
return instrumentedCallback;
}
originalFunction.attachHandler = emptyFunction;
originalFunction.detachHandler = emptyFunction;
return originalFunction;
},
/**
* Attaches a handler to all methods instrumented with the supplied name.
*
* function createRenderer() {
* return RelayProfiler.instrument('render', function() {...});
* }
* var renderA = createRenderer();
* var renderB = createRenderer();
*
* // Only profiles `renderA`.
* renderA.attachHandler(...);
*
* // Profiles both `renderA` and `renderB`.
* RelayProfiler.attachAggregateHandler('render', ...);
*
*/
attachAggregateHandler: function attachAggregateHandler(name, handler) {
if (true) {
if (!aggregateHandlersByName.hasOwnProperty(name)) {
aggregateHandlersByName[name] = [];
}
aggregateHandlersByName[name].push(handler);
}
},
/**
* Detaches a handler attached via `attachAggregateHandler`.
*/
detachAggregateHandler: function detachAggregateHandler(name, handler) {
if (true) {
if (aggregateHandlersByName.hasOwnProperty(name)) {
removeFromArray(aggregateHandlersByName[name], handler);
}
}
},
/**
* Instruments profiling for arbitrarily asynchronous code by a name.
*
* var timerProfiler = RelayProfiler.profile('timeout');
* setTimeout(function() {
* timerProfiler.stop();
* }, 1000);
*
* RelayProfiler.attachProfileHandler('timeout', ...);
*
* Arbitrary state can also be passed into `profile` as a second argument. The
* attached profile handlers will receive this as the second argument.
*/
profile: function profile(name, state) {
if (enableProfile) {
if (profileHandlersByName.hasOwnProperty(name)) {
var profileHandlers = profileHandlersByName[name];
for (var ii = profileHandlers.length - 1; ii >= 0; ii--) {
var profileHandler = profileHandlers[ii];
if (profileHandler.onStart) {
profileHandler.onStart(name, state);
}
}
return {
stop: function stop() {
profileHandlersByName[name].forEach(function (profileHandler) {
if (profileHandler.onStop) {
profileHandler.onStop(name, state);
}
});
}
};
}
}
return defaultProfiler;
},
/**
* Attaches a handler to profiles with the supplied name.
*/
attachProfileHandler: function attachProfileHandler(name, handler) {
if (enableProfile) {
if (!profileHandlersByName.hasOwnProperty(name)) {
profileHandlersByName[name] = [];
}
profileHandlersByName[name].push(handler);
}
},
/**
* Detaches a handler attached via `attachProfileHandler`.
*/
detachProfileHandler: function detachProfileHandler(name, handler) {
if (enableProfile) {
if (profileHandlersByName.hasOwnProperty(name)) {
removeFromArray(profileHandlersByName[name], handler);
}
}
}
};
module.exports = RelayProfiler;
/***/ },
/* 5 */
/***/ function(module, exports, __webpack_require__) {
"use strict";
module.exports = { "default": __webpack_require__(187), __esModule: true };
/***/ },
/* 6 */
/***/ function(module, exports) {
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule forEachObject
* @typechecks
*/
'use strict';
var hasOwnProperty = Object.prototype.hasOwnProperty;
/**
* Executes the provided `callback` once for each enumerable own property in the
* object. The `callback` is invoked with three arguments:
*
* - the property value
* - the property name
* - the object being traversed
*
* Properties that are added after the call to `forEachObject` will not be
* visited by `callback`. If the values of existing properties are changed, the
* value passed to `callback` will be the value at the time `forEachObject`
* visits them. Properties that are deleted before being visited are not
* visited.
*
* @param {?object} object
* @param {function} callback
* @param {*} context
*/
function forEachObject(object, callback, context) {
for (var name in object) {
if (hasOwnProperty.call(object, name)) {
callback.call(context, object[name], name, object);
}
}
}
module.exports = forEachObject;
/***/ },
/* 7 */
/***/ function(module, exports, __webpack_require__) {
"use strict";
var _Object$create = __webpack_require__(177)["default"];
var _Object$setPrototypeOf = __webpack_require__(179)["default"];
exports["default"] = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = _Object$create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) _Object$setPrototypeOf ? _Object$setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
};
exports.__esModule = true;
/***/ },
/* 8 */
/***/ function(module, exports) {
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file