How to use the @apollo/react-common.getApolloContext function in @apollo/react-common

To help you get started, we’ve selected a few @apollo/react-common examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github apollographql / react-apollo / packages / ssr / src / getDataFromTree.ts View on Github external
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;
  }
github apollographql / react-apollo / packages / components / lib / react-components.cjs.js View on Github external
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;
github apollographql / react-apollo / packages / components / lib / react-components.cjs.js View on Github external
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) {
github apollographql / react-apollo / packages / components / lib / react-components.esm.js View on Github external
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) {
github apollographql / react-apollo / packages / components / lib / react-components.esm.js View on Github external
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);
github apollographql / react-apollo / packages / components / lib / react-components.cjs.js View on Github external
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);
github apollographql / react-apollo / packages / components / lib / react-components.cjs.js View on Github external
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;
}
github apollographql / react-apollo / packages / hooks / src / useQuery.ts View on Github external
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();