#How to override a custom (slotted) pipeline resolver?

17 messages · Page 1 of 1 (latest)

sleek estuary
#

What is the recommended way to override the DataSource for a single resolver function (not the entire pipeline)?

Say, I have the default pipeline resolver for updateComment. I have added a custom resolver Mutation.updateComment.postUpdate.1.req.vtl but I want the DataSource to point to PostTable instead. How would I go about this?

#

@merry grove , I've added it here as suggested 🙂

merry grove
#

Excellent, thank you @sleek estuary !

sleek estuary
#

My current approach to this problem is as follows. I use amplify override api then I locate and update the DataSource name for the targeted pipeline function as shown below:

import { AmplifyApiGraphQlResourceStackTemplate } from '@aws-amplify/cli-extensibility-helper';

export function override(resources: AmplifyApiGraphQlResourceStackTemplate) {
  // ...
  // The declarations for the variables below are ommitted for brevity 
  functionName = `${typeName}${fieldName}${slotName}${adjustedSlotPlacement}Function${typeName}${fieldName}${slotName}${adjustedSlotPlacement}Function.AppSyncFunction`;

  resources.models["Comments"].appsyncFunctions[functionName].dataSourceName = "Post";
}

The problem is that this fails during an initial deployment of the API because PostTable may not have been created by the Post stack. Further, since this doesn't seem to be a known or supported use case it may break in the future.

merry grove
#

Got it, thanks for the added context @sleek estuary . I'm going to reach out to my peers on the API side to see if we can get you a better answer in this thread.

merry grove
#

@sleek estuary, sorry we didn't get back yet on this. Didn't forget about you! In looking at your comments on @azure ruin's thread too... it appears you've tried what is in the following comment/link, but ran into different issues with the table not being created. That sound right?

https://github.com/aws-amplify/amplify-cli/issues/9623#issuecomment-1023528618

GitHub

Which Category is your question related to? api Amplify CLI Version 7.6.8 Provide additional details e.g. code snippets Is this possible to change data source for new resolver that extends Amplify-...

sleek estuary
#

Hi @merry grove . Yes, that's exactly what guided my approach! The problem I ran into was that the table was not available at the time when a new environment is set up.

sleek estuary
#

I say "I think", because I've recreated a new environment about 4 or 5 times to see if the deployment would fail. It didn't. Whereas without the remapping it failed each of the 5 times I tried.

merry grove
#

Oh awesome, so that unblocked you essentially and you get no failed builds anymore after remapping? Or has this only been attempted on specific environments (test/dev) and not necessarily a production env?

sleek estuary
#

I've tested it in temporary Amplify projects so I could start from scratch to see if it would manifest. The bug had existed in a feature branch for weeks/months but didn't manifest because all the tables were already present.

#

I'm in the process of rolling it into prod.

#

I've raised this though because this approach feels like a hack that may break later on.

azure ruin
#

I'm looking at this again, but I'm pretty stuck.

I've added:

import { AmplifyApiGraphQlResourceStackTemplate } from '@aws-amplify/cli-extensibility-helper';

export function override(resources: AmplifyApiGraphQlResourceStackTemplate) {
    resources.models["TaskAssignee"].appsyncFunctions["MutationcreateTaskAssigneepostAuth1FunctionMutationcreateTaskAssigneepostAuth1Function.AppSyncFunction"].dataSourceName = "TaskTable";
}

to my override.ts file, however on push I get error:

Error: Skipping override due to TypeError: Cannot read property 'MutationcreateTaskAssigneepostAuth1FunctionMutationcreateTaskAssigneepostAuth1Function.AppSyncFunction' of undefined

I'm also not sure what I'm supposed to put in the vtl file. I can see there is a way to reject a request with an error, but I don't know how to access the associated Task data to find out if it is archived or not.

My other thread for some more context #1080055263685525596 message

could anyone please help me through this? I've never touched vtl files before and the existing documentation doesn't really cover this use case.

#

I did add the file:

amplify/backend/api/platelet/resolvers/Mutation.createTaskAssignee.postAuth.2.req.vtl and put just a single line to throw an error. it does seem to be working there at least.

sleek estuary
#

Hi @azure ruin , I think I can help you with this. I'll jump over to the other thread as I think it flows better with the history that you have there.