import ApolloClient, { ApolloQueryResult, QueryOptions } from 'apollo-client'; import { DocumentNode } from 'graphql'; import hoistNonReactStatics from 'hoist-non-react-statics'; import * as PropTypes from 'prop-types'; import * as React from "react"; import { getClient } from "react-apollo/component-utils"; export function withLazyQuery) => Promise>; } | {} = {}>( document: DocumentNode, operationOptions: { name?: string; options?: QueryOptions } = {} = {}, ) { return ( WrappedComponent: React.ComponentType, ): React.ComponentType => { class GraphQL extends React.Component { static WrappedComponent = WrappedComponent; static contextTypes = { client: PropTypes.object, }; private client: ApolloClient; constructor(props, context) { super(props, context); this.client = getClient(props, context); } fetch = (options?: QueryOptions): Promise> => { const queryOptions = operationOptions.options || {}; return (this.client as ApolloClient).query({ query: document, ...queryOptions, ...options, }); } render() { const { name = 'fetch' } = operationOptions; return ( ); } } // Make sure we preserve any custom statics on the original component. return hoistNonReactStatics(GraphQL, WrappedComponent, {}); }; }