All files / src ApolloConsumer.tsx

100% Statements 8/8
100% Branches 0/0
100% Functions 1/1
100% Lines 8/8
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29  27x     27x           27x 6x         5x     27x       27x       27x  
import * as React from 'react';
import * as PropTypes from 'prop-types';
import ApolloClient from 'apollo-client';
 
const invariant = require('invariant');
 
export interface ApolloConsumerProps {
  children: (client: ApolloClient<any>) => React.ReactElement<any> | null;
}
 
const ApolloConsumer: React.StatelessComponent<ApolloConsumerProps> = (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,
};
 
export default ApolloConsumer;