@constructive-io/graphql-test 3.1.1 → 4.0.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.
@@ -1,51 +1,60 @@
1
- import { getGraphileSettings } from 'graphile-settings';
2
- import { createPostGraphileSchema } from 'postgraphile';
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, graphile } = input;
13
+ const { schemas, authRole, preset: userPreset } = input;
6
14
  let schema;
7
- let options;
15
+ let resolvedPreset;
16
+ let pgService;
8
17
  const pgPool = conn.manager.getPool(conn.pg.config);
9
18
  const setup = async () => {
10
- // Get base settings from graphile-settings
11
- const baseOptions = getGraphileSettings({ graphile: { schema: schemas } });
12
- // Merge custom graphile options
13
- options = {
14
- ...baseOptions,
15
- // Merge appendPlugins if provided
16
- ...(graphile?.appendPlugins && {
17
- appendPlugins: [
18
- ...(baseOptions.appendPlugins || []),
19
- ...graphile.appendPlugins
20
- ]
21
- }),
22
- // Merge graphileBuildOptions if provided
23
- ...(graphile?.graphileBuildOptions && {
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
- schema = await createPostGraphileSchema(pgPool, schemas, options);
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
- options,
40
- authRole,
45
+ resolvedPreset,
46
+ authRole: authRole ?? 'anonymous',
41
47
  pgPool,
48
+ pgService,
42
49
  conn,
43
- ...opts
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
  };
@@ -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 postgraphile_1 = require("postgraphile");
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, graphile } = input;
16
+ const { schemas, authRole, preset: userPreset } = input;
9
17
  let schema;
10
- let options;
18
+ let resolvedPreset;
19
+ let pgService;
11
20
  const pgPool = conn.manager.getPool(conn.pg.config);
12
21
  const setup = async () => {
13
- // Get base settings from graphile-settings
14
- const baseOptions = (0, graphile_settings_1.getGraphileSettings)({ graphile: { schema: schemas } });
15
- // Merge custom graphile options
16
- options = {
17
- ...baseOptions,
18
- // Merge appendPlugins if provided
19
- ...(graphile?.appendPlugins && {
20
- appendPlugins: [
21
- ...(baseOptions.appendPlugins || []),
22
- ...graphile.appendPlugins
23
- ]
24
- }),
25
- // Merge graphileBuildOptions if provided
26
- ...(graphile?.graphileBuildOptions && {
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
- schema = await (0, postgraphile_1.createPostGraphileSchema)(pgPool, schemas, options);
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
- options,
43
- authRole,
48
+ resolvedPreset,
49
+ authRole: authRole ?? 'anonymous',
44
50
  pgPool,
51
+ pgService,
45
52
  conn,
46
- ...opts
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.1.1",
3
+ "version": "4.0.1",
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.12"
34
+ "makage": "^0.1.10"
35
35
  },
36
36
  "dependencies": {
37
- "@constructive-io/graphql-env": "^2.10.0",
38
- "@constructive-io/graphql-types": "^2.15.0",
37
+ "@constructive-io/graphql-env": "^3.0.0",
38
+ "@constructive-io/graphql-types": "^3.0.0",
39
39
  "@pgpmjs/types": "^2.16.0",
40
- "graphile-settings": "^3.1.1",
41
- "graphile-test": "^3.1.1",
42
- "graphql": "15.10.1",
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.1",
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": "^3.1.1",
46
- "postgraphile": "^4.14.1"
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": "49049ad3ddd762d35625f657cb42fa0862b829a0"
59
+ "gitHead": "c05d6bd3dfa36690aefe21079042666dfae801a1"
56
60
  }