Skip to content

Commit

Permalink
chore: upgrade to latest version of graphql-subscriptions (#330)
Browse files Browse the repository at this point in the history
Closes #327
  • Loading branch information
TriPSs authored Dec 12, 2024
2 parents 3eeeb22 + b662cc1 commit 6f9c1a2
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 40 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"eslint-plugin-tsdoc": "0.2.17",
"graphql": "16.9.0",
"graphql-query-complexity": "1.0.0",
"graphql-subscriptions": "2.0.0",
"graphql-subscriptions": "^3.0.0",
"graphql-tools": "9.0.1",
"husky": "9.1.5",
"jest": "29.7.0",
Expand All @@ -113,7 +113,7 @@
"ts-node": "10.9.2",
"tsconfig-extends": "1.0.1",
"tsconfig-paths": "4.2.0",
"typescript": "5.5.4"
"typescript": "^5.7.2"
},
"packageManager": "[email protected]"
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { anything, deepEqual, instance, mock, objectContaining, verify, when } f
import { CreatedEvent } from '../../src/resolvers/create.resolver'
import { EventType, getDTOEventName } from '../../src/subscription'
import { createResolverFromNest, generateSchema, TestResolverDTO, TestResolverInputDTO, TestService } from '../__fixtures__'
import { PubSubAsyncIterableIterator } from 'graphql-subscriptions/dist/pubsub-async-iterable-iterator'

describe('CreateResolver', () => {
const expectResolverSDL = async (opts?: CreateResolverOpts<TestResolverDTO>) => {
Expand Down Expand Up @@ -307,11 +308,11 @@ describe('CreateResolver', () => {
stringField: 'foo'
}
}
const mockIterator = mock<AsyncIterator<CreatedEvent<TestResolverDTO>>>()
when(mockPubSub.asyncIterator(eventName)).thenReturn(instance(mockIterator))
const mockIterator = mock<PubSubAsyncIterableIterator<CreatedEvent<TestResolverDTO>>>()
when(mockPubSub.asyncIterableIterator(eventName)).thenReturn(instance(mockIterator))
when(mockIterator.next()).thenResolve({ done: false, value: event })
const result = await resolver.createdSubscription().next()
verify(mockPubSub.asyncIterator(eventName)).once()
verify(mockPubSub.asyncIterableIterator(eventName)).once()
return expect(result).toEqual({
done: false,
value: event
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { DeleteManyInputType, DeleteOneInputType, DeleteResolver, DeleteResolver
import { DeletedEvent } from '../../src/resolvers/delete.resolver'
import { EventType, getDTOEventName } from '../../src/subscription'
import { createResolverFromNest, generateSchema, TestResolverDTO, TestService } from '../__fixtures__'
import { PubSubAsyncIterableIterator } from 'graphql-subscriptions/dist/pubsub-async-iterable-iterator'

describe('DeleteResolver', () => {
const expectResolverSDL = async (opts?: DeleteResolverOpts<TestResolverDTO>) => {
Expand Down Expand Up @@ -341,14 +342,14 @@ describe('DeleteResolver', () => {
stringField: 'foo'
}
}
const mockIterator = mock<AsyncIterator<DeletedEvent<TestResolverDTO>>>()
const mockIterator = mock<PubSubAsyncIterableIterator<DeletedEvent<TestResolverDTO>>>()

when(mockPubSub.asyncIterator(eventName)).thenReturn(instance(mockIterator))
when(mockPubSub.asyncIterableIterator(eventName)).thenReturn(instance(mockIterator))
when(mockIterator.next()).thenResolve({ done: false, value: event })

const result = await resolver.deletedOneSubscription().next()

verify(mockPubSub.asyncIterator(eventName)).once()
verify(mockPubSub.asyncIterableIterator(eventName)).once()

return expect(result).toEqual({
done: false,
Expand Down Expand Up @@ -379,14 +380,14 @@ describe('DeleteResolver', () => {
const { resolver, mockPubSub } = await createTestResolver({ enableSubscriptions: true })
const eventName = getDTOEventName(EventType.DELETED_MANY, TestResolverDTO)
const event: DeleteManyResponse = { deletedCount: 1 }
const mockIterator = mock<AsyncIterator<DeleteManyResponse>>()
const mockIterator = mock<PubSubAsyncIterableIterator<DeleteManyResponse>>()

when(mockPubSub.asyncIterator(eventName)).thenReturn(instance(mockIterator))
when(mockPubSub.asyncIterableIterator(eventName)).thenReturn(instance(mockIterator))
when(mockIterator.next()).thenResolve({ done: false, value: event })

const result = await resolver.deletedManySubscription().next()

verify(mockPubSub.asyncIterator(eventName)).once()
verify(mockPubSub.asyncIterableIterator(eventName)).once()

return expect(result).toEqual({
done: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { anything, deepEqual, instance, mock, objectContaining, verify, when } f
import { UpdatedEvent } from '../../src/resolvers/update.resolver'
import { EventType, getDTOEventName } from '../../src/subscription'
import { createResolverFromNest, generateSchema, TestResolverDTO, TestResolverInputDTO, TestService } from '../__fixtures__'
import { PubSubAsyncIterableIterator } from 'graphql-subscriptions/dist/pubsub-async-iterable-iterator'

describe('UpdateResolver', () => {
const expectResolverSDL = async (opts?: UpdateResolverOpts<TestResolverDTO>) => {
Expand Down Expand Up @@ -361,11 +362,11 @@ describe('UpdateResolver', () => {
stringField: 'foo'
}
}
const mockIterator = mock<AsyncIterator<UpdatedEvent<TestResolverDTO>>>()
when(mockPubSub.asyncIterator(eventName)).thenReturn(instance(mockIterator))
const mockIterator = mock<PubSubAsyncIterableIterator<UpdatedEvent<TestResolverDTO>>>()
when(mockPubSub.asyncIterableIterator(eventName)).thenReturn(instance(mockIterator))
when(mockIterator.next()).thenResolve({ done: false, value: event })
const result = await resolver.updatedOneSubscription().next()
verify(mockPubSub.asyncIterator(eventName)).once()
verify(mockPubSub.asyncIterableIterator(eventName)).once()
return expect(result).toEqual({
done: false,
value: event
Expand Down Expand Up @@ -395,11 +396,11 @@ describe('UpdateResolver', () => {
const { resolver, mockPubSub } = await createTestResolver({ enableSubscriptions: true })
const eventName = getDTOEventName(EventType.UPDATED_MANY, TestResolverDTO)
const event: UpdateManyResponse = { updatedCount: 1 }
const mockIterator = mock<AsyncIterator<UpdateManyResponse>>()
when(mockPubSub.asyncIterator(eventName)).thenReturn(instance(mockIterator))
const mockIterator = mock<PubSubAsyncIterableIterator<UpdateManyResponse>>()
when(mockPubSub.asyncIterableIterator(eventName)).thenReturn(instance(mockIterator))
when(mockIterator.next()).thenResolve({ done: false, value: event })
const result = await resolver.updatedManySubscription().next()
verify(mockPubSub.asyncIterator(eventName)).once()
verify(mockPubSub.asyncIterableIterator(eventName)).once()
return expect(result).toEqual({
done: false,
value: event
Expand Down
2 changes: 1 addition & 1 deletion packages/query-graphql/src/resolvers/create.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export const Creatable =
}

const eventName = getSubscriptionEventName(createdEvent, authorizeFilter)
return this.pubSub.asyncIterator<CreatedEvent<DTO>>(eventName)
return this.pubSub.asyncIterableIterator<CreatedEvent<DTO>>(eventName)
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/query-graphql/src/resolvers/delete.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export const Deletable =
throw new Error(`Unable to subscribe to ${deletedOneEvent}`)
}
const eventName = getSubscriptionEventName(deletedOneEvent, authorizeFilter)
return this.pubSub.asyncIterator(eventName)
return this.pubSub.asyncIterableIterator(eventName)
}

@ResolverSubscription(() => DMR, { name: deletedManyEvent }, commonResolverOpts, {
Expand All @@ -214,7 +214,7 @@ export const Deletable =
throw new Error(`Unable to subscribe to ${deletedManyEvent}`)
}
const eventName = getSubscriptionEventName(deletedManyEvent, authorizeFilter)
return this.pubSub.asyncIterator(eventName)
return this.pubSub.asyncIterableIterator(eventName)
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/query-graphql/src/resolvers/update.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export const Updateable =
throw new Error(`Unable to subscribe to ${updateOneEvent}`)
}
const eventName = getSubscriptionEventName(updateOneEvent, authorizeFilter)
return this.pubSub.asyncIterator(eventName)
return this.pubSub.asyncIterableIterator(eventName)
}

@ResolverSubscription(() => UMR, { name: updateManyEvent }, commonResolverOpts, {
Expand All @@ -219,7 +219,7 @@ export const Updateable =
throw new Error(`Unable to subscribe to ${updateManyEvent}`)
}
const eventName = getSubscriptionEventName(updateManyEvent, authorizeFilter)
return this.pubSub.asyncIterator(eventName)
return this.pubSub.asyncIterableIterator(eventName)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ export interface GraphQLPubSub {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
unsubscribe(subId: number): any

asyncIterator<T>(triggers: string | string[]): AsyncIterator<T>
asyncIterableIterator<T>(triggers: string | string[]): AsyncIterator<T>
}
32 changes: 15 additions & 17 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11177,14 +11177,12 @@ __metadata:
languageName: node
linkType: hard

"graphql-subscriptions@npm:2.0.0":
version: 2.0.0
resolution: "graphql-subscriptions@npm:2.0.0"
dependencies:
iterall: "npm:^1.3.0"
"graphql-subscriptions@npm:^3.0.0":
version: 3.0.0
resolution: "graphql-subscriptions@npm:3.0.0"
peerDependencies:
graphql: ^15.7.2 || ^16.0.0
checksum: 10/fcf47bd8cef90f3d38f07b49b4b0e70514c22d56e3604a6cde03a250d3129a6c5b3e8420953a6fe5dab68e48d092a4d13fa39bcc61610bdd6c4a0804b9ee2f82
checksum: 10/9dbee94d1f8a8742631e6deba33fed4a688b893bb5e287c346b5d01a237b80f96eb4ed2576a3b44c608e553cfd1f2cb400f88b0ffc882cb4effaa4db789f1ce0
languageName: node
linkType: hard

Expand Down Expand Up @@ -12709,7 +12707,7 @@ __metadata:
languageName: node
linkType: hard

"iterall@npm:1.3.0, iterall@npm:^1.2.1, iterall@npm:^1.3.0":
"iterall@npm:1.3.0, iterall@npm:^1.2.1":
version: 1.3.0
resolution: "iterall@npm:1.3.0"
checksum: 10/700c3e9ae194a00b66dc8dcb449195f84add4e64afaf7ed624177e19565393f9bddd34d621ea70c8eceab87a8536fc0e45bb1c9d1ea7c710d41ed0c3d937b19f
Expand Down Expand Up @@ -15556,7 +15554,7 @@ __metadata:
eslint-plugin-tsdoc: "npm:0.2.17"
graphql: "npm:16.9.0"
graphql-query-complexity: "npm:1.0.0"
graphql-subscriptions: "npm:2.0.0"
graphql-subscriptions: "npm:^3.0.0"
graphql-tools: "npm:9.0.1"
husky: "npm:9.1.5"
jest: "npm:29.7.0"
Expand Down Expand Up @@ -15587,7 +15585,7 @@ __metadata:
tsconfig-paths: "npm:4.2.0"
tslib: "npm:^2.6.3"
typeorm: "npm:0.3.17"
typescript: "npm:5.5.4"
typescript: "npm:^5.7.2"
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -20334,13 +20332,13 @@ __metadata:
languageName: node
linkType: hard

"typescript@npm:5.5.4":
version: 5.5.4
resolution: "typescript@npm:5.5.4"
"typescript@npm:^5.7.2":
version: 5.7.2
resolution: "typescript@npm:5.7.2"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 10/1689ccafef894825481fc3d856b4834ba3cc185a9c2878f3c76a9a1ef81af04194849840f3c69e7961e2312771471bb3b460ca92561e1d87599b26c37d0ffb6f
checksum: 10/4caa3904df69db9d4a8bedc31bafc1e19ffb7b24fbde2997a1633ae1398d0de5bdbf8daf602ccf3b23faddf1aeeb9b795223a2ed9c9a4fdcaf07bfde114a401a
languageName: node
linkType: hard

Expand All @@ -20364,13 +20362,13 @@ __metadata:
languageName: node
linkType: hard

"typescript@patch:typescript@npm%3A5.5.4#optional!builtin<compat/typescript>":
version: 5.5.4
resolution: "typescript@patch:typescript@npm%3A5.5.4#optional!builtin<compat/typescript>::version=5.5.4&hash=379a07"
"typescript@patch:typescript@npm%3A^5.7.2#optional!builtin<compat/typescript>":
version: 5.7.2
resolution: "typescript@patch:typescript@npm%3A5.7.2#optional!builtin<compat/typescript>::version=5.7.2&hash=74658d"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 10/746fdd0865c5ce4f15e494c57ede03a9e12ede59cfdb40da3a281807853fe63b00ef1c912d7222143499aa82f18b8b472baa1830df8804746d09b55f6cf5b1cc
checksum: 10/ff27fc124bceb8969be722baa38af945b2505767cf794de3e2715e58f61b43780284060287d651fcbbdfb6f917f4653b20f4751991f17e0706db389b9bb3f75d
languageName: node
linkType: hard

Expand Down

0 comments on commit 6f9c1a2

Please sign in to comment.