aws-amplify / amplify-cli

The AWS Amplify CLI is a toolchain for simplifying serverless web and mobile development.
Apache License 2.0
2.82k stars 820 forks source link

Amplify CLI provision for converting resolver to pipeline and chaining with other AppSync functions. #5785

Closed ramakrishnan closed 4 years ago

ramakrishnan commented 4 years ago

Is your feature request related to a problem? Please describe. Customising resolver pipelines and chaining with other AppSync functions through cli

Describe the solution you'd like amplify api addFunction amplify api convertToPipeline

Describe alternatives you've considered Currently there are few workaround in updating the customResource.json but the process is too cumbersome and needs heavy maintenance.

Additional context Using direct AWS API to create and manage. But the down side is on every amplify push, amplify wipes off the changes with what is present in customResource json. Currently invoking the AWS API scripts after every amplify push.

akshbhu commented 4 years ago

Hi @ramakrishnan

If I am understanding correctly we have @function directive that should support the use case you describe. The @function directive supports AWS AppSync pipeline resolvers (chaining functions) . Here is the documentation: https://docs.amplify.aws/cli/graphql-transformer/function#chaining-functions.

If this is not the case , Can you elaborate more on your use case?

ramakrishnan commented 4 years ago

@akshbhu Agree @function will internally create the pipeline but it is currently limited to Query, in order to get this working for a Mutation one has to create a custom mutation. please correct me if I am wrong.

To elaborate my use case.

I would like to use the existing CRUD functions created while using @model directive and chain additional custom function.

Example I would like to apply a custom pre-validation on every resolver (For all CRUD operations) in this case I would either create a AppSync function having data source as Lambda or HTTP. I would now like to convert all the existing resolver into pipeline and chain this AppSync function.

Talking about @function it makes me ask of additional use case is it possible to specify the operations where the function has to be applied? Example

// schema.graphql
type User @model @function(name: "customValidation") {
   id: ID!
  username: String!
  password: String! @function(name: "hashPassword", on: ["create"])
}

So that when anyone who looks at schema.graphql will understand about the model and the custom operation happening to password filed during create, without even going through the pipeline chain.

Basically my questions can be summarised into two.

  1. How to include a pipeline function on a model level chaining to its existing CRUD functions
  2. How to restrict function per operation, when added to an attribute
akshbhu commented 4 years ago

Hello @ramakrishnan

I understood your point.Currently Amplify CLI does not currently support pipeline resolvers but this is something we are working on.Follow this RFC for those updates and some possible implementations: aws-amplify/amplify-category-api#430 Closing in favour of aws-amplify/amplify-category-api#430

github-actions[bot] commented 3 years ago

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels for those types of questions.