Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Querying Assets

Sam Patzer edited this page Oct 5, 2020 · 1 revision

To integrate Amplify Video managed resources into your application, use the Amplify API javascript library and import the queries generated by Amplify.

import Amplify, { API, graphqlOperation } from 'aws-amplify';
import * as queries from '../../graphql/queries';

Use the listVodAssets query to retrieve all assets in the CMS.

const assets = await API.graphql(graphqlOperation(queries.listVodAssets));

You can also use GraphQL subscriptions to monitor for any newly created assets.

API.graphql(
  graphqlOperation(onCreateVodAsset),
).subscribe({
  next: (((data) => {
    const { items } = this.state;
    items.push(data.value.data.onCreateVodAsset);
    this.setState({
      items,
    });
  })),
});

If you're using content protection, you may want to omit calling the token field within the CMS, as it will incur extra costs calling the lambda resolver for tokens each time you call ListVodAssets. You can edit the queries within /src/graphql/queries.js

export const listVodAssets = /* GraphQL */ 
  query ListVodAssets(
    $filter: ModelvodAssetFilterInput
    $limit: Int
    $nextToken: String
  ) {
    listVodAssets(filter: $filter, limit: $limit, nextToken: $nextToken) {
      items {
          ...
        video {
          id
          token // remove this if you don't want lambda to be called on each invocation
        }