@constructive-io/graphql-test 3.1.0 → 4.0.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/esm/graphile-test.js +40 -31
- package/graphile-test.d.ts +7 -0
- package/graphile-test.js +39 -30
- package/package.json +14 -10
package/esm/graphile-test.js
CHANGED
|
@@ -1,51 +1,60 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { ConstructivePreset } from 'graphile-settings';
|
|
2
|
+
import { makeSchema } from 'graphile-build';
|
|
3
|
+
import { makePgService } from 'graphile-settings';
|
|
3
4
|
import { runGraphQLInContext } from 'graphile-test/context';
|
|
5
|
+
/**
|
|
6
|
+
* Creates a GraphQL test context using PostGraphile v5 with ConstructivePreset.
|
|
7
|
+
*
|
|
8
|
+
* This is the Constructive-specific test wrapper that pre-loads all plugins
|
|
9
|
+
* from graphile-settings. For generic PostGraphile testing without the
|
|
10
|
+
* Constructive preset, use graphile-test directly.
|
|
11
|
+
*/
|
|
4
12
|
export const GraphQLTest = (input, conn) => {
|
|
5
|
-
const { schemas, authRole,
|
|
13
|
+
const { schemas, authRole, preset: userPreset } = input;
|
|
6
14
|
let schema;
|
|
7
|
-
let
|
|
15
|
+
let resolvedPreset;
|
|
16
|
+
let pgService;
|
|
8
17
|
const pgPool = conn.manager.getPool(conn.pg.config);
|
|
9
18
|
const setup = async () => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}),
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
graphileBuildOptions: {
|
|
25
|
-
...baseOptions.graphileBuildOptions,
|
|
26
|
-
...graphile.graphileBuildOptions
|
|
27
|
-
}
|
|
28
|
-
}),
|
|
29
|
-
// Apply overrideSettings if provided
|
|
30
|
-
...(graphile?.overrideSettings || {})
|
|
19
|
+
pgService = makePgService({
|
|
20
|
+
pool: pgPool,
|
|
21
|
+
schemas,
|
|
22
|
+
});
|
|
23
|
+
const completePreset = {
|
|
24
|
+
extends: [
|
|
25
|
+
ConstructivePreset,
|
|
26
|
+
...(userPreset?.extends ?? []),
|
|
27
|
+
],
|
|
28
|
+
...(userPreset?.disablePlugins && { disablePlugins: userPreset.disablePlugins }),
|
|
29
|
+
...(userPreset?.plugins && { plugins: userPreset.plugins }),
|
|
30
|
+
...(userPreset?.schema && { schema: userPreset.schema }),
|
|
31
|
+
...(userPreset?.grafast && { grafast: userPreset.grafast }),
|
|
32
|
+
pgServices: [pgService],
|
|
31
33
|
};
|
|
32
|
-
|
|
34
|
+
const result = await makeSchema(completePreset);
|
|
35
|
+
schema = result.schema;
|
|
36
|
+
resolvedPreset = result.resolvedPreset;
|
|
37
|
+
};
|
|
38
|
+
const teardown = async () => {
|
|
39
|
+
// Optional cleanup - schema is garbage collected
|
|
33
40
|
};
|
|
34
|
-
const teardown = async () => { };
|
|
35
41
|
const query = async (opts) => {
|
|
36
42
|
return await runGraphQLInContext({
|
|
37
43
|
input,
|
|
38
44
|
schema,
|
|
39
|
-
|
|
40
|
-
authRole,
|
|
45
|
+
resolvedPreset,
|
|
46
|
+
authRole: authRole ?? 'anonymous',
|
|
41
47
|
pgPool,
|
|
48
|
+
pgService,
|
|
42
49
|
conn,
|
|
43
|
-
|
|
50
|
+
query: opts.query,
|
|
51
|
+
variables: opts.variables,
|
|
52
|
+
reqOptions: opts.reqOptions,
|
|
44
53
|
});
|
|
45
54
|
};
|
|
46
55
|
return {
|
|
47
56
|
setup,
|
|
48
57
|
teardown,
|
|
49
|
-
query
|
|
58
|
+
query,
|
|
50
59
|
};
|
|
51
60
|
};
|
package/graphile-test.d.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
1
|
import type { GraphQLTestContext, GetConnectionsInput } from 'graphile-test';
|
|
2
2
|
import type { GetConnectionOpts, GetConnectionResult } from 'pgsql-test';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a GraphQL test context using PostGraphile v5 with ConstructivePreset.
|
|
5
|
+
*
|
|
6
|
+
* This is the Constructive-specific test wrapper that pre-loads all plugins
|
|
7
|
+
* from graphile-settings. For generic PostGraphile testing without the
|
|
8
|
+
* Constructive preset, use graphile-test directly.
|
|
9
|
+
*/
|
|
3
10
|
export declare const GraphQLTest: (input: GetConnectionsInput & GetConnectionOpts, conn: GetConnectionResult) => GraphQLTestContext;
|
package/graphile-test.js
CHANGED
|
@@ -2,54 +2,63 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.GraphQLTest = void 0;
|
|
4
4
|
const graphile_settings_1 = require("graphile-settings");
|
|
5
|
-
const
|
|
5
|
+
const graphile_build_1 = require("graphile-build");
|
|
6
|
+
const graphile_settings_2 = require("graphile-settings");
|
|
6
7
|
const context_1 = require("graphile-test/context");
|
|
8
|
+
/**
|
|
9
|
+
* Creates a GraphQL test context using PostGraphile v5 with ConstructivePreset.
|
|
10
|
+
*
|
|
11
|
+
* This is the Constructive-specific test wrapper that pre-loads all plugins
|
|
12
|
+
* from graphile-settings. For generic PostGraphile testing without the
|
|
13
|
+
* Constructive preset, use graphile-test directly.
|
|
14
|
+
*/
|
|
7
15
|
const GraphQLTest = (input, conn) => {
|
|
8
|
-
const { schemas, authRole,
|
|
16
|
+
const { schemas, authRole, preset: userPreset } = input;
|
|
9
17
|
let schema;
|
|
10
|
-
let
|
|
18
|
+
let resolvedPreset;
|
|
19
|
+
let pgService;
|
|
11
20
|
const pgPool = conn.manager.getPool(conn.pg.config);
|
|
12
21
|
const setup = async () => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}),
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
graphileBuildOptions: {
|
|
28
|
-
...baseOptions.graphileBuildOptions,
|
|
29
|
-
...graphile.graphileBuildOptions
|
|
30
|
-
}
|
|
31
|
-
}),
|
|
32
|
-
// Apply overrideSettings if provided
|
|
33
|
-
...(graphile?.overrideSettings || {})
|
|
22
|
+
pgService = (0, graphile_settings_2.makePgService)({
|
|
23
|
+
pool: pgPool,
|
|
24
|
+
schemas,
|
|
25
|
+
});
|
|
26
|
+
const completePreset = {
|
|
27
|
+
extends: [
|
|
28
|
+
graphile_settings_1.ConstructivePreset,
|
|
29
|
+
...(userPreset?.extends ?? []),
|
|
30
|
+
],
|
|
31
|
+
...(userPreset?.disablePlugins && { disablePlugins: userPreset.disablePlugins }),
|
|
32
|
+
...(userPreset?.plugins && { plugins: userPreset.plugins }),
|
|
33
|
+
...(userPreset?.schema && { schema: userPreset.schema }),
|
|
34
|
+
...(userPreset?.grafast && { grafast: userPreset.grafast }),
|
|
35
|
+
pgServices: [pgService],
|
|
34
36
|
};
|
|
35
|
-
|
|
37
|
+
const result = await (0, graphile_build_1.makeSchema)(completePreset);
|
|
38
|
+
schema = result.schema;
|
|
39
|
+
resolvedPreset = result.resolvedPreset;
|
|
40
|
+
};
|
|
41
|
+
const teardown = async () => {
|
|
42
|
+
// Optional cleanup - schema is garbage collected
|
|
36
43
|
};
|
|
37
|
-
const teardown = async () => { };
|
|
38
44
|
const query = async (opts) => {
|
|
39
45
|
return await (0, context_1.runGraphQLInContext)({
|
|
40
46
|
input,
|
|
41
47
|
schema,
|
|
42
|
-
|
|
43
|
-
authRole,
|
|
48
|
+
resolvedPreset,
|
|
49
|
+
authRole: authRole ?? 'anonymous',
|
|
44
50
|
pgPool,
|
|
51
|
+
pgService,
|
|
45
52
|
conn,
|
|
46
|
-
|
|
53
|
+
query: opts.query,
|
|
54
|
+
variables: opts.variables,
|
|
55
|
+
reqOptions: opts.reqOptions,
|
|
47
56
|
});
|
|
48
57
|
};
|
|
49
58
|
return {
|
|
50
59
|
setup,
|
|
51
60
|
teardown,
|
|
52
|
-
query
|
|
61
|
+
query,
|
|
53
62
|
};
|
|
54
63
|
};
|
|
55
64
|
exports.GraphQLTest = GraphQLTest;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@constructive-io/graphql-test",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"author": "Constructive <developers@constructive.io>",
|
|
5
5
|
"description": "Constructive GraphQL Testing with all plugins loaded",
|
|
6
6
|
"main": "index.js",
|
|
@@ -31,19 +31,23 @@
|
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@types/pg": "^8.16.0",
|
|
33
33
|
"graphql-tag": "2.12.6",
|
|
34
|
-
"makage": "^0.1.
|
|
34
|
+
"makage": "^0.1.10"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@constructive-io/graphql-env": "^
|
|
38
|
-
"@constructive-io/graphql-types": "^
|
|
37
|
+
"@constructive-io/graphql-env": "^3.0.0",
|
|
38
|
+
"@constructive-io/graphql-types": "^3.0.0",
|
|
39
39
|
"@pgpmjs/types": "^2.16.0",
|
|
40
|
-
"
|
|
41
|
-
"graphile-
|
|
42
|
-
"
|
|
40
|
+
"grafast": "^1.0.0-rc.4",
|
|
41
|
+
"graphile-build": "^5.0.0-rc.3",
|
|
42
|
+
"graphile-build-pg": "^5.0.0-rc.3",
|
|
43
|
+
"graphile-config": "1.0.0-rc.3",
|
|
44
|
+
"graphile-settings": "^4.0.0",
|
|
45
|
+
"graphile-test": "^4.0.0",
|
|
46
|
+
"graphql": "^16.9.0",
|
|
43
47
|
"mock-req": "^0.2.0",
|
|
44
48
|
"pg": "^8.17.1",
|
|
45
|
-
"pgsql-test": "^
|
|
46
|
-
"postgraphile": "^
|
|
49
|
+
"pgsql-test": "^4.0.0",
|
|
50
|
+
"postgraphile": "^5.0.0-rc.4"
|
|
47
51
|
},
|
|
48
52
|
"keywords": [
|
|
49
53
|
"testing",
|
|
@@ -52,5 +56,5 @@
|
|
|
52
56
|
"constructive",
|
|
53
57
|
"test"
|
|
54
58
|
],
|
|
55
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "b2daeefe49cdefb3d01ea63cf778fb9b847ab5fe"
|
|
56
60
|
}
|