Skip to content

Commit

Permalink
fix: typeguard
Browse files Browse the repository at this point in the history
  • Loading branch information
macrozone committed Apr 28, 2020
1 parent 167d1fb commit 6fb00a4
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/dataprovider/src/buildVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,12 @@ const getUpdateInputDataTypeForList = (
) as IntrospectionInputObjectType;
};

type ThingWithId = {
id: string;
};
function isObjectWithId(data: any): data is ThingWithId {
return Boolean(data?.id);
}
const buildNewInputValue = (
fieldData: any,
previousFieldData: any,
Expand Down Expand Up @@ -241,7 +247,7 @@ const buildNewInputValue = (

const variables = fieldData.reduce<UpdateManyInput>(
(inputs, referencedField) => {
if (isObject(referencedField)) {
if (isObjectWithId(referencedField)) {
if (!updateListInputType) {
throw new Error(
`Input data for "${fieldName}" is of type "Object" but graphql endpoints does not expose the "update" mutation for "${fullFieldObjectType.name}"`,
Expand Down Expand Up @@ -333,7 +339,7 @@ const buildNewInputValue = (
disconnect: true,
};
}
if (isObject(fieldData)) {
if (isObjectWithId(fieldData)) {
// TODO: we assume ".id" to be the id
if (!fieldData.id) {
const createObjectModifierType = getFinalType(
Expand Down

0 comments on commit 6fb00a4

Please sign in to comment.