11/* @flow */
22/* eslint-disable no-param-reassign */
33
4- import { ResolverMiddleware , TypeComposer , InputTypeComposer } from 'graphql-compose' ;
54import {
65 GraphQLID ,
76 GraphQLString ,
@@ -10,6 +9,7 @@ import {
109 GraphQLInputObjectType ,
1110 GraphQLNonNull ,
1211} from 'graphql' ;
12+ import { ResolverMiddleware , TypeComposer , InputTypeComposer } from 'graphql-compose' ;
1313import { toGlobalId } from './globalId' ;
1414import type {
1515 Resolver ,
@@ -19,10 +19,14 @@ import type {
1919 ResolverMWResolve ,
2020 ResolverMWOutputTypeFn ,
2121 ResolverMWOutputType ,
22+ ObjectMap ,
2223} from './definition' ;
2324
25+
2426export default class MutationMiddleware extends ResolverMiddleware {
25- constructor ( typeComposer : TypeComposer , typeResolver : Resolver , opts : mixed = { } ) {
27+ isArgsWrapped : boolean ;
28+
29+ constructor ( typeComposer : TypeComposer , typeResolver : Resolver , opts : ObjectMap = { } ) {
2630 super ( typeComposer , typeResolver , opts ) ;
2731
2832 this . isArgsWrapped = false ;
@@ -35,7 +39,10 @@ export default class MutationMiddleware extends ResolverMiddleware {
3539
3640 if ( nextArgs . input && nextArgs . input . type ) {
3741 // pass args unchanged
38- inputTC = new InputTypeComposer ( getNamedType ( nextArgs . input . type ) ) ;
42+ const inputNamedType = getNamedType ( nextArgs . input . type ) ;
43+ if ( inputNamedType instanceof GraphQLInputObjectType ) {
44+ inputTC = new InputTypeComposer ( inputNamedType ) ;
45+ }
3946 newNextArgs = nextArgs ;
4047 } else {
4148 // create input arg, and put into all current args
@@ -53,7 +60,7 @@ export default class MutationMiddleware extends ResolverMiddleware {
5360 }
5461
5562 // add `clientMutationId` to args.input field
56- if ( ! inputTC . hasField ( 'clientMutationId' ) ) {
63+ if ( inputTC && ! inputTC . hasField ( 'clientMutationId' ) ) {
5764 inputTC . addField ( 'clientMutationId' , {
5865 type : GraphQLString ,
5966 description : 'The client mutation ID used by clients like Relay to track the mutation. '
0 commit comments