Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function process(): Promise | string {
// Always re-render from the rootElement, even though it might seem
// better to render the children of the component responsible for the
// promise, because it is not possible to reconstruct the full context
// of the original rendering (including all unknown context provider
// elements) for a subtree of the original component tree.
const ApolloContext = getApolloContext();
const html = renderFunction(
React.createElement(
ApolloContext.Provider,
{ value: { ...context, renderPromises } },
tree
)
);
return renderPromises.hasPromises()
? renderPromises.consumeAndAwaitPromises().then(process)
: html;
}
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.currentClient(),
};
return children(this.runMutation, result);
};
Mutation.prototype.currentClient = function () {
return getClient(this.props, this.context);
};
Mutation.contextType = reactCommon.getApolloContext();
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;
Query.prototype.render = function () {
var _this = this;
var ApolloContext = reactCommon.getApolloContext();
return (React.createElement(ApolloContext.Consumer, null, function (context) {
return _this.renderData(context);
}));
};
Query.prototype.fetchData = function (client, context) {
Query.prototype.render = function () {
var _this = this;
var ApolloContext = getApolloContext();
return (React.createElement(ApolloContext.Consumer, null, function (context) {
return _this.renderData(context);
}));
};
Query.prototype.fetchData = function (client, context) {
function process() {
var ApolloContext = getApolloContext();
var html = renderFunction(React.createElement(ApolloContext.Provider, { value: __assign({}, context, { renderPromises: renderPromises }) }, tree));
return renderPromises.hasPromises()
? renderPromises.consumeAndAwaitPromises().then(process)
: html;
}
return Promise.resolve().then(process);
function process() {
var ApolloContext = reactCommon.getApolloContext();
var html = renderFunction(React.createElement(ApolloContext.Provider, { value: tslib.__assign({}, context, { renderPromises: renderPromises }) }, tree));
return renderPromises.hasPromises()
? renderPromises.consumeAndAwaitPromises().then(process)
: html;
}
return Promise.resolve().then(process);
function useApolloClient() {
var client = React.useContext(reactCommon.getApolloContext()).client;
process.env.NODE_ENV === "production" ? tsInvariant.invariant(!client) : tsInvariant.invariant(!client, 'No Apollo Client instance can be found. Please ensure that you ' +
'have called `ApolloProvider` higher up in your tree.');
return client;
}
export function useQuery(
query: DocumentNode,
options?: QueryHookOptions
): QueryResult {
const context = useContext(getApolloContext());
const [tick, forceUpdate] = useReducer(x => x + 1, 0);
const updatedOptions = options ? { ...options, query } : { query };
const queryDataRef = useRef>();
function getQueryDataRef() {
if (!queryDataRef.current) {
queryDataRef.current = new QueryData({
options: updatedOptions as QueryOptions,
context,
forceUpdate
});
}
return queryDataRef.current;
}
const queryData = getQueryDataRef();