aws-amplify / amplify-category-api

The AWS Amplify CLI is a toolchain for simplifying serverless web and mobile development. This plugin provides functionality for the API category, allowing for the creation and management of GraphQL and REST based backends for your amplify project.
https://docs.amplify.aws/
Apache License 2.0
82 stars 71 forks source link

Real-Time Data Issue with Modeling Relationships #2686

Open jewells07 opened 1 week ago

jewells07 commented 1 week ago

Amplify CLI Version

12.12.2

Question

I'm trying to get real-time data using observeQuery. I have a Chat model that has a relationship with a Message model. However, I'm unable to fetch the real-time data when I use observeQuery on the Chat model. If I add observeQuery on the Message model, I can fetch the data, but this isn't ideal because the Message model contains a very large amount of data. Is there a way to effectively use observeQuery on the Chat model to get all related messages without dealing with the Message model's data?

I'm using Nuxt 3.

NOT WORKING šŸ‘‡

$Amplify.GraphQL.client.models.Chat.observeQuery({
    filter: {
      id: { eq: chatId },
    },
    selectionSet: [
      'messages.id',
      'messages.content',
    ],
    authMode: 'userPool',
  }).subscribe({
    next: ({ items }) => {
      allMessages.value = [...items[0].messages];
    },
  });

WORKING šŸ‘‡

$Amplify.GraphQL.client.models.Message.observeQuery({
    filter: {
      chatId: { eq: chatId },
    },
    selectionSet: ['id', 'content'],
    authMode: 'userPool',
  }).subscribe({
    next: ({ items }) => {
      allMessages.value = [...items];
    },
  });
dpilch commented 4 days ago

This may be expected and related to https://github.com/aws-amplify/amplify-category-api/issues/2609.

Please see the updates to the following docs: