@@ -7,6 +7,7 @@ import RootState from "@vuex-orm/core/lib/modules/contracts/RootState";
77import Transformer from "../graphql/transformer" ;
88import Schema from "../graphql/schema" ;
99import { singularize } from "../support/utils" ;
10+ import { GraphQLType } from "../support/interfaces" ;
1011
1112/**
1213 * Base class for all Vuex actions. Contains some utility and convenience methods.
@@ -46,19 +47,19 @@ export default class Action {
4647 newData . id = parseInt ( newData . id , 10 ) ;
4748
4849 const insertedData : Data = await Store . insertData (
49- { [ model . pluralName ] : newData } as Data ,
50+ { [ model . singularName ] : newData } as Data ,
5051 dispatch
5152 ) ;
5253
5354 // Try to find the record to return
54- const records = insertedData [ model . pluralName ] ;
55+ const records = insertedData [ model . singularName ] ;
5556 const newRecord = records [ records . length - 1 ] ;
5657 if ( newRecord ) {
5758 return newRecord ;
5859 } else {
5960 Context . getInstance ( ) . logger . log (
6061 "Couldn't find the record of type '" ,
61- model . pluralName ,
62+ model . singularName ,
6263 "' within" ,
6364 insertedData ,
6465 ". Falling back to find()"
@@ -104,7 +105,12 @@ export default class Action {
104105 * @returns {Arguments }
105106 */
106107 static addRecordToArgs ( args : Arguments , model : Model , data : Data ) : Arguments {
107- args [ model . singularName ] = Transformer . transformOutgoingData ( model , data , false ) ;
108+ args [ model . singularName ] = Transformer . transformOutgoingData (
109+ model ,
110+ data ,
111+ false ,
112+ this . getInputType ( model )
113+ ) ;
108114 return args ;
109115 }
110116
@@ -121,7 +127,12 @@ export default class Action {
121127
122128 if ( value instanceof context . components . Model ) {
123129 const model = context . getModel ( singularize ( value . $self ( ) . entity ) ) ;
124- const transformedValue = Transformer . transformOutgoingData ( model , value , false ) ;
130+ const transformedValue = Transformer . transformOutgoingData (
131+ model ,
132+ value ,
133+ false ,
134+ this . getInputType ( model )
135+ ) ;
125136 context . logger . log (
126137 "A" ,
127138 key ,
@@ -136,4 +147,15 @@ export default class Action {
136147
137148 return args ;
138149 }
150+
151+ /**
152+ * Gets the mutation input type for the given model
153+ * @param {Model } model
154+ * @returns {GraphQLType | null }
155+ */
156+ protected static getInputType ( model : Model ) : GraphQLType | null {
157+ const context : Context = Context . getInstance ( ) ;
158+ const inputTypeName : string = context . adapter . getInputTypeName ( model ) ;
159+ return context . schema ! . getType ( inputTypeName ) ;
160+ }
139161}
0 commit comments