@stonecrop/rockfoil 0.30.0 → 0.32.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/dist/rockfoil.js +32 -25
- package/dist/rockfoil.js.map +1 -1
- package/dist/tsdoc-metadata.json +1 -1
- package/package.json +27 -22
- package/dist/rockfoil.tsbuildinfo +0 -1
- package/dist/src/index.d.ts +0 -3
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/index.js +0 -2
- package/dist/src/middleware/postgraphile.d.ts +0 -8
- package/dist/src/middleware/postgraphile.d.ts.map +0 -1
- package/dist/src/middleware/postgraphile.js +0 -50
- package/dist/src/types/index.d.ts +0 -32
- package/dist/src/types/index.d.ts.map +0 -1
- package/dist/src/types/index.js +0 -0
- package/src/index.ts +0 -2
- package/src/middleware/postgraphile.ts +0 -62
- package/src/types/index.ts +0 -33
package/dist/rockfoil.js
CHANGED
|
@@ -1,26 +1,33 @@
|
|
|
1
|
-
import { wrapPlans
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
import { wrapPlans } from "postgraphile/utils";
|
|
2
|
+
//#region src/middleware/postgraphile.ts
|
|
3
|
+
/**
|
|
4
|
+
* Creates a PostGraphile plugin that wraps GraphQL query and mutation plans with before/after hooks
|
|
5
|
+
* @param hookMap - Configuration mapping field names to before/after hook functions
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
var createPglRockfoilPlugin = (hookMap) => {
|
|
9
|
+
const queryPlans = {};
|
|
10
|
+
const mutationPlans = {};
|
|
11
|
+
for (const [fieldname, plans] of Object.entries(hookMap)) {
|
|
12
|
+
if (plans.beforeQuery || plans.afterQuery) queryPlans[fieldname] = { plan: (plan, $source, fieldArgs, info) => {
|
|
13
|
+
if (plans.beforeQuery) plans.beforeQuery(plan, $source, fieldArgs, info);
|
|
14
|
+
let $result = plan();
|
|
15
|
+
if (plans.afterQuery) $result = plans.afterQuery($result, plan, $source, fieldArgs, info);
|
|
16
|
+
return $result;
|
|
17
|
+
} };
|
|
18
|
+
if (plans.beforeMutation || plans.afterMutation) mutationPlans[fieldname] = { plan: (plan, $source, fieldArgs, info) => {
|
|
19
|
+
if (plans.beforeMutation) plans.beforeMutation(plan, $source, fieldArgs, info);
|
|
20
|
+
let $result = plan();
|
|
21
|
+
if (plans.afterMutation) $result = plans.afterMutation($result, plan, $source, fieldArgs, info);
|
|
22
|
+
return $result;
|
|
23
|
+
} };
|
|
24
|
+
}
|
|
25
|
+
return wrapPlans({
|
|
26
|
+
Query: queryPlans,
|
|
27
|
+
Mutation: mutationPlans
|
|
28
|
+
});
|
|
22
29
|
};
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
//# sourceMappingURL=rockfoil.js.map
|
|
30
|
+
//#endregion
|
|
31
|
+
export { createPglRockfoilPlugin };
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=rockfoil.js.map
|
package/dist/rockfoil.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rockfoil.js","sources":["../src/middleware/postgraphile.ts"],"sourcesContent":["import { wrapPlans } from 'postgraphile/utils'\n\nimport type { HookConfig, HookPlan } from '../types'\n\n/**\n * Creates a PostGraphile plugin that wraps GraphQL query and mutation plans with before/after hooks\n * @param hookMap - Configuration mapping field names to before/after hook functions\n * @public\n */\nexport const createPglRockfoilPlugin = (hookMap: HookConfig) => {\n\tconst queryPlans: HookPlan = {}\n\tconst mutationPlans: HookPlan = {}\n\n\tfor (const [fieldname, plans] of Object.entries(hookMap)) {\n\t\tif (plans.beforeQuery || plans.afterQuery) {\n\t\t\tqueryPlans[fieldname] = {\n\t\t\t\tplan: (plan, $source, fieldArgs, info) => {\n\t\t\t\t\t// Process before query hooks\n\t\t\t\t\tif (plans.beforeQuery) {\n\t\t\t\t\t\tplans.beforeQuery(plan, $source, fieldArgs, info)\n\t\t\t\t\t}\n\n\t\t\t\t\t// Execute the query plan\n\t\t\t\t\tlet $result = plan()\n\n\t\t\t\t\t// Process after query hooks\n\t\t\t\t\tif (plans.afterQuery) {\n\t\t\t\t\t\t$result = plans.afterQuery($result, plan, $source, fieldArgs, info)\n\t\t\t\t\t}\n\n\t\t\t\t\treturn $result\n\t\t\t\t},\n\t\t\t}\n\t\t}\n\n\t\tif (plans.beforeMutation || plans.afterMutation) {\n\t\t\tmutationPlans[fieldname] = {\n\t\t\t\tplan: (plan, $source, fieldArgs, info) => {\n\t\t\t\t\t// Process before mutation hooks\n\t\t\t\t\tif (plans.beforeMutation) {\n\t\t\t\t\t\tplans.beforeMutation(plan, $source, fieldArgs, info)\n\t\t\t\t\t}\n\n\t\t\t\t\t// Execute the mutation plan\n\t\t\t\t\tlet $result = plan()\n\n\t\t\t\t\t// Process after mutation hooks\n\t\t\t\t\tif (plans.afterMutation) {\n\t\t\t\t\t\t$result = plans.afterMutation($result, plan, $source, fieldArgs, info)\n\t\t\t\t\t}\n\n\t\t\t\t\treturn $result\n\t\t\t\t},\n\t\t\t}\n\t\t}\n\t}\n\n\treturn wrapPlans({\n\t\tQuery: queryPlans,\n\t\tMutation: mutationPlans,\n\t})\n}\n"],"
|
|
1
|
+
{"version":3,"file":"rockfoil.js","names":[],"sources":["../src/middleware/postgraphile.ts"],"sourcesContent":["import { wrapPlans } from 'postgraphile/utils'\n\nimport type { HookConfig, HookPlan } from '../types'\n\n/**\n * Creates a PostGraphile plugin that wraps GraphQL query and mutation plans with before/after hooks\n * @param hookMap - Configuration mapping field names to before/after hook functions\n * @public\n */\nexport const createPglRockfoilPlugin = (hookMap: HookConfig) => {\n\tconst queryPlans: HookPlan = {}\n\tconst mutationPlans: HookPlan = {}\n\n\tfor (const [fieldname, plans] of Object.entries(hookMap)) {\n\t\tif (plans.beforeQuery || plans.afterQuery) {\n\t\t\tqueryPlans[fieldname] = {\n\t\t\t\tplan: (plan, $source, fieldArgs, info) => {\n\t\t\t\t\t// Process before query hooks\n\t\t\t\t\tif (plans.beforeQuery) {\n\t\t\t\t\t\tplans.beforeQuery(plan, $source, fieldArgs, info)\n\t\t\t\t\t}\n\n\t\t\t\t\t// Execute the query plan\n\t\t\t\t\tlet $result = plan()\n\n\t\t\t\t\t// Process after query hooks\n\t\t\t\t\tif (plans.afterQuery) {\n\t\t\t\t\t\t$result = plans.afterQuery($result, plan, $source, fieldArgs, info)\n\t\t\t\t\t}\n\n\t\t\t\t\treturn $result\n\t\t\t\t},\n\t\t\t}\n\t\t}\n\n\t\tif (plans.beforeMutation || plans.afterMutation) {\n\t\t\tmutationPlans[fieldname] = {\n\t\t\t\tplan: (plan, $source, fieldArgs, info) => {\n\t\t\t\t\t// Process before mutation hooks\n\t\t\t\t\tif (plans.beforeMutation) {\n\t\t\t\t\t\tplans.beforeMutation(plan, $source, fieldArgs, info)\n\t\t\t\t\t}\n\n\t\t\t\t\t// Execute the mutation plan\n\t\t\t\t\tlet $result = plan()\n\n\t\t\t\t\t// Process after mutation hooks\n\t\t\t\t\tif (plans.afterMutation) {\n\t\t\t\t\t\t$result = plans.afterMutation($result, plan, $source, fieldArgs, info)\n\t\t\t\t\t}\n\n\t\t\t\t\treturn $result\n\t\t\t\t},\n\t\t\t}\n\t\t}\n\t}\n\n\treturn wrapPlans({\n\t\tQuery: queryPlans,\n\t\tMutation: mutationPlans,\n\t})\n}\n"],"mappings":";;;;;;;AASA,IAAa,2BAA2B,YAAwB;CAC/D,MAAM,aAAuB,CAAC;CAC9B,MAAM,gBAA0B,CAAC;CAEjC,KAAK,MAAM,CAAC,WAAW,UAAU,OAAO,QAAQ,OAAO,GAAG;EACzD,IAAI,MAAM,eAAe,MAAM,YAC9B,WAAW,aAAa,EACvB,OAAO,MAAM,SAAS,WAAW,SAAS;GAEzC,IAAI,MAAM,aACT,MAAM,YAAY,MAAM,SAAS,WAAW,IAAI;GAIjD,IAAI,UAAU,KAAK;GAGnB,IAAI,MAAM,YACT,UAAU,MAAM,WAAW,SAAS,MAAM,SAAS,WAAW,IAAI;GAGnE,OAAO;EACR,EACD;EAGD,IAAI,MAAM,kBAAkB,MAAM,eACjC,cAAc,aAAa,EAC1B,OAAO,MAAM,SAAS,WAAW,SAAS;GAEzC,IAAI,MAAM,gBACT,MAAM,eAAe,MAAM,SAAS,WAAW,IAAI;GAIpD,IAAI,UAAU,KAAK;GAGnB,IAAI,MAAM,eACT,UAAU,MAAM,cAAc,SAAS,MAAM,SAAS,WAAW,IAAI;GAGtE,OAAO;EACR,EACD;CAEF;CAEA,OAAO,UAAU;EAChB,OAAO;EACP,UAAU;CACX,CAAC;AACF"}
|
package/dist/tsdoc-metadata.json
CHANGED
package/package.json
CHANGED
|
@@ -1,43 +1,51 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stonecrop/rockfoil",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.32.0",
|
|
4
4
|
"description": "PostGraphile plugin for Stonecrop schema integration",
|
|
5
|
-
"
|
|
5
|
+
"keywords": [
|
|
6
|
+
"graphql",
|
|
7
|
+
"plugin",
|
|
8
|
+
"postgraphile",
|
|
9
|
+
"schema",
|
|
10
|
+
"stonecrop"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://github.com/agritheory/stonecrop#readme",
|
|
6
13
|
"bugs": {
|
|
7
14
|
"url": "https://github.com/agritheory/stonecrop/issues"
|
|
8
15
|
},
|
|
9
|
-
"repository": {
|
|
10
|
-
"type": "git",
|
|
11
|
-
"url": "https://github.com/agritheory/stonecrop",
|
|
12
|
-
"directory": "rockfoil"
|
|
13
|
-
},
|
|
14
16
|
"license": "MIT",
|
|
15
17
|
"author": {
|
|
16
18
|
"name": "Tyler Matteson",
|
|
17
19
|
"email": "tyler@agritheory.com"
|
|
18
20
|
},
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "https://github.com/agritheory/stonecrop",
|
|
24
|
+
"directory": "rockfoil"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist",
|
|
28
|
+
"!dist/src"
|
|
29
|
+
],
|
|
30
|
+
"type": "module",
|
|
19
31
|
"sideEffects": [
|
|
20
32
|
"**/*.css"
|
|
21
33
|
],
|
|
22
|
-
"
|
|
34
|
+
"types": "./dist/rockfoil.d.ts",
|
|
23
35
|
"exports": {
|
|
24
36
|
".": {
|
|
25
37
|
"types": "./dist/rockfoil.d.ts",
|
|
26
38
|
"import": "./dist/rockfoil.js"
|
|
27
39
|
},
|
|
28
|
-
"./types": "./dist/
|
|
40
|
+
"./types": "./dist/rockfoil.d.ts",
|
|
41
|
+
"./package.json": "./package.json"
|
|
29
42
|
},
|
|
30
|
-
"types": "./dist/rockfoil.d.ts",
|
|
31
|
-
"files": [
|
|
32
|
-
"dist/*",
|
|
33
|
-
"src/*"
|
|
34
|
-
],
|
|
35
43
|
"dependencies": {
|
|
36
44
|
"graphql": "^16.14.0",
|
|
37
45
|
"postgraphile": "^5.0.3"
|
|
38
46
|
},
|
|
39
47
|
"devDependencies": {
|
|
40
|
-
"@
|
|
48
|
+
"@microsoft/api-extractor": "^7.58.7",
|
|
41
49
|
"@types/node": "^24.12.4",
|
|
42
50
|
"@vitest/coverage-istanbul": "^4.1.5",
|
|
43
51
|
"@vitest/ui": "^4.1.5",
|
|
@@ -47,18 +55,15 @@
|
|
|
47
55
|
"oxlint": "1.67.0",
|
|
48
56
|
"oxlint-tsgolint": "0.23.0",
|
|
49
57
|
"typescript": "^6.0.3",
|
|
50
|
-
"vite": "^
|
|
51
|
-
"vitest": "^4.1.5"
|
|
52
|
-
"stonecrop-rig": "0.7.0"
|
|
58
|
+
"vite": "^8.2.2",
|
|
59
|
+
"vitest": "^4.1.5"
|
|
53
60
|
},
|
|
54
61
|
"engines": {
|
|
55
62
|
"node": ">=24.0.0"
|
|
56
63
|
},
|
|
57
64
|
"scripts": {
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"dev": "vite",
|
|
61
|
-
"docs": "bash ../common/scripts/run-docs.sh rockfoil",
|
|
65
|
+
"dev": "vite build --watch",
|
|
66
|
+
"docs": "bash ../tools/scripts/run-docs.sh rockfoil",
|
|
62
67
|
"lint": "oxlint",
|
|
63
68
|
"lint:fix": "oxlint --fix",
|
|
64
69
|
"preview": "vite preview",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":"6.0.3"}
|
package/dist/src/index.d.ts
DELETED
package/dist/src/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAA;AACzC,cAAc,SAAS,CAAA"}
|
package/dist/src/index.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { HookConfig } from '../types';
|
|
2
|
-
/**
|
|
3
|
-
* Creates a PostGraphile plugin that wraps GraphQL query and mutation plans with before/after hooks
|
|
4
|
-
* @param hookMap - Configuration mapping field names to before/after hook functions
|
|
5
|
-
* @public
|
|
6
|
-
*/
|
|
7
|
-
export declare const createPglRockfoilPlugin: (hookMap: HookConfig) => GraphileConfig.Plugin;
|
|
8
|
-
//# sourceMappingURL=postgraphile.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"postgraphile.d.ts","sourceRoot":"","sources":["../../../src/middleware/postgraphile.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAY,MAAM,UAAU,CAAA;AAEpD;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,GAAI,SAAS,UAAU,0BAoD1D,CAAA"}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { wrapPlans } from 'postgraphile/utils';
|
|
2
|
-
/**
|
|
3
|
-
* Creates a PostGraphile plugin that wraps GraphQL query and mutation plans with before/after hooks
|
|
4
|
-
* @param hookMap - Configuration mapping field names to before/after hook functions
|
|
5
|
-
* @public
|
|
6
|
-
*/
|
|
7
|
-
export const createPglRockfoilPlugin = (hookMap) => {
|
|
8
|
-
const queryPlans = {};
|
|
9
|
-
const mutationPlans = {};
|
|
10
|
-
for (const [fieldname, plans] of Object.entries(hookMap)) {
|
|
11
|
-
if (plans.beforeQuery || plans.afterQuery) {
|
|
12
|
-
queryPlans[fieldname] = {
|
|
13
|
-
plan: (plan, $source, fieldArgs, info) => {
|
|
14
|
-
// Process before query hooks
|
|
15
|
-
if (plans.beforeQuery) {
|
|
16
|
-
plans.beforeQuery(plan, $source, fieldArgs, info);
|
|
17
|
-
}
|
|
18
|
-
// Execute the query plan
|
|
19
|
-
let $result = plan();
|
|
20
|
-
// Process after query hooks
|
|
21
|
-
if (plans.afterQuery) {
|
|
22
|
-
$result = plans.afterQuery($result, plan, $source, fieldArgs, info);
|
|
23
|
-
}
|
|
24
|
-
return $result;
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
if (plans.beforeMutation || plans.afterMutation) {
|
|
29
|
-
mutationPlans[fieldname] = {
|
|
30
|
-
plan: (plan, $source, fieldArgs, info) => {
|
|
31
|
-
// Process before mutation hooks
|
|
32
|
-
if (plans.beforeMutation) {
|
|
33
|
-
plans.beforeMutation(plan, $source, fieldArgs, info);
|
|
34
|
-
}
|
|
35
|
-
// Execute the mutation plan
|
|
36
|
-
let $result = plan();
|
|
37
|
-
// Process after mutation hooks
|
|
38
|
-
if (plans.afterMutation) {
|
|
39
|
-
$result = plans.afterMutation($result, plan, $source, fieldArgs, info);
|
|
40
|
-
}
|
|
41
|
-
return $result;
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return wrapPlans({
|
|
47
|
-
Query: queryPlans,
|
|
48
|
-
Mutation: mutationPlans,
|
|
49
|
-
});
|
|
50
|
-
};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import type { ExecutableStep, FieldArgs, FieldInfo } from 'postgraphile/grafast';
|
|
2
|
-
import type { PlanWrapperFn, PlanWrapperRule } from 'postgraphile/utils';
|
|
3
|
-
/**
|
|
4
|
-
* Configuration object mapping field names to their before/after hooks for queries and mutations
|
|
5
|
-
* @public
|
|
6
|
-
*/
|
|
7
|
-
export interface HookConfig {
|
|
8
|
-
/**
|
|
9
|
-
* Hook configuration for a specific field
|
|
10
|
-
*/
|
|
11
|
-
[fieldName: string]: {
|
|
12
|
-
/** Function to execute before a query operation */
|
|
13
|
-
beforeQuery?: PlanWrapperFn;
|
|
14
|
-
/** Function to execute after a query operation */
|
|
15
|
-
afterQuery?: (result: any, plan: any, $source: ExecutableStep, fieldArgs: FieldArgs, info: FieldInfo) => any;
|
|
16
|
-
/** Function to execute before a mutation operation */
|
|
17
|
-
beforeMutation?: PlanWrapperFn;
|
|
18
|
-
/** Function to execute after a mutation operation */
|
|
19
|
-
afterMutation?: (result: any, plan: any, $source: ExecutableStep, fieldArgs: FieldArgs, info: FieldInfo) => any;
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Internal mapping of field names to their plan wrapper rules
|
|
24
|
-
* @public
|
|
25
|
-
*/
|
|
26
|
-
export interface HookPlan {
|
|
27
|
-
/**
|
|
28
|
-
* Plan wrapper rule for a specific field
|
|
29
|
-
*/
|
|
30
|
-
[fieldName: string]: PlanWrapperRule;
|
|
31
|
-
}
|
|
32
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAChF,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAExE;;;GAGG;AACH,MAAM,WAAW,UAAU;IAC1B;;OAEG;IACH,CAAC,SAAS,EAAE,MAAM,GAAG;QACpB,mDAAmD;QACnD,WAAW,CAAC,EAAE,aAAa,CAAA;QAC3B,kDAAkD;QAClD,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,KAAK,GAAG,CAAA;QAC5G,sDAAsD;QACtD,cAAc,CAAC,EAAE,aAAa,CAAA;QAC9B,qDAAqD;QACrD,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,KAAK,GAAG,CAAA;KAC/G,CAAA;CACD;AAED;;;GAGG;AACH,MAAM,WAAW,QAAQ;IACxB;;OAEG;IACH,CAAC,SAAS,EAAE,MAAM,GAAG,eAAe,CAAA;CACpC"}
|
package/dist/src/types/index.js
DELETED
|
File without changes
|
package/src/index.ts
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { wrapPlans } from 'postgraphile/utils'
|
|
2
|
-
|
|
3
|
-
import type { HookConfig, HookPlan } from '../types'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Creates a PostGraphile plugin that wraps GraphQL query and mutation plans with before/after hooks
|
|
7
|
-
* @param hookMap - Configuration mapping field names to before/after hook functions
|
|
8
|
-
* @public
|
|
9
|
-
*/
|
|
10
|
-
export const createPglRockfoilPlugin = (hookMap: HookConfig) => {
|
|
11
|
-
const queryPlans: HookPlan = {}
|
|
12
|
-
const mutationPlans: HookPlan = {}
|
|
13
|
-
|
|
14
|
-
for (const [fieldname, plans] of Object.entries(hookMap)) {
|
|
15
|
-
if (plans.beforeQuery || plans.afterQuery) {
|
|
16
|
-
queryPlans[fieldname] = {
|
|
17
|
-
plan: (plan, $source, fieldArgs, info) => {
|
|
18
|
-
// Process before query hooks
|
|
19
|
-
if (plans.beforeQuery) {
|
|
20
|
-
plans.beforeQuery(plan, $source, fieldArgs, info)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// Execute the query plan
|
|
24
|
-
let $result = plan()
|
|
25
|
-
|
|
26
|
-
// Process after query hooks
|
|
27
|
-
if (plans.afterQuery) {
|
|
28
|
-
$result = plans.afterQuery($result, plan, $source, fieldArgs, info)
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return $result
|
|
32
|
-
},
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (plans.beforeMutation || plans.afterMutation) {
|
|
37
|
-
mutationPlans[fieldname] = {
|
|
38
|
-
plan: (plan, $source, fieldArgs, info) => {
|
|
39
|
-
// Process before mutation hooks
|
|
40
|
-
if (plans.beforeMutation) {
|
|
41
|
-
plans.beforeMutation(plan, $source, fieldArgs, info)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// Execute the mutation plan
|
|
45
|
-
let $result = plan()
|
|
46
|
-
|
|
47
|
-
// Process after mutation hooks
|
|
48
|
-
if (plans.afterMutation) {
|
|
49
|
-
$result = plans.afterMutation($result, plan, $source, fieldArgs, info)
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return $result
|
|
53
|
-
},
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return wrapPlans({
|
|
59
|
-
Query: queryPlans,
|
|
60
|
-
Mutation: mutationPlans,
|
|
61
|
-
})
|
|
62
|
-
}
|
package/src/types/index.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import type { ExecutableStep, FieldArgs, FieldInfo } from 'postgraphile/grafast'
|
|
2
|
-
import type { PlanWrapperFn, PlanWrapperRule } from 'postgraphile/utils'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Configuration object mapping field names to their before/after hooks for queries and mutations
|
|
6
|
-
* @public
|
|
7
|
-
*/
|
|
8
|
-
export interface HookConfig {
|
|
9
|
-
/**
|
|
10
|
-
* Hook configuration for a specific field
|
|
11
|
-
*/
|
|
12
|
-
[fieldName: string]: {
|
|
13
|
-
/** Function to execute before a query operation */
|
|
14
|
-
beforeQuery?: PlanWrapperFn
|
|
15
|
-
/** Function to execute after a query operation */
|
|
16
|
-
afterQuery?: (result: any, plan: any, $source: ExecutableStep, fieldArgs: FieldArgs, info: FieldInfo) => any
|
|
17
|
-
/** Function to execute before a mutation operation */
|
|
18
|
-
beforeMutation?: PlanWrapperFn
|
|
19
|
-
/** Function to execute after a mutation operation */
|
|
20
|
-
afterMutation?: (result: any, plan: any, $source: ExecutableStep, fieldArgs: FieldArgs, info: FieldInfo) => any
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Internal mapping of field names to their plan wrapper rules
|
|
26
|
-
* @public
|
|
27
|
-
*/
|
|
28
|
-
export interface HookPlan {
|
|
29
|
-
/**
|
|
30
|
-
* Plan wrapper rule for a specific field
|
|
31
|
-
*/
|
|
32
|
-
[fieldName: string]: PlanWrapperRule
|
|
33
|
-
}
|