add context subscription
This commit is contained in:
@@ -109,7 +109,10 @@ export class MessageSchema extends PothosSchema {
|
||||
...query,
|
||||
data: args.input,
|
||||
});
|
||||
ctx.pubSub.publish('MESSAGE_SENT', message);
|
||||
if (ctx.isSubscription) {
|
||||
throw new Error('Not allowed');
|
||||
}
|
||||
ctx.http.pubSub.publish('MESSAGE_SENT', message);
|
||||
return message;
|
||||
},
|
||||
}),
|
||||
@@ -124,9 +127,12 @@ export class MessageSchema extends PothosSchema {
|
||||
this.builder.subscriptionFields((t) => ({
|
||||
messageSent: t.field({
|
||||
subscribe: (_, __, ctx) => {
|
||||
if (!ctx.isSubscription) {
|
||||
throw new Error('Not allowed');
|
||||
}
|
||||
return {
|
||||
[Symbol.asyncIterator]: () =>
|
||||
ctx.pubSub.asyncIterator('MESSAGE_SENT'),
|
||||
ctx.websocket.pubSub.asyncIterator('MESSAGE_SENT'),
|
||||
};
|
||||
},
|
||||
type: this.message(), // Add the type property
|
||||
|
||||
Reference in New Issue
Block a user