File tree Expand file tree Collapse file tree 3 files changed +37
-2
lines changed Expand file tree Collapse file tree 3 files changed +37
-2
lines changed Original file line number Diff line number Diff line change 11// @ts -check
2- const { makePgService } = require ( "postgraphile/adaptors/pg" ) ;
2+ const {
3+ makePgService,
4+ makeWithPgClientViaPgClientAlreadyInTransaction,
5+ } = require ( "postgraphile/adaptors/pg" ) ;
36const pg = require ( "pg" ) ;
47const { readFile } = require ( "fs/promises" ) ;
58const { default : PgOrderByRelatedPlugin } = require ( "../dist/index.js" ) ;
@@ -19,10 +22,28 @@ afterAll(() => {
1922 pool ?. end ( ) ;
2023} ) ;
2124
25+ /** @type {GraphileConfig.Plugin } */
26+ const ShoveClientIntoContextPlugin = {
27+ name : "ShoveClientIntoContextPlugin" ,
28+
29+ grafast : {
30+ middleware : {
31+ prepareArgs ( next , event ) {
32+ const pgClient = event . args . contextValue . pgClient ;
33+ if ( pgClient ) {
34+ event . args . contextValue . withPgClient =
35+ makeWithPgClientViaPgClientAlreadyInTransaction ( pgClient , true ) ;
36+ }
37+ return next ( ) ;
38+ } ,
39+ } ,
40+ } ,
41+ } ;
42+
2243/** @type {(schemas: string[], options: import("postgraphile/presets/v4").V4Options) => GraphileConfig.Preset } */
2344const makePreset = ( schemas , options ) => ( {
2445 extends : [ makeV4Preset ( options ) ] ,
25- plugins : [ PgOrderByRelatedPlugin ] ,
46+ plugins : [ PgOrderByRelatedPlugin , ShoveClientIntoContextPlugin ] ,
2647 pgServices : [
2748 makePgService ( {
2849 pool,
Original file line number Diff line number Diff line change @@ -69,6 +69,10 @@ beforeAll(() => {
6969 const result = await grafast ( {
7070 schema,
7171 source,
72+ variableValues : { } ,
73+ contextValue : {
74+ pgClient,
75+ } ,
7276 resolvedPreset,
7377 requestContext : { } ,
7478 } ) ;
Original file line number Diff line number Diff line change 1+ declare global {
2+ namespace Grafast {
3+ interface Context {
4+ pgClient ?: import ( "pg" ) . PoolClient ;
5+ }
6+ }
7+ }
8+
9+ // TypeScript hack since this has to be a module
10+ export const hack = 1 ;
You can’t perform that action at this time.
0 commit comments