aws-amplify / amplify-category-api

The AWS Amplify CLI is a toolchain for simplifying serverless web and mobile development. This plugin provides functionality for the API category, allowing for the creation and management of GraphQL and REST based backends for your amplify project.
https://docs.amplify.aws/
Apache License 2.0
89 stars 77 forks source link

Allow Amplify-generated resolvers to be extended for Custom Mutations/Queries #753

Open SteveJamesDev opened 2 years ago

SteveJamesDev commented 2 years ago

Is this feature request related to a new or existing Amplify category?

function, api

Is this related to another service?

No response

Describe the feature you'd like to request

Currently, the VTL templates for custom mutations do not allow the same extension capabilities as the @model based resolvers

https://docs.amplify.aws/cli/graphql/custom-business-logic/#override-amplify-generated-resolvers

For example, consider the following Mutations.graphql:-

type Mutation {
   doThing(input: DoThingINput): Boolean @function(name: "doThing-${env}")
}

If I create a Mutation.doThing.auth.1.req.vtl file and add it to my resolves directory ... it is ignored as part of the final AppSync deployment

My only option is to override the Mutation.doThing.auth.req.vtl

Describe the solution you'd like

I'd like custom Mutation/Query resolvers to be extendable in the same way as other resolvers outlined below

https://docs.amplify.aws/cli/graphql/custom-business-logic/#override-amplify-generated-resolvers

Describe alternatives you've considered

Only option is to Override (not extend)

Additional context

No response

Is this something that you'd be interested in working on?

Would this feature include a breaking change?

josefaidt commented 2 years ago

Hey @SteveJamesDev :wave: thanks for raising this and for providing those details! I was able to successfully reproduce this issue using the following schema:

type Mutation {
  doThing(input: String): Boolean
    @function(name: "doThing-${env}")
    @auth(rules: [{ allow: public }])
}

By including the at-auth directive, the CLI will generate the ...auth.req.vtl resolver. Then when we create Mutation.doThing.auth.1.req.vtl resolver and re-run amplify api gql-compile we see the extended resolver is carried to build/resolvers, however the stack is missing the mapping:

image

Marking as a bug 🙂

uniknife commented 1 year ago

Any update on this? I'm facing similar issues. Custom ...auth.req.vtl resolvers are not included in the stack mapping and hence not being uploaded to the AppSync.