-
Notifications
You must be signed in to change notification settings - Fork 237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
made mercurius's implicitly injected pubsub subscribe/publish methods type safe #1115
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -23,9 +23,20 @@ | |||||||||||||
type Mercurius = typeof mercurius | ||||||||||||||
|
||||||||||||||
declare namespace mercurius { | ||||||||||||||
export interface PubSub { | ||||||||||||||
subscribe<TResult = any>(topics: string | string[]): Promise<Readable & AsyncIterableIterator<TResult>>; | ||||||||||||||
publish<TResult = any>(event: { topic: string; payload: TResult }, callback?: () => void): void; | ||||||||||||||
export type PubSubPublishArgsByKey = { | ||||||||||||||
[key: string]: any; | ||||||||||||||
}; | ||||||||||||||
Check failure on line 28 in index.d.ts GitHub Actions / test (20.x, macOS-latest)
Check failure on line 28 in index.d.ts GitHub Actions / test (22.x, macOS-latest)
Check failure on line 28 in index.d.ts GitHub Actions / test (20.x, ubuntu-latest)
Check failure on line 28 in index.d.ts GitHub Actions / test (22.x, ubuntu-latest)
Check failure on line 28 in index.d.ts GitHub Actions / test (22.x, windows-latest)
|
||||||||||||||
|
||||||||||||||
export interface PubSub< | ||||||||||||||
Check warning on line 30 in index.d.ts GitHub Actions / test (20.x, macOS-latest)
Check warning on line 30 in index.d.ts GitHub Actions / test (22.x, macOS-latest)
Check warning on line 30 in index.d.ts GitHub Actions / test (20.x, ubuntu-latest)
Check warning on line 30 in index.d.ts GitHub Actions / test (22.x, ubuntu-latest)
Check warning on line 30 in index.d.ts GitHub Actions / test (22.x, windows-latest)
|
||||||||||||||
TPubSubPublishArgsByKey extends PubSubPublishArgsByKey, | ||||||||||||||
> { | ||||||||||||||
Comment on lines
+30
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unless you do this, this is a breaking change, as
Suggested change
|
||||||||||||||
subscribe<TKey extends Extract<keyof TPubSubPublishArgsByKey, string>>( | ||||||||||||||
Check failure on line 33 in index.d.ts GitHub Actions / test (20.x, macOS-latest)
Check failure on line 33 in index.d.ts GitHub Actions / test (22.x, macOS-latest)
Check failure on line 33 in index.d.ts GitHub Actions / test (20.x, ubuntu-latest)
Check failure on line 33 in index.d.ts GitHub Actions / test (22.x, ubuntu-latest)
Check failure on line 33 in index.d.ts GitHub Actions / test (22.x, windows-latest)
|
||||||||||||||
topics: TKey | TKey[], | ||||||||||||||
Check failure on line 34 in index.d.ts GitHub Actions / test (20.x, macOS-latest)
Check failure on line 34 in index.d.ts GitHub Actions / test (22.x, macOS-latest)
Check failure on line 34 in index.d.ts GitHub Actions / test (20.x, ubuntu-latest)
Check failure on line 34 in index.d.ts GitHub Actions / test (22.x, ubuntu-latest)
Check failure on line 34 in index.d.ts GitHub Actions / test (22.x, windows-latest)
|
||||||||||||||
): Promise<Readable & AsyncIterableIterator<TPubSubPublishArgsByKey[TKey]>>; | ||||||||||||||
Check failure on line 35 in index.d.ts GitHub Actions / test (20.x, macOS-latest)
Check failure on line 35 in index.d.ts GitHub Actions / test (22.x, macOS-latest)
Check failure on line 35 in index.d.ts GitHub Actions / test (20.x, ubuntu-latest)
Check failure on line 35 in index.d.ts GitHub Actions / test (22.x, ubuntu-latest)
Check failure on line 35 in index.d.ts GitHub Actions / test (22.x, windows-latest)
|
||||||||||||||
Comment on lines
+34
to
+35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this work properly when |
||||||||||||||
publish<TKey extends Extract<keyof TPubSubPublishArgsByKey, string>>( | ||||||||||||||
Check failure on line 36 in index.d.ts GitHub Actions / test (20.x, macOS-latest)
Check failure on line 36 in index.d.ts GitHub Actions / test (22.x, macOS-latest)
Check failure on line 36 in index.d.ts GitHub Actions / test (20.x, ubuntu-latest)
Check failure on line 36 in index.d.ts GitHub Actions / test (22.x, ubuntu-latest)
Check failure on line 36 in index.d.ts GitHub Actions / test (22.x, windows-latest)
|
||||||||||||||
event: { topic: TKey; payload: TPubSubPublishArgsByKey[TKey] }, | ||||||||||||||
Check failure on line 37 in index.d.ts GitHub Actions / test (20.x, macOS-latest)
Check failure on line 37 in index.d.ts GitHub Actions / test (22.x, macOS-latest)
Check failure on line 37 in index.d.ts GitHub Actions / test (20.x, ubuntu-latest)
Check failure on line 37 in index.d.ts GitHub Actions / test (22.x, ubuntu-latest)
Check failure on line 37 in index.d.ts GitHub Actions / test (22.x, windows-latest)
|
||||||||||||||
callback?: () => void, | ||||||||||||||
Check failure on line 38 in index.d.ts GitHub Actions / test (20.x, macOS-latest)
Check failure on line 38 in index.d.ts GitHub Actions / test (22.x, macOS-latest)
Check failure on line 38 in index.d.ts GitHub Actions / test (20.x, ubuntu-latest)
Check failure on line 38 in index.d.ts GitHub Actions / test (22.x, ubuntu-latest)
Check failure on line 38 in index.d.ts GitHub Actions / test (22.x, windows-latest)
|
||||||||||||||
): void; | ||||||||||||||
Check failure on line 39 in index.d.ts GitHub Actions / test (20.x, macOS-latest)
Check failure on line 39 in index.d.ts GitHub Actions / test (22.x, macOS-latest)
Check failure on line 39 in index.d.ts GitHub Actions / test (20.x, ubuntu-latest)
Check failure on line 39 in index.d.ts GitHub Actions / test (22.x, ubuntu-latest)
Check failure on line 39 in index.d.ts GitHub Actions / test (22.x, windows-latest)
|
||||||||||||||
Comment on lines
+33
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The export type Message = Record<string, any> & { topic: string } on(topic: string, listener: (message: Message, done: () => void) => void, callback?: () => void): this
emit(message: Message, callback?: (error?: Error) => void): void There is some mismatch here, both in the old and in the new types. Eg: the publish callback should be: I think the Line 449 in a45fd77
(Ideally the |
||||||||||||||
} | ||||||||||||||
|
||||||||||||||
export interface MercuriusContext { | ||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably mimic eg
MercuriusContext
and be one can extend, rather than (or in addition) to being needed to specify likePubSub<MyTopics>
– that way it will work automatically in all the places that use thePubSub
type.The name should also be in the style of the other interfaces.