Skip to content

Commit

Permalink
make sure a mutation preprocessor returns values as new input
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskalmar committed Jan 31, 2021
1 parent 27d72b9 commit b3811bc
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/graphqlProtocol/resolver.ts
Expand Up @@ -405,7 +405,7 @@ export const getMutationResolver: GetMutationResolverParams = ({

try {
if (entityMutation.preProcessor) {
args.input[typeName] = await entityMutation.preProcessor({
const preProcessorResult = await entityMutation.preProcessor({
entity,
id,
source,
Expand All @@ -415,6 +415,14 @@ export const getMutationResolver: GetMutationResolverParams = ({
context,
info,
});

if (!preProcessorResult) {
throw new Error(
`preProcessor '${entityMutation.name}' of entity '${entity.name}' needs to return a new input object`,
);
}

args.input[typeName] = preProcessorResult;
}

if (entityMutation.type === MUTATION_TYPE_CREATE) {
Expand Down

0 comments on commit b3811bc

Please sign in to comment.