graphile-test 2.8.3 → 2.8.5

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
@@ -194,6 +194,8 @@ expect(result.data.createUser.username).toBe('alice');
194
194
  * Start with `getConnections()` for most use cases.
195
195
  * Consider `getConnectionsUnwrapped()` for cleaner test assertions.
196
196
 
197
+ ---
198
+
197
199
  ## Education and Tutorials
198
200
 
199
201
  1. 🚀 [Quickstart: Getting Up and Running](https://launchql.com/learn/quickstart)
@@ -268,4 +270,3 @@ Common issues and solutions for pgpm, PostgreSQL, and testing.
268
270
  AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
269
271
 
270
272
  No developer or entity involved in creating this software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the code, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.
271
-
package/context.js CHANGED
@@ -13,6 +13,7 @@ const runGraphQLInContext = async ({ input, conn, pgPool, schema, options, authR
13
13
  if (!conn.pg.client) {
14
14
  throw new Error('pgClient is required and must be provided externally.');
15
15
  }
16
+ const { res: reqRes, ...restReqOptions } = reqOptions ?? {};
16
17
  const req = new mock_req_1.default({
17
18
  url: options.graphqlRoute || '/graphql',
18
19
  method: 'POST',
@@ -20,25 +21,30 @@ const runGraphQLInContext = async ({ input, conn, pgPool, schema, options, authR
20
21
  Accept: 'application/json',
21
22
  'Content-Type': 'application/json'
22
23
  },
23
- ...reqOptions
24
+ ...restReqOptions
24
25
  });
26
+ const res = reqRes ?? {};
25
27
  const pgSettingsGenerator = options.pgSettings;
26
28
  // @ts-ignore
27
29
  const pgSettings = typeof pgSettingsGenerator === 'function'
28
30
  ? await pgSettingsGenerator(req)
29
31
  : pgSettingsGenerator || {};
32
+ const contextOptions = { ...options, pgPool, pgSettings, req, res };
30
33
  // @ts-ignore
31
- return await (0, postgraphile_1.withPostGraphileContext)({ ...options, pgPool, pgSettings }, async (context) => {
34
+ return await (0, postgraphile_1.withPostGraphileContext)(contextOptions, async (context) => {
32
35
  const pgConn = input.useRoot ? conn.pg : conn.db;
33
36
  const pgClient = pgConn.client;
34
37
  // IS THIS BAD TO HAVE ROLE HERE
35
38
  await setContextOnClient(pgClient, pgSettings, authRole);
36
39
  await pgConn.ctxQuery();
40
+ const additionalContext = typeof options.additionalGraphQLContextFromRequest === 'function'
41
+ ? await options.additionalGraphQLContextFromRequest(req, res)
42
+ : {};
37
43
  const printed = typeof query === 'string' ? query : (0, graphql_1.print)(query);
38
44
  const result = await (0, graphql_1.graphql)({
39
45
  schema,
40
46
  source: printed,
41
- contextValue: { ...context, pgClient },
47
+ contextValue: { ...context, ...additionalContext, pgClient },
42
48
  variableValues: variables ?? null
43
49
  });
44
50
  return result;
package/esm/context.js CHANGED
@@ -6,6 +6,7 @@ export const runGraphQLInContext = async ({ input, conn, pgPool, schema, options
6
6
  if (!conn.pg.client) {
7
7
  throw new Error('pgClient is required and must be provided externally.');
8
8
  }
9
+ const { res: reqRes, ...restReqOptions } = reqOptions ?? {};
9
10
  const req = new MockReq({
10
11
  url: options.graphqlRoute || '/graphql',
11
12
  method: 'POST',
@@ -13,25 +14,30 @@ export const runGraphQLInContext = async ({ input, conn, pgPool, schema, options
13
14
  Accept: 'application/json',
14
15
  'Content-Type': 'application/json'
15
16
  },
16
- ...reqOptions
17
+ ...restReqOptions
17
18
  });
19
+ const res = reqRes ?? {};
18
20
  const pgSettingsGenerator = options.pgSettings;
19
21
  // @ts-ignore
20
22
  const pgSettings = typeof pgSettingsGenerator === 'function'
21
23
  ? await pgSettingsGenerator(req)
22
24
  : pgSettingsGenerator || {};
25
+ const contextOptions = { ...options, pgPool, pgSettings, req, res };
23
26
  // @ts-ignore
24
- return await withPostGraphileContext({ ...options, pgPool, pgSettings }, async (context) => {
27
+ return await withPostGraphileContext(contextOptions, async (context) => {
25
28
  const pgConn = input.useRoot ? conn.pg : conn.db;
26
29
  const pgClient = pgConn.client;
27
30
  // IS THIS BAD TO HAVE ROLE HERE
28
31
  await setContextOnClient(pgClient, pgSettings, authRole);
29
32
  await pgConn.ctxQuery();
33
+ const additionalContext = typeof options.additionalGraphQLContextFromRequest === 'function'
34
+ ? await options.additionalGraphQLContextFromRequest(req, res)
35
+ : {};
30
36
  const printed = typeof query === 'string' ? query : print(query);
31
37
  const result = await graphql({
32
38
  schema,
33
39
  source: printed,
34
- contextValue: { ...context, pgClient },
40
+ contextValue: { ...context, ...additionalContext, pgClient },
35
41
  variableValues: variables ?? null
36
42
  });
37
43
  return result;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graphile-test",
3
- "version": "2.8.3",
3
+ "version": "2.8.5",
4
4
  "author": "Dan Lynch <pyramation@gmail.com>",
5
5
  "description": "PostGraphile Testing",
6
6
  "main": "index.js",
@@ -20,25 +20,25 @@
20
20
  "url": "https://github.com/launchql/launchql/issues"
21
21
  },
22
22
  "scripts": {
23
- "copy": "copyfiles -f ../../LICENSE README.md package.json dist",
24
- "clean": "rimraf dist/**",
23
+ "clean": "makage clean",
25
24
  "prepack": "npm run build",
26
- "build": "npm run clean; tsc -p tsconfig.json; tsc -p tsconfig.esm.json; npm run copy",
27
- "build:dev": "npm run clean; tsc -p tsconfig.json --declarationMap; tsc -p tsconfig.esm.json; npm run copy",
25
+ "build": "makage build",
26
+ "build:dev": "makage build --dev",
28
27
  "lint": "eslint . --fix",
29
28
  "test": "jest",
30
29
  "test:watch": "jest --watch"
31
30
  },
32
31
  "devDependencies": {
33
32
  "@types/pg": "^8.15.2",
34
- "graphql-tag": "2.12.6"
33
+ "graphql-tag": "2.12.6",
34
+ "makage": "^0.1.6"
35
35
  },
36
36
  "dependencies": {
37
- "@launchql/types": "^2.8.3",
37
+ "@launchql/types": "^2.8.5",
38
38
  "graphql": "15.10.1",
39
39
  "mock-req": "^0.2.0",
40
40
  "pg": "^8.16.0",
41
- "pgsql-test": "^2.14.6",
41
+ "pgsql-test": "^2.14.8",
42
42
  "postgraphile": "^4.14.1"
43
43
  },
44
44
  "keywords": [
@@ -48,5 +48,5 @@
48
48
  "launchql",
49
49
  "test"
50
50
  ],
51
- "gitHead": "4850ef84ce134d1bb43dc9132619a59257bd1157"
51
+ "gitHead": "e4643c07b6a961b964bbb132308366fc549504a1"
52
52
  }