From e4cbcb3bb1689cb54c18a29e00e8328784e80fb1 Mon Sep 17 00:00:00 2001 From: Christiaan Scheermeijer Date: Fri, 12 Mar 2021 09:28:57 +0100 Subject: [PATCH] fix(project): fix error when updating or creating a node without created and modified properties --- src/transformers/createdUpdatedFieldTransformer.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/transformers/createdUpdatedFieldTransformer.js b/src/transformers/createdUpdatedFieldTransformer.js index 4159875..fc0a96f 100644 --- a/src/transformers/createdUpdatedFieldTransformer.js +++ b/src/transformers/createdUpdatedFieldTransformer.js @@ -18,6 +18,15 @@ export const createdUpdatedFieldTransformer = new TransformRootFields((operation const next = field.resolve field.resolve = (object, params, context, info) => { + const returnTypeFields = info.returnType.getFields() + const hasModifiedField = !!returnTypeFields['modified'] + const hasCreatedField = !!returnTypeFields['created'] + + // returnType is missing either the created or modified fields + if (!hasModifiedField || !hasCreatedField) { + return next(object, params, context, info) + } + info.fieldNodes = info.fieldNodes.map(fieldNode => { const createdIndex = fieldNode.arguments.findIndex(argument => argument.name.value === 'created') const modifiedIndex = fieldNode.arguments.findIndex(argument => argument.name.value === 'modified')