Vulcan/packages/nova-users/lib/containers/withCurrentUser.js
2016-11-29 14:08:24 +01:00

36 lines
No EOL
807 B
JavaScript

import Telescope from 'meteor/nova:lib';
import Users from '../collection.js';
import { graphql } from 'react-apollo';
import gql from 'graphql-tag';
const withCurrentUser = component => {
const preloadedFields = _.compact(_.map(Users.simpleSchema()._schema, (field, fieldName) => {
return field.preload ? fieldName : undefined;
}));
// console.log('preloaded fields', preloadedFields);
return graphql(
gql`query getCurrentUser {
currentUser {
_id
username
createdAt
isAdmin
${preloadedFields.join('\n')}
}
}
`, {
props(props) {
const {data: {loading, currentUser}} = props;
return {
loading,
currentUser,
};
},
}
)(component);
};
export default withCurrentUser;