Skip to content

Commit 02ec784

Browse files
author
John Rix
committed
Fixed problem with $isPersisted not being set on array elements when using ConnectionMode.PLAIN
1 parent c2d1832 commit 02ec784

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

src/graphql/transformer.ts

100644100755
Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
singularize
1111
} from "../support/utils";
1212
import { ConnectionMode } from "../adapters/adapter";
13+
import { GraphQLType, GraphQLField } from "../support/interfaces";
1314

1415
/**
1516
* This class provides methods to transform incoming data from GraphQL in to a format Vuex-ORM understands and
@@ -32,13 +33,15 @@ export default class Transformer {
3233
model: Model,
3334
data: Data,
3435
read: boolean,
36+
inputType?: GraphQLType,
3537
whitelist?: Array<String>,
3638
outgoingRecords?: Map<string, Array<string>>,
3739
recursiveCall?: boolean
3840
): Data {
3941
const context = Context.getInstance();
4042
const relations: Map<string, Relation> = model.getRelations();
4143
const returnValue: Data = {} as Data;
44+
const inputFields = inputType ? inputType.inputFields : undefined;
4245
if (outgoingRecords === undefined) outgoingRecords = new Map<string, Array<string>>();
4346
if (recursiveCall === undefined) recursiveCall = false;
4447

@@ -64,7 +67,8 @@ export default class Transformer {
6467
key,
6568
value,
6669
model,
67-
whitelist
70+
whitelist,
71+
inputFields
6872
)
6973
) {
7074
let relatedModel = Model.getRelatedModel(relations.get(key)!);
@@ -81,6 +85,7 @@ export default class Transformer {
8185
v,
8286
read,
8387
undefined,
88+
undefined,
8489
outgoingRecords,
8590
true
8691
);
@@ -102,6 +107,7 @@ export default class Transformer {
102107
value,
103108
read,
104109
undefined,
110+
undefined,
105111
outgoingRecords,
106112
true
107113
);
@@ -176,6 +182,12 @@ export default class Transformer {
176182
result[key] = parseFloat(data[key]);
177183
} else if (key.endsWith("Type") && model.isTypeFieldOfPolymorphicRelation(key)) {
178184
result[key] = pluralize(downcaseFirstLetter(data[key]));
185+
} else if (Array.isArray(data[key])) {
186+
const relation: Relation | undefined = model.getRelations().get(key);
187+
if (relation) {
188+
const related: Model | null = Model.getRelatedModel(relation)!;
189+
result[key] = this.transformIncomingData(data[key], related, mutation, true);
190+
}
179191
} else {
180192
result[key] = data[key];
181193
}
@@ -201,14 +213,16 @@ export default class Transformer {
201213
* @param {any} value Value of the field.
202214
* @param {Model} model Model class which contains the field.
203215
* @param {Array<String>|undefined} whitelist Contains a list of fields which should always be included.
216+
* @param {Array<GraphQLField>|undefined} schemaFields Contains a list of schema fields which are defined in the model input type for the mutation.
204217
* @returns {boolean}
205218
*/
206219
public static shouldIncludeOutgoingField(
207220
forFilter: boolean,
208221
fieldName: string,
209222
value: any,
210223
model: Model,
211-
whitelist?: Array<String>
224+
whitelist?: Array<String>,
225+
schemaFields?: Array<GraphQLField>
212226
): boolean {
213227
// Always add fields on the whitelist.
214228
if (whitelist && whitelist.includes(fieldName)) return true;
@@ -219,6 +233,9 @@ export default class Transformer {
219233
// Ignore empty fields
220234
if (value === null || value === undefined) return false;
221235

236+
// Is the field in the mutation type field list, if provided?
237+
if (schemaFields && !schemaFields.find(f => f.name === fieldName)) return false;
238+
222239
// Include all eager save connections
223240
if (model.getRelations().has(fieldName)) {
224241
// We never add relations to filters.

0 commit comments

Comments
 (0)