2016-11-22 16:15:00 +09:00
|
|
|
import Telescope from 'meteor/nova:lib';
|
|
|
|
import React, { PropTypes, Component } from 'react';
|
|
|
|
import { graphql } from 'react-apollo';
|
|
|
|
import gql from 'graphql-tag';
|
|
|
|
|
|
|
|
export default function withSingle (options) {
|
|
|
|
|
|
|
|
const { queryName, collection } = options,
|
|
|
|
singleResolverName = collection.options.resolvers.single.name,
|
2016-11-23 11:07:48 +09:00
|
|
|
fragment = options.fragment,
|
|
|
|
fragmentName = options.fragmentName;
|
2016-11-22 16:15:00 +09:00
|
|
|
|
|
|
|
return graphql(gql`
|
|
|
|
query ${queryName}($documentId: String) {
|
|
|
|
${singleResolverName}(_id: $documentId) {
|
|
|
|
...${fragmentName}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
${fragment}
|
|
|
|
`, {
|
|
|
|
options(ownProps) {
|
|
|
|
return {
|
|
|
|
variables: { documentId: ownProps.documentId },
|
|
|
|
pollInterval: 20000,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
props: returnedProps => {
|
|
|
|
const { ownProps, data } = returnedProps;
|
|
|
|
return {
|
|
|
|
loading: data.loading,
|
2016-11-23 11:07:48 +09:00
|
|
|
document: data[singleResolverName],
|
|
|
|
fragmentName,
|
|
|
|
fragment,
|
2016-11-22 16:15:00 +09:00
|
|
|
};
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|