All files / src component-utils.tsx

100% Statements 5/5
100% Branches 2/2
100% Functions 1/1
100% Lines 5/5
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  27x                   27x       375x   375x             375x    
import ApolloClient from 'apollo-client';
const invariant = require('invariant');
 
export interface CommonComponentProps {
  client?: ApolloClient<Object>;
}
 
export interface CommonComponentContext {
  client?: ApolloClient<Object>;
}
 
export function getClient(
  props: CommonComponentProps,
  context: CommonComponentContext,
): ApolloClient<Object> {
  const client = props.client || context.client;
 
  invariant(
    !!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 as ApolloClient<Object>;
}