graphql-server-test 3.1.1 → 3.3.2
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 +11 -9
- package/esm/get-connections.js +8 -3
- package/esm/server.js +14 -0
- package/get-connections.js +7 -2
- package/package.json +15 -14
- package/server.d.ts +7 -0
- package/server.js +16 -1
- package/types.d.ts +12 -5
package/README.md
CHANGED
|
@@ -181,17 +181,22 @@ The `server.api` option provides full control over the GraphQL server configurat
|
|
|
181
181
|
|
|
182
182
|
| Property | Type | Default | Description |
|
|
183
183
|
|----------|------|---------|-------------|
|
|
184
|
-
| `enableScopedRouting` | `boolean` | package default | Resolve host routing through the scoped plane (`constructive_routing_public.resolve_route`); disable for static single-tenant mode |
|
|
185
184
|
| `scopedRoutingSchema` | `string` | `constructive_routing_public` | Schema that owns `resolve_route()` and the routing tables |
|
|
186
185
|
| `exposedSchemas` | `string[]` | from `schemas` | Database schemas to expose (overridden by `schemas`) |
|
|
187
186
|
| `anonRole` | `string` | from `authRole` | Anonymous role name (overridden by `authRole`) |
|
|
188
187
|
| `roleName` | `string` | from `authRole` | Default role name (overridden by `authRole`) |
|
|
189
|
-
| `defaultDatabaseId` | `string` | package default | Default database identifier |
|
|
190
188
|
| `isPublic` | `boolean` | package default | Whether the API is publicly accessible |
|
|
191
189
|
| `metaSchemas` | `string[]` | package default | Schemas containing metadata tables |
|
|
192
190
|
|
|
193
191
|
The convenience properties (`schemas`, `authRole`) take precedence over corresponding values in `server.api`.
|
|
194
192
|
|
|
193
|
+
### Choosing the server (`server.scopedRouting`)
|
|
194
|
+
|
|
195
|
+
The harness runs suites against one of two servers:
|
|
196
|
+
|
|
197
|
+
- `server.scopedRouting: true` (default) — the production `@constructive-io/graphql-server`. Every request resolves through the scoped-routing plane, so the suite must seed real routing/database records and use a real database id.
|
|
198
|
+
- `server.scopedRouting: false` — the single-tenant `@constructive-io/graphql-dev-server` (pure PostGraphile, no routing, no database id). It exposes the configured schemas directly and is for local/static suites only.
|
|
199
|
+
|
|
195
200
|
```typescript
|
|
196
201
|
// Basic usage with convenience properties
|
|
197
202
|
const { query } = await getConnections({
|
|
@@ -199,27 +204,24 @@ const { query } = await getConnections({
|
|
|
199
204
|
authRole: 'anonymous'
|
|
200
205
|
});
|
|
201
206
|
|
|
202
|
-
// Static single-tenant mode for testing (
|
|
207
|
+
// Static single-tenant mode for testing (runs the dev server, no routing)
|
|
203
208
|
const { query } = await getConnections({
|
|
204
209
|
schemas: ['app_public'],
|
|
205
210
|
server: {
|
|
206
|
-
|
|
207
|
-
enableScopedRouting: false
|
|
208
|
-
}
|
|
211
|
+
scopedRouting: false
|
|
209
212
|
}
|
|
210
213
|
});
|
|
211
214
|
|
|
212
|
-
// Full server configuration
|
|
215
|
+
// Full server configuration (production scoped-routing server)
|
|
213
216
|
const { query } = await getConnections({
|
|
214
217
|
schemas: ['app_public'],
|
|
215
218
|
authRole: 'authenticated',
|
|
216
219
|
server: {
|
|
217
220
|
port: 5555,
|
|
218
221
|
host: 'localhost',
|
|
222
|
+
scopedRouting: true,
|
|
219
223
|
api: {
|
|
220
|
-
enableScopedRouting: false,
|
|
221
224
|
isPublic: false,
|
|
222
|
-
defaultDatabaseId: 'my-test-db',
|
|
223
225
|
metaSchemas: ['constructive_routing_public', 'metaschema_public']
|
|
224
226
|
}
|
|
225
227
|
}
|
package/esm/get-connections.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getConnections as getPgConnections } from 'pgsql-test';
|
|
2
2
|
import { getEnvOptions } from '@constructive-io/graphql-env';
|
|
3
|
-
import { createTestServer } from './server';
|
|
3
|
+
import { createDevTestServer, createTestServer } from './server';
|
|
4
4
|
import { createSuperTestAgent, createQueryFn } from './supertest';
|
|
5
5
|
/**
|
|
6
6
|
* Creates connections with an HTTP server for SuperTest testing
|
|
@@ -48,8 +48,13 @@ export const getConnections = async (input, seedAdapters) => {
|
|
|
48
48
|
},
|
|
49
49
|
graphile: input.graphile
|
|
50
50
|
});
|
|
51
|
-
// Start the HTTP server
|
|
52
|
-
|
|
51
|
+
// Start the HTTP server. Suites default to the production scoped-routing
|
|
52
|
+
// server; static/single-tenant suites opt into the dev server with
|
|
53
|
+
// `server.scopedRouting: false`.
|
|
54
|
+
const scopedRouting = input.server?.scopedRouting ?? true;
|
|
55
|
+
const server = scopedRouting
|
|
56
|
+
? await createTestServer(serverOpts, input.server)
|
|
57
|
+
: await createDevTestServer(serverOpts, input.server);
|
|
53
58
|
// Create SuperTest agent
|
|
54
59
|
const request = createSuperTestAgent(server);
|
|
55
60
|
// Combined teardown function
|
package/esm/server.js
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
|
+
import { createDevServer } from '@constructive-io/graphql-dev-server';
|
|
1
2
|
import { Server } from '@constructive-io/graphql-server';
|
|
3
|
+
/**
|
|
4
|
+
* Create a single-tenant dev test server (no scoped routing, no database id).
|
|
5
|
+
*
|
|
6
|
+
* Wraps `@constructive-io/graphql-dev-server` for suites that exercise a plain
|
|
7
|
+
* PostGraphile surface against one seeded database.
|
|
8
|
+
*/
|
|
9
|
+
export const createDevTestServer = async (opts, serverOpts = {}) => {
|
|
10
|
+
const { httpServer, url, graphqlUrl, port, host, stop } = await createDevServer(opts, {
|
|
11
|
+
host: serverOpts.host ?? '127.0.0.1',
|
|
12
|
+
port: serverOpts.port ?? 0
|
|
13
|
+
});
|
|
14
|
+
return { httpServer, url, graphqlUrl, port, host, stop };
|
|
15
|
+
};
|
|
2
16
|
/**
|
|
3
17
|
* Create a test server for SuperTest testing
|
|
4
18
|
*
|
package/get-connections.js
CHANGED
|
@@ -51,8 +51,13 @@ const getConnections = async (input, seedAdapters) => {
|
|
|
51
51
|
},
|
|
52
52
|
graphile: input.graphile
|
|
53
53
|
});
|
|
54
|
-
// Start the HTTP server
|
|
55
|
-
|
|
54
|
+
// Start the HTTP server. Suites default to the production scoped-routing
|
|
55
|
+
// server; static/single-tenant suites opt into the dev server with
|
|
56
|
+
// `server.scopedRouting: false`.
|
|
57
|
+
const scopedRouting = input.server?.scopedRouting ?? true;
|
|
58
|
+
const server = scopedRouting
|
|
59
|
+
? await (0, server_1.createTestServer)(serverOpts, input.server)
|
|
60
|
+
: await (0, server_1.createDevTestServer)(serverOpts, input.server);
|
|
56
61
|
// Create SuperTest agent
|
|
57
62
|
const request = (0, supertest_1.createSuperTestAgent)(server);
|
|
58
63
|
// Combined teardown function
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "graphql-server-test",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.2",
|
|
4
4
|
"author": "Constructive <developers@constructive.io>",
|
|
5
5
|
"description": "Constructive GraphQL Server Testing with SuperTest HTTP requests",
|
|
6
6
|
"main": "index.js",
|
|
@@ -30,30 +30,31 @@
|
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@0no-co/graphql.web": "^1.2.0",
|
|
33
|
-
"@agentic-kit/ollama": "2.
|
|
34
|
-
"@constructive-io/graphql-codegen": "^5.
|
|
35
|
-
"@constructive-io/graphql-query": "^4.
|
|
33
|
+
"@agentic-kit/ollama": "2.4.2",
|
|
34
|
+
"@constructive-io/graphql-codegen": "^5.2.2",
|
|
35
|
+
"@constructive-io/graphql-query": "^4.1.2",
|
|
36
36
|
"@types/express": "^5.0.6",
|
|
37
37
|
"@types/pg": "^8.20.0",
|
|
38
38
|
"@types/supertest": "^7.2.0",
|
|
39
39
|
"appstash": "^0.7.0",
|
|
40
|
-
"gql-ast": "^3.
|
|
40
|
+
"gql-ast": "^3.14.2",
|
|
41
41
|
"inquirerer": "^4.9.1",
|
|
42
42
|
"makage": "^0.3.0",
|
|
43
43
|
"nested-obj": "^0.2.2"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@constructive-io/graphql-
|
|
47
|
-
"@constructive-io/graphql-
|
|
48
|
-
"@constructive-io/graphql-
|
|
49
|
-
"@constructive-io/
|
|
50
|
-
"@
|
|
46
|
+
"@constructive-io/graphql-dev-server": "^3.3.2",
|
|
47
|
+
"@constructive-io/graphql-env": "^3.19.2",
|
|
48
|
+
"@constructive-io/graphql-server": "^5.3.2",
|
|
49
|
+
"@constructive-io/graphql-types": "^3.18.2",
|
|
50
|
+
"@constructive-io/upload-client": "0.17.2",
|
|
51
|
+
"@pgpmjs/types": "^2.37.2",
|
|
51
52
|
"express": "^5.2.1",
|
|
52
|
-
"graphile-schema": "^2.
|
|
53
|
+
"graphile-schema": "^2.1.2",
|
|
53
54
|
"graphql": "16.13.0",
|
|
54
55
|
"pg": "^8.21.0",
|
|
55
|
-
"pg-cache": "^3.
|
|
56
|
-
"pgsql-test": "^5.
|
|
56
|
+
"pg-cache": "^3.16.2",
|
|
57
|
+
"pgsql-test": "^5.1.2",
|
|
57
58
|
"supertest": "^7.0.0"
|
|
58
59
|
},
|
|
59
60
|
"keywords": [
|
|
@@ -67,5 +68,5 @@
|
|
|
67
68
|
"e2e",
|
|
68
69
|
"server"
|
|
69
70
|
],
|
|
70
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "08741ce3a6897192c2dbc7d1da48b9f456ffb59f"
|
|
71
72
|
}
|
package/server.d.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import type { ConstructiveOptions } from '@constructive-io/graphql-types';
|
|
2
2
|
import type { ServerInfo, ServerOptions } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Create a single-tenant dev test server (no scoped routing, no database id).
|
|
5
|
+
*
|
|
6
|
+
* Wraps `@constructive-io/graphql-dev-server` for suites that exercise a plain
|
|
7
|
+
* PostGraphile surface against one seeded database.
|
|
8
|
+
*/
|
|
9
|
+
export declare const createDevTestServer: (opts: ConstructiveOptions, serverOpts?: ServerOptions) => Promise<ServerInfo>;
|
|
3
10
|
/**
|
|
4
11
|
* Create a test server for SuperTest testing
|
|
5
12
|
*
|
package/server.js
CHANGED
|
@@ -1,7 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createTestServer = void 0;
|
|
3
|
+
exports.createTestServer = exports.createDevTestServer = void 0;
|
|
4
|
+
const graphql_dev_server_1 = require("@constructive-io/graphql-dev-server");
|
|
4
5
|
const graphql_server_1 = require("@constructive-io/graphql-server");
|
|
6
|
+
/**
|
|
7
|
+
* Create a single-tenant dev test server (no scoped routing, no database id).
|
|
8
|
+
*
|
|
9
|
+
* Wraps `@constructive-io/graphql-dev-server` for suites that exercise a plain
|
|
10
|
+
* PostGraphile surface against one seeded database.
|
|
11
|
+
*/
|
|
12
|
+
const createDevTestServer = async (opts, serverOpts = {}) => {
|
|
13
|
+
const { httpServer, url, graphqlUrl, port, host, stop } = await (0, graphql_dev_server_1.createDevServer)(opts, {
|
|
14
|
+
host: serverOpts.host ?? '127.0.0.1',
|
|
15
|
+
port: serverOpts.port ?? 0
|
|
16
|
+
});
|
|
17
|
+
return { httpServer, url, graphqlUrl, port, host, stop };
|
|
18
|
+
};
|
|
19
|
+
exports.createDevTestServer = createDevTestServer;
|
|
5
20
|
/**
|
|
6
21
|
* Create a test server for SuperTest testing
|
|
7
22
|
*
|
package/types.d.ts
CHANGED
|
@@ -11,6 +11,17 @@ export interface ServerOptions {
|
|
|
11
11
|
port?: number;
|
|
12
12
|
/** Host to bind the server to (defaults to localhost) */
|
|
13
13
|
host?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Which server to run this suite against:
|
|
16
|
+
* - `true` (default): the production `@constructive-io/graphql-server`, which
|
|
17
|
+
* resolves every request through the scoped-routing plane. Suites must seed
|
|
18
|
+
* real routing/database records so `resolve_route()` returns a real
|
|
19
|
+
* database id.
|
|
20
|
+
* - `false`: the single-tenant `@constructive-io/graphql-dev-server`
|
|
21
|
+
* (pure PostGraphile, no routing, no database id) exposing the configured
|
|
22
|
+
* schemas directly. For local/static suites only.
|
|
23
|
+
*/
|
|
24
|
+
scopedRouting?: boolean;
|
|
14
25
|
/**
|
|
15
26
|
* API configuration options for the GraphQL server.
|
|
16
27
|
* These options control how the server handles requests and which features are enabled.
|
|
@@ -21,11 +32,7 @@ export interface ServerOptions {
|
|
|
21
32
|
* schemas: ['app_public'],
|
|
22
33
|
* server: {
|
|
23
34
|
* port: 5555,
|
|
24
|
-
*
|
|
25
|
-
* enableScopedRouting: false,
|
|
26
|
-
* isPublic: false,
|
|
27
|
-
* defaultDatabaseId: 'my-database'
|
|
28
|
-
* }
|
|
35
|
+
* scopedRouting: false
|
|
29
36
|
* }
|
|
30
37
|
* });
|
|
31
38
|
* ```
|