Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Commit

Permalink
Merge pull request #106 from apollostack/mutation-options
Browse files Browse the repository at this point in the history
Pass through all mutate options
  • Loading branch information
Sashko Stubailo authored Jul 12, 2016
2 parents 57d280f + 989c01b commit 7b659b1
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/connect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ export default function connect(opts?: ConnectOptions) {
// add props and state as last argument of method
args.push(stateAndProps);

const { mutation, variables } = method.apply(this.client, args);
const mutationOptions = method.apply(this.client, args);
return new Promise((resolve, reject) => {
this.data[key] = assign(this.data[key], {
loading: true,
Expand All @@ -514,7 +514,7 @@ export default function connect(opts?: ConnectOptions) {
resolve();
})
.then(() => {
return mutate({ mutation, variables });
return mutate(mutationOptions);
})
.then(forceRender)
.catch(errors => forceRender({ errors }));
Expand Down
44 changes: 44 additions & 0 deletions test/client/connect/mutations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -739,4 +739,48 @@ describe('mutations', () => {
);
});

it('passes through all mutate options', (done) => {
const mutation = 'mutation M {}';
const variables = {};
const optimisticResponse = {};
const fragments = [];
function mapMutationsToProps({ ownProps }) {
return {
runMutation: () => {
return {
mutation,
variables,
optimisticResponse,
fragments,
};
},
};
};

const client = new ApolloClient();
(client as any).mutate = (options) => {
expect(options.mutation).to.equal(mutation);
expect(options.variables).to.equal(variables);
expect(options.optimisticResponse).to.equal(optimisticResponse);
expect(options.fragments).to.equal(fragments);
done();
};

@connect({ mapMutationsToProps })
class Container extends React.Component<any, any> {
componentDidMount() {
this.props.mutations.runMutation();
}

render() {
return <Passthrough {...this.props} />;
}
};

mount(
<ProviderMock client={client}>
<Container/>
</ProviderMock>
);
});
});

0 comments on commit 7b659b1

Please sign in to comment.