graphql-server-test 0.3.0 → 0.3.1
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 +30 -8
- package/esm/get-connections.js +3 -2
- package/get-connections.js +3 -2
- package/package.json +2 -2
- package/types.d.ts +7 -0
package/README.md
CHANGED
|
@@ -157,14 +157,36 @@ it('matches snapshot', async () => {
|
|
|
157
157
|
|
|
158
158
|
### GetConnectionsInput
|
|
159
159
|
|
|
160
|
-
| Option | Type | Description |
|
|
161
|
-
|
|
162
|
-
| `schemas` | `string[]` | PostgreSQL schemas to expose in GraphQL |
|
|
163
|
-
| `authRole` | `string` | Default role for anonymous requests |
|
|
164
|
-
| `useRoot` | `boolean` | Use root/superuser for queries (bypasses RLS) |
|
|
165
|
-
| `graphile` | `GraphileOptions` | Graphile/PostGraphile configuration |
|
|
166
|
-
| `server.port` | `number` | Port to run the server on
|
|
167
|
-
| `server.host` | `string` | Host to bind the server to
|
|
160
|
+
| Option | Type | Default | Description |
|
|
161
|
+
|--------|------|---------|-------------|
|
|
162
|
+
| `schemas` | `string[]` | required | PostgreSQL schemas to expose in GraphQL |
|
|
163
|
+
| `authRole` | `string` | - | Default role for anonymous requests |
|
|
164
|
+
| `useRoot` | `boolean` | `false` | Use root/superuser for queries (bypasses RLS) |
|
|
165
|
+
| `graphile` | `GraphileOptions` | - | Graphile/PostGraphile configuration |
|
|
166
|
+
| `server.port` | `number` | random | Port to run the server on |
|
|
167
|
+
| `server.host` | `string` | `localhost` | Host to bind the server to |
|
|
168
|
+
| `enableServicesApi` | `boolean` | `false` | Enable domain/subdomain routing via services_public |
|
|
169
|
+
|
|
170
|
+
### Services API
|
|
171
|
+
|
|
172
|
+
By default, `enableServicesApi` is set to `false`, which bypasses domain/subdomain routing and directly exposes the schemas you specify. This is the recommended setting for most testing scenarios.
|
|
173
|
+
|
|
174
|
+
When `enableServicesApi` is `true`, the server uses the `services_public` schema to resolve which API and schemas to expose based on the incoming request's domain/subdomain. This is useful when you need to test the full domain routing behavior.
|
|
175
|
+
|
|
176
|
+
```typescript
|
|
177
|
+
// Default: bypasses domain routing, directly exposes specified schemas
|
|
178
|
+
const { query } = await getConnections({
|
|
179
|
+
schemas: ['app_public'],
|
|
180
|
+
authRole: 'anonymous'
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
// With Services API enabled: uses domain/subdomain routing
|
|
184
|
+
const { query } = await getConnections({
|
|
185
|
+
schemas: ['app_public'],
|
|
186
|
+
authRole: 'anonymous',
|
|
187
|
+
enableServicesApi: true
|
|
188
|
+
});
|
|
189
|
+
```
|
|
168
190
|
|
|
169
191
|
## Comparison with Other Test Packages
|
|
170
192
|
|
package/esm/get-connections.js
CHANGED
|
@@ -35,11 +35,12 @@ export const getConnections = async (input, seedAdapters) => {
|
|
|
35
35
|
// Get database connections using pgsql-test
|
|
36
36
|
const conn = await getPgConnections(input, seedAdapters);
|
|
37
37
|
const { pg, db, teardown: dbTeardown } = conn;
|
|
38
|
-
// Build options for the HTTP server
|
|
38
|
+
// Build options for the HTTP server
|
|
39
|
+
// enableServicesApi defaults to false for testing (bypasses domain routing)
|
|
39
40
|
const serverOpts = getEnvOptions({
|
|
40
41
|
pg: pg.config,
|
|
41
42
|
api: {
|
|
42
|
-
enableServicesApi: false,
|
|
43
|
+
enableServicesApi: input.enableServicesApi ?? false,
|
|
43
44
|
exposedSchemas: input.schemas,
|
|
44
45
|
defaultDatabaseId: 'test-database',
|
|
45
46
|
...(input.authRole && { anonRole: input.authRole, roleName: input.authRole })
|
package/get-connections.js
CHANGED
|
@@ -38,11 +38,12 @@ const getConnections = async (input, seedAdapters) => {
|
|
|
38
38
|
// Get database connections using pgsql-test
|
|
39
39
|
const conn = await (0, pgsql_test_1.getConnections)(input, seedAdapters);
|
|
40
40
|
const { pg, db, teardown: dbTeardown } = conn;
|
|
41
|
-
// Build options for the HTTP server
|
|
41
|
+
// Build options for the HTTP server
|
|
42
|
+
// enableServicesApi defaults to false for testing (bypasses domain routing)
|
|
42
43
|
const serverOpts = (0, graphql_env_1.getEnvOptions)({
|
|
43
44
|
pg: pg.config,
|
|
44
45
|
api: {
|
|
45
|
-
enableServicesApi: false,
|
|
46
|
+
enableServicesApi: input.enableServicesApi ?? false,
|
|
46
47
|
exposedSchemas: input.schemas,
|
|
47
48
|
defaultDatabaseId: 'test-database',
|
|
48
49
|
...(input.authRole && { anonRole: input.authRole, roleName: input.authRole })
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "graphql-server-test",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
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": "480672e14ed6050622f50bace9c647580128688e"
|
|
61
61
|
}
|
package/types.d.ts
CHANGED
|
@@ -43,6 +43,13 @@ export interface GetConnectionsInput {
|
|
|
43
43
|
graphile?: GraphileOptions;
|
|
44
44
|
/** Server configuration options */
|
|
45
45
|
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;
|
|
46
53
|
}
|
|
47
54
|
/**
|
|
48
55
|
* GraphQL response structure
|