11/* @flow */
22/* eslint-disable no-param-reassign */
33
4- import {
5- GraphQLObjectType ,
6- getNamedType ,
7- GraphQLInputObjectType ,
8- GraphQLNonNull ,
9- } from 'graphql' ;
4+ import { GraphQLObjectType , getNamedType , GraphQLInputObjectType , GraphQLNonNull } from 'graphql' ;
105import { TypeComposer , InputTypeComposer } from 'graphql-compose' ;
116import { toGlobalId } from './globalId' ;
12- import type {
13- Resolver ,
14- WrapMutationResolverOpts ,
15- } from './definition' ;
7+ import type { Resolver , WrapMutationResolverOpts } from './definition' ;
168
179function upperFirst ( str ) {
1810 return str . charAt ( 0 ) . toUpperCase ( ) + str . slice ( 1 ) ;
1911}
2012
21- export default function wrapMutationResolver (
22- resolver : Resolver ,
23- opts : WrapMutationResolverOpts = { }
24- ) : Resolver {
13+ export default function wrapMutationResolver < TSource , TContext > (
14+ resolver : Resolver < TSource , TContext > ,
15+ opts : WrapMutationResolverOpts ,
16+ ) : Resolver < TSource , TContext > {
2517 const { resolverName, rootTypeName } = opts ;
2618
2719 function prepareArgs ( newResolver ) {
@@ -44,15 +36,17 @@ export default function wrapMutationResolver(
4436 type : new GraphQLNonNull ( ITC . getType ( ) ) ,
4537 } ,
4638 } ) ;
39+ // $FlowFixMe
4740 newResolver . _relayIsArgsWrapped = true ;
4841 }
4942
5043 // add `clientMutationId` to args.input field
5144 if ( ITC && ! ITC . hasField ( 'clientMutationId' ) ) {
5245 ITC . setField ( 'clientMutationId' , {
5346 type : 'String' ,
54- description : 'The client mutation ID used by clients like Relay to track the mutation. '
55- + 'If given, returned in the response payload of the mutation.' ,
47+ description :
48+ 'The client mutation ID used by clients like Relay to track the mutation. ' +
49+ 'If given, returned in the response payload of the mutation.' ,
5650 } ) ;
5751 }
5852 }
@@ -69,21 +63,16 @@ export default function wrapMutationResolver(
6963 }
7064
7165 if ( newResolver . _relayIsArgsWrapped ) {
72- // $FlowFixMe
7366 resolveParams . args = resolveParams . args . input ;
7467 }
7568
76- return prevResolver . resolve ( resolveParams )
77- . then ( res => {
78- res . nodeId = toGlobalId (
79- rootTypeName ,
80- res . recordId
81- ) ;
82- if ( clientMutationId ) {
83- res . clientMutationId = clientMutationId ;
84- }
85- return res ;
86- } ) ;
69+ return prevResolver . resolve ( resolveParams ) . then ( ( res ) => {
70+ res . nodeId = toGlobalId ( rootTypeName , res . recordId ) ;
71+ if ( clientMutationId ) {
72+ res . clientMutationId = clientMutationId ;
73+ }
74+ return res ;
75+ } ) ;
8776 } ) ;
8877 }
8978
@@ -105,17 +94,22 @@ export default function wrapMutationResolver(
10594 if ( ! outputTC . hasField ( 'clientMutationId' ) ) {
10695 outputTC . setField ( 'clientMutationId' , {
10796 type : 'String' ,
108- description : 'The client mutation ID used by clients like Relay to track the mutation. '
109- + 'If given, returned in the response payload of the mutation.' ,
97+ description :
98+ 'The client mutation ID used by clients like Relay to track the mutation. ' +
99+ 'If given, returned in the response payload of the mutation.' ,
110100 } ) ;
111101 }
112102
113103 newResolver . setType ( outputTC . getType ( ) ) ;
114104 }
115105
116- return resolver . wrap ( ( newResolver , prevResolver ) => {
117- prepareArgs ( newResolver ) ;
118- prepareResolve ( newResolver , prevResolver ) ;
119- prepareType ( newResolver , prevResolver ) ;
120- } , { name : 'RelayMutation' } ) ;
106+ return resolver . wrap (
107+ ( newResolver , prevResolver ) => {
108+ prepareArgs ( newResolver ) ;
109+ prepareResolve ( newResolver , prevResolver ) ;
110+ prepareType ( newResolver , prevResolver ) ;
111+ return newResolver ;
112+ } ,
113+ { name : 'RelayMutation' } ,
114+ ) ;
121115}
0 commit comments