Repository: michalkvasnicak/aws-lambda-graphql (ts)

Issue:
Publishing to undefined topic breaks dynamoDB trigger
When you try to publish subscription message like this
```await pubSub.publish(undefined, payload)```
It will allow to publish such message however lambda trigger will throw this error:

> ExpressionAttributeValues must not be empty

Moreover because trigger lambda failed it will try to invoke it again with same parameter creating a loop which is possible to break only when you delete your dynamoDB trigger

I think `event` property should be part of composite key on dynamoDB Events table, and we should throw an error in PubSub when trying to publish event without a topic

Pull request description:
Do not allow publishing event with empty name
Closes #49 

Patch:
diff --git a/packages/aws-lambda-graphql/src/PubSub.ts b/packages/aws-lambda-graphql/src/PubSub.ts
index 038939b..dc9167f 100644
--- a/packages/aws-lambda-graphql/src/PubSub.ts
+++ b/packages/aws-lambda-graphql/src/PubSub.ts
@@ -1,3 +1,4 @@
+import * as assert from 'assert';
 import { IEventStore, OperationRequest, SubcribeResolveFn } from './types';
 
 type Options = {
@@ -43,6 +44,11 @@ class PubSub {
    * So you should not expect to fire in same process
    */
   publish = async (eventName: string, payload: any) => {
+    assert.ok(
+      typeof eventName === 'string' && eventName !== '',
+      'Event name cannot be empty',
+    );
+
     await this.eventStore.publish({
       payload: JSON.stringify(payload),
       event: eventName,


Test patch:
diff --git a/packages/aws-lambda-graphql/src/__tests__/PubSub.test.ts b/packages/aws-lambda-graphql/src/__tests__/PubSub.test.ts
index 5f711d0..a5a808a 100644
--- a/packages/aws-lambda-graphql/src/__tests__/PubSub.test.ts
+++ b/packages/aws-lambda-graphql/src/__tests__/PubSub.test.ts
@@ -65,6 +65,20 @@ describe('PubSub', () => {
   });
 
   describe('publish', () => {
+    it('does not allow to publish event with empty name', async () => {
+      const ps = new PubSub({ eventStore: eventStore as any });
+
+      await expect(ps.publish(undefined, {})).rejects.toThrowError(
+        'Event name cannot be empty',
+      );
+      await expect(ps.publish(null, {})).rejects.toThrowError(
+        'Event name cannot be empty',
+      );
+      await expect(ps.publish('', {})).rejects.toThrowError(
+        'Event name cannot be empty',
+      );
+    });
+
     it('works correctly', async () => {
       const ps = new PubSub({ eventStore: eventStore as any });