Skip to content
This repository was archived by the owner on May 17, 2025. It is now read-only.

Commit b2a3842

Browse files
authored
fix: server instance event handler types to match their actual functions (#30)
- dried up those type definitions so they don't drift - renamed some files to match function names
1 parent 6bcc957 commit b2a3842

File tree

6 files changed

+11
-16
lines changed

6 files changed

+11
-16
lines changed

lib/gateway.ts renamed to lib/handleGatewayEvent.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
import { GRAPHQL_TRANSPORT_WS_PROTOCOL, MessageType } from 'graphql-ws'
2-
import {
3-
ApiGatewayHandler,
4-
APIGatewayWebSocketEvent,
5-
ServerClosure,
6-
WebsocketResponse,
7-
} from './types'
2+
import { ServerClosure, ServerInstance } from './types'
83
import { disconnect } from './messages/disconnect'
94
import { ping } from './messages/ping'
105
import { complete } from './messages/complete'
116
import { subscribe } from './messages/subscribe'
127
import { connection_init } from './messages/connection_init'
138
import { pong } from './messages/pong'
149

15-
export const handleGatewayEvent = (server: ServerClosure): ApiGatewayHandler<APIGatewayWebSocketEvent, WebsocketResponse> => async (event) => {
10+
export const handleGatewayEvent = (server: ServerClosure): ServerInstance['gatewayHandler'] => async (event) => {
1611
if (!event.requestContext) {
1712
server.log('handleGatewayEvent unknown')
1813
return {

lib/stepFunctionHandler.ts renamed to lib/handleStateMachineEvent.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { MessageType } from 'graphql-ws'
2-
import { ServerClosure, StateFunctionInput } from './types'
2+
import { ServerClosure, ServerInstance } from './types'
33
import { sendMessage } from './utils/sendMessage'
44
import { deleteConnection } from './utils/deleteConnection'
55

6-
export const handleStateMachineEvent = (c: ServerClosure) => async (input: StateFunctionInput): Promise<StateFunctionInput> => {
6+
export const handleStateMachineEvent = (c: ServerClosure): ServerInstance['stateMachineHandler'] => async (input) => {
77
if (!c.pingpong) {
88
throw new Error('Invalid pingpong settings')
99
}

lib/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { ServerArgs, ServerClosure, ServerInstance } from './types'
22
import { publish } from './pubsub/publish'
33
import { complete } from './pubsub/complete'
4-
import { handleGatewayEvent } from './gateway'
5-
import { handleStateMachineEvent } from './stepFunctionHandler'
4+
import { handleGatewayEvent } from './handleGatewayEvent'
5+
import { handleStateMachineEvent } from './handleStateMachineEvent'
66
import { makeServerClosure } from './makeServerClosure'
77

88
export const createInstance = (opts: ServerArgs): ServerInstance => {

lib/pubsub/complete.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import AggregateError from 'aggregate-error'
22
import { parse } from 'graphql'
33
import { CompleteMessage, MessageType } from 'graphql-ws'
44
import { buildExecutionContext } from 'graphql/execution/execute'
5-
import { ServerClosure, PubSubEvent, SubscribePseudoIterable, PartialBy } from '../types'
5+
import { ServerClosure, PubSubEvent, SubscribePseudoIterable, ServerInstance } from '../types'
66
import { sendMessage } from '../utils/sendMessage'
77
import { constructContext } from '../utils/constructContext'
88
import { getResolverAndArgs } from '../utils/getResolverAndArgs'
99
import { isArray } from '../utils/isArray'
1010
import { getFilteredSubs } from './getFilteredSubs'
1111

12-
export const complete = (server: ServerClosure) => async (event: PartialBy<PubSubEvent, 'payload'>): Promise<void> => {
12+
export const complete = (server: ServerClosure): ServerInstance['complete'] => async event => {
1313
const subscriptions = await getFilteredSubs({ server, event })
1414
server.log('pubsub:complete %j', { event, subscriptions })
1515

lib/pubsub/publish.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { parse, execute } from 'graphql'
22
import { MessageType, NextMessage } from 'graphql-ws'
3-
import { PubSubEvent, ServerClosure } from '../types'
3+
import { ServerClosure, ServerInstance } from '../types'
44
import { sendMessage } from '../utils/sendMessage'
55
import { constructContext } from '../utils/constructContext'
66
import { getFilteredSubs } from './getFilteredSubs'
77

8-
export const publish = (server: ServerClosure) => async <T extends PubSubEvent>(event: T): Promise<void> => {
8+
export const publish = (server: ServerClosure): ServerInstance['publish'] => async event => {
99
server.log('pubsub:publish %j', { event })
1010
const subscriptions = await getFilteredSubs({ server, event })
1111
server.log('pubsub:publish %j', { subscriptions: subscriptions.map(({ connectionId, filter, subscription }) => ({ connectionId, filter, subscription }) ) })

lib/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export interface ServerInstance {
5353
gatewayHandler: ApiGatewayHandler<APIGatewayWebSocketEvent, WebsocketResponse>
5454
stateMachineHandler: (input: StateFunctionInput) => Promise<StateFunctionInput>
5555
publish: (event: PubSubEvent) => Promise<void>
56-
complete: (event: PubSubEvent) => Promise<void>
56+
complete: (event: PartialBy<PubSubEvent, 'payload'>) => Promise<void>
5757
}
5858

5959
export type TableNames = {

0 commit comments

Comments
 (0)