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.

asked 4 months ago179 views
1 Answer
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
answered 4 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions