How to run Graphql subsciptions with type-graphql and aws-lambda-graphql

267 Views Asked by At

Hi I managed to publish data but I am struggling with subcribe, here is my code

  Subscription,
  Root,
  ResolverFilterData
} from 'type-graphql';

import { DynamoDBEventStore, PubSub } from 'aws-lambda-graphql';
import { awsClient } from '../../config/database';
import { Notification, NotificationPayload } from './notification.type';
const eventStore = new DynamoDBEventStore({
  dynamoDbClient: awsClient
});
const pubSub = new PubSub({ eventStore });

and the subscriptions:

  @Subscription({
    subscribe: (rootValue, args, context, info) => {
      return context.pubSub.subscribe('NEW_MESSAGE')(rootValue.message);
    }
  })
  normalSubs(@Root() { id, message }: NotificationPayload): Notification {
    return { id, message, date: new Date() };
  }
1

There are 1 best solutions below

0
On BEST ANSWER

You need to have a listener set to your Subscription through a web-socket connection sample listener to the Subscription

After the listener is set successfully, you can publish the message to a topic and the subscriber would receive the message sent to the respective topic listener receives the message subscribed to a specific topic