Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 | 2x | import * as React from 'react';
import gql from 'graphql-tag';
import {Query} from 'react-apollo';
export default function withQuery(Com) {
return class ComWithQuery extends React.Component {
render() {
const {graphql, variables, getValue, ...restProps} = this.props;
return (
<Query query={gql`${graphql}`} variables={variables}>
{({loading, error, data, ...graphqlProps}) => {
if (loading) return null;
if (error) return `Error!: ${error}`;
const key = Object.keys(data)[0];
let value = data[key];
if (Array.isArray(value)) {
// delete symbol in every item to let vega works
value = value.map(v => ({...v}));
}
if (getValue) {
value = getValue(value);
}
return (
<Com value={value} {...restProps} {...graphqlProps} />
);
}}
</Query>
);
}
}
} |