mirror of
https://github.com/vale981/Vulcan
synced 2025-03-10 04:26:41 -04:00
36 lines
No EOL
1,009 B
JavaScript
36 lines
No EOL
1,009 B
JavaScript
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, fragment } = options,
|
|
fragmentName = fragment.definitions[0].name.value,
|
|
singleResolverName = collection.options.resolvers.single.name;
|
|
|
|
return graphql(gql`
|
|
query ${queryName}($documentId: String, $slug: String) {
|
|
${singleResolverName}(documentId: $documentId, slug: $slug) {
|
|
...${fragmentName}
|
|
}
|
|
}
|
|
${fragment}
|
|
`, {
|
|
options(ownProps) {
|
|
return {
|
|
variables: { documentId: ownProps.documentId, slug: ownProps.slug },
|
|
pollInterval: 20000,
|
|
};
|
|
},
|
|
props: returnedProps => {
|
|
const { ownProps, data } = returnedProps;
|
|
return {
|
|
loading: data.loading,
|
|
document: data[singleResolverName],
|
|
fragmentName,
|
|
fragment,
|
|
};
|
|
},
|
|
});
|
|
} |