index.tsx 763 Bytes
import Component from "./Component";
import * as React from "react";
import { graphql, Query, Mutation } from "react-apollo";
import { withRouter, RouteComponentProps } from "react-router";

const FETCH_ALL_ORGS = require("./fetchAllOrgs.gql");

interface Props {
  orgs: Array<any>;
}

class FetchContractQuery extends Query<Props> {}

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

export default withRouter(QueryComponent);