Skip to content

Commit

Permalink
fix: Issue with array of enum
Browse files Browse the repository at this point in the history
  • Loading branch information
izziaraffaele committed Aug 25, 2020
1 parent c5b01de commit 63abd00
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions packages/dataprovider/src/buildVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,26 @@ const buildNewInputValue = (
(t) => t.name === fieldObjectType.name,
) as IntrospectionInputObjectType;

const isRelationship = fullFieldObjectType?.inputFields.every((i) => {
return Object.keys(ModifiersParams).includes(i.name);
});

const setModifier = fullFieldObjectType?.inputFields.find(
(i) => i.name === ModifiersParams.set,
);

const connectModifier = fullFieldObjectType?.inputFields.find(
(i) => i.name === ModifiersParams.connect,
);

const disconnectModifier = fullFieldObjectType?.inputFields.find(
(i) => i.name === ModifiersParams.disconnect,
);

if (setModifier && !connectModifier && !disconnectModifier) {
return { set: fieldData };
}

const isRelationship = fullFieldObjectType?.inputFields.every((i) => {
return Object.keys(ModifiersParams).includes(i.name);
});

// is it a relation?
if (isRelationship) {
// if it has a set modifier, it is an update array
Expand All @@ -214,15 +226,11 @@ const buildNewInputValue = (
(i) => i.name === ModifiersParams.update,
);

const connectModifier = fullFieldObjectType?.inputFields.find(
(i) => i.name === ModifiersParams.connect,
);

const disconnectModifier = fullFieldObjectType?.inputFields.find(
(i) => i.name === ModifiersParams.disconnect,
);
const isList = fullFieldObjectType?.inputFields.some((i) => {
return i.type.kind === "LIST";
});

if (createModifier?.type.kind === "LIST") {
if (isList) {
if (Array.isArray(fieldData)) {
const createListInputType = getCreateInputDataTypeForList(
createModifier,
Expand Down Expand Up @@ -395,8 +403,6 @@ const buildNewInputValue = (
return { connect: { id: fieldData } };
}
}
} else if (setModifier) {
return { set: fieldData };
}
return;
}
Expand Down

0 comments on commit 63abd00

Please sign in to comment.