|
| 1 | +/* eslint-disable @typescript-eslint/no-empty-function */ |
1 | 2 | import { makeExecutableSchema } from '@graphql-tools/schema' |
2 | 3 | import { tables as arcTables } from '@architect/functions' |
3 | 4 | import { makeServerClosure } from '../makeServerClosure' |
@@ -33,26 +34,33 @@ const schema = makeExecutableSchema({ |
33 | 34 | resolvers, |
34 | 35 | }) |
35 | 36 |
|
| 37 | +const ensureName = (tables: any, table: string) => { |
| 38 | + const actualTableName = tables.name(table) |
| 39 | + if (!actualTableName) { |
| 40 | + throw new Error(`No table found for ${table}`) |
| 41 | + } |
| 42 | + return actualTableName |
| 43 | +} |
36 | 44 |
|
37 | | -export const mockServerContext = async (args: Partial<ServerArgs>): Promise<ServerClosure> => { |
| 45 | +export const mockServerArgs = async (args: Partial<ServerArgs> = {}): Promise<ServerArgs> => { |
38 | 46 | const tables = await arcTables() |
39 | 47 |
|
40 | | - const ensureName = (table) => { |
41 | | - const actualTableName = tables.name(table) |
42 | | - if (!actualTableName) { |
43 | | - throw new Error(`No table found for ${table}`) |
44 | | - } |
45 | | - return actualTableName |
46 | | - } |
47 | | - |
48 | | - return makeServerClosure({ |
| 48 | + return { |
49 | 49 | dynamodb: arcTables.db, |
50 | 50 | schema, |
51 | 51 | tableNames: { |
52 | | - connections: ensureName('Connection'), |
53 | | - subscriptions: ensureName('Subscription'), |
| 52 | + connections: ensureName(tables, 'Connection'), |
| 53 | + subscriptions: ensureName(tables, 'Subscription'), |
| 54 | + }, |
| 55 | + apiGatewayManagementApi: { |
| 56 | + postToConnection: () => ({ promise: async () => { } }), |
| 57 | + deleteConnection: () => ({ promise: async () => { } }), |
54 | 58 | }, |
55 | 59 | onError: (err) => { console.log('onError'); throw err }, |
56 | 60 | ...args, |
57 | | - }) |
| 61 | + } |
| 62 | +} |
| 63 | + |
| 64 | +export const mockServerContext = async (args?: Partial<ServerArgs>): Promise<ServerClosure> => { |
| 65 | + return makeServerClosure(await mockServerArgs(args)) |
58 | 66 | } |
0 commit comments