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.

preguntada hace 4 meses192 visualizaciones
1 Respuesta
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
respondido hace 4 meses

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas