graphql-server-test 0.3.0 → 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 CHANGED
@@ -157,14 +157,73 @@ 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 (default: random) |
167
- | `server.host` | `string` | Host to bind the server to (default: localhost) |
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` | `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
+ |--------|------|---------|-------------|
174
+ | `server.port` | `number` | random | Port to run the server on |
175
+ | `server.host` | `string` | `localhost` | Host to bind the server to |
176
+ | `server.api` | `Partial<ApiOptions>` | - | API configuration options (see below) |
177
+
178
+ ### API Options
179
+
180
+ The `server.api` option provides full control over the GraphQL server configuration. It accepts a partial `ApiOptions` object from `@constructive-io/graphql-types`:
181
+
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 |
191
+
192
+ The convenience properties (`schemas`, `authRole`) take precedence over corresponding values in `server.api`.
193
+
194
+ ```typescript
195
+ // Basic usage with convenience properties
196
+ const { query } = await getConnections({
197
+ schemas: ['app_public'],
198
+ authRole: 'anonymous'
199
+ });
200
+
201
+ // Disabling Services API for testing (bypasses domain routing)
202
+ const { query } = await getConnections({
203
+ schemas: ['app_public'],
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
+ }
225
+ });
226
+ ```
168
227
 
169
228
  ## Comparison with Other Test Packages
170
229
 
@@ -35,13 +35,15 @@ 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 with enableServicesApi: false
38
+ // Build options for the HTTP server
39
+ // Merge user-provided server.api options with convenience properties (schemas, authRole)
39
40
  const serverOpts = getEnvOptions({
40
41
  pg: pg.config,
41
42
  api: {
42
- enableServicesApi: false,
43
+ // Start with user-provided api options from server.api
44
+ ...input.server?.api,
45
+ // Apply convenience properties (these take precedence)
43
46
  exposedSchemas: input.schemas,
44
- defaultDatabaseId: 'test-database',
45
47
  ...(input.authRole && { anonRole: input.authRole, roleName: input.authRole })
46
48
  },
47
49
  graphile: input.graphile
@@ -38,13 +38,15 @@ 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 with enableServicesApi: false
41
+ // Build options for the HTTP server
42
+ // Merge user-provided server.api options with convenience properties (schemas, authRole)
42
43
  const serverOpts = (0, graphql_env_1.getEnvOptions)({
43
44
  pg: pg.config,
44
45
  api: {
45
- enableServicesApi: false,
46
+ // Start with user-provided api options from server.api
47
+ ...input.server?.api,
48
+ // Apply convenience properties (these take precedence)
46
49
  exposedSchemas: input.schemas,
47
- defaultDatabaseId: 'test-database',
48
50
  ...(input.authRole && { anonRole: input.authRole, roleName: input.authRole })
49
51
  },
50
52
  graphile: input.graphile
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graphql-server-test",
3
- "version": "0.3.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": "03a70081e7a3d761c43432866726ddf641e05531"
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,7 +61,7 @@ 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
66
  }
47
67
  /**