From 882959b5e8737d615664763330c70da3564d218c Mon Sep 17 00:00:00 2001 From: Barrie Treloar Date: Thu, 6 Jul 2017 04:22:53 +0930 Subject: [PATCH] Refactor dataForChild on DocumentType.Mutation to use new bound function. (#772) dataForChild previously returned a new function for type DocumentType.Mutation causing React shallowEqual render optimizations to fail. Refactored the mutation specific code into its own method with a binding to 'this' in the constructor. --- src/graphql.tsx | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/graphql.tsx b/src/graphql.tsx index cc6c1997e0..ca5f958794 100644 --- a/src/graphql.tsx +++ b/src/graphql.tsx @@ -213,6 +213,7 @@ export default function graphql { - 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);