BugQuery.js

 1import CircularProgress from '@material-ui/core/CircularProgress';
 2import gql from 'graphql-tag';
 3import React from 'react';
 4import { Query } from 'react-apollo';
 5
 6import Bug from './Bug';
 7
 8const QUERY = gql`
 9  query GetBug($id: String!) {
10    defaultRepository {
11      bug(prefix: $id) {
12        ...Bug
13      }
14    }
15  }
16
17  ${Bug.fragment}
18`;
19
20const BugQuery = ({ match }) => (
21  <Query query={QUERY} variables={{ id: match.params.id }}>
22    {({ loading, error, data }) => {
23      if (loading) return <CircularProgress />;
24      if (error) return <p>Error: {error}</p>;
25      return <Bug bug={data.defaultRepository.bug} />;
26    }}
27  </Query>
28);
29
30export default BugQuery;