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.

Basics

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:

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

Reference the S3Object type from some @model type:

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

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:

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 }
14}