graphile-test 2.1.10 → 2.1.12
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 +89 -6
- package/context.d.ts +1 -1
- package/esm/get-connections.js +162 -0
- package/esm/index.js +2 -1
- package/get-connections.d.ts +76 -0
- package/get-connections.js +173 -0
- package/graphile-test.d.ts +1 -1
- package/index.d.ts +2 -1
- package/index.js +2 -1
- package/package.json +2 -2
- package/types.d.ts +23 -4
- package/connect.d.ts +0 -19
- package/connect.js +0 -26
- package/esm/connect.js +0 -22
package/README.md
CHANGED
|
@@ -56,8 +56,8 @@ afterEach(() => db.afterEach());
|
|
|
56
56
|
afterAll(() => teardown());
|
|
57
57
|
|
|
58
58
|
it('runs a GraphQL mutation', async () => {
|
|
59
|
-
const res = await query(`mutation { ... }
|
|
60
|
-
expect(res.
|
|
59
|
+
const res = await query(`mutation { ... }`, { input: { ... } });
|
|
60
|
+
expect(res.data.createUser.username).toBe('alice');
|
|
61
61
|
});
|
|
62
62
|
```
|
|
63
63
|
|
|
@@ -67,10 +67,16 @@ it('runs a GraphQL mutation', async () => {
|
|
|
67
67
|
|
|
68
68
|
Returns an object with:
|
|
69
69
|
|
|
70
|
-
* `query` – A GraphQL executor function
|
|
70
|
+
* `query(gqlString, variables?)` – A GraphQL executor function with positional arguments
|
|
71
71
|
* `db`, `pg` – `PgTestClient` instances
|
|
72
72
|
* `teardown()` – Clean up temp DBs
|
|
73
73
|
|
|
74
|
+
**Basic Usage:**
|
|
75
|
+
```ts
|
|
76
|
+
const result = await query(`mutation { ... }`, { input: { ... } });
|
|
77
|
+
expect(result.data.createUser.username).toBe('alice');
|
|
78
|
+
```
|
|
79
|
+
|
|
74
80
|
### `PgTestClient`
|
|
75
81
|
|
|
76
82
|
Supports:
|
|
@@ -86,18 +92,93 @@ Supports:
|
|
|
86
92
|
### GraphQL mutation + snapshot
|
|
87
93
|
|
|
88
94
|
```ts
|
|
89
|
-
const res = await query(
|
|
90
|
-
expect(snapshot(res)).toMatchSnapshot();
|
|
95
|
+
const res = await query(`mutation { ... }`, { input: { ... } });
|
|
96
|
+
expect(snapshot(res.data)).toMatchSnapshot();
|
|
91
97
|
```
|
|
92
98
|
|
|
93
99
|
### RLS testing with role switch
|
|
94
100
|
|
|
95
101
|
```ts
|
|
96
102
|
db.setContext({ role: 'anonymous' });
|
|
97
|
-
const res = await query(
|
|
103
|
+
const res = await query(`query { ... }`);
|
|
98
104
|
expect(res.errors[0].message).toMatch(/permission denied/);
|
|
99
105
|
```
|
|
100
106
|
|
|
107
|
+
### Typed queries for better safety
|
|
108
|
+
|
|
109
|
+
```ts
|
|
110
|
+
interface CreateUserVariables {
|
|
111
|
+
input: {
|
|
112
|
+
user: {
|
|
113
|
+
username: string;
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
interface CreateUserResult {
|
|
119
|
+
createUser: {
|
|
120
|
+
user: {
|
|
121
|
+
id: number;
|
|
122
|
+
username: string;
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const res = await query<CreateUserResult, CreateUserVariables>(`
|
|
128
|
+
mutation CreateUser($input: CreateUserInput!) {
|
|
129
|
+
createUser(input: $input) {
|
|
130
|
+
user {
|
|
131
|
+
id
|
|
132
|
+
username
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
`,
|
|
137
|
+
{ input: { user: { username: 'alice' } } }
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
expect(res.data?.createUser.user.username).toBe('alice');
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## 🔧 Advanced Connection Options
|
|
144
|
+
|
|
145
|
+
For specific testing needs, additional connection functions are available:
|
|
146
|
+
|
|
147
|
+
### Error Handling Variants
|
|
148
|
+
- `getConnectionsUnwrapped()` – Automatically throws on GraphQL errors, returns data directly
|
|
149
|
+
|
|
150
|
+
### Debugging Variants
|
|
151
|
+
- `getConnectionsWithLogging()` – Logs all queries and responses
|
|
152
|
+
- `getConnectionsWithTiming()` – Times query execution
|
|
153
|
+
|
|
154
|
+
### Object-Based API
|
|
155
|
+
- `getConnectionsObject()` – Uses `query({ query: "...", variables: {} })` syntax
|
|
156
|
+
- `getConnectionsObjectUnwrapped()` – Object-based with automatic error throwing
|
|
157
|
+
|
|
158
|
+
**Unwrapped Example (cleaner assertions):**
|
|
159
|
+
```ts
|
|
160
|
+
import { getConnectionsUnwrapped } from 'graphile-test';
|
|
161
|
+
|
|
162
|
+
const { query } = await getConnectionsUnwrapped(config);
|
|
163
|
+
|
|
164
|
+
// Throws automatically on GraphQL errors, returns data directly
|
|
165
|
+
const result = await query(`mutation { ... }`, { input: { ... } });
|
|
166
|
+
expect(result.createUser.username).toBe('alice'); // No .data needed!
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
**Object-Based Example:**
|
|
170
|
+
```ts
|
|
171
|
+
import { getConnectionsObject } from 'graphile-test';
|
|
172
|
+
|
|
173
|
+
const { query } = await getConnectionsObject(config);
|
|
174
|
+
|
|
175
|
+
const result = await query({
|
|
176
|
+
query: `mutation { ... }`,
|
|
177
|
+
variables: { input: { ... } }
|
|
178
|
+
});
|
|
179
|
+
expect(result.data.createUser.username).toBe('alice');
|
|
180
|
+
```
|
|
181
|
+
|
|
101
182
|
## 🧱 Under the Hood
|
|
102
183
|
|
|
103
184
|
`graphile-test` wraps and extends `pgsql-test` with GraphQL helpers like `query()` and introspection snapshot tools. You can drop into raw SQL testing anytime via `pg.client.query()` (superuser) or `db.client.query()` (RLS user).
|
|
@@ -108,6 +189,8 @@ expect(res.errors[0].message).toMatch(/permission denied/);
|
|
|
108
189
|
* Always wrap tests with `beforeEach` / `afterEach`.
|
|
109
190
|
* Use `snapshot()` to track GraphQL result changes.
|
|
110
191
|
* Use `useRoot: true` to test schema visibility without RLS.
|
|
192
|
+
* Start with `getConnections()` for most use cases.
|
|
193
|
+
* Consider `getConnectionsUnwrapped()` for cleaner test assertions.
|
|
111
194
|
|
|
112
195
|
## Related LaunchQL Tooling
|
|
113
196
|
|
package/context.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { ExecutionResult, DocumentNode } from 'graphql';
|
|
|
2
2
|
import { PostGraphileOptions } from 'postgraphile';
|
|
3
3
|
import type { Client, Pool } from 'pg';
|
|
4
4
|
import { GetConnectionOpts, GetConnectionResult } from 'pgsql-test';
|
|
5
|
-
import { GetConnectionsInput } from './
|
|
5
|
+
import { GetConnectionsInput } from './types';
|
|
6
6
|
export declare const runGraphQLInContext: <T = ExecutionResult<{
|
|
7
7
|
[key: string]: any;
|
|
8
8
|
}, {
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { getConnections as getPgConnections } from 'pgsql-test';
|
|
2
|
+
import { GraphQLTest } from './graphile-test';
|
|
3
|
+
// Core unwrapping utility
|
|
4
|
+
const unwrap = (res) => {
|
|
5
|
+
if (res.errors?.length) {
|
|
6
|
+
throw new Error(JSON.stringify(res.errors, null, 2));
|
|
7
|
+
}
|
|
8
|
+
if (!res.data) {
|
|
9
|
+
throw new Error('No data returned from GraphQL query');
|
|
10
|
+
}
|
|
11
|
+
return res.data;
|
|
12
|
+
};
|
|
13
|
+
// Base connection setup - shared across all variants
|
|
14
|
+
const createConnectionsBase = async (input, seedAdapters) => {
|
|
15
|
+
const conn = await getPgConnections(input, seedAdapters);
|
|
16
|
+
const { pg, db, teardown: dbTeardown } = conn;
|
|
17
|
+
const gqlContext = GraphQLTest(input, conn);
|
|
18
|
+
await gqlContext.setup();
|
|
19
|
+
const teardown = async () => {
|
|
20
|
+
await gqlContext.teardown();
|
|
21
|
+
await dbTeardown();
|
|
22
|
+
};
|
|
23
|
+
const baseQuery = (opts) => gqlContext.query(opts);
|
|
24
|
+
const baseQueryPositional = (query, variables, commit, reqOptions) => gqlContext.query({ query, variables, commit, reqOptions });
|
|
25
|
+
return {
|
|
26
|
+
pg,
|
|
27
|
+
db,
|
|
28
|
+
teardown,
|
|
29
|
+
baseQuery,
|
|
30
|
+
baseQueryPositional
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
// ============================================================================
|
|
34
|
+
// REGULAR QUERY VERSIONS
|
|
35
|
+
// ============================================================================
|
|
36
|
+
/**
|
|
37
|
+
* Creates connections with raw GraphQL responses
|
|
38
|
+
*/
|
|
39
|
+
export const getConnectionsObject = async (input, seedAdapters) => {
|
|
40
|
+
const { pg, db, teardown, baseQuery } = await createConnectionsBase(input, seedAdapters);
|
|
41
|
+
return {
|
|
42
|
+
pg,
|
|
43
|
+
db,
|
|
44
|
+
teardown,
|
|
45
|
+
query: baseQuery
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Creates connections with unwrapped GraphQL responses (throws on errors)
|
|
50
|
+
*/
|
|
51
|
+
export const getConnectionsObjectUnwrapped = async (input, seedAdapters) => {
|
|
52
|
+
const { pg, db, teardown, baseQuery } = await createConnectionsBase(input, seedAdapters);
|
|
53
|
+
const query = async (opts) => unwrap(await baseQuery(opts));
|
|
54
|
+
return {
|
|
55
|
+
pg,
|
|
56
|
+
db,
|
|
57
|
+
teardown,
|
|
58
|
+
query
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Creates connections with logging for GraphQL queries
|
|
63
|
+
*/
|
|
64
|
+
export const getConnectionsObjectWithLogging = async (input, seedAdapters) => {
|
|
65
|
+
const { pg, db, teardown, baseQuery } = await createConnectionsBase(input, seedAdapters);
|
|
66
|
+
const query = async (opts) => {
|
|
67
|
+
console.log('Executing GraphQL query:', opts.query);
|
|
68
|
+
const result = await baseQuery(opts);
|
|
69
|
+
console.log('GraphQL result:', result);
|
|
70
|
+
return result;
|
|
71
|
+
};
|
|
72
|
+
return {
|
|
73
|
+
pg,
|
|
74
|
+
db,
|
|
75
|
+
teardown,
|
|
76
|
+
query
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Creates connections with timing for GraphQL queries
|
|
81
|
+
*/
|
|
82
|
+
export const getConnectionsObjectWithTiming = async (input, seedAdapters) => {
|
|
83
|
+
const { pg, db, teardown, baseQuery } = await createConnectionsBase(input, seedAdapters);
|
|
84
|
+
const query = async (opts) => {
|
|
85
|
+
const start = Date.now();
|
|
86
|
+
const result = await baseQuery(opts);
|
|
87
|
+
const duration = Date.now() - start;
|
|
88
|
+
console.log(`GraphQL query took ${duration}ms`);
|
|
89
|
+
return result;
|
|
90
|
+
};
|
|
91
|
+
return {
|
|
92
|
+
pg,
|
|
93
|
+
db,
|
|
94
|
+
teardown,
|
|
95
|
+
query
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
// ============================================================================
|
|
99
|
+
// POSITIONAL QUERY VERSIONS
|
|
100
|
+
// ============================================================================
|
|
101
|
+
/**
|
|
102
|
+
* Creates connections with raw GraphQL responses (positional API)
|
|
103
|
+
*/
|
|
104
|
+
export const getConnections = async (input, seedAdapters) => {
|
|
105
|
+
const { pg, db, teardown, baseQueryPositional } = await createConnectionsBase(input, seedAdapters);
|
|
106
|
+
return {
|
|
107
|
+
pg,
|
|
108
|
+
db,
|
|
109
|
+
teardown,
|
|
110
|
+
query: baseQueryPositional
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* Creates connections with unwrapped GraphQL responses (positional API, throws on errors)
|
|
115
|
+
*/
|
|
116
|
+
export const getConnectionsUnwrapped = async (input, seedAdapters) => {
|
|
117
|
+
const { pg, db, teardown, baseQueryPositional } = await createConnectionsBase(input, seedAdapters);
|
|
118
|
+
const query = async (query, variables, commit, reqOptions) => unwrap(await baseQueryPositional(query, variables, commit, reqOptions));
|
|
119
|
+
return {
|
|
120
|
+
pg,
|
|
121
|
+
db,
|
|
122
|
+
teardown,
|
|
123
|
+
query
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* Creates connections with logging for GraphQL queries (positional API)
|
|
128
|
+
*/
|
|
129
|
+
export const getConnectionsWithLogging = async (input, seedAdapters) => {
|
|
130
|
+
const { pg, db, teardown, baseQueryPositional } = await createConnectionsBase(input, seedAdapters);
|
|
131
|
+
const query = async (query, variables, commit, reqOptions) => {
|
|
132
|
+
console.log('Executing positional GraphQL query:', query);
|
|
133
|
+
const result = await baseQueryPositional(query, variables, commit, reqOptions);
|
|
134
|
+
console.log('GraphQL result:', result);
|
|
135
|
+
return result;
|
|
136
|
+
};
|
|
137
|
+
return {
|
|
138
|
+
pg,
|
|
139
|
+
db,
|
|
140
|
+
teardown,
|
|
141
|
+
query
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* Creates connections with timing for GraphQL queries (positional API)
|
|
146
|
+
*/
|
|
147
|
+
export const getConnectionsWithTiming = async (input, seedAdapters) => {
|
|
148
|
+
const { pg, db, teardown, baseQueryPositional } = await createConnectionsBase(input, seedAdapters);
|
|
149
|
+
const query = async (query, variables, commit, reqOptions) => {
|
|
150
|
+
const start = Date.now();
|
|
151
|
+
const result = await baseQueryPositional(query, variables, commit, reqOptions);
|
|
152
|
+
const duration = Date.now() - start;
|
|
153
|
+
console.log(`Positional GraphQL query took ${duration}ms`);
|
|
154
|
+
return result;
|
|
155
|
+
};
|
|
156
|
+
return {
|
|
157
|
+
pg,
|
|
158
|
+
db,
|
|
159
|
+
teardown,
|
|
160
|
+
query
|
|
161
|
+
};
|
|
162
|
+
};
|
package/esm/index.js
CHANGED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { GetConnectionOpts } from 'pgsql-test';
|
|
2
|
+
import type { PgTestClient } from 'pgsql-test/test-client';
|
|
3
|
+
import type { SeedAdapter } from 'pgsql-test/seed/types';
|
|
4
|
+
import type { GraphQLQueryFnObj, GraphQLQueryFn, GraphQLQueryUnwrappedFnObj, GraphQLQueryUnwrappedFn, GetConnectionsInput } from './types';
|
|
5
|
+
/**
|
|
6
|
+
* Creates connections with raw GraphQL responses
|
|
7
|
+
*/
|
|
8
|
+
export declare const getConnectionsObject: (input: GetConnectionsInput & GetConnectionOpts, seedAdapters?: SeedAdapter[]) => Promise<{
|
|
9
|
+
pg: PgTestClient;
|
|
10
|
+
db: PgTestClient;
|
|
11
|
+
teardown: () => Promise<void>;
|
|
12
|
+
query: GraphQLQueryFnObj;
|
|
13
|
+
}>;
|
|
14
|
+
/**
|
|
15
|
+
* Creates connections with unwrapped GraphQL responses (throws on errors)
|
|
16
|
+
*/
|
|
17
|
+
export declare const getConnectionsObjectUnwrapped: (input: GetConnectionsInput & GetConnectionOpts, seedAdapters?: SeedAdapter[]) => Promise<{
|
|
18
|
+
pg: PgTestClient;
|
|
19
|
+
db: PgTestClient;
|
|
20
|
+
teardown: () => Promise<void>;
|
|
21
|
+
query: GraphQLQueryUnwrappedFnObj;
|
|
22
|
+
}>;
|
|
23
|
+
/**
|
|
24
|
+
* Creates connections with logging for GraphQL queries
|
|
25
|
+
*/
|
|
26
|
+
export declare const getConnectionsObjectWithLogging: (input: GetConnectionsInput & GetConnectionOpts, seedAdapters?: SeedAdapter[]) => Promise<{
|
|
27
|
+
pg: PgTestClient;
|
|
28
|
+
db: PgTestClient;
|
|
29
|
+
teardown: () => Promise<void>;
|
|
30
|
+
query: GraphQLQueryFnObj;
|
|
31
|
+
}>;
|
|
32
|
+
/**
|
|
33
|
+
* Creates connections with timing for GraphQL queries
|
|
34
|
+
*/
|
|
35
|
+
export declare const getConnectionsObjectWithTiming: (input: GetConnectionsInput & GetConnectionOpts, seedAdapters?: SeedAdapter[]) => Promise<{
|
|
36
|
+
pg: PgTestClient;
|
|
37
|
+
db: PgTestClient;
|
|
38
|
+
teardown: () => Promise<void>;
|
|
39
|
+
query: GraphQLQueryFnObj;
|
|
40
|
+
}>;
|
|
41
|
+
/**
|
|
42
|
+
* Creates connections with raw GraphQL responses (positional API)
|
|
43
|
+
*/
|
|
44
|
+
export declare const getConnections: (input: GetConnectionsInput & GetConnectionOpts, seedAdapters?: SeedAdapter[]) => Promise<{
|
|
45
|
+
pg: PgTestClient;
|
|
46
|
+
db: PgTestClient;
|
|
47
|
+
teardown: () => Promise<void>;
|
|
48
|
+
query: GraphQLQueryFn;
|
|
49
|
+
}>;
|
|
50
|
+
/**
|
|
51
|
+
* Creates connections with unwrapped GraphQL responses (positional API, throws on errors)
|
|
52
|
+
*/
|
|
53
|
+
export declare const getConnectionsUnwrapped: (input: GetConnectionsInput & GetConnectionOpts, seedAdapters?: SeedAdapter[]) => Promise<{
|
|
54
|
+
pg: PgTestClient;
|
|
55
|
+
db: PgTestClient;
|
|
56
|
+
teardown: () => Promise<void>;
|
|
57
|
+
query: GraphQLQueryUnwrappedFn;
|
|
58
|
+
}>;
|
|
59
|
+
/**
|
|
60
|
+
* Creates connections with logging for GraphQL queries (positional API)
|
|
61
|
+
*/
|
|
62
|
+
export declare const getConnectionsWithLogging: (input: GetConnectionsInput & GetConnectionOpts, seedAdapters?: SeedAdapter[]) => Promise<{
|
|
63
|
+
pg: PgTestClient;
|
|
64
|
+
db: PgTestClient;
|
|
65
|
+
teardown: () => Promise<void>;
|
|
66
|
+
query: GraphQLQueryFn;
|
|
67
|
+
}>;
|
|
68
|
+
/**
|
|
69
|
+
* Creates connections with timing for GraphQL queries (positional API)
|
|
70
|
+
*/
|
|
71
|
+
export declare const getConnectionsWithTiming: (input: GetConnectionsInput & GetConnectionOpts, seedAdapters?: SeedAdapter[]) => Promise<{
|
|
72
|
+
pg: PgTestClient;
|
|
73
|
+
db: PgTestClient;
|
|
74
|
+
teardown: () => Promise<void>;
|
|
75
|
+
query: GraphQLQueryFn;
|
|
76
|
+
}>;
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getConnectionsWithTiming = exports.getConnectionsWithLogging = exports.getConnectionsUnwrapped = exports.getConnections = exports.getConnectionsObjectWithTiming = exports.getConnectionsObjectWithLogging = exports.getConnectionsObjectUnwrapped = exports.getConnectionsObject = void 0;
|
|
4
|
+
const pgsql_test_1 = require("pgsql-test");
|
|
5
|
+
const graphile_test_1 = require("./graphile-test");
|
|
6
|
+
// Core unwrapping utility
|
|
7
|
+
const unwrap = (res) => {
|
|
8
|
+
if (res.errors?.length) {
|
|
9
|
+
throw new Error(JSON.stringify(res.errors, null, 2));
|
|
10
|
+
}
|
|
11
|
+
if (!res.data) {
|
|
12
|
+
throw new Error('No data returned from GraphQL query');
|
|
13
|
+
}
|
|
14
|
+
return res.data;
|
|
15
|
+
};
|
|
16
|
+
// Base connection setup - shared across all variants
|
|
17
|
+
const createConnectionsBase = async (input, seedAdapters) => {
|
|
18
|
+
const conn = await (0, pgsql_test_1.getConnections)(input, seedAdapters);
|
|
19
|
+
const { pg, db, teardown: dbTeardown } = conn;
|
|
20
|
+
const gqlContext = (0, graphile_test_1.GraphQLTest)(input, conn);
|
|
21
|
+
await gqlContext.setup();
|
|
22
|
+
const teardown = async () => {
|
|
23
|
+
await gqlContext.teardown();
|
|
24
|
+
await dbTeardown();
|
|
25
|
+
};
|
|
26
|
+
const baseQuery = (opts) => gqlContext.query(opts);
|
|
27
|
+
const baseQueryPositional = (query, variables, commit, reqOptions) => gqlContext.query({ query, variables, commit, reqOptions });
|
|
28
|
+
return {
|
|
29
|
+
pg,
|
|
30
|
+
db,
|
|
31
|
+
teardown,
|
|
32
|
+
baseQuery,
|
|
33
|
+
baseQueryPositional
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
// ============================================================================
|
|
37
|
+
// REGULAR QUERY VERSIONS
|
|
38
|
+
// ============================================================================
|
|
39
|
+
/**
|
|
40
|
+
* Creates connections with raw GraphQL responses
|
|
41
|
+
*/
|
|
42
|
+
const getConnectionsObject = async (input, seedAdapters) => {
|
|
43
|
+
const { pg, db, teardown, baseQuery } = await createConnectionsBase(input, seedAdapters);
|
|
44
|
+
return {
|
|
45
|
+
pg,
|
|
46
|
+
db,
|
|
47
|
+
teardown,
|
|
48
|
+
query: baseQuery
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
exports.getConnectionsObject = getConnectionsObject;
|
|
52
|
+
/**
|
|
53
|
+
* Creates connections with unwrapped GraphQL responses (throws on errors)
|
|
54
|
+
*/
|
|
55
|
+
const getConnectionsObjectUnwrapped = async (input, seedAdapters) => {
|
|
56
|
+
const { pg, db, teardown, baseQuery } = await createConnectionsBase(input, seedAdapters);
|
|
57
|
+
const query = async (opts) => unwrap(await baseQuery(opts));
|
|
58
|
+
return {
|
|
59
|
+
pg,
|
|
60
|
+
db,
|
|
61
|
+
teardown,
|
|
62
|
+
query
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
exports.getConnectionsObjectUnwrapped = getConnectionsObjectUnwrapped;
|
|
66
|
+
/**
|
|
67
|
+
* Creates connections with logging for GraphQL queries
|
|
68
|
+
*/
|
|
69
|
+
const getConnectionsObjectWithLogging = async (input, seedAdapters) => {
|
|
70
|
+
const { pg, db, teardown, baseQuery } = await createConnectionsBase(input, seedAdapters);
|
|
71
|
+
const query = async (opts) => {
|
|
72
|
+
console.log('Executing GraphQL query:', opts.query);
|
|
73
|
+
const result = await baseQuery(opts);
|
|
74
|
+
console.log('GraphQL result:', result);
|
|
75
|
+
return result;
|
|
76
|
+
};
|
|
77
|
+
return {
|
|
78
|
+
pg,
|
|
79
|
+
db,
|
|
80
|
+
teardown,
|
|
81
|
+
query
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
exports.getConnectionsObjectWithLogging = getConnectionsObjectWithLogging;
|
|
85
|
+
/**
|
|
86
|
+
* Creates connections with timing for GraphQL queries
|
|
87
|
+
*/
|
|
88
|
+
const getConnectionsObjectWithTiming = async (input, seedAdapters) => {
|
|
89
|
+
const { pg, db, teardown, baseQuery } = await createConnectionsBase(input, seedAdapters);
|
|
90
|
+
const query = async (opts) => {
|
|
91
|
+
const start = Date.now();
|
|
92
|
+
const result = await baseQuery(opts);
|
|
93
|
+
const duration = Date.now() - start;
|
|
94
|
+
console.log(`GraphQL query took ${duration}ms`);
|
|
95
|
+
return result;
|
|
96
|
+
};
|
|
97
|
+
return {
|
|
98
|
+
pg,
|
|
99
|
+
db,
|
|
100
|
+
teardown,
|
|
101
|
+
query
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
exports.getConnectionsObjectWithTiming = getConnectionsObjectWithTiming;
|
|
105
|
+
// ============================================================================
|
|
106
|
+
// POSITIONAL QUERY VERSIONS
|
|
107
|
+
// ============================================================================
|
|
108
|
+
/**
|
|
109
|
+
* Creates connections with raw GraphQL responses (positional API)
|
|
110
|
+
*/
|
|
111
|
+
const getConnections = async (input, seedAdapters) => {
|
|
112
|
+
const { pg, db, teardown, baseQueryPositional } = await createConnectionsBase(input, seedAdapters);
|
|
113
|
+
return {
|
|
114
|
+
pg,
|
|
115
|
+
db,
|
|
116
|
+
teardown,
|
|
117
|
+
query: baseQueryPositional
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
exports.getConnections = getConnections;
|
|
121
|
+
/**
|
|
122
|
+
* Creates connections with unwrapped GraphQL responses (positional API, throws on errors)
|
|
123
|
+
*/
|
|
124
|
+
const getConnectionsUnwrapped = async (input, seedAdapters) => {
|
|
125
|
+
const { pg, db, teardown, baseQueryPositional } = await createConnectionsBase(input, seedAdapters);
|
|
126
|
+
const query = async (query, variables, commit, reqOptions) => unwrap(await baseQueryPositional(query, variables, commit, reqOptions));
|
|
127
|
+
return {
|
|
128
|
+
pg,
|
|
129
|
+
db,
|
|
130
|
+
teardown,
|
|
131
|
+
query
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
exports.getConnectionsUnwrapped = getConnectionsUnwrapped;
|
|
135
|
+
/**
|
|
136
|
+
* Creates connections with logging for GraphQL queries (positional API)
|
|
137
|
+
*/
|
|
138
|
+
const getConnectionsWithLogging = async (input, seedAdapters) => {
|
|
139
|
+
const { pg, db, teardown, baseQueryPositional } = await createConnectionsBase(input, seedAdapters);
|
|
140
|
+
const query = async (query, variables, commit, reqOptions) => {
|
|
141
|
+
console.log('Executing positional GraphQL query:', query);
|
|
142
|
+
const result = await baseQueryPositional(query, variables, commit, reqOptions);
|
|
143
|
+
console.log('GraphQL result:', result);
|
|
144
|
+
return result;
|
|
145
|
+
};
|
|
146
|
+
return {
|
|
147
|
+
pg,
|
|
148
|
+
db,
|
|
149
|
+
teardown,
|
|
150
|
+
query
|
|
151
|
+
};
|
|
152
|
+
};
|
|
153
|
+
exports.getConnectionsWithLogging = getConnectionsWithLogging;
|
|
154
|
+
/**
|
|
155
|
+
* Creates connections with timing for GraphQL queries (positional API)
|
|
156
|
+
*/
|
|
157
|
+
const getConnectionsWithTiming = async (input, seedAdapters) => {
|
|
158
|
+
const { pg, db, teardown, baseQueryPositional } = await createConnectionsBase(input, seedAdapters);
|
|
159
|
+
const query = async (query, variables, commit, reqOptions) => {
|
|
160
|
+
const start = Date.now();
|
|
161
|
+
const result = await baseQueryPositional(query, variables, commit, reqOptions);
|
|
162
|
+
const duration = Date.now() - start;
|
|
163
|
+
console.log(`Positional GraphQL query took ${duration}ms`);
|
|
164
|
+
return result;
|
|
165
|
+
};
|
|
166
|
+
return {
|
|
167
|
+
pg,
|
|
168
|
+
db,
|
|
169
|
+
teardown,
|
|
170
|
+
query
|
|
171
|
+
};
|
|
172
|
+
};
|
|
173
|
+
exports.getConnectionsWithTiming = getConnectionsWithTiming;
|
package/graphile-test.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { GraphQLTestContext } from './types';
|
|
2
|
-
import { GetConnectionsInput } from './
|
|
2
|
+
import { GetConnectionsInput } from './types';
|
|
3
3
|
import { GetConnectionOpts, GetConnectionResult } from 'pgsql-test';
|
|
4
4
|
export declare const GraphQLTest: (input: GetConnectionsInput & GetConnectionOpts, conn: GetConnectionResult) => GraphQLTestContext;
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
exports.seed = void 0;
|
|
18
18
|
__exportStar(require("./clean"), exports);
|
|
19
19
|
__exportStar(require("./graphile-test"), exports);
|
|
20
|
-
__exportStar(require("./
|
|
20
|
+
__exportStar(require("./get-connections"), exports);
|
|
21
|
+
__exportStar(require("./types"), exports);
|
|
21
22
|
var pgsql_test_1 = require("pgsql-test");
|
|
22
23
|
Object.defineProperty(exports, "seed", { enumerable: true, get: function () { return pgsql_test_1.seed; } });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "graphile-test",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.12",
|
|
4
4
|
"author": "Dan Lynch <pyramation@gmail.com>",
|
|
5
5
|
"description": "PostGraphile Testing",
|
|
6
6
|
"main": "index.js",
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
"launchql",
|
|
49
49
|
"test"
|
|
50
50
|
],
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "b14a3f6f36ed88684022b95b1b5d819c7ca1ad9f"
|
|
52
52
|
}
|
package/types.d.ts
CHANGED
|
@@ -1,12 +1,31 @@
|
|
|
1
|
-
import { DocumentNode,
|
|
2
|
-
export interface GraphQLQueryOptions {
|
|
1
|
+
import { DocumentNode, GraphQLError } from 'graphql';
|
|
2
|
+
export interface GraphQLQueryOptions<TVariables = Record<string, any>> {
|
|
3
3
|
query: string | DocumentNode;
|
|
4
|
-
variables?:
|
|
4
|
+
variables?: TVariables;
|
|
5
5
|
commit?: boolean;
|
|
6
6
|
reqOptions?: Record<string, any>;
|
|
7
7
|
}
|
|
8
8
|
export interface GraphQLTestContext {
|
|
9
9
|
setup: () => Promise<void>;
|
|
10
10
|
teardown: () => Promise<void>;
|
|
11
|
-
query: <
|
|
11
|
+
query: <TResult = any, TVariables = Record<string, any>>(opts: GraphQLQueryOptions<TVariables>) => Promise<TResult>;
|
|
12
12
|
}
|
|
13
|
+
export interface GetConnectionsInput {
|
|
14
|
+
useRoot?: boolean;
|
|
15
|
+
schemas: string[];
|
|
16
|
+
authRole?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface GraphQLQueryOptions<TVariables = Record<string, any>> {
|
|
19
|
+
query: string | DocumentNode;
|
|
20
|
+
variables?: TVariables;
|
|
21
|
+
commit?: boolean;
|
|
22
|
+
reqOptions?: Record<string, any>;
|
|
23
|
+
}
|
|
24
|
+
export interface GraphQLResponse<T> {
|
|
25
|
+
data?: T;
|
|
26
|
+
errors?: readonly GraphQLError[];
|
|
27
|
+
}
|
|
28
|
+
export type GraphQLQueryFnObj = <TResult = any, TVariables = Record<string, any>>(opts: GraphQLQueryOptions<TVariables>) => Promise<GraphQLResponse<TResult>>;
|
|
29
|
+
export type GraphQLQueryFn = <TResult = any, TVariables = Record<string, any>>(query: string | DocumentNode, variables?: TVariables, commit?: boolean, reqOptions?: Record<string, any>) => Promise<GraphQLResponse<TResult>>;
|
|
30
|
+
export type GraphQLQueryUnwrappedFnObj = <TResult = any, TVariables = Record<string, any>>(opts: GraphQLQueryOptions<TVariables>) => Promise<TResult>;
|
|
31
|
+
export type GraphQLQueryUnwrappedFn = <TResult = any, TVariables = Record<string, any>>(query: string | DocumentNode, variables?: TVariables, commit?: boolean, reqOptions?: Record<string, any>) => Promise<TResult>;
|
package/connect.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { GetConnectionOpts } from 'pgsql-test';
|
|
2
|
-
import type { PgTestClient } from 'pgsql-test/test-client';
|
|
3
|
-
import type { SeedAdapter } from 'pgsql-test/seed/types';
|
|
4
|
-
import type { DocumentNode, ExecutionResult } from 'graphql';
|
|
5
|
-
export type GraphQLQueryFn<T = ExecutionResult> = (query: string | DocumentNode, variables?: Record<string, any>, commit?: boolean, reqOptions?: Record<string, any>) => Promise<T>;
|
|
6
|
-
export interface GetConnectionsInput {
|
|
7
|
-
useRoot?: boolean;
|
|
8
|
-
schemas: string[];
|
|
9
|
-
authRole?: string;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Combines PostgreSQL test setup with GraphQL test context
|
|
13
|
-
*/
|
|
14
|
-
export declare const getConnections: (input: GetConnectionsInput & GetConnectionOpts, seedAdapters?: SeedAdapter[]) => Promise<{
|
|
15
|
-
pg: PgTestClient;
|
|
16
|
-
db: PgTestClient;
|
|
17
|
-
teardown: () => Promise<void>;
|
|
18
|
-
query: GraphQLQueryFn;
|
|
19
|
-
}>;
|
package/connect.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getConnections = void 0;
|
|
4
|
-
const pgsql_test_1 = require("pgsql-test");
|
|
5
|
-
const graphile_test_1 = require("./graphile-test");
|
|
6
|
-
/**
|
|
7
|
-
* Combines PostgreSQL test setup with GraphQL test context
|
|
8
|
-
*/
|
|
9
|
-
const getConnections = async (input, seedAdapters) => {
|
|
10
|
-
const conn = await (0, pgsql_test_1.getConnections)(input, seedAdapters);
|
|
11
|
-
const { pg, db, teardown: dbTeardown } = conn;
|
|
12
|
-
const gqlContext = (0, graphile_test_1.GraphQLTest)(input, conn);
|
|
13
|
-
await gqlContext.setup();
|
|
14
|
-
const teardown = async () => {
|
|
15
|
-
await gqlContext.teardown();
|
|
16
|
-
await dbTeardown();
|
|
17
|
-
};
|
|
18
|
-
const query = (query, variables, commit, reqOptions) => gqlContext.query({ query, variables, commit, reqOptions });
|
|
19
|
-
return {
|
|
20
|
-
pg,
|
|
21
|
-
db,
|
|
22
|
-
teardown,
|
|
23
|
-
query
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
exports.getConnections = getConnections;
|
package/esm/connect.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { getConnections as getPgConnections } from 'pgsql-test';
|
|
2
|
-
import { GraphQLTest } from './graphile-test';
|
|
3
|
-
/**
|
|
4
|
-
* Combines PostgreSQL test setup with GraphQL test context
|
|
5
|
-
*/
|
|
6
|
-
export const getConnections = async (input, seedAdapters) => {
|
|
7
|
-
const conn = await getPgConnections(input, seedAdapters);
|
|
8
|
-
const { pg, db, teardown: dbTeardown } = conn;
|
|
9
|
-
const gqlContext = GraphQLTest(input, conn);
|
|
10
|
-
await gqlContext.setup();
|
|
11
|
-
const teardown = async () => {
|
|
12
|
-
await gqlContext.teardown();
|
|
13
|
-
await dbTeardown();
|
|
14
|
-
};
|
|
15
|
-
const query = (query, variables, commit, reqOptions) => gqlContext.query({ query, variables, commit, reqOptions });
|
|
16
|
-
return {
|
|
17
|
-
pg,
|
|
18
|
-
db,
|
|
19
|
-
teardown,
|
|
20
|
-
query
|
|
21
|
-
};
|
|
22
|
-
};
|