index.tsx
1.3 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
import Component from "./Component";
import * as React from "react";
import { Query, Mutation } from "react-apollo";
import { withRouter, RouteComponentProps } from "react-router";
const FETCH_CURRENT_USER = require("./fetchCurrentUser.gql");
const CREATE_CONTRACT = require("./createContract.gql");
class FetchCurrentUserQuery extends Query<{
user: any;
orgs: any;
}> {}
class CreateContractMutation extends Mutation<{}> {}
const update = (history: any) => (cache, result) => history.push("/my-page");
const QueryComponent: React.SFC<RouteComponentProps<{}>> = ({ history }) => (
<FetchCurrentUserQuery query={FETCH_CURRENT_USER} fetchPolicy="network-only">
{({ loading, error, data }) => {
if (loading) return <p>Loading...</p>;
else if (error) return <p>Error :(</p>;
else
return (
<CreateContractMutation
mutation={CREATE_CONTRACT}
update={update(history)}
>
{mutate => {
const createContract = input => mutate({ variables: { input } });
return (
<Component user={data!.user} orgs={data!.orgs} createContract={createContract} />
);
}}
</CreateContractMutation>
);
}}
</FetchCurrentUserQuery>
);
export default withRouter(QueryComponent);