graphql-server-test 0.3.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -8
- package/esm/get-connections.js +4 -3
- package/get-connections.js +4 -3
- package/package.json +2 -2
- package/types.d.ts +22 -9
package/README.md
CHANGED
|
@@ -163,28 +163,65 @@ it('matches snapshot', async () => {
|
|
|
163
163
|
| `authRole` | `string` | - | Default role for anonymous requests |
|
|
164
164
|
| `useRoot` | `boolean` | `false` | Use root/superuser for queries (bypasses RLS) |
|
|
165
165
|
| `graphile` | `GraphileOptions` | - | Graphile/PostGraphile configuration |
|
|
166
|
+
| `server` | `ServerOptions` | - | Server configuration (port, host, and API options) |
|
|
167
|
+
|
|
168
|
+
### ServerOptions
|
|
169
|
+
|
|
170
|
+
All server configuration lives under the `server` key:
|
|
171
|
+
|
|
172
|
+
| Option | Type | Default | Description |
|
|
173
|
+
|--------|------|---------|-------------|
|
|
166
174
|
| `server.port` | `number` | random | Port to run the server on |
|
|
167
175
|
| `server.host` | `string` | `localhost` | Host to bind the server to |
|
|
168
|
-
| `
|
|
176
|
+
| `server.api` | `Partial<ApiOptions>` | - | API configuration options (see below) |
|
|
177
|
+
|
|
178
|
+
### API Options
|
|
169
179
|
|
|
170
|
-
|
|
180
|
+
The `server.api` option provides full control over the GraphQL server configuration. It accepts a partial `ApiOptions` object from `@constructive-io/graphql-types`:
|
|
171
181
|
|
|
172
|
-
|
|
182
|
+
| Property | Type | Default | Description |
|
|
183
|
+
|----------|------|---------|-------------|
|
|
184
|
+
| `enableServicesApi` | `boolean` | package default | Enable domain/subdomain routing via services_public |
|
|
185
|
+
| `exposedSchemas` | `string[]` | from `schemas` | Database schemas to expose (overridden by `schemas`) |
|
|
186
|
+
| `anonRole` | `string` | from `authRole` | Anonymous role name (overridden by `authRole`) |
|
|
187
|
+
| `roleName` | `string` | from `authRole` | Default role name (overridden by `authRole`) |
|
|
188
|
+
| `defaultDatabaseId` | `string` | package default | Default database identifier |
|
|
189
|
+
| `isPublic` | `boolean` | package default | Whether the API is publicly accessible |
|
|
190
|
+
| `metaSchemas` | `string[]` | package default | Schemas containing metadata tables |
|
|
173
191
|
|
|
174
|
-
|
|
192
|
+
The convenience properties (`schemas`, `authRole`) take precedence over corresponding values in `server.api`.
|
|
175
193
|
|
|
176
194
|
```typescript
|
|
177
|
-
//
|
|
195
|
+
// Basic usage with convenience properties
|
|
178
196
|
const { query } = await getConnections({
|
|
179
197
|
schemas: ['app_public'],
|
|
180
198
|
authRole: 'anonymous'
|
|
181
199
|
});
|
|
182
200
|
|
|
183
|
-
//
|
|
201
|
+
// Disabling Services API for testing (bypasses domain routing)
|
|
184
202
|
const { query } = await getConnections({
|
|
185
203
|
schemas: ['app_public'],
|
|
186
|
-
|
|
187
|
-
|
|
204
|
+
server: {
|
|
205
|
+
api: {
|
|
206
|
+
enableServicesApi: false
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
// Full server configuration
|
|
212
|
+
const { query } = await getConnections({
|
|
213
|
+
schemas: ['app_public'],
|
|
214
|
+
authRole: 'authenticated',
|
|
215
|
+
server: {
|
|
216
|
+
port: 5555,
|
|
217
|
+
host: 'localhost',
|
|
218
|
+
api: {
|
|
219
|
+
enableServicesApi: false,
|
|
220
|
+
isPublic: false,
|
|
221
|
+
defaultDatabaseId: 'my-test-db',
|
|
222
|
+
metaSchemas: ['services_public', 'metaschema_public']
|
|
223
|
+
}
|
|
224
|
+
}
|
|
188
225
|
});
|
|
189
226
|
```
|
|
190
227
|
|
package/esm/get-connections.js
CHANGED
|
@@ -36,13 +36,14 @@ export const getConnections = async (input, seedAdapters) => {
|
|
|
36
36
|
const conn = await getPgConnections(input, seedAdapters);
|
|
37
37
|
const { pg, db, teardown: dbTeardown } = conn;
|
|
38
38
|
// Build options for the HTTP server
|
|
39
|
-
//
|
|
39
|
+
// Merge user-provided server.api options with convenience properties (schemas, authRole)
|
|
40
40
|
const serverOpts = getEnvOptions({
|
|
41
41
|
pg: pg.config,
|
|
42
42
|
api: {
|
|
43
|
-
|
|
43
|
+
// Start with user-provided api options from server.api
|
|
44
|
+
...input.server?.api,
|
|
45
|
+
// Apply convenience properties (these take precedence)
|
|
44
46
|
exposedSchemas: input.schemas,
|
|
45
|
-
defaultDatabaseId: 'test-database',
|
|
46
47
|
...(input.authRole && { anonRole: input.authRole, roleName: input.authRole })
|
|
47
48
|
},
|
|
48
49
|
graphile: input.graphile
|
package/get-connections.js
CHANGED
|
@@ -39,13 +39,14 @@ const getConnections = async (input, seedAdapters) => {
|
|
|
39
39
|
const conn = await (0, pgsql_test_1.getConnections)(input, seedAdapters);
|
|
40
40
|
const { pg, db, teardown: dbTeardown } = conn;
|
|
41
41
|
// Build options for the HTTP server
|
|
42
|
-
//
|
|
42
|
+
// Merge user-provided server.api options with convenience properties (schemas, authRole)
|
|
43
43
|
const serverOpts = (0, graphql_env_1.getEnvOptions)({
|
|
44
44
|
pg: pg.config,
|
|
45
45
|
api: {
|
|
46
|
-
|
|
46
|
+
// Start with user-provided api options from server.api
|
|
47
|
+
...input.server?.api,
|
|
48
|
+
// Apply convenience properties (these take precedence)
|
|
47
49
|
exposedSchemas: input.schemas,
|
|
48
|
-
defaultDatabaseId: 'test-database',
|
|
49
50
|
...(input.authRole && { anonRole: input.authRole, roleName: input.authRole })
|
|
50
51
|
},
|
|
51
52
|
graphile: input.graphile
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "graphql-server-test",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"author": "Constructive <developers@constructive.io>",
|
|
5
5
|
"description": "Constructive GraphQL Server Testing with SuperTest HTTP requests",
|
|
6
6
|
"main": "index.js",
|
|
@@ -57,5 +57,5 @@
|
|
|
57
57
|
"e2e",
|
|
58
58
|
"server"
|
|
59
59
|
],
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "2c23de7fdbb836104fc02610d32f7e46c3a87048"
|
|
61
61
|
}
|
package/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Server } from 'http';
|
|
2
2
|
import type { DocumentNode, GraphQLError } from 'graphql';
|
|
3
3
|
import type { PgTestClient } from 'pgsql-test/test-client';
|
|
4
|
-
import type { GraphileOptions } from '@constructive-io/graphql-types';
|
|
4
|
+
import type { GraphileOptions, ApiOptions } from '@constructive-io/graphql-types';
|
|
5
5
|
import type supertest from 'supertest';
|
|
6
6
|
/**
|
|
7
7
|
* Options for creating a test server
|
|
@@ -11,6 +11,26 @@ export interface ServerOptions {
|
|
|
11
11
|
port?: number;
|
|
12
12
|
/** Host to bind the server to (defaults to localhost) */
|
|
13
13
|
host?: string;
|
|
14
|
+
/**
|
|
15
|
+
* API configuration options for the GraphQL server.
|
|
16
|
+
* These options control how the server handles requests and which features are enabled.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const { query } = await getConnections({
|
|
21
|
+
* schemas: ['app_public'],
|
|
22
|
+
* server: {
|
|
23
|
+
* port: 5555,
|
|
24
|
+
* api: {
|
|
25
|
+
* enableServicesApi: false,
|
|
26
|
+
* isPublic: false,
|
|
27
|
+
* defaultDatabaseId: 'my-database'
|
|
28
|
+
* }
|
|
29
|
+
* }
|
|
30
|
+
* });
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
api?: Partial<ApiOptions>;
|
|
14
34
|
}
|
|
15
35
|
/**
|
|
16
36
|
* Server information returned by createTestServer
|
|
@@ -41,15 +61,8 @@ export interface GetConnectionsInput {
|
|
|
41
61
|
authRole?: string;
|
|
42
62
|
/** Graphile/PostGraphile configuration options */
|
|
43
63
|
graphile?: GraphileOptions;
|
|
44
|
-
/** Server configuration options */
|
|
64
|
+
/** Server configuration options (port, host, and API configuration) */
|
|
45
65
|
server?: ServerOptions;
|
|
46
|
-
/**
|
|
47
|
-
* Enable the Services API (domain/subdomain routing via services_public).
|
|
48
|
-
* When false (default), bypasses domain routing and directly exposes the specified schemas.
|
|
49
|
-
* When true, uses services_public to resolve which API/schemas to expose based on domain/subdomain.
|
|
50
|
-
* @default false
|
|
51
|
-
*/
|
|
52
|
-
enableServicesApi?: boolean;
|
|
53
66
|
}
|
|
54
67
|
/**
|
|
55
68
|
* GraphQL response structure
|