Hi! I am using GraphQL subscriptions.
I have this table:
type UserViewState @model {
id: String! @primaryKey
userId: ID!
viewStateId: ID!
enabled: Boolean
}
And automatically amplify generated the following subscription:
export const onUpdateUserViewState = /* GraphQL */ subscription OnUpdateUserViewState( $filter: ModelSubscriptionUserViewStateFilterInput ) { onUpdateUserViewState(filter: $filter) { id userId viewStateId enabled createdAt updatedAt userViewStatesId __typename } };
The idea is that when I update something for a specific id on UserViewState that it gets detected by the subscription.
However, when I run the code below to initialized the subscription event and then I use do a mutation on the table using graphQL playground, the subscription doesn't return anything, either data or an error. What could possible be doing wrong?
For the sake of testing I am using a .js script.
Code (graph_test.js)
import { generateClient } from 'aws-amplify/api';
import * as subscriptions from './src/graphql/subscriptions.js';
import { Amplify } from "aws-amplify";
import amplifyconfig from './src/amplifyconfiguration.json' assert { type: 'json' };
Amplify.configure(amplifyconfig);
const client = generateClient();
export const onUpdateUserViewState = /* GraphQL */ subscription OnUpdateUserViewState( $filter: ModelSubscriptionUserViewStateFilterInput ) { onUpdateUserViewState(filter: $filter) { id userId viewStateId enabled createdAt updatedAt userViewStatesId __typename } };
const createSub = client
.graphql({ query: onUpdateUserViewState, variables: { id: '123123123211323'} })
.subscribe({ next: ({ data }) => console.log(data), error: (error) => console.warn(error) });
I am following this documentation: https://docs.amplify.aws/gen1/react/build-a-backend/graphqlapi/subscribe-data/
Thanks in advance!