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
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v3
with:
node-version: 14
node-version: 16
- run: npm ci
- name: Release
env:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v3
with:
node-version: 14
node-version: 16
- run: npm ci
- name: Test
run: npm run test
Expand All @@ -21,7 +21,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v3
with:
node-version: 14
node-version: 16
- run: npm ci
- name: Lint
run: npm run lint
1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
16.16.0
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,10 @@ Subscription
```

```ts
import { tables } from '@architect/functions'
import { tables as arcTables } from '@architect/functions'

const fetchTableNames = async () => {
const tables = await tables()
const tables = await arcTables()

const ensureName = (table) => {
const actualTableName = tables.name(table)
Expand All @@ -165,7 +165,7 @@ const fetchTableNames = async () => {
}

const subscriptionServer = makeServer({
dynamodb: tables.db,
dynamodb: tables._db,
schema,
tableNames: fetchTableNames(),
})
Expand Down
7 changes: 4 additions & 3 deletions lib/index-test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { assert } from 'chai'
import { Handler } from 'aws-lambda'
import { tables } from '@architect/sandbox'
import { start, end } from '@architect/sandbox'
import { makeServer } from '.'
import { mockServerArgs } from './test/mockServer'
import { APIGatewayWebSocketEvent, WebSocketResponse } from './types'
import { join } from 'path'

describe('makeServer', () => {
describe('webSocketHandler', () => {
before(async () => {
await tables.start({ cwd: './mocks/arc-basic-events', quiet: true })
await start({ cwd: join(process.cwd(),'./mocks/arc-basic-events'), quiet: true })
})

after(async () => {
await tables.end()
await end()
})

it('is type compatible with aws-lambda handler', async () => {
Expand Down
7 changes: 4 additions & 3 deletions lib/messages/subscribe-test.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { assert } from 'chai'
import { tables } from '@architect/sandbox'
import { start, end } from '@architect/sandbox'
import { subscribe } from './subscribe'
import { mockServerContext } from '../test/mockServer'
import { connection_init } from './connection_init'
import { collect } from 'streaming-iterables'
import { subscribe as pubsubSubscribe } from '../pubsub/subscribe'
import { makeExecutableSchema } from '@graphql-tools/schema'
import { join } from 'path'

const connectionId = '7rWmyMbMr'
const ConnectionId = connectionId
const connectionInitEvent: any = { requestContext: { connectedAt: 1628905962601, connectionId, domainName: 'localhost:6001', eventType: 'MESSAGE', messageDirection: 'IN', messageId: 'Pn6evkpk2', requestId: 'gN1MPybyL', requestTimeEpoch: 1628905962602, routeKey: '$default', stage: 'testing' }, isBase64Encoded: false, body: '{"type":"connection_init"}' }

describe('messages/subscribe', () => {
beforeEach(async () => {
await tables.start({ cwd: './mocks/arc-basic-events', quiet: true })
await start({ cwd: join(process.cwd(),'./mocks/arc-basic-events'), quiet: true })
})

afterEach(async () => {
await tables.end()
await end()
})

it('executes a query/mutation', async () => {
Expand Down
7 changes: 4 additions & 3 deletions lib/pubsub/complete-test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { tables } from '@architect/sandbox'
import { start, end } from '@architect/sandbox'
import { join } from 'path'
import { mockServerContext } from '../test/mockServer'
import { complete } from './complete'

describe('pubsub:complete', () => {
before(async () => {
await tables.start({ cwd: './mocks/arc-basic-events', quiet: true })
await start({ cwd: join(process.cwd(), './mocks/arc-basic-events'), quiet: true })
})

after(async () => {
await tables.end()
await end()
})

it('takes a topic', async () => {
Expand Down
7 changes: 4 additions & 3 deletions lib/pubsub/getFilteredSubs-test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { tables } from '@architect/sandbox'
import { start, end } from '@architect/sandbox'
import { assert } from 'chai'
import { join } from 'path'
import { mockServerContext } from '../test/mockServer'
import { collapseKeys, getFilteredSubs } from './getFilteredSubs'

Expand Down Expand Up @@ -29,11 +30,11 @@ const makeTopic = () => `topic-${count++}`

describe('getFilteredSubs', () => {
before(async () => {
await tables.start({ cwd: './mocks/arc-basic-events', quiet: true })
await start({ cwd: join(process.cwd(),'./mocks/arc-basic-events'), quiet: true })
})

after(async () => {
await tables.end()
await end()
})

it('can match on no filter', async () => {
Expand Down
11 changes: 7 additions & 4 deletions lib/test/integration-events-test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { assert } from 'chai'
import { start as sandBoxStart, end as sandBoxStop } from '@architect/sandbox'
import { start as sandboxStart, end as sandboxEnd } from '@architect/sandbox'
import { collect, map } from 'streaming-iterables'
import { executeDoubleQuery, executeQuery, executeToComplete, executeToDisconnect } from './execute-helper'
import { startGqlWSServer } from './graphql-ws-schema'
import { join } from 'path'

describe('Events', () => {
before(async () => {
await sandBoxStart({ cwd: './mocks/arc-basic-events', quiet: true })
await sandboxStart({ cwd: join(process.cwd(), './mocks/arc-basic-events'), quiet: true })
})

after(async () => {
await new Promise(resolve => setTimeout(resolve, 100)) // pending ddb writes need to finish
await sandBoxStop()
// pending ddb writes need to finish, this is annoying
await new Promise(resolve => setTimeout(resolve, 100))
await sandboxEnd()
})

describe('Basic Events', () => {
it('queries', async () => {
const { url, stop } = await startGqlWSServer()
Expand Down
2 changes: 1 addition & 1 deletion lib/test/mockServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const mockServerArgs = async (args: Partial<ServerArgs> = {}): Promise<Se
const tables = await arcTables()

return {
dynamodb: arcTables.db,
dynamodb: tables._db,
schema,
tableNames: {
connections: ensureName(tables, 'Connection'),
Expand Down
8 changes: 8 additions & 0 deletions lib/test/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { use, assert } from 'chai'
import chaiSubset from 'chai-subset'

process.env.PORT = '6001'

global.assert = assert

use(chaiSubset)
4 changes: 0 additions & 4 deletions lib/test/setupContains.js

This file was deleted.

3 changes: 0 additions & 3 deletions lib/test/setupPorts.js

This file was deleted.

4 changes: 2 additions & 2 deletions lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ export type MessageHandler<T> = (arg: { server: ServerClosure, event: APIGateway
Matches the ApiGatewayManagementApi class from aws-sdk but only provides the methods we use
*/
export interface ApiGatewayManagementApiSubset {
postToConnection(input: { ConnectionId: string, Data: string }): { promise: () => Promise<void> }
deleteConnection(input: { ConnectionId: string }): { promise: () => Promise<void> }
postToConnection(input: { ConnectionId: string, Data: string }): { promise: () => Promise<any> }
deleteConnection(input: { ConnectionId: string }): { promise: () => Promise<any> }
}


Expand Down
6 changes: 1 addition & 5 deletions mocks/arc-basic-events/app.arc
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ basic-events

@ws

@static
folder dist

@tables
Connection
id *String
Expand All @@ -14,8 +11,7 @@ Subscription
id *String
ttl TTL

@indexes

@tables-indexes
Subscription
connectionId *String
name ConnectionIndex
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/* eslint-disable @typescript-eslint/no-var-requires */
require('esbuild-register')
const { makeExecutableSchema } = require('@graphql-tools/schema')
const { tables: arcTables, ws } = require('@architect/functions')
const { makeServer, subscribe } = require('../../../lib')
const { GraphQLError } = require('graphql')
import { makeExecutableSchema } from '@graphql-tools/schema'
import { tables as arcTables, ws } from '@architect/functions'
import { makeServer, subscribe } from '../../../lib'
import { GraphQLError } from 'graphql'

const typeDefs = `
type Query {
Expand Down Expand Up @@ -148,7 +146,7 @@ const schema = makeExecutableSchema({
const fetchTableNames = async () => {
const tables = await arcTables()

const ensureName = (table) => {
const ensureName = (table: string) => {
const actualTableName = tables.name(table)
if (!actualTableName) {
throw new Error(`No table found for ${table}`)
Expand All @@ -163,7 +161,7 @@ const fetchTableNames = async () => {
}

const subscriptionServer = makeServer({
dynamodb: arcTables.db,
dynamodb: arcTables().then(tables => tables._db),
schema,
tableNames: fetchTableNames(),
apiGatewayManagementApi: ws._api,
Expand All @@ -172,4 +170,4 @@ const subscriptionServer = makeServer({
},
})

module.exports = { subscriptionServer }
export { subscriptionServer }
1 change: 1 addition & 0 deletions mocks/arc-basic-events/src/ws/connect/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require('esbuild-register')
const { subscriptionServer } = require('../../../lib/graphql')

exports.handler = subscriptionServer.webSocketHandler
1 change: 1 addition & 0 deletions mocks/arc-basic-events/src/ws/default/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require('esbuild-register')
const { subscriptionServer } = require('../../../lib/graphql')

exports.handler = subscriptionServer.webSocketHandler
1 change: 1 addition & 0 deletions mocks/arc-basic-events/src/ws/disconnect/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require('esbuild-register')
const { subscriptionServer } = require('../../../lib/graphql')

exports.handler = subscriptionServer.webSocketHandler
Loading