Other Operations

Finally, let’s implement the remainder of our Amplify strategy for our Speaker, Track, and Location operations.

//// Speakers
speakerById(speakerId: string): Observable<Speaker> {
  const args = { key: speakerId };
  return from(performGraphqlOperation<Speaker>(queries.getSpeaker, args))
    .pipe(utils.keyToId());
}

listSpeakers(): Observable<Speaker[]> {
  return from(performGraphqlOperation<Speaker[]>(queries.listSpeakers))
    .pipe(utils.keysToIds())
    .pipe(utils.sortByName());
}

//// Tracks
listTracks(): Observable<Track[]> {
  return from(performGraphqlOperation<Track[]>(queries.listTracks));
}

//// Locations
listLocations(): Observable<Location[]> {
  this.unsubscribe(this.subscriptions.listLocations);
  const res = subscribe<Location>(subscriptions.updatedLocation);
  this.subscriptions.listLocations = res.subscription;
  return merge(
    from(performGraphqlOperation<Location[]>(queries.listLocations)),
    res.observable.pipe(map((it) => [it]))
  );
}

Nice work! At this point we have a fully functional Amplify-backed repository.