What is the Amplify backend best practice for adding calculated fields to GraphQL?
I am using Amplify's GraphQL backend, which works perfectly for generating standard CRUD operations.
However, what if I want to add a calculated field to the model?
For instance, I want to make a query that fetches a set of prices, and some of those prices are in my DynamoDB table, while others will come from an API call to a third party.
I can see two options from the Amplify docs:
- Modify the existing query resolver lambda pipeline, which entails writing a bunch of VTL boilerplate - exactly the kind of work I think Amplify is designed to automate
- Make the query with the @function directive, but then we don't get all the nice benefits of Amplify's generated pipeline, including auth and so on
Neither of these is ideal, or makes for a great developer experience. Let me know if you have a better way!
Hello,
Thank you for reaching out to us
'@function' directive can be used in combination with field level authorization to get auth, the other components you would build yourself.
Is there a specific feature request you have in mind?
Apart from customizing resolvers we don't currently have a way to make something like this work.
Relevant questions
Visualizing amplify graphql definition
asked 3 months agoAWS Amplify and AWS Cognito: Website subscription verification
asked 6 months agoHow to achieve multiple Graphql endpoints
asked 4 months agoHow to efficiently retrieve tokens from Cognito while using amplify with react-native ?
asked 4 months agoWhat is the Amplify backend best practice for adding calculated fields to GraphQL?
Accepted Answerasked 2 months agoHow delete application when backend is empty ?
Accepted Answerasked 2 months agoHow client to do Graphql subcription with a provided token?
asked 2 months agoAllow AWS Amplify access a restricted site for npm builds
asked 2 months agoAmplify - Not able to delete app
Accepted Answerasked 5 months agoCan we use both GraphQL and REST API in the same project?
asked a year ago
Thanks!
I think we didn't realize that we could use field level authorization with @function.
We will try this for our use case and come back if we have any other questions.