add context subscription
This commit is contained in:
@@ -25,13 +25,25 @@ import { getDatamodel } from '../types/pothos.generated';
|
||||
|
||||
// import { rules } from '../common/graphql/common.graphql.auth-rule';
|
||||
|
||||
export interface SchemaContext {
|
||||
req: Request;
|
||||
res: Response;
|
||||
me: User;
|
||||
pubSub: PubSub;
|
||||
generator: PrismaCrudGenerator<BuilderTypes>;
|
||||
}
|
||||
export type SchemaContext =
|
||||
| {
|
||||
isSubscription: true;
|
||||
websocket: {
|
||||
pubSub: PubSub;
|
||||
me: User;
|
||||
generator: PrismaCrudGenerator<BuilderTypes>;
|
||||
};
|
||||
}
|
||||
| {
|
||||
isSubscription: false;
|
||||
http: {
|
||||
req: Request;
|
||||
res: Response;
|
||||
me: User;
|
||||
pubSub: PubSub;
|
||||
generator: PrismaCrudGenerator<BuilderTypes>;
|
||||
};
|
||||
};
|
||||
|
||||
// extend prisma types to contain string type
|
||||
export interface SchemaBuilderOption {
|
||||
@@ -79,8 +91,11 @@ export class Builder extends SchemaBuilder<SchemaBuilderOption> {
|
||||
],
|
||||
smartSubscriptions: {
|
||||
debounceDelay: 1000,
|
||||
...subscribeOptionsFromIterator((name, { pubSub }) => {
|
||||
return pubSub.asyncIterator(name);
|
||||
...subscribeOptionsFromIterator((name, ctx) => {
|
||||
if (ctx.isSubscription) {
|
||||
return ctx.websocket.pubSub.asyncIterator(name);
|
||||
}
|
||||
return ctx.http.pubSub.asyncIterator(name);
|
||||
}),
|
||||
},
|
||||
relay: {},
|
||||
|
||||
Reference in New Issue
Block a user