Amplify JS API Documentation
    Preparing search index...

    Function syncExpression

    • Build an expression that can be used to filter which items of a given Model are synchronized down from the GraphQL service. E.g.,

      import { DataStore, syncExpression } from 'aws-amplify/datastore';
      import { Post, Comment } from './models';


      DataStore.configure({
      syncExpressions: [
      syncExpression(Post, () => {
      return (post) => post.rating.gt(5);
      }),
      syncExpression(Comment, () => {
      return (comment) => comment.status.eq('active');
      })
      ]
      });

      When DataStore starts syncing, only Posts with rating > 5 and Comments with status === 'active' will be synced down to the user's local store.

      Type Parameters

      • T extends Readonly<Record<string, any>>
      • A extends Option<T>

      Parameters

      • modelConstructor: PersistentModelConstructor<T>

        The Model from the schema.

      • conditionProducer: ConditionProducer<T, A>

        A function that builds a condition object that can describe how to filter the model.

      Returns Promise<
          {
              conditionProducer: ConditionProducer<T, A>;
              modelConstructor: PersistentModelConstructor<T>;
          },
      >

      An sync expression object that can be attached to the DataStore syncExpressions configuration property.