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

Refactor dataForChild on DocumentType.Mutation to use new bound funct… #772

Merged
merged 3 commits into from
Jul 5, 2017
Merged
Changes from 1 commit
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
19 changes: 11 additions & 8 deletions src/graphql.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ export default function graphql<TResult = {}, TProps = {}, TChildProps = Default

this.store = this.client.store;
this.type = operation.type;
this.dataForChildViaMutation = this.dataForChildViaMutation.bind(this);
}

componentWillMount() {
Expand Down Expand Up @@ -479,16 +480,18 @@ export default function graphql<TResult = {}, TProps = {}, TChildProps = Default
return (this.refs as any).wrappedInstance;
}

dataForChild() {
if (this.type === DocumentType.Mutation) {
return (mutationOpts: MutationOpts) => {
const opts = this.calculateOptions(this.props, mutationOpts);
dataForChildViaMutation(mutationOpts: MutationOpts) {
const opts = this.calculateOptions(this.props, mutationOpts);

if (typeof opts.variables === 'undefined') delete opts.variables;

if (typeof opts.variables === 'undefined') delete opts.variables;
(opts as any).mutation = document;
return this.client.mutate((opts as any));
}

(opts as any).mutation = document;
return this.client.mutate((opts as any));
};
dataForChild() {
if (this.type === DocumentType.Mutation) {
return this.dataForChildViaMutation;
}

const opts = this.calculateOptions(this.props);
Expand Down