index.tsx 783 Bytes
import * as React from "react";
import Component from "./Component";
import { graphql, Query, Mutation } from "react-apollo";
import { withRouter, RouteComponentProps } from "react-router";
const FETCH_CURRENT_USER = require("./fetchCurrentUser.gql");

interface Props {
  user: any;
}

class FetchUserPageQuery extends Query<Props> {}

const QueryComponent: React.SFC<RouteComponentProps<{}>> = props => (
  <FetchUserPageQuery 
  query={FETCH_CURRENT_USER} fetchPolicy="network-only">
    {({ loading, error, data }) => {
      if (loading) return <p>Loading...</p>;
      else if (error || !data!.user) return <p>Error :(</p>;
      else return <Component user={data!.user} history={props.history} />;
    }}
  </FetchUserPageQuery>
);

export default withRouter(QueryComponent);