Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to run a function before all generated resolvers ? #2714

Closed
moshir opened this issue Nov 11, 2019 · 3 comments
Closed

how to run a function before all generated resolvers ? #2714

moshir opened this issue Nov 11, 2019 · 3 comments
Labels
graphql-transformer-v1 Issue related to GraphQL Transformer v1 pending-response Issue is pending response from the issue author question General question

Comments

@moshir
Copy link

moshir commented Nov 11, 2019

Which Category is your question related to?
@function directive

Amplify CLI Version
3.17.0

What AWS Services are you utilizing?
lambda, dynamodb

Provide additional details e.g. code snippets

As an example, i have a custom lambda function which performs custom authorization checks before an action. (@auth directive does not match my requirements, where users can belong to hundreds of groups). The function acts as a gate keeper, throwing an Unautorized exception when the user is not allowed to perform the action on a resource, otherwise forwarding the initial request.

I'd like to run this "gatekeeper" function before the generated vtl runs.
As per the documentation, the @function directive overrides the vtl.
Is it possible to implement some sort of pipeline resolver mixing lambda and vtl.

Another example might be to use a custom lambda function to filter items out from a vtl.

I was thinking about a custom directives like

enum Action{
  CREATE 
 UPDATE 
 DELETE
 ALL
}
directive @before(actions:[Action], function:String!) on OBJECT

That would be used as follow:

type MyType 
@model
@before(actions:[ALL], function : "check"){
   id : ID! 
  name : String!
  description : String
}

When query/mutation is run, the check function is called with all initial arguments, the function performs whatever logic it needs to do and can also update the arguments, including $context.stash and the execution resumes to the generated VTL.

@yuth yuth added enhancement graphql-transformer-v1 Issue related to GraphQL Transformer v1 labels Nov 12, 2019
@yuth
Copy link
Contributor

yuth commented Nov 12, 2019

Amplify CLI out of the box won't have support for this but a custom directive can be written as you mentioned. We recently added support for custom transformer plugin. We have docs for transformer plugin and docs for how to use these custom plugins in PR aws-amplify/docs#992.

We also have an RFC for supporting pipeline resolvers in a generic way. Feel free to comment there to so the issue includes your use case mentioned here.

The other alternative is to chain @function directive as documented under Chaining functions section.

@yuth yuth added question General question pending-response Issue is pending response from the issue author and removed enhancement labels Nov 12, 2019
@deagudelo
Copy link

Did you solve this issue? Is that directive available somewhere? What about an @after following similar logic?

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
graphql-transformer-v1 Issue related to GraphQL Transformer v1 pending-response Issue is pending response from the issue author question General question
Projects
None yet
Development

No branches or pull requests

4 participants