Skip to content
This repository was archived by the owner on Apr 11, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion config/generators/container/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ module.exports = {
default: true,
message: 'Do you want actions/constants/reducer for this container?',
},
{
type: 'confirm',
name: 'wantGraphQL',
default: false,
message: 'Do you want a colocated GraphQL / Apollo query and mutation for this container?',
},
],
actions: (data) => {
const actions = [{
Expand Down Expand Up @@ -76,7 +82,7 @@ module.exports = {
templateFile: './container/actions.test.js.hbs',
abortOnFail: true,
});

actions.push({
type: 'modify',
path: '../../app/src/store.js',
Expand Down
46 changes: 42 additions & 4 deletions config/generators/container/index.js.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ import * as {{ properCase name }}ActionCreators from './actions';
import cssModules from 'react-css-modules';
import styles from './index.module.scss';
{{/if}}
{{#if wantGraphQL}}
import { graphql } from 'react-apollo';
import gql from 'graphql-tag';
{{/if}}

class {{ properCase name }} extends Component { // eslint-disable-line react/prefer-stateless-function
class {{ properCase name }}Container extends Component { // eslint-disable-line react/prefer-stateless-function
render() {
return (
{{#if wantSCSSModules}}
Expand All @@ -36,18 +40,52 @@ const mapDispatchToProps = (dispatch) => ({
),
});
{{/if}}

{{#if wantSCSSModules}}
const Container = cssModules({{ properCase name }}, styles);

const Container = cssModules({{ properCase name }}Container, styles);
{{else}}
const Container = {{ properCase name }};

const Container = {{ properCase name }}Container;
{{/if}}

{{#if wantGraphQL}}
const {{ camelCase name }}Query = gql`
query {{ camelCase name }} {
id
}
`;

const ContainerWithData = graphql({{ camelCase name }}Query, {
props: ({ data: { loading, error, {{ camelCase name }} } }) => ({
{{ camelCase name }},
loading,
error,
}),
})(Container);

const {{ camelCase name }}Mutation = gql`
mutation {{ camelCase name }} {
id
}
`;

const ContainerWithMutation = graphql({{ camelCase name }}Mutation)(ContainerWithData);
{{/if}}
{{#if wantActionsAndReducer}}
{{#if wantGraphQL}}

export default connect(
mapStateToProps,
mapDispatchToProps
)(ContainerWithMutation);
{{else}}

export default connect(
mapStateToProps,
mapDispatchToProps
)(Container);
{{/if}}
{{else}}

export default Container;
{{/if}}