react-apollo
Advanced tools
Comparing version 2.4.1 to 2.5.0-beta.0
@@ -0,0 +0,0 @@ import * as React from 'react'; |
@@ -1,2 +0,5 @@ | ||
import * as PropTypes from 'prop-types'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var PropTypes = tslib_1.__importStar(require("prop-types")); | ||
var invariant = require('invariant'); | ||
@@ -13,3 +16,3 @@ var ApolloConsumer = function (props, context) { | ||
}; | ||
export default ApolloConsumer; | ||
exports.default = ApolloConsumer; | ||
//# sourceMappingURL=ApolloConsumer.js.map |
@@ -0,0 +0,0 @@ import * as React from 'react'; |
@@ -1,19 +0,9 @@ | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
} | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
import * as PropTypes from 'prop-types'; | ||
import { Component } from 'react'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var PropTypes = tslib_1.__importStar(require("prop-types")); | ||
var react_1 = require("react"); | ||
var invariant = require('invariant'); | ||
var ApolloProvider = (function (_super) { | ||
__extends(ApolloProvider, _super); | ||
tslib_1.__extends(ApolloProvider, _super); | ||
function ApolloProvider(props, context) { | ||
@@ -47,4 +37,4 @@ var _this = _super.call(this, props, context) || this; | ||
return ApolloProvider; | ||
}(Component)); | ||
export default ApolloProvider; | ||
}(react_1.Component)); | ||
exports.default = ApolloProvider; | ||
//# sourceMappingURL=ApolloProvider.js.map |
@@ -0,0 +0,0 @@ import ApolloClient from 'apollo-client'; |
@@ -0,3 +1,5 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var invariant = require('invariant'); | ||
export function getClient(props, context) { | ||
function getClient(props, context) { | ||
var client = props.client || context.client; | ||
@@ -9,2 +11,3 @@ invariant(!!client, 'Could not find "client" in the context or passed in as a prop. ' + | ||
} | ||
exports.getClient = getClient; | ||
//# sourceMappingURL=component-utils.js.map |
@@ -0,0 +0,0 @@ import * as React from 'react'; |
@@ -1,27 +0,6 @@ | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
} | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
import * as React from 'react'; | ||
import * as PropTypes from 'prop-types'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var React = tslib_1.__importStar(require("react")); | ||
var PropTypes = tslib_1.__importStar(require("prop-types")); | ||
function makeDefaultQueryInfo() { | ||
@@ -81,4 +60,4 @@ return { | ||
}()); | ||
export { RenderPromises }; | ||
export default function getDataFromTree(tree, context) { | ||
exports.RenderPromises = RenderPromises; | ||
function getDataFromTree(tree, context) { | ||
if (context === void 0) { context = {}; } | ||
@@ -91,7 +70,8 @@ return getMarkupFromTree({ | ||
} | ||
export function getMarkupFromTree(_a) { | ||
exports.default = getDataFromTree; | ||
function getMarkupFromTree(_a) { | ||
var tree = _a.tree, _b = _a.context, context = _b === void 0 ? {} : _b, _c = _a.renderFunction, renderFunction = _c === void 0 ? require("react-dom/server").renderToStaticMarkup : _c; | ||
var renderPromises = new RenderPromises(); | ||
var RenderPromisesProvider = (function (_super) { | ||
__extends(RenderPromisesProvider, _super); | ||
tslib_1.__extends(RenderPromisesProvider, _super); | ||
function RenderPromisesProvider() { | ||
@@ -101,3 +81,3 @@ return _super !== null && _super.apply(this, arguments) || this; | ||
RenderPromisesProvider.prototype.getChildContext = function () { | ||
return __assign({}, context, { renderPromises: renderPromises }); | ||
return tslib_1.__assign({}, context, { renderPromises: renderPromises }); | ||
}; | ||
@@ -123,2 +103,3 @@ RenderPromisesProvider.prototype.render = function () { | ||
} | ||
exports.getMarkupFromTree = getMarkupFromTree; | ||
//# sourceMappingURL=getDataFromTree.js.map |
@@ -0,0 +0,0 @@ import * as React from 'react'; |
@@ -1,17 +0,20 @@ | ||
import { parser, DocumentType } from './parser'; | ||
import { withQuery } from './query-hoc'; | ||
import { withMutation } from './mutation-hoc'; | ||
import { withSubscription } from './subscription-hoc'; | ||
export function graphql(document, operationOptions) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var parser_1 = require("./parser"); | ||
var query_hoc_1 = require("./query-hoc"); | ||
var mutation_hoc_1 = require("./mutation-hoc"); | ||
var subscription_hoc_1 = require("./subscription-hoc"); | ||
function graphql(document, operationOptions) { | ||
if (operationOptions === void 0) { operationOptions = {}; } | ||
switch (parser(document).type) { | ||
case DocumentType.Mutation: | ||
return withMutation(document, operationOptions); | ||
case DocumentType.Subscription: | ||
return withSubscription(document, operationOptions); | ||
case DocumentType.Query: | ||
switch (parser_1.parser(document).type) { | ||
case parser_1.DocumentType.Mutation: | ||
return mutation_hoc_1.withMutation(document, operationOptions); | ||
case parser_1.DocumentType.Subscription: | ||
return subscription_hoc_1.withSubscription(document, operationOptions); | ||
case parser_1.DocumentType.Query: | ||
default: | ||
return withQuery(document, operationOptions); | ||
return query_hoc_1.withQuery(document, operationOptions); | ||
} | ||
} | ||
exports.graphql = graphql; | ||
//# sourceMappingURL=graphql.js.map |
@@ -0,0 +0,0 @@ import * as React from 'react'; |
@@ -1,24 +0,15 @@ | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
} | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
import * as React from 'react'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var React = tslib_1.__importStar(require("react")); | ||
var invariant = require('invariant'); | ||
import { DocumentType } from './parser'; | ||
export var defaultMapPropsToOptions = function () { return ({}); }; | ||
export var defaultMapResultToProps = function (props) { return props; }; | ||
export var defaultMapPropsToSkip = function () { return false; }; | ||
export function getDisplayName(WrappedComponent) { | ||
var parser_1 = require("./parser"); | ||
exports.defaultMapPropsToOptions = function () { return ({}); }; | ||
exports.defaultMapResultToProps = function (props) { return props; }; | ||
exports.defaultMapPropsToSkip = function () { return false; }; | ||
function getDisplayName(WrappedComponent) { | ||
return WrappedComponent.displayName || WrappedComponent.name || 'Component'; | ||
} | ||
export function calculateVariablesFromProps(operation, props, graphQLDisplayName, wrapperName) { | ||
exports.getDisplayName = getDisplayName; | ||
function calculateVariablesFromProps(operation, props, graphQLDisplayName, wrapperName) { | ||
var variables = {}; | ||
@@ -39,3 +30,3 @@ for (var _i = 0, _a = operation.variables; _i < _a.length; _i++) { | ||
} | ||
if (operation.type === DocumentType.Mutation) | ||
if (operation.type === parser_1.DocumentType.Mutation) | ||
return; | ||
@@ -48,4 +39,5 @@ invariant(typeof variableProp !== 'undefined', "The operation '" + operation.name + "' wrapping '" + wrapperName + "' " + | ||
} | ||
exports.calculateVariablesFromProps = calculateVariablesFromProps; | ||
var GraphQLBase = (function (_super) { | ||
__extends(GraphQLBase, _super); | ||
tslib_1.__extends(GraphQLBase, _super); | ||
function GraphQLBase(props) { | ||
@@ -66,3 +58,3 @@ var _this = _super.call(this, props) || this; | ||
}(React.Component)); | ||
export { GraphQLBase }; | ||
exports.GraphQLBase = GraphQLBase; | ||
//# sourceMappingURL=hoc-utils.js.map |
@@ -1,2 +0,21 @@ | ||
export * from './browser'; | ||
export { default as ApolloConsumer } from './ApolloConsumer'; | ||
export * from './ApolloConsumer'; | ||
export { default as ApolloProvider } from './ApolloProvider'; | ||
export * from './ApolloProvider'; | ||
export { default as Query } from './Query'; | ||
export * from './Query'; | ||
export { default as Mutation } from './Mutation'; | ||
export * from './Mutation'; | ||
export { default as Subscription } from './Subscriptions'; | ||
export * from './Subscriptions'; | ||
export { graphql } from './graphql'; | ||
export { withQuery } from './query-hoc'; | ||
export { withMutation } from './mutation-hoc'; | ||
export { withSubscription } from './subscription-hoc'; | ||
export { default as withApollo } from './withApollo'; | ||
export * from './withApollo'; | ||
export * from './getDataFromTree'; | ||
export { default as getDataFromTree } from './getDataFromTree'; | ||
export { renderToStringWithData } from './renderToStringWithData'; | ||
export * from './types'; | ||
export { compose } from './utils/flowRight'; |
38
index.js
@@ -1,3 +0,37 @@ | ||
export * from './browser'; | ||
export { renderToStringWithData } from './renderToStringWithData'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var ApolloConsumer_1 = require("./ApolloConsumer"); | ||
exports.ApolloConsumer = ApolloConsumer_1.default; | ||
tslib_1.__exportStar(require("./ApolloConsumer"), exports); | ||
var ApolloProvider_1 = require("./ApolloProvider"); | ||
exports.ApolloProvider = ApolloProvider_1.default; | ||
tslib_1.__exportStar(require("./ApolloProvider"), exports); | ||
var Query_1 = require("./Query"); | ||
exports.Query = Query_1.default; | ||
tslib_1.__exportStar(require("./Query"), exports); | ||
var Mutation_1 = require("./Mutation"); | ||
exports.Mutation = Mutation_1.default; | ||
tslib_1.__exportStar(require("./Mutation"), exports); | ||
var Subscriptions_1 = require("./Subscriptions"); | ||
exports.Subscription = Subscriptions_1.default; | ||
tslib_1.__exportStar(require("./Subscriptions"), exports); | ||
var graphql_1 = require("./graphql"); | ||
exports.graphql = graphql_1.graphql; | ||
var query_hoc_1 = require("./query-hoc"); | ||
exports.withQuery = query_hoc_1.withQuery; | ||
var mutation_hoc_1 = require("./mutation-hoc"); | ||
exports.withMutation = mutation_hoc_1.withMutation; | ||
var subscription_hoc_1 = require("./subscription-hoc"); | ||
exports.withSubscription = subscription_hoc_1.withSubscription; | ||
var withApollo_1 = require("./withApollo"); | ||
exports.withApollo = withApollo_1.default; | ||
tslib_1.__exportStar(require("./withApollo"), exports); | ||
tslib_1.__exportStar(require("./getDataFromTree"), exports); | ||
var getDataFromTree_1 = require("./getDataFromTree"); | ||
exports.getDataFromTree = getDataFromTree_1.default; | ||
var renderToStringWithData_1 = require("./renderToStringWithData"); | ||
exports.renderToStringWithData = renderToStringWithData_1.renderToStringWithData; | ||
var flowRight_1 = require("./utils/flowRight"); | ||
exports.compose = flowRight_1.compose; | ||
//# sourceMappingURL=index.js.map |
@@ -0,0 +0,0 @@ import * as React from 'react'; |
@@ -1,34 +0,13 @@ | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
} | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
import * as React from 'react'; | ||
import hoistNonReactStatics from 'hoist-non-react-statics'; | ||
import { parser } from './parser'; | ||
import { default as Mutation } from './Mutation'; | ||
import { defaultMapPropsToOptions, getDisplayName, calculateVariablesFromProps, GraphQLBase, } from './hoc-utils'; | ||
export function withMutation(document, operationOptions) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var React = tslib_1.__importStar(require("react")); | ||
var hoist_non_react_statics_1 = tslib_1.__importDefault(require("hoist-non-react-statics")); | ||
var parser_1 = require("./parser"); | ||
var Mutation_1 = tslib_1.__importDefault(require("./Mutation")); | ||
var hoc_utils_1 = require("./hoc-utils"); | ||
function withMutation(document, operationOptions) { | ||
if (operationOptions === void 0) { operationOptions = {}; } | ||
var operation = parser(document); | ||
var _a = operationOptions.options, options = _a === void 0 ? defaultMapPropsToOptions : _a, _b = operationOptions.alias, alias = _b === void 0 ? 'Apollo' : _b; | ||
var operation = parser_1.parser(document); | ||
var _a = operationOptions.options, options = _a === void 0 ? hoc_utils_1.defaultMapPropsToOptions : _a, _b = operationOptions.alias, alias = _b === void 0 ? 'Apollo' : _b; | ||
var mapPropsToOptions = options; | ||
@@ -38,5 +17,5 @@ if (typeof mapPropsToOptions !== 'function') | ||
return function (WrappedComponent) { | ||
var graphQLDisplayName = alias + "(" + getDisplayName(WrappedComponent) + ")"; | ||
var graphQLDisplayName = alias + "(" + hoc_utils_1.getDisplayName(WrappedComponent) + ")"; | ||
var GraphQL = (function (_super) { | ||
__extends(GraphQL, _super); | ||
tslib_1.__extends(GraphQL, _super); | ||
function GraphQL() { | ||
@@ -55,5 +34,5 @@ return _super !== null && _super.apply(this, arguments) || this; | ||
if (!opts.variables && operation.variables.length > 0) { | ||
opts.variables = calculateVariablesFromProps(operation, props, graphQLDisplayName, getDisplayName(WrappedComponent)); | ||
opts.variables = hoc_utils_1.calculateVariablesFromProps(operation, props, graphQLDisplayName, hoc_utils_1.getDisplayName(WrappedComponent)); | ||
} | ||
return (React.createElement(Mutation, __assign({}, opts, { mutation: document, ignoreResults: true }), function (mutate, _result) { | ||
return (React.createElement(Mutation_1.default, tslib_1.__assign({}, opts, { mutation: document, ignoreResults: true }), function (mutate, _result) { | ||
var _a, _b; | ||
@@ -69,3 +48,3 @@ var name = operationOptions.name || 'mutate'; | ||
} | ||
return React.createElement(WrappedComponent, __assign({}, props, childProps)); | ||
return React.createElement(WrappedComponent, tslib_1.__assign({}, props, childProps)); | ||
})); | ||
@@ -76,6 +55,7 @@ }; | ||
return GraphQL; | ||
}(GraphQLBase)); | ||
return hoistNonReactStatics(GraphQL, WrappedComponent, {}); | ||
}(hoc_utils_1.GraphQLBase)); | ||
return hoist_non_react_statics_1.default(GraphQL, WrappedComponent, {}); | ||
}; | ||
} | ||
exports.withMutation = withMutation; | ||
//# sourceMappingURL=mutation-hoc.js.map |
@@ -73,3 +73,3 @@ import * as React from 'react'; | ||
optimisticResponse: PropTypes.Requireable<object>; | ||
refetchQueries: PropTypes.Requireable<((...args: any[]) => any) | (string | object | null)[]>; | ||
refetchQueries: PropTypes.Requireable<(string | object | null)[] | ((...args: any[]) => any)>; | ||
awaitRefetchQueries: PropTypes.Requireable<boolean>; | ||
@@ -76,0 +76,0 @@ update: PropTypes.Requireable<(...args: any[]) => any>; |
@@ -1,32 +0,11 @@ | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
} | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
import * as React from 'react'; | ||
import * as PropTypes from 'prop-types'; | ||
import { ApolloError } from 'apollo-client'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var React = tslib_1.__importStar(require("react")); | ||
var PropTypes = tslib_1.__importStar(require("prop-types")); | ||
var apollo_client_1 = require("apollo-client"); | ||
var invariant = require('invariant'); | ||
var shallowEqual = require('fbjs/lib/shallowEqual'); | ||
import { parser, DocumentType } from './parser'; | ||
import { getClient } from './component-utils'; | ||
var shallowEqual_1 = tslib_1.__importDefault(require("./utils/shallowEqual")); | ||
var parser_1 = require("./parser"); | ||
var component_utils_1 = require("./component-utils"); | ||
var initialState = { | ||
@@ -39,3 +18,3 @@ loading: false, | ||
var Mutation = (function (_super) { | ||
__extends(Mutation, _super); | ||
tslib_1.__extends(Mutation, _super); | ||
function Mutation(props, context) { | ||
@@ -61,3 +40,3 @@ var _this = _super.call(this, props, context) || this; | ||
var _a = _this.props, mutation = _a.mutation, variables = _a.variables, optimisticResponse = _a.optimisticResponse, update = _a.update, _b = _a.context, context = _b === void 0 ? {} : _b, _c = _a.awaitRefetchQueries, awaitRefetchQueries = _c === void 0 ? false : _c, fetchPolicy = _a.fetchPolicy; | ||
var mutateOptions = __assign({}, options); | ||
var mutateOptions = tslib_1.__assign({}, options); | ||
var refetchQueries = mutateOptions.refetchQueries || _this.props.refetchQueries; | ||
@@ -74,3 +53,3 @@ if (refetchQueries && refetchQueries.length && Array.isArray(refetchQueries)) { | ||
delete mutateOptions.variables; | ||
return _this.client.mutate(__assign({ mutation: mutation, | ||
return _this.client.mutate(tslib_1.__assign({ mutation: mutation, | ||
optimisticResponse: optimisticResponse, | ||
@@ -96,3 +75,3 @@ refetchQueries: refetchQueries, | ||
var data = response.data, errors = response.errors; | ||
var error = errors && errors.length > 0 ? new ApolloError({ graphQLErrors: errors }) : undefined; | ||
var error = errors && errors.length > 0 ? new apollo_client_1.ApolloError({ graphQLErrors: errors }) : undefined; | ||
var callOncomplete = function () { return (onCompleted ? onCompleted(data) : null); }; | ||
@@ -124,6 +103,6 @@ if (_this.hasMounted && _this.isMostRecentMutation(mutationId) && !ignoreResults) { | ||
_this.verifyDocumentIsMutation = function (mutation) { | ||
var operation = parser(mutation); | ||
invariant(operation.type === DocumentType.Mutation, "The <Mutation /> component requires a graphql mutation, but got a " + (operation.type === DocumentType.Query ? 'query' : 'subscription') + "."); | ||
var operation = parser_1.parser(mutation); | ||
invariant(operation.type === parser_1.DocumentType.Mutation, "The <Mutation /> component requires a graphql mutation, but got a " + (operation.type === parser_1.DocumentType.Query ? 'query' : 'subscription') + "."); | ||
}; | ||
_this.client = getClient(props, context); | ||
_this.client = component_utils_1.getClient(props, context); | ||
_this.verifyDocumentIsMutation(props.mutation); | ||
@@ -141,4 +120,4 @@ _this.mostRecentMutationId = 0; | ||
Mutation.prototype.componentWillReceiveProps = function (nextProps, nextContext) { | ||
var nextClient = getClient(nextProps, nextContext); | ||
if (shallowEqual(this.props, nextProps) && this.client === nextClient) { | ||
var nextClient = component_utils_1.getClient(nextProps, nextContext); | ||
if (shallowEqual_1.default(this.props, nextProps) && this.client === nextClient) { | ||
return; | ||
@@ -187,3 +166,3 @@ } | ||
}(React.Component)); | ||
export default Mutation; | ||
exports.default = Mutation; | ||
//# sourceMappingURL=Mutation.js.map |
{ | ||
"name": "react-apollo", | ||
"version": "2.4.1", | ||
"version": "2.5.0-beta.0", | ||
"author": "opensource@apollographql.com", | ||
"browser": "react-apollo.browser.umd.js", | ||
"description": "React data container for Apollo Client", | ||
@@ -13,7 +12,7 @@ "keywords": [ | ||
"license": "MIT", | ||
"main": "react-apollo.umd.js", | ||
"main": "index.js", | ||
"module": "react-apollo.esm.js", | ||
"react-native": { | ||
"react-dom/server": false | ||
}, | ||
"module": "index.js", | ||
"typings": "index.d.ts", | ||
@@ -32,9 +31,8 @@ "repository": { | ||
"dependencies": { | ||
"fbjs": "^1.0.0", | ||
"hoist-non-react-statics": "^3.0.0", | ||
"invariant": "^2.2.2", | ||
"lodash.flowright": "^3.5.0", | ||
"lodash.isequal": "^4.5.0", | ||
"prop-types": "^15.6.0" | ||
"prop-types": "^15.6.0", | ||
"tslib": "^1.9.3" | ||
} | ||
} |
@@ -0,0 +0,0 @@ import { DocumentNode, VariableDefinitionNode } from 'graphql'; |
@@ -0,3 +1,5 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var invariant = require('invariant'); | ||
export var DocumentType; | ||
var DocumentType; | ||
(function (DocumentType) { | ||
@@ -7,5 +9,5 @@ DocumentType[DocumentType["Query"] = 0] = "Query"; | ||
DocumentType[DocumentType["Subscription"] = 2] = "Subscription"; | ||
})(DocumentType || (DocumentType = {})); | ||
})(DocumentType = exports.DocumentType || (exports.DocumentType = {})); | ||
var cache = new Map(); | ||
export function parser(document) { | ||
function parser(document) { | ||
var cached = cache.get(document); | ||
@@ -47,2 +49,3 @@ if (cached) | ||
} | ||
exports.parser = parser; | ||
//# sourceMappingURL=parser.js.map |
@@ -0,0 +0,0 @@ import * as React from 'react'; |
@@ -1,43 +0,13 @@ | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
} | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __rest = (this && this.__rest) || function (s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0) | ||
t[p[i]] = s[p[i]]; | ||
return t; | ||
}; | ||
import * as React from 'react'; | ||
import hoistNonReactStatics from 'hoist-non-react-statics'; | ||
import { parser } from './parser'; | ||
import { default as Query } from './Query'; | ||
import { getDisplayName, GraphQLBase, calculateVariablesFromProps, defaultMapPropsToOptions, defaultMapPropsToSkip, } from './hoc-utils'; | ||
export function withQuery(document, operationOptions) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var React = tslib_1.__importStar(require("react")); | ||
var hoist_non_react_statics_1 = tslib_1.__importDefault(require("hoist-non-react-statics")); | ||
var parser_1 = require("./parser"); | ||
var Query_1 = tslib_1.__importDefault(require("./Query")); | ||
var hoc_utils_1 = require("./hoc-utils"); | ||
function withQuery(document, operationOptions) { | ||
if (operationOptions === void 0) { operationOptions = {}; } | ||
var operation = parser(document); | ||
var _a = operationOptions.options, options = _a === void 0 ? defaultMapPropsToOptions : _a, _b = operationOptions.skip, skip = _b === void 0 ? defaultMapPropsToSkip : _b, _c = operationOptions.alias, alias = _c === void 0 ? 'Apollo' : _c; | ||
var operation = parser_1.parser(document); | ||
var _a = operationOptions.options, options = _a === void 0 ? hoc_utils_1.defaultMapPropsToOptions : _a, _b = operationOptions.skip, skip = _b === void 0 ? hoc_utils_1.defaultMapPropsToSkip : _b, _c = operationOptions.alias, alias = _c === void 0 ? 'Apollo' : _c; | ||
var mapPropsToOptions = options; | ||
@@ -53,5 +23,5 @@ if (typeof mapPropsToOptions !== 'function') { | ||
return function (WrappedComponent) { | ||
var graphQLDisplayName = alias + "(" + getDisplayName(WrappedComponent) + ")"; | ||
var graphQLDisplayName = alias + "(" + hoc_utils_1.getDisplayName(WrappedComponent) + ")"; | ||
var GraphQL = (function (_super) { | ||
__extends(GraphQL, _super); | ||
tslib_1.__extends(GraphQL, _super); | ||
function GraphQL() { | ||
@@ -64,8 +34,8 @@ return _super !== null && _super.apply(this, arguments) || this; | ||
var shouldSkip = mapPropsToSkip(props); | ||
var opts = shouldSkip ? Object.create(null) : __assign({}, mapPropsToOptions(props)); | ||
var opts = shouldSkip ? Object.create(null) : tslib_1.__assign({}, mapPropsToOptions(props)); | ||
if (!shouldSkip && !opts.variables && operation.variables.length > 0) { | ||
opts.variables = calculateVariablesFromProps(operation, props, graphQLDisplayName, getDisplayName(WrappedComponent)); | ||
opts.variables = hoc_utils_1.calculateVariablesFromProps(operation, props, graphQLDisplayName, hoc_utils_1.getDisplayName(WrappedComponent)); | ||
} | ||
return (React.createElement(Query, __assign({}, opts, { displayName: graphQLDisplayName, skip: shouldSkip, query: document, warnUnhandledError: true }), function (_a) { | ||
var _ = _a.client, data = _a.data, r = __rest(_a, ["client", "data"]); | ||
return (React.createElement(Query_1.default, tslib_1.__assign({}, opts, { displayName: graphQLDisplayName, skip: shouldSkip, query: document, warnUnhandledError: true }), function (_a) { | ||
var _ = _a.client, data = _a.data, r = tslib_1.__rest(_a, ["client", "data"]); | ||
var _b, _c; | ||
@@ -79,3 +49,3 @@ if (operationOptions.withRef) { | ||
if (shouldSkip) | ||
return React.createElement(WrappedComponent, __assign({}, props)); | ||
return React.createElement(WrappedComponent, tslib_1.__assign({}, props)); | ||
var result = Object.assign(r, data || {}); | ||
@@ -92,3 +62,3 @@ var name = operationOptions.name || 'data'; | ||
} | ||
return React.createElement(WrappedComponent, __assign({}, props, childProps)); | ||
return React.createElement(WrappedComponent, tslib_1.__assign({}, props, childProps)); | ||
})); | ||
@@ -99,6 +69,7 @@ }; | ||
return GraphQL; | ||
}(GraphQLBase)); | ||
return hoistNonReactStatics(GraphQL, WrappedComponent, {}); | ||
}(hoc_utils_1.GraphQLBase)); | ||
return hoist_non_react_statics_1.default(GraphQL, WrappedComponent, {}); | ||
}; | ||
} | ||
exports.withQuery = withQuery; | ||
//# sourceMappingURL=query-hoc.js.map |
@@ -0,0 +0,0 @@ import * as React from 'react'; |
74
Query.js
@@ -1,40 +0,10 @@ | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
} | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __rest = (this && this.__rest) || function (s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0) | ||
t[p[i]] = s[p[i]]; | ||
return t; | ||
}; | ||
import * as React from 'react'; | ||
import * as PropTypes from 'prop-types'; | ||
import { ApolloError, NetworkStatus, } from 'apollo-client'; | ||
import { parser, DocumentType } from './parser'; | ||
import { getClient } from './component-utils'; | ||
var shallowEqual = require('fbjs/lib/shallowEqual'); | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var React = tslib_1.__importStar(require("react")); | ||
var PropTypes = tslib_1.__importStar(require("prop-types")); | ||
var apollo_client_1 = require("apollo-client"); | ||
var parser_1 = require("./parser"); | ||
var component_utils_1 = require("./component-utils"); | ||
var shallowEqual_1 = tslib_1.__importDefault(require("./utils/shallowEqual")); | ||
var invariant = require('invariant'); | ||
@@ -62,3 +32,3 @@ function compact(obj) { | ||
var Query = (function (_super) { | ||
__extends(Query, _super); | ||
tslib_1.__extends(Query, _super); | ||
function Query(props, context) { | ||
@@ -75,3 +45,3 @@ var _this = _super.call(this, props, context) || this; | ||
var data = _a.data; | ||
if (initial && initial.networkStatus === 7 && shallowEqual(initial.data, data)) { | ||
if (initial && initial.networkStatus === 7 && shallowEqual_1.default(initial.data, data)) { | ||
initial = undefined; | ||
@@ -105,3 +75,3 @@ return; | ||
if (_this.props.skip) { | ||
data = __assign({}, data, { data: undefined, error: undefined, loading: false }); | ||
data = tslib_1.__assign({}, data, { data: undefined, error: undefined, loading: false }); | ||
} | ||
@@ -113,3 +83,3 @@ else { | ||
if (errors && errors.length > 0) { | ||
error = new ApolloError({ graphQLErrors: errors }); | ||
error = new apollo_client_1.ApolloError({ graphQLErrors: errors }); | ||
} | ||
@@ -132,3 +102,3 @@ Object.assign(data, { loading: loading, networkStatus: networkStatus, error: error }); | ||
fetchPolicy !== 'cache-only') { | ||
Object.assign(data, { loading: true, networkStatus: NetworkStatus.loading }); | ||
Object.assign(data, { loading: true, networkStatus: apollo_client_1.NetworkStatus.loading }); | ||
data.refetch(); | ||
@@ -157,3 +127,3 @@ return data; | ||
}; | ||
_this.client = getClient(props, context); | ||
_this.client = component_utils_1.getClient(props, context); | ||
_this.initializeQueryObservable(props); | ||
@@ -165,3 +135,3 @@ return _this; | ||
return false; | ||
var _a = this.props, children = _a.children, ssr = _a.ssr, displayName = _a.displayName, skip = _a.skip, client = _a.client, onCompleted = _a.onCompleted, onError = _a.onError, partialRefetch = _a.partialRefetch, opts = __rest(_a, ["children", "ssr", "displayName", "skip", "client", "onCompleted", "onError", "partialRefetch"]); | ||
var _a = this.props, children = _a.children, ssr = _a.ssr, displayName = _a.displayName, skip = _a.skip, client = _a.client, onCompleted = _a.onCompleted, onError = _a.onError, partialRefetch = _a.partialRefetch, opts = tslib_1.__rest(_a, ["children", "ssr", "displayName", "skip", "client", "onCompleted", "onError", "partialRefetch"]); | ||
var fetchPolicy = opts.fetchPolicy; | ||
@@ -173,3 +143,3 @@ if (ssr === false) | ||
} | ||
var observable = this.client.watchQuery(__assign({}, opts, { fetchPolicy: fetchPolicy })); | ||
var observable = this.client.watchQuery(tslib_1.__assign({}, opts, { fetchPolicy: fetchPolicy })); | ||
if (this.context && this.context.renderPromises) { | ||
@@ -198,4 +168,4 @@ this.context.renderPromises.registerSSRObservable(this, observable); | ||
} | ||
var nextClient = getClient(nextProps, nextContext); | ||
if (shallowEqual(this.props, nextProps) && this.client === nextClient) { | ||
var nextClient = component_utils_1.getClient(nextProps, nextContext); | ||
if (shallowEqual_1.default(this.props, nextProps) && this.client === nextClient) { | ||
return; | ||
@@ -246,4 +216,4 @@ } | ||
var variables = props.variables, pollInterval = props.pollInterval, fetchPolicy = props.fetchPolicy, errorPolicy = props.errorPolicy, notifyOnNetworkStatusChange = props.notifyOnNetworkStatusChange, query = props.query, _a = props.displayName, displayName = _a === void 0 ? 'Query' : _a, _b = props.context, context = _b === void 0 ? {} : _b; | ||
this.operation = parser(query); | ||
invariant(this.operation.type === DocumentType.Query, "The <Query /> component requires a graphql query, but got a " + (this.operation.type === DocumentType.Mutation ? 'mutation' : 'subscription') + "."); | ||
this.operation = parser_1.parser(query); | ||
invariant(this.operation.type === parser_1.DocumentType.Query, "The <Query /> component requires a graphql query, but got a " + (this.operation.type === parser_1.DocumentType.Mutation ? 'mutation' : 'subscription') + "."); | ||
return compact({ | ||
@@ -316,3 +286,3 @@ variables: variables, | ||
}(React.Component)); | ||
export default Query; | ||
exports.default = Query; | ||
//# sourceMappingURL=Query.js.map |
@@ -0,0 +0,0 @@ import { ObservableQuery } from 'apollo-client'; |
@@ -1,22 +0,5 @@ | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __rest = (this && this.__rest) || function (s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0) | ||
t[p[i]] = s[p[i]]; | ||
return t; | ||
}; | ||
var shallowEqual = require('fbjs/lib/shallowEqual'); | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var shallowEqual_1 = tslib_1.__importDefault(require("./utils/shallowEqual")); | ||
var ObservableQueryRecycler = (function () { | ||
@@ -47,6 +30,6 @@ function ObservableQueryRecycler() { | ||
subscription.unsubscribe(); | ||
var ssr = options.ssr, client = options.client, modifiableOpts = __rest(options, ["ssr", "client"]); | ||
if (!shallowEqual(modifiableOpts.variables || {}, observableQuery.variables)) | ||
var ssr = options.ssr, client = options.client, modifiableOpts = tslib_1.__rest(options, ["ssr", "client"]); | ||
if (!shallowEqual_1.default(modifiableOpts.variables || {}, observableQuery.variables)) | ||
return null; | ||
observableQuery.setOptions(__assign({}, modifiableOpts, { pollInterval: options.pollInterval, fetchPolicy: options.fetchPolicy })); | ||
observableQuery.setOptions(tslib_1.__assign({}, modifiableOpts, { pollInterval: options.pollInterval, fetchPolicy: options.fetchPolicy })); | ||
return observableQuery; | ||
@@ -56,3 +39,3 @@ }; | ||
}()); | ||
export { ObservableQueryRecycler }; | ||
exports.ObservableQueryRecycler = ObservableQueryRecycler; | ||
//# sourceMappingURL=queryRecycler.js.map |
import { ReactElement } from 'react'; | ||
export declare function renderToStringWithData(component: ReactElement<any>): Promise<string>; |
@@ -1,4 +0,6 @@ | ||
import { getMarkupFromTree } from './getDataFromTree'; | ||
export function renderToStringWithData(component) { | ||
return getMarkupFromTree({ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var getDataFromTree_1 = require("./getDataFromTree"); | ||
function renderToStringWithData(component) { | ||
return getDataFromTree_1.getMarkupFromTree({ | ||
tree: component, | ||
@@ -8,2 +10,3 @@ renderFunction: require("react-dom/server").renderToString, | ||
} | ||
exports.renderToStringWithData = renderToStringWithData; | ||
//# sourceMappingURL=renderToStringWithData.js.map |
@@ -0,0 +0,0 @@ import * as React from 'react'; |
@@ -1,43 +0,13 @@ | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
} | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __rest = (this && this.__rest) || function (s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0) | ||
t[p[i]] = s[p[i]]; | ||
return t; | ||
}; | ||
import * as React from 'react'; | ||
import hoistNonReactStatics from 'hoist-non-react-statics'; | ||
import { parser } from './parser'; | ||
import { default as Subscription } from './Subscriptions'; | ||
import { getDisplayName, GraphQLBase, calculateVariablesFromProps, defaultMapPropsToOptions, defaultMapPropsToSkip, } from './hoc-utils'; | ||
export function withSubscription(document, operationOptions) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var React = tslib_1.__importStar(require("react")); | ||
var hoist_non_react_statics_1 = tslib_1.__importDefault(require("hoist-non-react-statics")); | ||
var parser_1 = require("./parser"); | ||
var Subscriptions_1 = tslib_1.__importDefault(require("./Subscriptions")); | ||
var hoc_utils_1 = require("./hoc-utils"); | ||
function withSubscription(document, operationOptions) { | ||
if (operationOptions === void 0) { operationOptions = {}; } | ||
var operation = parser(document); | ||
var _a = operationOptions.options, options = _a === void 0 ? defaultMapPropsToOptions : _a, _b = operationOptions.skip, skip = _b === void 0 ? defaultMapPropsToSkip : _b, _c = operationOptions.alias, alias = _c === void 0 ? 'Apollo' : _c, shouldResubscribe = operationOptions.shouldResubscribe; | ||
var operation = parser_1.parser(document); | ||
var _a = operationOptions.options, options = _a === void 0 ? hoc_utils_1.defaultMapPropsToOptions : _a, _b = operationOptions.skip, skip = _b === void 0 ? hoc_utils_1.defaultMapPropsToSkip : _b, _c = operationOptions.alias, alias = _c === void 0 ? 'Apollo' : _c, shouldResubscribe = operationOptions.shouldResubscribe; | ||
var mapPropsToOptions = options; | ||
@@ -51,5 +21,5 @@ if (typeof mapPropsToOptions !== 'function') | ||
return function (WrappedComponent) { | ||
var graphQLDisplayName = alias + "(" + getDisplayName(WrappedComponent) + ")"; | ||
var graphQLDisplayName = alias + "(" + hoc_utils_1.getDisplayName(WrappedComponent) + ")"; | ||
var GraphQL = (function (_super) { | ||
__extends(GraphQL, _super); | ||
tslib_1.__extends(GraphQL, _super); | ||
function GraphQL(props) { | ||
@@ -73,6 +43,6 @@ var _this = _super.call(this, props) || this; | ||
if (!shouldSkip && !opts.variables && operation.variables.length > 0) { | ||
opts.variables = calculateVariablesFromProps(operation, props, graphQLDisplayName, getDisplayName(WrappedComponent)); | ||
opts.variables = hoc_utils_1.calculateVariablesFromProps(operation, props, graphQLDisplayName, hoc_utils_1.getDisplayName(WrappedComponent)); | ||
} | ||
return (React.createElement(Subscription, __assign({}, opts, { displayName: graphQLDisplayName, skip: shouldSkip, subscription: document, shouldResubscribe: this.state.resubscribe }), function (_a) { | ||
var data = _a.data, r = __rest(_a, ["data"]); | ||
return (React.createElement(Subscriptions_1.default, tslib_1.__assign({}, opts, { displayName: graphQLDisplayName, skip: shouldSkip, subscription: document, shouldResubscribe: this.state.resubscribe }), function (_a) { | ||
var data = _a.data, r = tslib_1.__rest(_a, ["data"]); | ||
var _b, _c; | ||
@@ -86,3 +56,3 @@ if (operationOptions.withRef) { | ||
if (shouldSkip) | ||
return React.createElement(WrappedComponent, __assign({}, props)); | ||
return React.createElement(WrappedComponent, tslib_1.__assign({}, props)); | ||
var result = Object.assign(r, data || {}); | ||
@@ -99,3 +69,3 @@ var name = operationOptions.name || 'data'; | ||
} | ||
return React.createElement(WrappedComponent, __assign({}, props, childProps)); | ||
return React.createElement(WrappedComponent, tslib_1.__assign({}, props, childProps)); | ||
})); | ||
@@ -106,6 +76,7 @@ }; | ||
return GraphQL; | ||
}(GraphQLBase)); | ||
return hoistNonReactStatics(GraphQL, WrappedComponent, {}); | ||
}(hoc_utils_1.GraphQLBase)); | ||
return hoist_non_react_statics_1.default(GraphQL, WrappedComponent, {}); | ||
}; | ||
} | ||
exports.withSubscription = withSubscription; | ||
//# sourceMappingURL=subscription-hoc.js.map |
@@ -0,0 +0,0 @@ import * as React from 'react'; |
@@ -1,21 +0,11 @@ | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
} | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
import * as React from 'react'; | ||
import * as PropTypes from 'prop-types'; | ||
import { getClient } from './component-utils'; | ||
var shallowEqual = require('fbjs/lib/shallowEqual'); | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var React = tslib_1.__importStar(require("react")); | ||
var PropTypes = tslib_1.__importStar(require("prop-types")); | ||
var component_utils_1 = require("./component-utils"); | ||
var shallowEqual_1 = tslib_1.__importDefault(require("./utils/shallowEqual")); | ||
var invariant = require('invariant'); | ||
var Subscription = (function (_super) { | ||
__extends(Subscription, _super); | ||
tslib_1.__extends(Subscription, _super); | ||
function Subscription(props, context) { | ||
@@ -74,3 +64,3 @@ var _this = _super.call(this, props, context) || this; | ||
}; | ||
_this.client = getClient(props, context); | ||
_this.client = component_utils_1.getClient(props, context); | ||
_this.initialize(props); | ||
@@ -84,4 +74,4 @@ _this.state = _this.getInitialState(); | ||
Subscription.prototype.componentWillReceiveProps = function (nextProps, nextContext) { | ||
var nextClient = getClient(nextProps, nextContext); | ||
if (shallowEqual(this.props.variables, nextProps.variables) && | ||
var nextClient = component_utils_1.getClient(nextProps, nextContext); | ||
if (shallowEqual_1.default(this.props.variables, nextProps.variables) && | ||
this.client === nextClient && | ||
@@ -135,3 +125,3 @@ this.props.subscription === nextProps.subscription) { | ||
}(React.Component)); | ||
export default Subscription; | ||
exports.default = Subscription; | ||
//# sourceMappingURL=Subscriptions.js.map |
@@ -0,0 +0,0 @@ import { Operation, GraphQLRequest, ApolloLink, FetchResult, Observable } from 'apollo-link'; |
@@ -1,156 +0,139 @@ | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('apollo-link'), require('graphql/language/printer'), require('apollo-utilities')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'apollo-link', 'graphql/language/printer', 'apollo-utilities'], factory) : | ||
(global = global || self, factory(global['react-apollo'] = {}, global.apolloLink, global.printer, global.apolloUtilities)); | ||
}(this, function (exports, apolloLink, printer, apolloUtilities) { 'use strict'; | ||
var __extends = (undefined && undefined.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var isEqual = require('lodash.isequal'); | ||
var MockLink = (function (_super) { | ||
__extends(MockLink, _super); | ||
function MockLink(mockedResponses, addTypename) { | ||
if (addTypename === void 0) { addTypename = true; } | ||
var _this = _super.call(this) || this; | ||
_this.addTypename = true; | ||
_this.mockedResponsesByKey = {}; | ||
_this.addTypename = addTypename; | ||
if (mockedResponses) | ||
mockedResponses.forEach(function (mockedResponse) { | ||
_this.addMockedResponse(mockedResponse); | ||
}); | ||
return _this; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var apollo_link_1 = require("apollo-link"); | ||
var printer_1 = require("graphql/language/printer"); | ||
var apollo_utilities_1 = require("apollo-utilities"); | ||
var isEqual = require('lodash.isequal'); | ||
var MockLink = (function (_super) { | ||
tslib_1.__extends(MockLink, _super); | ||
function MockLink(mockedResponses, addTypename) { | ||
if (addTypename === void 0) { addTypename = true; } | ||
var _this = _super.call(this) || this; | ||
_this.addTypename = true; | ||
_this.mockedResponsesByKey = {}; | ||
_this.addTypename = addTypename; | ||
if (mockedResponses) | ||
mockedResponses.forEach(function (mockedResponse) { | ||
_this.addMockedResponse(mockedResponse); | ||
}); | ||
return _this; | ||
} | ||
MockLink.prototype.addMockedResponse = function (mockedResponse) { | ||
var key = requestToKey(mockedResponse.request, this.addTypename); | ||
var mockedResponses = this.mockedResponsesByKey[key]; | ||
if (!mockedResponses) { | ||
mockedResponses = []; | ||
this.mockedResponsesByKey[key] = mockedResponses; | ||
} | ||
MockLink.prototype.addMockedResponse = function (mockedResponse) { | ||
var key = requestToKey(mockedResponse.request, this.addTypename); | ||
var mockedResponses = this.mockedResponsesByKey[key]; | ||
if (!mockedResponses) { | ||
mockedResponses = []; | ||
this.mockedResponsesByKey[key] = mockedResponses; | ||
mockedResponses.push(mockedResponse); | ||
}; | ||
MockLink.prototype.request = function (operation) { | ||
var key = requestToKey(operation, this.addTypename); | ||
var responseIndex; | ||
var response = (this.mockedResponsesByKey[key] || []).find(function (res, index) { | ||
var requestVariables = operation.variables || {}; | ||
var mockedResponseVariables = res.request.variables || {}; | ||
if (!isEqual(requestVariables, mockedResponseVariables)) { | ||
return false; | ||
} | ||
mockedResponses.push(mockedResponse); | ||
}; | ||
MockLink.prototype.request = function (operation) { | ||
var key = requestToKey(operation, this.addTypename); | ||
var responseIndex; | ||
var response = (this.mockedResponsesByKey[key] || []).find(function (res, index) { | ||
var requestVariables = operation.variables || {}; | ||
var mockedResponseVariables = res.request.variables || {}; | ||
if (!isEqual(requestVariables, mockedResponseVariables)) { | ||
return false; | ||
} | ||
responseIndex = index; | ||
return true; | ||
}); | ||
if (!response || typeof responseIndex === 'undefined') { | ||
throw new Error("No more mocked responses for the query: " + printer.print(operation.query) + ", variables: " + JSON.stringify(operation.variables)); | ||
} | ||
this.mockedResponsesByKey[key].splice(responseIndex, 1); | ||
var result = response.result, error = response.error, delay = response.delay, newData = response.newData; | ||
if (newData) { | ||
response.result = newData(); | ||
this.mockedResponsesByKey[key].push(response); | ||
} | ||
if (!result && !error) { | ||
throw new Error("Mocked response should contain either result or error: " + key); | ||
} | ||
return new apolloLink.Observable(function (observer) { | ||
var timer = setTimeout(function () { | ||
if (error) { | ||
observer.error(error); | ||
} | ||
else { | ||
if (result) | ||
observer.next(result); | ||
observer.complete(); | ||
} | ||
}, delay ? delay : 0); | ||
return function () { | ||
clearTimeout(timer); | ||
}; | ||
}); | ||
}; | ||
return MockLink; | ||
}(apolloLink.ApolloLink)); | ||
var MockSubscriptionLink = (function (_super) { | ||
__extends(MockSubscriptionLink, _super); | ||
function MockSubscriptionLink() { | ||
var _this = _super.call(this) || this; | ||
_this.unsubscribers = []; | ||
_this.setups = []; | ||
return _this; | ||
responseIndex = index; | ||
return true; | ||
}); | ||
if (!response || typeof responseIndex === 'undefined') { | ||
throw new Error("No more mocked responses for the query: " + printer_1.print(operation.query) + ", variables: " + JSON.stringify(operation.variables)); | ||
} | ||
MockSubscriptionLink.prototype.request = function (_req) { | ||
var _this = this; | ||
return new apolloLink.Observable(function (observer) { | ||
_this.setups.forEach(function (x) { return x(); }); | ||
_this.observer = observer; | ||
return function () { | ||
_this.unsubscribers.forEach(function (x) { return x(); }); | ||
}; | ||
}); | ||
}; | ||
MockSubscriptionLink.prototype.simulateResult = function (result, complete) { | ||
var _this = this; | ||
if (complete === void 0) { complete = false; } | ||
setTimeout(function () { | ||
var observer = _this.observer; | ||
if (!observer) | ||
throw new Error('subscription torn down'); | ||
if (complete && observer.complete) | ||
observer.complete(); | ||
if (result.result && observer.next) | ||
observer.next(result.result); | ||
if (result.error && observer.error) | ||
observer.error(result.error); | ||
}, result.delay || 0); | ||
}; | ||
MockSubscriptionLink.prototype.onSetup = function (listener) { | ||
this.setups = this.setups.concat([listener]); | ||
}; | ||
MockSubscriptionLink.prototype.onUnsubscribe = function (listener) { | ||
this.unsubscribers = this.unsubscribers.concat([listener]); | ||
}; | ||
return MockSubscriptionLink; | ||
}(apolloLink.ApolloLink)); | ||
function requestToKey(request, addTypename) { | ||
var queryString = request.query && printer.print(addTypename ? apolloUtilities.addTypenameToDocument(request.query) : request.query); | ||
var requestKey = { query: queryString }; | ||
return JSON.stringify(requestKey); | ||
} | ||
function mockSingleLink() { | ||
var mockedResponses = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
mockedResponses[_i] = arguments[_i]; | ||
this.mockedResponsesByKey[key].splice(responseIndex, 1); | ||
var result = response.result, error = response.error, delay = response.delay, newData = response.newData; | ||
if (newData) { | ||
response.result = newData(); | ||
this.mockedResponsesByKey[key].push(response); | ||
} | ||
var maybeTypename = mockedResponses[mockedResponses.length - 1]; | ||
var mocks = mockedResponses.slice(0, mockedResponses.length - 1); | ||
if (typeof maybeTypename !== 'boolean') { | ||
mocks = mockedResponses; | ||
maybeTypename = true; | ||
if (!result && !error) { | ||
throw new Error("Mocked response should contain either result or error: " + key); | ||
} | ||
return new MockLink(mocks, maybeTypename); | ||
return new apollo_link_1.Observable(function (observer) { | ||
var timer = setTimeout(function () { | ||
if (error) { | ||
observer.error(error); | ||
} | ||
else { | ||
if (result) | ||
observer.next(result); | ||
observer.complete(); | ||
} | ||
}, delay ? delay : 0); | ||
return function () { | ||
clearTimeout(timer); | ||
}; | ||
}); | ||
}; | ||
return MockLink; | ||
}(apollo_link_1.ApolloLink)); | ||
exports.MockLink = MockLink; | ||
var MockSubscriptionLink = (function (_super) { | ||
tslib_1.__extends(MockSubscriptionLink, _super); | ||
function MockSubscriptionLink() { | ||
var _this = _super.call(this) || this; | ||
_this.unsubscribers = []; | ||
_this.setups = []; | ||
return _this; | ||
} | ||
function mockObservableLink() { | ||
return new MockSubscriptionLink(); | ||
MockSubscriptionLink.prototype.request = function (_req) { | ||
var _this = this; | ||
return new apollo_link_1.Observable(function (observer) { | ||
_this.setups.forEach(function (x) { return x(); }); | ||
_this.observer = observer; | ||
return function () { | ||
_this.unsubscribers.forEach(function (x) { return x(); }); | ||
}; | ||
}); | ||
}; | ||
MockSubscriptionLink.prototype.simulateResult = function (result, complete) { | ||
var _this = this; | ||
if (complete === void 0) { complete = false; } | ||
setTimeout(function () { | ||
var observer = _this.observer; | ||
if (!observer) | ||
throw new Error('subscription torn down'); | ||
if (complete && observer.complete) | ||
observer.complete(); | ||
if (result.result && observer.next) | ||
observer.next(result.result); | ||
if (result.error && observer.error) | ||
observer.error(result.error); | ||
}, result.delay || 0); | ||
}; | ||
MockSubscriptionLink.prototype.onSetup = function (listener) { | ||
this.setups = this.setups.concat([listener]); | ||
}; | ||
MockSubscriptionLink.prototype.onUnsubscribe = function (listener) { | ||
this.unsubscribers = this.unsubscribers.concat([listener]); | ||
}; | ||
return MockSubscriptionLink; | ||
}(apollo_link_1.ApolloLink)); | ||
exports.MockSubscriptionLink = MockSubscriptionLink; | ||
function requestToKey(request, addTypename) { | ||
var queryString = request.query && printer_1.print(addTypename ? apollo_utilities_1.addTypenameToDocument(request.query) : request.query); | ||
var requestKey = { query: queryString }; | ||
return JSON.stringify(requestKey); | ||
} | ||
function mockSingleLink() { | ||
var mockedResponses = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
mockedResponses[_i] = arguments[_i]; | ||
} | ||
exports.MockLink = MockLink; | ||
exports.MockSubscriptionLink = MockSubscriptionLink; | ||
exports.mockSingleLink = mockSingleLink; | ||
exports.mockObservableLink = mockObservableLink; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
})); | ||
var maybeTypename = mockedResponses[mockedResponses.length - 1]; | ||
var mocks = mockedResponses.slice(0, mockedResponses.length - 1); | ||
if (typeof maybeTypename !== 'boolean') { | ||
mocks = mockedResponses; | ||
maybeTypename = true; | ||
} | ||
return new MockLink(mocks, maybeTypename); | ||
} | ||
exports.mockSingleLink = mockSingleLink; | ||
function mockObservableLink() { | ||
return new MockSubscriptionLink(); | ||
} | ||
exports.mockObservableLink = mockObservableLink; | ||
//# sourceMappingURL=test-links.js.map |
@@ -0,0 +0,0 @@ import * as React from 'react'; |
1123
test-utils.js
@@ -1,1096 +0,35 @@ | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('apollo-client'), require('apollo-cache-inmemory'), require('prop-types'), require('hoist-non-react-statics'), require('apollo-link'), require('graphql/language/printer'), require('apollo-utilities')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'react', 'apollo-client', 'apollo-cache-inmemory', 'prop-types', 'hoist-non-react-statics', 'apollo-link', 'graphql/language/printer', 'apollo-utilities'], factory) : | ||
(global = global || self, factory(global['react-apollo'] = {}, global.React, global.ApolloClient, global.apolloCacheInmemory, global.PropTypes, global.hoistNonReactStatics, global.apolloLink, global.printer, global.apolloUtilities)); | ||
}(this, function (exports, React, ApolloClient, apolloCacheInmemory, PropTypes, hoistNonReactStatics, apolloLink, printer, apolloUtilities) { 'use strict'; | ||
var ApolloClient__default = 'default' in ApolloClient ? ApolloClient['default'] : ApolloClient; | ||
hoistNonReactStatics = hoistNonReactStatics && hoistNonReactStatics.hasOwnProperty('default') ? hoistNonReactStatics['default'] : hoistNonReactStatics; | ||
var __extends = (undefined && undefined.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __assign = (undefined && undefined.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var invariant = require('invariant'); | ||
var ApolloConsumer = function (props, context) { | ||
invariant(!!context.client, "Could not find \"client\" in the context of ApolloConsumer. Wrap the root component in an <ApolloProvider>"); | ||
return props.children(context.client); | ||
}; | ||
ApolloConsumer.contextTypes = { | ||
client: PropTypes.object.isRequired, | ||
}; | ||
ApolloConsumer.propTypes = { | ||
children: PropTypes.func.isRequired, | ||
}; | ||
var __extends$1 = (undefined && undefined.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var invariant$1 = require('invariant'); | ||
var ApolloProvider = (function (_super) { | ||
__extends$1(ApolloProvider, _super); | ||
function ApolloProvider(props, context) { | ||
var _this = _super.call(this, props, context) || this; | ||
_this.operations = new Map(); | ||
invariant$1(props.client, 'ApolloProvider was not passed a client instance. Make ' + | ||
'sure you pass in your client via the "client" prop.'); | ||
if (!props.client.__operations_cache__) { | ||
props.client.__operations_cache__ = _this.operations; | ||
} | ||
return _this; | ||
} | ||
ApolloProvider.prototype.getChildContext = function () { | ||
return { | ||
client: this.props.client, | ||
operations: this.props.client.__operations_cache__, | ||
}; | ||
}; | ||
ApolloProvider.prototype.render = function () { | ||
return this.props.children; | ||
}; | ||
ApolloProvider.propTypes = { | ||
client: PropTypes.object.isRequired, | ||
children: PropTypes.node.isRequired, | ||
}; | ||
ApolloProvider.childContextTypes = { | ||
client: PropTypes.object.isRequired, | ||
operations: PropTypes.object, | ||
}; | ||
return ApolloProvider; | ||
}(React.Component)); | ||
var invariant$2 = require('invariant'); | ||
var DocumentType; | ||
(function (DocumentType) { | ||
DocumentType[DocumentType["Query"] = 0] = "Query"; | ||
DocumentType[DocumentType["Mutation"] = 1] = "Mutation"; | ||
DocumentType[DocumentType["Subscription"] = 2] = "Subscription"; | ||
})(DocumentType || (DocumentType = {})); | ||
var cache = new Map(); | ||
function parser(document) { | ||
var cached = cache.get(document); | ||
if (cached) | ||
return cached; | ||
var variables, type, name; | ||
invariant$2(!!document && !!document.kind, "Argument of " + document + " passed to parser was not a valid GraphQL " + | ||
"DocumentNode. You may need to use 'graphql-tag' or another method " + | ||
"to convert your operation into a document"); | ||
var fragments = document.definitions.filter(function (x) { return x.kind === 'FragmentDefinition'; }); | ||
var queries = document.definitions.filter(function (x) { return x.kind === 'OperationDefinition' && x.operation === 'query'; }); | ||
var mutations = document.definitions.filter(function (x) { return x.kind === 'OperationDefinition' && x.operation === 'mutation'; }); | ||
var subscriptions = document.definitions.filter(function (x) { return x.kind === 'OperationDefinition' && x.operation === 'subscription'; }); | ||
invariant$2(!fragments.length || (queries.length || mutations.length || subscriptions.length), "Passing only a fragment to 'graphql' is not yet supported. " + | ||
"You must include a query, subscription or mutation as well"); | ||
invariant$2(queries.length + mutations.length + subscriptions.length <= 1, "react-apollo only supports a query, subscription, or a mutation per HOC. " + | ||
(document + " had " + queries.length + " queries, " + subscriptions.length + " ") + | ||
("subscriptions and " + mutations.length + " mutations. ") + | ||
"You can use 'compose' to join multiple operation types to a component"); | ||
type = queries.length ? DocumentType.Query : DocumentType.Mutation; | ||
if (!queries.length && !mutations.length) | ||
type = DocumentType.Subscription; | ||
var definitions = queries.length ? queries : mutations.length ? mutations : subscriptions; | ||
invariant$2(definitions.length === 1, "react-apollo only supports one defintion per HOC. " + document + " had " + | ||
(definitions.length + " definitions. ") + | ||
"You can use 'compose' to join multiple operation types to a component"); | ||
var definition = definitions[0]; | ||
variables = definition.variableDefinitions || []; | ||
if (definition.name && definition.name.kind === 'Name') { | ||
name = definition.name.value; | ||
} | ||
else { | ||
name = 'data'; | ||
} | ||
var payload = { name: name, type: type, variables: variables }; | ||
cache.set(document, payload); | ||
return payload; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var React = tslib_1.__importStar(require("react")); | ||
var apollo_client_1 = tslib_1.__importDefault(require("apollo-client")); | ||
var apollo_cache_inmemory_1 = require("apollo-cache-inmemory"); | ||
var index_1 = require("./index"); | ||
var test_links_1 = require("./test-links"); | ||
tslib_1.__exportStar(require("./test-links"), exports); | ||
var MockedProvider = (function (_super) { | ||
tslib_1.__extends(MockedProvider, _super); | ||
function MockedProvider(props) { | ||
var _this = _super.call(this, props) || this; | ||
var _a = _this.props, mocks = _a.mocks, addTypename = _a.addTypename, defaultOptions = _a.defaultOptions, cache = _a.cache; | ||
var client = new apollo_client_1.default({ | ||
cache: cache || new apollo_cache_inmemory_1.InMemoryCache({ addTypename: addTypename }), | ||
defaultOptions: defaultOptions, | ||
link: new test_links_1.MockLink(mocks || [], addTypename), | ||
}); | ||
_this.state = { client: client }; | ||
return _this; | ||
} | ||
var invariant$3 = require('invariant'); | ||
function getClient(props, context) { | ||
var client = props.client || context.client; | ||
invariant$3(!!client, 'Could not find "client" in the context or passed in as a prop. ' + | ||
'Wrap the root component in an <ApolloProvider>, or pass an ' + | ||
'ApolloClient instance in via props.'); | ||
return client; | ||
} | ||
var __extends$2 = (undefined && undefined.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __assign$1 = (undefined && undefined.__assign) || function () { | ||
__assign$1 = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign$1.apply(this, arguments); | ||
MockedProvider.prototype.render = function () { | ||
return React.createElement(index_1.ApolloProvider, { client: this.state.client }, this.props.children); | ||
}; | ||
var __rest = (undefined && undefined.__rest) || function (s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0) | ||
t[p[i]] = s[p[i]]; | ||
return t; | ||
MockedProvider.prototype.componentWillUnmount = function () { | ||
this.state.client.stop(); | ||
}; | ||
var shallowEqual = require('fbjs/lib/shallowEqual'); | ||
var invariant$4 = require('invariant'); | ||
function compact(obj) { | ||
return Object.keys(obj).reduce(function (acc, key) { | ||
if (obj[key] !== undefined) { | ||
acc[key] = obj[key]; | ||
} | ||
return acc; | ||
}, {}); | ||
} | ||
function observableQueryFields(observable) { | ||
var fields = { | ||
variables: observable.variables, | ||
refetch: observable.refetch.bind(observable), | ||
fetchMore: observable.fetchMore.bind(observable), | ||
updateQuery: observable.updateQuery.bind(observable), | ||
startPolling: observable.startPolling.bind(observable), | ||
stopPolling: observable.stopPolling.bind(observable), | ||
subscribeToMore: observable.subscribeToMore.bind(observable), | ||
}; | ||
return fields; | ||
} | ||
var Query = (function (_super) { | ||
__extends$2(Query, _super); | ||
function Query(props, context) { | ||
var _this = _super.call(this, props, context) || this; | ||
_this.previousData = {}; | ||
_this.hasMounted = false; | ||
_this.startQuerySubscription = function () { | ||
if (_this.querySubscription) | ||
return; | ||
var initial = _this.getQueryResult(); | ||
_this.querySubscription = _this.queryObservable.subscribe({ | ||
next: function (_a) { | ||
var data = _a.data; | ||
if (initial && initial.networkStatus === 7 && shallowEqual(initial.data, data)) { | ||
initial = undefined; | ||
return; | ||
} | ||
initial = undefined; | ||
_this.updateCurrentData(); | ||
}, | ||
error: function (error) { | ||
_this.resubscribeToQuery(); | ||
if (!error.hasOwnProperty('graphQLErrors')) | ||
throw error; | ||
_this.updateCurrentData(); | ||
}, | ||
}); | ||
}; | ||
_this.removeQuerySubscription = function () { | ||
if (_this.querySubscription) { | ||
_this.querySubscription.unsubscribe(); | ||
delete _this.querySubscription; | ||
} | ||
}; | ||
_this.updateCurrentData = function () { | ||
if (_this.hasMounted) | ||
_this.forceUpdate(); | ||
}; | ||
_this.getQueryResult = function () { | ||
var data = { data: Object.create(null) }; | ||
Object.assign(data, observableQueryFields(_this.queryObservable)); | ||
if (_this.props.skip) { | ||
data = __assign$1({}, data, { data: undefined, error: undefined, loading: false }); | ||
} | ||
else { | ||
var currentResult = _this.queryObservable.currentResult(); | ||
var loading = currentResult.loading, partial = currentResult.partial, networkStatus = currentResult.networkStatus, errors = currentResult.errors; | ||
var error = currentResult.error; | ||
if (errors && errors.length > 0) { | ||
error = new ApolloClient.ApolloError({ graphQLErrors: errors }); | ||
} | ||
Object.assign(data, { loading: loading, networkStatus: networkStatus, error: error }); | ||
if (loading) { | ||
Object.assign(data.data, _this.previousData, currentResult.data); | ||
} | ||
else if (error) { | ||
Object.assign(data, { | ||
data: (_this.queryObservable.getLastResult() || {}).data, | ||
}); | ||
} | ||
else { | ||
var fetchPolicy = _this.queryObservable.options.fetchPolicy; | ||
var partialRefetch = _this.props.partialRefetch; | ||
if (partialRefetch && | ||
Object.keys(currentResult.data).length === 0 && | ||
partial && | ||
fetchPolicy !== 'cache-only') { | ||
Object.assign(data, { loading: true, networkStatus: ApolloClient.NetworkStatus.loading }); | ||
data.refetch(); | ||
return data; | ||
} | ||
Object.assign(data.data, currentResult.data); | ||
_this.previousData = currentResult.data; | ||
} | ||
} | ||
if (!_this.querySubscription) { | ||
var oldRefetch_1 = data.refetch; | ||
data.refetch = function (args) { | ||
if (_this.querySubscription) { | ||
return oldRefetch_1(args); | ||
} | ||
else { | ||
return new Promise(function (r, f) { | ||
_this.refetcherQueue = { resolve: r, reject: f, args: args }; | ||
}); | ||
} | ||
}; | ||
} | ||
data.client = _this.client; | ||
return data; | ||
}; | ||
_this.client = getClient(props, context); | ||
_this.initializeQueryObservable(props); | ||
return _this; | ||
} | ||
Query.prototype.fetchData = function () { | ||
if (this.props.skip) | ||
return false; | ||
var _a = this.props, children = _a.children, ssr = _a.ssr, displayName = _a.displayName, skip = _a.skip, client = _a.client, onCompleted = _a.onCompleted, onError = _a.onError, partialRefetch = _a.partialRefetch, opts = __rest(_a, ["children", "ssr", "displayName", "skip", "client", "onCompleted", "onError", "partialRefetch"]); | ||
var fetchPolicy = opts.fetchPolicy; | ||
if (ssr === false) | ||
return false; | ||
if (fetchPolicy === 'network-only' || fetchPolicy === 'cache-and-network') { | ||
fetchPolicy = 'cache-first'; | ||
} | ||
var observable = this.client.watchQuery(__assign$1({}, opts, { fetchPolicy: fetchPolicy })); | ||
if (this.context && this.context.renderPromises) { | ||
this.context.renderPromises.registerSSRObservable(this, observable); | ||
} | ||
var result = this.queryObservable.currentResult(); | ||
return result.loading ? observable.result() : false; | ||
}; | ||
Query.prototype.componentDidMount = function () { | ||
this.hasMounted = true; | ||
if (this.props.skip) | ||
return; | ||
this.startQuerySubscription(); | ||
if (this.refetcherQueue) { | ||
var _a = this.refetcherQueue, args = _a.args, resolve = _a.resolve, reject = _a.reject; | ||
this.queryObservable.refetch(args) | ||
.then(resolve) | ||
.catch(reject); | ||
} | ||
}; | ||
Query.prototype.componentWillReceiveProps = function (nextProps, nextContext) { | ||
if (nextProps.skip && !this.props.skip) { | ||
this.removeQuerySubscription(); | ||
return; | ||
} | ||
var nextClient = getClient(nextProps, nextContext); | ||
if (shallowEqual(this.props, nextProps) && this.client === nextClient) { | ||
return; | ||
} | ||
if (this.client !== nextClient) { | ||
this.client = nextClient; | ||
this.removeQuerySubscription(); | ||
this.queryObservable = null; | ||
this.previousData = {}; | ||
this.updateQuery(nextProps); | ||
} | ||
if (this.props.query !== nextProps.query) { | ||
this.removeQuerySubscription(); | ||
} | ||
this.updateQuery(nextProps); | ||
if (nextProps.skip) | ||
return; | ||
this.startQuerySubscription(); | ||
}; | ||
Query.prototype.componentWillUnmount = function () { | ||
this.removeQuerySubscription(); | ||
this.hasMounted = false; | ||
}; | ||
Query.prototype.componentDidUpdate = function () { | ||
var _a = this.props, onCompleted = _a.onCompleted, onError = _a.onError; | ||
if (onCompleted || onError) { | ||
var currentResult = this.queryObservable.currentResult(); | ||
var loading = currentResult.loading, error = currentResult.error, data = currentResult.data; | ||
if (onCompleted && !loading && !error) { | ||
onCompleted(data); | ||
} | ||
else if (onError && !loading && error) { | ||
onError(error); | ||
} | ||
} | ||
}; | ||
Query.prototype.render = function () { | ||
var _this = this; | ||
var context = this.context; | ||
var finish = function () { return _this.props.children(_this.getQueryResult()); }; | ||
if (context && context.renderPromises) { | ||
return context.renderPromises.addQueryPromise(this, finish); | ||
} | ||
return finish(); | ||
}; | ||
Query.prototype.extractOptsFromProps = function (props) { | ||
var variables = props.variables, pollInterval = props.pollInterval, fetchPolicy = props.fetchPolicy, errorPolicy = props.errorPolicy, notifyOnNetworkStatusChange = props.notifyOnNetworkStatusChange, query = props.query, _a = props.displayName, displayName = _a === void 0 ? 'Query' : _a, _b = props.context, context = _b === void 0 ? {} : _b; | ||
this.operation = parser(query); | ||
invariant$4(this.operation.type === DocumentType.Query, "The <Query /> component requires a graphql query, but got a " + (this.operation.type === DocumentType.Mutation ? 'mutation' : 'subscription') + "."); | ||
return compact({ | ||
variables: variables, | ||
pollInterval: pollInterval, | ||
query: query, | ||
fetchPolicy: fetchPolicy, | ||
errorPolicy: errorPolicy, | ||
notifyOnNetworkStatusChange: notifyOnNetworkStatusChange, | ||
metadata: { reactComponent: { displayName: displayName } }, | ||
context: context, | ||
}); | ||
}; | ||
Query.prototype.initializeQueryObservable = function (props) { | ||
var opts = this.extractOptsFromProps(props); | ||
this.setOperations(opts); | ||
if (this.context && this.context.renderPromises) { | ||
this.queryObservable = this.context.renderPromises.getSSRObservable(this); | ||
} | ||
if (!this.queryObservable) { | ||
this.queryObservable = this.client.watchQuery(opts); | ||
} | ||
}; | ||
Query.prototype.setOperations = function (props) { | ||
if (this.context.operations) { | ||
this.context.operations.set(this.operation.name, { | ||
query: props.query, | ||
variables: props.variables, | ||
}); | ||
} | ||
}; | ||
Query.prototype.updateQuery = function (props) { | ||
if (!this.queryObservable) { | ||
this.initializeQueryObservable(props); | ||
} | ||
else { | ||
this.setOperations(props); | ||
} | ||
this.queryObservable.setOptions(this.extractOptsFromProps(props)) | ||
.catch(function () { return null; }); | ||
}; | ||
Query.prototype.resubscribeToQuery = function () { | ||
this.removeQuerySubscription(); | ||
var lastError = this.queryObservable.getLastError(); | ||
var lastResult = this.queryObservable.getLastResult(); | ||
this.queryObservable.resetLastResults(); | ||
this.startQuerySubscription(); | ||
Object.assign(this.queryObservable, { lastError: lastError, lastResult: lastResult }); | ||
}; | ||
Query.contextTypes = { | ||
client: PropTypes.object, | ||
operations: PropTypes.object, | ||
renderPromises: PropTypes.object, | ||
}; | ||
Query.propTypes = { | ||
client: PropTypes.object, | ||
children: PropTypes.func.isRequired, | ||
fetchPolicy: PropTypes.string, | ||
notifyOnNetworkStatusChange: PropTypes.bool, | ||
onCompleted: PropTypes.func, | ||
onError: PropTypes.func, | ||
pollInterval: PropTypes.number, | ||
query: PropTypes.object.isRequired, | ||
variables: PropTypes.object, | ||
ssr: PropTypes.bool, | ||
partialRefetch: PropTypes.bool, | ||
}; | ||
return Query; | ||
}(React.Component)); | ||
var __extends$3 = (undefined && undefined.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __assign$2 = (undefined && undefined.__assign) || function () { | ||
__assign$2 = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign$2.apply(this, arguments); | ||
MockedProvider.defaultProps = { | ||
addTypename: true, | ||
}; | ||
var invariant$5 = require('invariant'); | ||
var shallowEqual$1 = require('fbjs/lib/shallowEqual'); | ||
var initialState = { | ||
loading: false, | ||
called: false, | ||
error: undefined, | ||
data: undefined, | ||
}; | ||
var Mutation = (function (_super) { | ||
__extends$3(Mutation, _super); | ||
function Mutation(props, context) { | ||
var _this = _super.call(this, props, context) || this; | ||
_this.hasMounted = false; | ||
_this.runMutation = function (options) { | ||
if (options === void 0) { options = {}; } | ||
_this.onMutationStart(); | ||
var mutationId = _this.generateNewMutationId(); | ||
return _this.mutate(options) | ||
.then(function (response) { | ||
_this.onMutationCompleted(response, mutationId); | ||
return response; | ||
}) | ||
.catch(function (e) { | ||
_this.onMutationError(e, mutationId); | ||
if (!_this.props.onError) | ||
throw e; | ||
}); | ||
}; | ||
_this.mutate = function (options) { | ||
var _a = _this.props, mutation = _a.mutation, variables = _a.variables, optimisticResponse = _a.optimisticResponse, update = _a.update, _b = _a.context, context = _b === void 0 ? {} : _b, _c = _a.awaitRefetchQueries, awaitRefetchQueries = _c === void 0 ? false : _c, fetchPolicy = _a.fetchPolicy; | ||
var mutateOptions = __assign$2({}, options); | ||
var refetchQueries = mutateOptions.refetchQueries || _this.props.refetchQueries; | ||
if (refetchQueries && refetchQueries.length && Array.isArray(refetchQueries)) { | ||
refetchQueries = refetchQueries.map(function (x) { | ||
if (typeof x === 'string' && _this.context.operations) | ||
return _this.context.operations.get(x) || x; | ||
return x; | ||
}); | ||
delete mutateOptions.refetchQueries; | ||
} | ||
var mutateVariables = Object.assign({}, variables, mutateOptions.variables); | ||
delete mutateOptions.variables; | ||
return _this.client.mutate(__assign$2({ mutation: mutation, | ||
optimisticResponse: optimisticResponse, | ||
refetchQueries: refetchQueries, | ||
awaitRefetchQueries: awaitRefetchQueries, | ||
update: update, | ||
context: context, | ||
fetchPolicy: fetchPolicy, variables: mutateVariables }, mutateOptions)); | ||
}; | ||
_this.onMutationStart = function () { | ||
if (!_this.state.loading && !_this.props.ignoreResults) { | ||
_this.setState({ | ||
loading: true, | ||
error: undefined, | ||
data: undefined, | ||
called: true, | ||
}); | ||
} | ||
}; | ||
_this.onMutationCompleted = function (response, mutationId) { | ||
var _a = _this.props, onCompleted = _a.onCompleted, ignoreResults = _a.ignoreResults; | ||
var data = response.data, errors = response.errors; | ||
var error = errors && errors.length > 0 ? new ApolloClient.ApolloError({ graphQLErrors: errors }) : undefined; | ||
var callOncomplete = function () { return (onCompleted ? onCompleted(data) : null); }; | ||
if (_this.hasMounted && _this.isMostRecentMutation(mutationId) && !ignoreResults) { | ||
_this.setState({ loading: false, data: data, error: error }, callOncomplete); | ||
} | ||
else { | ||
callOncomplete(); | ||
} | ||
}; | ||
_this.onMutationError = function (error, mutationId) { | ||
var onError = _this.props.onError; | ||
var callOnError = function () { return (onError ? onError(error) : null); }; | ||
if (_this.hasMounted && _this.isMostRecentMutation(mutationId)) { | ||
_this.setState({ loading: false, error: error }, callOnError); | ||
} | ||
else { | ||
callOnError(); | ||
} | ||
}; | ||
_this.generateNewMutationId = function () { | ||
_this.mostRecentMutationId = _this.mostRecentMutationId + 1; | ||
return _this.mostRecentMutationId; | ||
}; | ||
_this.isMostRecentMutation = function (mutationId) { | ||
return _this.mostRecentMutationId === mutationId; | ||
}; | ||
_this.verifyDocumentIsMutation = function (mutation) { | ||
var operation = parser(mutation); | ||
invariant$5(operation.type === DocumentType.Mutation, "The <Mutation /> component requires a graphql mutation, but got a " + (operation.type === DocumentType.Query ? 'query' : 'subscription') + "."); | ||
}; | ||
_this.client = getClient(props, context); | ||
_this.verifyDocumentIsMutation(props.mutation); | ||
_this.mostRecentMutationId = 0; | ||
_this.state = initialState; | ||
return _this; | ||
} | ||
Mutation.prototype.componentDidMount = function () { | ||
this.hasMounted = true; | ||
}; | ||
Mutation.prototype.componentWillUnmount = function () { | ||
this.hasMounted = false; | ||
}; | ||
Mutation.prototype.componentWillReceiveProps = function (nextProps, nextContext) { | ||
var nextClient = getClient(nextProps, nextContext); | ||
if (shallowEqual$1(this.props, nextProps) && this.client === nextClient) { | ||
return; | ||
} | ||
if (this.props.mutation !== nextProps.mutation) { | ||
this.verifyDocumentIsMutation(nextProps.mutation); | ||
} | ||
if (this.client !== nextClient) { | ||
this.client = nextClient; | ||
this.setState(initialState); | ||
} | ||
}; | ||
Mutation.prototype.render = function () { | ||
var children = this.props.children; | ||
var _a = this.state, loading = _a.loading, data = _a.data, error = _a.error, called = _a.called; | ||
var result = { | ||
called: called, | ||
loading: loading, | ||
data: data, | ||
error: error, | ||
client: this.client, | ||
}; | ||
return children(this.runMutation, result); | ||
}; | ||
Mutation.contextTypes = { | ||
client: PropTypes.object, | ||
operations: PropTypes.object, | ||
}; | ||
Mutation.propTypes = { | ||
mutation: PropTypes.object.isRequired, | ||
variables: PropTypes.object, | ||
optimisticResponse: PropTypes.object, | ||
refetchQueries: PropTypes.oneOfType([ | ||
PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.object])), | ||
PropTypes.func, | ||
]), | ||
awaitRefetchQueries: PropTypes.bool, | ||
update: PropTypes.func, | ||
children: PropTypes.func.isRequired, | ||
onCompleted: PropTypes.func, | ||
onError: PropTypes.func, | ||
fetchPolicy: PropTypes.string, | ||
}; | ||
return Mutation; | ||
}(React.Component)); | ||
var __extends$4 = (undefined && undefined.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var shallowEqual$2 = require('fbjs/lib/shallowEqual'); | ||
var invariant$6 = require('invariant'); | ||
var Subscription = (function (_super) { | ||
__extends$4(Subscription, _super); | ||
function Subscription(props, context) { | ||
var _this = _super.call(this, props, context) || this; | ||
_this.initialize = function (props) { | ||
if (_this.queryObservable) | ||
return; | ||
_this.queryObservable = _this.client.subscribe({ | ||
query: props.subscription, | ||
variables: props.variables, | ||
fetchPolicy: props.fetchPolicy, | ||
}); | ||
}; | ||
_this.startSubscription = function () { | ||
if (_this.querySubscription) | ||
return; | ||
_this.querySubscription = _this.queryObservable.subscribe({ | ||
next: _this.updateCurrentData, | ||
error: _this.updateError, | ||
complete: _this.completeSubscription | ||
}); | ||
}; | ||
_this.getInitialState = function () { return ({ | ||
loading: true, | ||
error: undefined, | ||
data: undefined, | ||
}); }; | ||
_this.updateCurrentData = function (result) { | ||
var _a = _this, client = _a.client, onSubscriptionData = _a.props.onSubscriptionData; | ||
if (onSubscriptionData) | ||
onSubscriptionData({ client: client, subscriptionData: result }); | ||
_this.setState({ | ||
data: result.data, | ||
loading: false, | ||
error: undefined, | ||
}); | ||
}; | ||
_this.updateError = function (error) { | ||
_this.setState({ | ||
error: error, | ||
loading: false, | ||
}); | ||
}; | ||
_this.completeSubscription = function () { | ||
var onSubscriptionComplete = _this.props.onSubscriptionComplete; | ||
if (onSubscriptionComplete) | ||
onSubscriptionComplete(); | ||
_this.endSubscription(); | ||
}; | ||
_this.endSubscription = function () { | ||
if (_this.querySubscription) { | ||
_this.querySubscription.unsubscribe(); | ||
delete _this.querySubscription; | ||
} | ||
}; | ||
_this.client = getClient(props, context); | ||
_this.initialize(props); | ||
_this.state = _this.getInitialState(); | ||
return _this; | ||
} | ||
Subscription.prototype.componentDidMount = function () { | ||
this.startSubscription(); | ||
}; | ||
Subscription.prototype.componentWillReceiveProps = function (nextProps, nextContext) { | ||
var nextClient = getClient(nextProps, nextContext); | ||
if (shallowEqual$2(this.props.variables, nextProps.variables) && | ||
this.client === nextClient && | ||
this.props.subscription === nextProps.subscription) { | ||
return; | ||
} | ||
var shouldResubscribe = nextProps.shouldResubscribe; | ||
if (typeof shouldResubscribe === 'function') { | ||
shouldResubscribe = !!shouldResubscribe(this.props, nextProps); | ||
} | ||
var shouldNotResubscribe = shouldResubscribe === false; | ||
if (this.client !== nextClient) { | ||
this.client = nextClient; | ||
} | ||
if (!shouldNotResubscribe) { | ||
this.endSubscription(); | ||
delete this.queryObservable; | ||
this.initialize(nextProps); | ||
this.startSubscription(); | ||
this.setState(this.getInitialState()); | ||
return; | ||
} | ||
this.initialize(nextProps); | ||
this.startSubscription(); | ||
}; | ||
Subscription.prototype.componentWillUnmount = function () { | ||
this.endSubscription(); | ||
}; | ||
Subscription.prototype.render = function () { | ||
var renderFn = this.props.children; | ||
if (!renderFn) | ||
return null; | ||
var result = Object.assign({}, this.state, { | ||
variables: this.props.variables, | ||
}); | ||
return renderFn(result); | ||
}; | ||
Subscription.contextTypes = { | ||
client: PropTypes.object, | ||
}; | ||
Subscription.propTypes = { | ||
subscription: PropTypes.object.isRequired, | ||
variables: PropTypes.object, | ||
children: PropTypes.func, | ||
onSubscriptionData: PropTypes.func, | ||
onSubscriptionComplete: PropTypes.func, | ||
shouldResubscribe: PropTypes.oneOfType([PropTypes.func, PropTypes.bool]), | ||
}; | ||
return Subscription; | ||
}(React.Component)); | ||
var __extends$5 = (undefined && undefined.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var invariant$7 = require('invariant'); | ||
var GraphQLBase = (function (_super) { | ||
__extends$5(GraphQLBase, _super); | ||
function GraphQLBase(props) { | ||
var _this = _super.call(this, props) || this; | ||
_this.withRef = false; | ||
_this.setWrappedInstance = _this.setWrappedInstance.bind(_this); | ||
return _this; | ||
} | ||
GraphQLBase.prototype.getWrappedInstance = function () { | ||
invariant$7(this.withRef, "To access the wrapped instance, you need to specify " + "{ withRef: true } in the options"); | ||
return this.wrappedInstance; | ||
}; | ||
GraphQLBase.prototype.setWrappedInstance = function (ref) { | ||
this.wrappedInstance = ref; | ||
}; | ||
return GraphQLBase; | ||
}(React.Component)); | ||
var __extends$6 = (undefined && undefined.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __assign$3 = (undefined && undefined.__assign) || function () { | ||
__assign$3 = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign$3.apply(this, arguments); | ||
}; | ||
var __rest$1 = (undefined && undefined.__rest) || function (s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0) | ||
t[p[i]] = s[p[i]]; | ||
return t; | ||
}; | ||
var __extends$7 = (undefined && undefined.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __assign$4 = (undefined && undefined.__assign) || function () { | ||
__assign$4 = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign$4.apply(this, arguments); | ||
}; | ||
var __extends$8 = (undefined && undefined.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __assign$5 = (undefined && undefined.__assign) || function () { | ||
__assign$5 = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign$5.apply(this, arguments); | ||
}; | ||
var __rest$2 = (undefined && undefined.__rest) || function (s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0) | ||
t[p[i]] = s[p[i]]; | ||
return t; | ||
}; | ||
var __extends$9 = (undefined && undefined.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __assign$6 = (undefined && undefined.__assign) || function () { | ||
__assign$6 = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign$6.apply(this, arguments); | ||
}; | ||
var invariant$8 = require('invariant'); | ||
var compose = require('lodash.flowright'); | ||
var __extends$a = (undefined && undefined.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var isEqual = require('lodash.isequal'); | ||
var MockLink = (function (_super) { | ||
__extends$a(MockLink, _super); | ||
function MockLink(mockedResponses, addTypename) { | ||
if (addTypename === void 0) { addTypename = true; } | ||
var _this = _super.call(this) || this; | ||
_this.addTypename = true; | ||
_this.mockedResponsesByKey = {}; | ||
_this.addTypename = addTypename; | ||
if (mockedResponses) | ||
mockedResponses.forEach(function (mockedResponse) { | ||
_this.addMockedResponse(mockedResponse); | ||
}); | ||
return _this; | ||
} | ||
MockLink.prototype.addMockedResponse = function (mockedResponse) { | ||
var key = requestToKey(mockedResponse.request, this.addTypename); | ||
var mockedResponses = this.mockedResponsesByKey[key]; | ||
if (!mockedResponses) { | ||
mockedResponses = []; | ||
this.mockedResponsesByKey[key] = mockedResponses; | ||
} | ||
mockedResponses.push(mockedResponse); | ||
}; | ||
MockLink.prototype.request = function (operation) { | ||
var key = requestToKey(operation, this.addTypename); | ||
var responseIndex; | ||
var response = (this.mockedResponsesByKey[key] || []).find(function (res, index) { | ||
var requestVariables = operation.variables || {}; | ||
var mockedResponseVariables = res.request.variables || {}; | ||
if (!isEqual(requestVariables, mockedResponseVariables)) { | ||
return false; | ||
} | ||
responseIndex = index; | ||
return true; | ||
}); | ||
if (!response || typeof responseIndex === 'undefined') { | ||
throw new Error("No more mocked responses for the query: " + printer.print(operation.query) + ", variables: " + JSON.stringify(operation.variables)); | ||
} | ||
this.mockedResponsesByKey[key].splice(responseIndex, 1); | ||
var result = response.result, error = response.error, delay = response.delay, newData = response.newData; | ||
if (newData) { | ||
response.result = newData(); | ||
this.mockedResponsesByKey[key].push(response); | ||
} | ||
if (!result && !error) { | ||
throw new Error("Mocked response should contain either result or error: " + key); | ||
} | ||
return new apolloLink.Observable(function (observer) { | ||
var timer = setTimeout(function () { | ||
if (error) { | ||
observer.error(error); | ||
} | ||
else { | ||
if (result) | ||
observer.next(result); | ||
observer.complete(); | ||
} | ||
}, delay ? delay : 0); | ||
return function () { | ||
clearTimeout(timer); | ||
}; | ||
}); | ||
}; | ||
return MockLink; | ||
}(apolloLink.ApolloLink)); | ||
var MockSubscriptionLink = (function (_super) { | ||
__extends$a(MockSubscriptionLink, _super); | ||
function MockSubscriptionLink() { | ||
var _this = _super.call(this) || this; | ||
_this.unsubscribers = []; | ||
_this.setups = []; | ||
return _this; | ||
} | ||
MockSubscriptionLink.prototype.request = function (_req) { | ||
var _this = this; | ||
return new apolloLink.Observable(function (observer) { | ||
_this.setups.forEach(function (x) { return x(); }); | ||
_this.observer = observer; | ||
return function () { | ||
_this.unsubscribers.forEach(function (x) { return x(); }); | ||
}; | ||
}); | ||
}; | ||
MockSubscriptionLink.prototype.simulateResult = function (result, complete) { | ||
var _this = this; | ||
if (complete === void 0) { complete = false; } | ||
setTimeout(function () { | ||
var observer = _this.observer; | ||
if (!observer) | ||
throw new Error('subscription torn down'); | ||
if (complete && observer.complete) | ||
observer.complete(); | ||
if (result.result && observer.next) | ||
observer.next(result.result); | ||
if (result.error && observer.error) | ||
observer.error(result.error); | ||
}, result.delay || 0); | ||
}; | ||
MockSubscriptionLink.prototype.onSetup = function (listener) { | ||
this.setups = this.setups.concat([listener]); | ||
}; | ||
MockSubscriptionLink.prototype.onUnsubscribe = function (listener) { | ||
this.unsubscribers = this.unsubscribers.concat([listener]); | ||
}; | ||
return MockSubscriptionLink; | ||
}(apolloLink.ApolloLink)); | ||
function requestToKey(request, addTypename) { | ||
var queryString = request.query && printer.print(addTypename ? apolloUtilities.addTypenameToDocument(request.query) : request.query); | ||
var requestKey = { query: queryString }; | ||
return JSON.stringify(requestKey); | ||
} | ||
function mockSingleLink() { | ||
var mockedResponses = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
mockedResponses[_i] = arguments[_i]; | ||
} | ||
var maybeTypename = mockedResponses[mockedResponses.length - 1]; | ||
var mocks = mockedResponses.slice(0, mockedResponses.length - 1); | ||
if (typeof maybeTypename !== 'boolean') { | ||
mocks = mockedResponses; | ||
maybeTypename = true; | ||
} | ||
return new MockLink(mocks, maybeTypename); | ||
} | ||
function mockObservableLink() { | ||
return new MockSubscriptionLink(); | ||
} | ||
var __extends$b = (undefined && undefined.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var MockedProvider = (function (_super) { | ||
__extends$b(MockedProvider, _super); | ||
function MockedProvider(props) { | ||
var _this = _super.call(this, props) || this; | ||
var _a = _this.props, mocks = _a.mocks, addTypename = _a.addTypename, defaultOptions = _a.defaultOptions, cache = _a.cache; | ||
var client = new ApolloClient__default({ | ||
cache: cache || new apolloCacheInmemory.InMemoryCache({ addTypename: addTypename }), | ||
defaultOptions: defaultOptions, | ||
link: new MockLink(mocks || [], addTypename), | ||
}); | ||
_this.state = { client: client }; | ||
return _this; | ||
} | ||
MockedProvider.prototype.render = function () { | ||
return React.createElement(ApolloProvider, { client: this.state.client }, this.props.children); | ||
}; | ||
MockedProvider.prototype.componentWillUnmount = function () { | ||
this.state.client.stop(); | ||
}; | ||
MockedProvider.defaultProps = { | ||
addTypename: true, | ||
}; | ||
return MockedProvider; | ||
}(React.Component)); | ||
exports.MockedProvider = MockedProvider; | ||
exports.MockLink = MockLink; | ||
exports.MockSubscriptionLink = MockSubscriptionLink; | ||
exports.mockSingleLink = mockSingleLink; | ||
exports.mockObservableLink = mockObservableLink; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
})); | ||
return MockedProvider; | ||
}(React.Component)); | ||
exports.MockedProvider = MockedProvider; | ||
//# sourceMappingURL=test-utils.js.map |
@@ -0,0 +0,0 @@ import ApolloClient, { ApolloQueryResult, ApolloError, FetchPolicy, ErrorPolicy, FetchMoreOptions, UpdateQueryOptions, FetchMoreQueryOptions, SubscribeToMoreOptions, PureQueryOptions, MutationUpdaterFn } from 'apollo-client'; |
@@ -0,1 +1,3 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
//# sourceMappingURL=types.js.map |
@@ -0,0 +0,0 @@ import * as React from 'react'; |
@@ -1,2 +0,5 @@ | ||
import * as React from 'react'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var React = tslib_1.__importStar(require("react")); | ||
function getProps(element) { | ||
@@ -14,3 +17,3 @@ return element.props || element.attributes; | ||
} | ||
export function walkTree(element, context, visitor, newContext) { | ||
function walkTree(element, context, visitor, newContext) { | ||
if (newContext === void 0) { newContext = new Map(); } | ||
@@ -121,2 +124,3 @@ if (!element) { | ||
} | ||
exports.walkTree = walkTree; | ||
//# sourceMappingURL=walkTree.js.map |
@@ -0,0 +0,0 @@ import * as React from 'react'; |
@@ -1,28 +0,7 @@ | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
} | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
import * as React from 'react'; | ||
import ApolloConsumer from './ApolloConsumer'; | ||
import hoistNonReactStatics from 'hoist-non-react-statics'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var React = tslib_1.__importStar(require("react")); | ||
var ApolloConsumer_1 = tslib_1.__importDefault(require("./ApolloConsumer")); | ||
var hoist_non_react_statics_1 = tslib_1.__importDefault(require("hoist-non-react-statics")); | ||
var invariant = require('invariant'); | ||
@@ -32,7 +11,7 @@ function getDisplayName(WrappedComponent) { | ||
} | ||
export default function withApollo(WrappedComponent, operationOptions) { | ||
function withApollo(WrappedComponent, operationOptions) { | ||
if (operationOptions === void 0) { operationOptions = {}; } | ||
var withDisplayName = "withApollo(" + getDisplayName(WrappedComponent) + ")"; | ||
var WithApollo = (function (_super) { | ||
__extends(WithApollo, _super); | ||
tslib_1.__extends(WithApollo, _super); | ||
function WithApollo(props) { | ||
@@ -52,3 +31,3 @@ var _this = _super.call(this, props) || this; | ||
var _this = this; | ||
return (React.createElement(ApolloConsumer, null, function (client) { | ||
return (React.createElement(ApolloConsumer_1.default, null, function (client) { | ||
var props = Object.assign({}, _this.props, { | ||
@@ -58,3 +37,3 @@ client: client, | ||
}); | ||
return React.createElement(WrappedComponent, __assign({}, props)); | ||
return React.createElement(WrappedComponent, tslib_1.__assign({}, props)); | ||
})); | ||
@@ -66,4 +45,5 @@ }; | ||
}(React.Component)); | ||
return hoistNonReactStatics(WithApollo, WrappedComponent, {}); | ||
return hoist_non_react_statics_1.default(WithApollo, WrappedComponent, {}); | ||
} | ||
exports.default = withApollo; | ||
//# sourceMappingURL=withApollo.js.map |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9
75
361888
1
4235
2
+ Addedtslib@^1.9.3
- Removedfbjs@^1.0.0
- Removedlodash.flowright@^3.5.0
- Removedasap@2.0.6(transitive)
- Removedcore-js@2.6.12(transitive)
- Removedencoding@0.1.13(transitive)
- Removedfbjs@1.0.0(transitive)
- Removedfbjs-css-vars@1.0.2(transitive)
- Removediconv-lite@0.6.3(transitive)
- Removedis-stream@1.1.0(transitive)
- Removedisomorphic-fetch@2.2.1(transitive)
- Removedlodash.flowright@3.5.0(transitive)
- Removednode-fetch@1.7.3(transitive)
- Removedpromise@7.3.1(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedsetimmediate@1.0.5(transitive)
- Removedua-parser-js@0.7.39(transitive)
- Removedwhatwg-fetch@3.6.20(transitive)