Skip to content
This repository was archived by the owner on May 17, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions lib/gateway.ts → lib/handleGatewayEvent.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import { GRAPHQL_TRANSPORT_WS_PROTOCOL, MessageType } from 'graphql-ws'
import {
ApiGatewayHandler,
APIGatewayWebSocketEvent,
ServerClosure,
WebsocketResponse,
} from './types'
import { ServerClosure, ServerInstance } from './types'
import { disconnect } from './messages/disconnect'
import { ping } from './messages/ping'
import { complete } from './messages/complete'
import { subscribe } from './messages/subscribe'
import { connection_init } from './messages/connection_init'
import { pong } from './messages/pong'

export const handleGatewayEvent = (server: ServerClosure): ApiGatewayHandler<APIGatewayWebSocketEvent, WebsocketResponse> => async (event) => {
export const handleGatewayEvent = (server: ServerClosure): ServerInstance['gatewayHandler'] => async (event) => {
if (!event.requestContext) {
server.log('handleGatewayEvent unknown')
return {
Expand Down
4 changes: 2 additions & 2 deletions lib/stepFunctionHandler.ts → lib/handleStateMachineEvent.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { MessageType } from 'graphql-ws'
import { ServerClosure, StateFunctionInput } from './types'
import { ServerClosure, ServerInstance } from './types'
import { sendMessage } from './utils/sendMessage'
import { deleteConnection } from './utils/deleteConnection'

export const handleStateMachineEvent = (c: ServerClosure) => async (input: StateFunctionInput): Promise<StateFunctionInput> => {
export const handleStateMachineEvent = (c: ServerClosure): ServerInstance['stateMachineHandler'] => async (input) => {
if (!c.pingpong) {
throw new Error('Invalid pingpong settings')
}
Expand Down
4 changes: 2 additions & 2 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ServerArgs, ServerClosure, ServerInstance } from './types'
import { publish } from './pubsub/publish'
import { complete } from './pubsub/complete'
import { handleGatewayEvent } from './gateway'
import { handleStateMachineEvent } from './stepFunctionHandler'
import { handleGatewayEvent } from './handleGatewayEvent'
import { handleStateMachineEvent } from './handleStateMachineEvent'
import { makeServerClosure } from './makeServerClosure'

export const createInstance = (opts: ServerArgs): ServerInstance => {
Expand Down
4 changes: 2 additions & 2 deletions lib/pubsub/complete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import AggregateError from 'aggregate-error'
import { parse } from 'graphql'
import { CompleteMessage, MessageType } from 'graphql-ws'
import { buildExecutionContext } from 'graphql/execution/execute'
import { ServerClosure, PubSubEvent, SubscribePseudoIterable, PartialBy } from '../types'
import { ServerClosure, PubSubEvent, SubscribePseudoIterable, ServerInstance } from '../types'
import { sendMessage } from '../utils/sendMessage'
import { constructContext } from '../utils/constructContext'
import { getResolverAndArgs } from '../utils/getResolverAndArgs'
import { isArray } from '../utils/isArray'
import { getFilteredSubs } from './getFilteredSubs'

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

Expand Down
4 changes: 2 additions & 2 deletions lib/pubsub/publish.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { parse, execute } from 'graphql'
import { MessageType, NextMessage } from 'graphql-ws'
import { PubSubEvent, ServerClosure } from '../types'
import { ServerClosure, ServerInstance } from '../types'
import { sendMessage } from '../utils/sendMessage'
import { constructContext } from '../utils/constructContext'
import { getFilteredSubs } from './getFilteredSubs'

export const publish = (server: ServerClosure) => async <T extends PubSubEvent>(event: T): Promise<void> => {
export const publish = (server: ServerClosure): ServerInstance['publish'] => async event => {
server.log('pubsub:publish %j', { event })
const subscriptions = await getFilteredSubs({ server, event })
server.log('pubsub:publish %j', { subscriptions: subscriptions.map(({ connectionId, filter, subscription }) => ({ connectionId, filter, subscription }) ) })
Expand Down
2 changes: 1 addition & 1 deletion lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export interface ServerInstance {
gatewayHandler: ApiGatewayHandler<APIGatewayWebSocketEvent, WebsocketResponse>
stateMachineHandler: (input: StateFunctionInput) => Promise<StateFunctionInput>
publish: (event: PubSubEvent) => Promise<void>
complete: (event: PubSubEvent) => Promise<void>
complete: (event: PartialBy<PubSubEvent, 'payload'>) => Promise<void>
}

export type TableNames = {
Expand Down