Amplify Subscriptions Filters are not filtering on the eq value

0

Hi all, I am hoping there is an quick solution or explanation regarding what is happening. I am using amplify subscriptions in a vue setting: The subscriptions I have are not filtering when attempting to use the eq filter. The result is that I am receiving items that are outside the filer conditions.

I am creating a subscription like this:

const createSub = API.graphql<GraphQLSubscription<OnCreateMediaSubscription> >({ query: subscriptions.onCreateMedia, variables: { filters: { groupId: { eq: groupId } } }, }).subscribe({ next: ({ value }) => { console.log(groupId === value.data.onCreateMedia.groupId } })

The console statement will print false which seems like it should not ever occur if I understand how subscriptions are working.

1回答
0

Hello,

This issue usually occurs if the filtering criteria based on groupId is not being applied correctly. As I can see from this documentation(https://docs.amplify.aws/javascript/build-a-backend/graphqlapi/query-data/#filter-list-queries), it looks like the groupId should contain some value and then should be passed inside the variables. For example :

const variables = {
  filter: {
    // Only receive messages where the "groupId" field is "A"
    groupId: { eq: 'A' }
  }
};

const sub = client
  .graphql({
    query: subscriptions.onCreateMedia,
    variables
  })
  .subscribe({
    next: ({ data }) => console.log(data),
  });

I would suggest you to first try getting the data printing on the console and further use subscribe method and pass "groupId === value.data.onCreateMedia.groupId" in the console statement. Debugging by fetching the data first and applying filtering logic over the groupId would help in identifying the issue and mitigating it. Hence, can you help me in sharing the complete client code used in your project for subscribing based on groupId?

Thank you.

AWS
回答済み 4ヶ月前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ