aws-amplify / amplify-js

A declarative JavaScript library for application development using cloud services.
https://docs.amplify.aws/lib/q/platform/js
Apache License 2.0
9.42k stars 2.13k forks source link

How to do server-side input creation, encoding, and validation with Amplify + Appsync? #2879

Closed kwhitejr closed 5 years ago

kwhitejr commented 5 years ago

Which Category is your question related to? API

What AWS Services are you utilizing? Amplify + AppSync

Provide additional details e.g. code snippets What is the best practice for performing server-side input creation and validation? For example, in a Create React App scenario with an AppSync backend, when performing a resource creation I've been using uuid within the component to create the necessary ID for the createResourceXYZ() mutation. This type of value seems like something that ought to happen server side.

I have some notion that the solution is to hook into and enrich the resolver, but my understanding is that the auto-generated resolvers are written in VTL. Is VTL robust enough to do more than just create IDs? What is best practice for (1) generating more complex inputs like urls, (2) input transforms like string encoding, or (3) input validations, e.g. regex checks?

Example schema for an Article

type Article @model {
  id: ID!    // should be generated on the server
  title: String!
  description: String!
  text: String!
  category: CATEGORY!
  slug: String!     // should be generated and validated by server
  url: String!     // includes slug + title; should be generated, encoded, validated by server
  lastModified: String!
  creationDate: String!
}
stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 5 years ago

This issue has been automatically closed because of inactivity. Please open a new issue if are still encountering problems.

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 or Discussions for those types of questions.