aws / aws/aws-appsync-community

Skip resolver pipeline function or exit resolver pipeline early

Open
#261 12 comments 17 reactions 0 assignees View on GitHub
feature-request
Dominant language
HTML
Stars
507
Forks
37
PR merge metrics
No merged PRs in 30d

Description

Greetings!

I Have been experimenting with the Javascript resolver functions and pipelines, and I was wondering if there was a way to:
- Conditionally passthrough a function in a pipeline, i.e. check if I need to make a request, if not, then pass the previous response to the next function.
- Conditionally exit the pipeline early with a response

As an example, the first resolver function in the pipeline queries a DynamoDB.
I then have the following resolver function that creates a new entry if nothing was found by the previous function.

``` Javascript
function request(ctx) {
if (ctx.prev.result) {
return; // Exit the function or pipeline here
}

const id = util.autoId();

return {
version: '2018-05-29',
operation: 'PutItem',
key: util.dynamodb.toMapValues({ id }),
attributeValues: util.dynamodb.toMapValues(ctx.args)
};
}

function response(ctx) {
const { error, result } = ctx;
if (error) {
return util.appendError(error.message, error.type, result);
}

// Check if there was a result, otherwise pass on the previous result (not sure if this would be needed)
if (result) {
return result;
} else {
return ctx.prev.result;
}
}
```

Is it possible in this sort of a situation to "pass through" this resolver, or even return early from the pipeline?

I have seen that in VTL there is the concept of `#return` which looks like what I need but I can't find an equivalent for JS (I could also be misunderstanding `#return` as I am not that familiar with VTL).

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the JavaScript resolver functions and pipeline behavior described in the example, including the DynamoDB request and response functions. Compare the requested conditional pass-through and early exit with the VTL #return concept; done means establishing and documenting whether an equivalent behavior is supported.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, graphql, javascript
Domain
api, backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.