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

Pass through all mutate options #106

Merged
merged 1 commit into from
Jul 12, 2016
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
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>
);
});
});