index.tsx
1.29 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
42
43
import Component from "./Component";
import * as React from "react";
import { Query, Mutation } from "react-apollo";
import { withRouter, RouteComponentProps } from "react-router";
const FETCH_ALL_MODELS = require("./fetchAllModels.gql");
const REGISTER_DRONE = require("./registerDrone.gql");
class FetchAllModelsQuery extends Query<{
models: Array<any>;
}> {}
class RegisterDroneMutation extends Mutation<{}> {}
const update = (history: any) => (cache, result) => history.push("/my-page");
const QueryComponent: React.SFC<RouteComponentProps<{}>> = ({ history }) => (
<FetchAllModelsQuery query={FETCH_ALL_MODELS}>
{({ loading, error, data }) => {
if (loading) return <p>Loading...</p>;
else if (error) return <p>Error :(</p>;
else
return (
<RegisterDroneMutation
mutation={REGISTER_DRONE}
update={update(history)}
>
{mutate => {
const registerDrone = input => mutate({ variables: { input } });
return (
<Component
models={data!.models}
registerDrone={registerDrone}
/>
);
}}
</RegisterDroneMutation>
);
}}
</FetchAllModelsQuery>
);
export default withRouter(QueryComponent);