GraphQL transform and Storage

The GraphQL Transform, Amplify CLI, and Amplify Library make it simple to add complex object support with Amazon S3 to an application.

Note: Complex objects are not supported by DataStore-enabled GraphQL APIs.


At a minimum the steps to add S3 Object support are as follows:

Create a Amazon S3 bucket to hold files via amplify add storage.

Create a user pool in Amazon Cognito User Pools via amplify add auth.

Create a GraphQL API via amplify add api and add the following type definition:

type S3Object { bucket: String! region: String! key: String! }
1type S3Object {
2 bucket: String!
3 region: String!
4 key: String!

Reference the S3Object type from some @model type:

type Picture @model @auth(rules: [{ allow: owner }]) { id: ID! name: String owner: String # Reference the S3Object type from a field. file: S3Object }
1type Picture @model @auth(rules: [{ allow: owner }]) {
2 id: ID!
3 name: String
4 owner: String
6 # Reference the S3Object type from a field.
7 file: S3Object

The GraphQL Transform handles creating the relevant input types and will store pointers to S3 objects in Amazon DynamoDB. The AppSync SDKs and Amplify library handle uploading the files to S3 transparently.

Run a mutation with S3 objects from your client app:

mutation ($input: CreatePictureInput!) { createPicture(input: $input) { id name visibility owner createdAt file { region bucket key } } }
1mutation ($input: CreatePictureInput!) {
2 createPicture(input: $input) {
3 id
4 name
5 visibility
6 owner
7 createdAt
8 file {
9 region
10 bucket
11 key
12 }
13 }