Skip to content

Commit

Permalink
Use Event from @whatwg-node/fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan committed Jul 27, 2022
1 parent 331e812 commit f64f21f
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 33 deletions.
2 changes: 1 addition & 1 deletion examples/error-handling/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"dependencies": {
"graphql-yoga": "2.13.4",
"@whatwg-node/fetch": "^0.1.1",
"@whatwg-node/fetch": "^0.2.3",
"graphql": "^16.1.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"typescript": "4.7.4"
},
"resolutions": {
"@whatwg-node/fetch": "0.1.1",
"@whatwg-node/fetch": "0.2.3",
"@changesets/apply-release-plan": "6.0.0",
"graphql": "16.5.0",
"@types/react": "17.0.39",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { TypedEvent } from '@graphql-yoga/typed-event-target'
import Redis from 'ioredis-mock'
import { createRedisEventTarget } from '../src'
import { Event, EventTarget } from '@whatwg-node/fetch'

describe('createRedisEventTarget', () => {
it('can listen to a simple publish', (done) => {
Expand Down
11 changes: 2 additions & 9 deletions packages/event-target/redis-event-target/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
import type {
TypedEventTarget,
EventAPI,
} from '@graphql-yoga/typed-event-target'
import type { TypedEventTarget } from '@graphql-yoga/typed-event-target'
import { Event } from '@whatwg-node/fetch'
import type { Redis, Cluster } from 'ioredis'

export type CreateRedisEventTargetArgs = {
publishClient: Redis | Cluster
subscribeClient: Redis | Cluster
/**
* Event and EventTarget implementation.
* Providing this is mandatory for a Node.js versions below 16.
*/
event?: EventAPI
}

export function createRedisEventTarget<TEvent extends Event>(
Expand Down
5 changes: 0 additions & 5 deletions packages/event-target/typed-event-target/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,3 @@ export interface TypedEventTarget<TEvent extends TypedEvent>
options?: EventListenerOptions | boolean,
): void
}

export type EventAPI = {
Event: typeof Event
EventTarget: typeof EventTarget
}
2 changes: 1 addition & 1 deletion packages/graphql-yoga/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"@graphql-tools/schema": "^8.5.0",
"@graphql-tools/utils": "^8.8.0",
"@graphql-yoga/subscription": "^2.2.2",
"@whatwg-node/fetch": "^0.1.1",
"@whatwg-node/fetch": "^0.2.3",
"@whatwg-node/server": "^0.0.3",
"dset": "^3.1.1",
"graphql-config": "^4.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/apq/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"access": "public"
},
"dependencies": {
"@whatwg-node/fetch": "^0.1.1",
"@whatwg-node/fetch": "^0.2.3",
"tiny-lru": "^8.0.2"
},
"peerDependencies": {
Expand Down
3 changes: 2 additions & 1 deletion packages/subscription/src/createPubSub.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Redis from 'ioredis-mock'
import { createRedisEventTarget } from '@graphql-yoga/redis-event-target'
import { createPubSub } from './createPubSub.js'
import { EventTarget } from '@whatwg-node/fetch'

async function collectAsyncIterableValues<TType>(
asyncIterable: AsyncIterable<TType>,
Expand All @@ -18,7 +19,7 @@ describe('createPubSub', () => {
})

describe.each([
['InMemory', () => new globalThis.EventTarget()],
['InMemory', () => new EventTarget()],
[
'Redis',
() =>
Expand Down
11 changes: 2 additions & 9 deletions packages/subscription/src/createPubSub.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { Repeater } from '@repeaterjs/repeater'
import type {
TypedEventTarget,
EventAPI,
} from '@graphql-yoga/typed-event-target'
import type { TypedEventTarget } from '@graphql-yoga/typed-event-target'
import { Event, EventTarget } from '@whatwg-node/fetch'

type PubSubPublishArgsByKey = {
[key: string]: [] | [any] | [number | string, any]
Expand Down Expand Up @@ -36,11 +34,6 @@ export type ChannelPubSubConfig<
* An event dispatched on the event target MUST have a `data` property.
*/
eventTarget?: PubSubEventTarget<TPubSubPublishArgsByKey>
/**
* Event and EventTarget implementation.
* Providing this is mandatory for a Node.js versions below 16.
*/
event?: EventAPI
}

export type PubSub<TPubSubPublishArgsByKey extends PubSubPublishArgsByKey> = {
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6492,10 +6492,10 @@
"@webassemblyjs/ast" "1.11.1"
"@xtuc/long" "4.2.2"

"@whatwg-node/fetch@0.1.1", "@whatwg-node/fetch@^0.0.2", "@whatwg-node/fetch@^0.1.1":
version "0.1.1"
resolved "https://registry.yarnpkg.com/@whatwg-node/fetch/-/fetch-0.1.1.tgz#b4c9379d52cdcdbc2ba74dcec62117c1c13685bc"
integrity sha512-SknQAeG0j+PSGLYSvR2/1OsuvkUZWlvfDbuZYQmQe6Z4I4Jbo9HFyxyj4VUgWvOVmvDcuZmMZHjnaoRUMNN6vA==
"@whatwg-node/fetch@0.2.3", "@whatwg-node/fetch@^0.0.2", "@whatwg-node/fetch@^0.2.3":
version "0.2.3"
resolved "https://registry.yarnpkg.com/@whatwg-node/fetch/-/fetch-0.2.3.tgz#616da791dd5dcd939fbe556c93d6f808fd523c00"
integrity sha512-ONxX5y7M4QvOqGWO5WVQz3Mrj5yMJI17Qf42vHJU1xCQIgZRNiCqTKfmJwyQ7Qtp66GAnv5smL1OlyVbWMNrDQ==
dependencies:
"@peculiar/webcrypto" "^1.4.0"
abort-controller "^3.0.0"
Expand Down Expand Up @@ -10494,7 +10494,7 @@ etag@^1.8.1, etag@~1.8.1:
resolved "https://registry.yarnpkg.com/etag/-/etag-1.8.1.tgz#41ae2eeb65efa62268aebfea83ac7d79299b0887"
integrity sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=

event-target-polyfill@0.0.3, event-target-polyfill@^0.0.3:
event-target-polyfill@^0.0.3:
version "0.0.3"
resolved "https://registry.yarnpkg.com/event-target-polyfill/-/event-target-polyfill-0.0.3.tgz#ed373295f3b257774b5d75afb2599331d9f3406c"
integrity sha512-ZMc6UuvmbinrCk4RzGyVmRyIsAyxMRlp4CqSrcQRO8Dy0A9ldbiRy5kdtBj4OtP7EClGdqGfIqo9JmOClMsGLQ==
Expand Down

0 comments on commit f64f21f

Please sign in to comment.