What is the Amplify backend best practice for adding calculated fields to GraphQL?

0

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!

James
질문됨 2년 전474회 조회
1개 답변
1
수락된 답변

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.

AWS
지원 엔지니어
답변함 2년 전
  • 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.

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠