@@ -17,9 +17,14 @@ By convention, scopes are camelCase strings. Scopes should be descriptive enough
17
17
to reduce the chance of either conflicts across libraries or conflicts with
18
18
future additions to Graphile Config.
19
19
20
+ <details >
21
+
22
+ <summary >Click for specifically reserved scope names</summary >
23
+
20
24
The following strings are reserved by Graphile Config, and should not be used as
21
25
preset scopes or plugin scopes:
22
26
27
+ - Anything beginning with an underscore (` _ ` )
23
28
- after
24
29
- appendPlugins (to avoid confusion with PostGraphile v4 plugins)
25
30
- before
@@ -47,6 +52,8 @@ preset scopes or plugin scopes:
47
52
- skipPlugins (to avoid confusion with PostGraphile v4 plugins)
48
53
- title
49
54
55
+ </details >
56
+
50
57
## Middleware
51
58
52
59
(This section was primarily written by Benjie for Benjie... so you may want to
@@ -56,9 +63,7 @@ If you need to create a middleware system for your library, you might follow
56
63
something along these lines (replacing ` libraryName ` with the name of your
57
64
library):
58
65
59
- ``` ts
60
- /** *** interfaces.ts *****/
61
-
66
+ ``` ts title="src/interfaces.ts"
62
67
// Define the middlewares that you support, their event type and their return type
63
68
export interface MyMiddleware {
64
69
someAction(event : SomeActionEvent ): PromiseOrDirect <SomeActionResult >;
@@ -78,9 +83,9 @@ interface SomeActionEvent {
78
83
type SomeActionResult = number ;
79
84
80
85
export type PromiseOrDirect <T > = Promise <T > | T ;
86
+ ```
81
87
82
- /** *** index.ts *****/
83
-
88
+ ``` ts title="src/index.ts"
84
89
import type { MiddlewareHandlers } from " graphile-config" ;
85
90
86
91
// Extend Plugin with support for registering handlers for the middleware activities:
@@ -89,24 +94,13 @@ declare global {
89
94
interface Plugin {
90
95
libraryName? : {
91
96
middleware? : MiddlewareHandlers <MyMiddleware >;
92
-
93
- // Prior to graphile-config@0.0.1-beta.12, a more verbose alternative was required:
94
- /*
95
- middleware?: {
96
- [key in keyof MyMiddleware]?: CallbackOrDescriptor<
97
- MyMiddleware[key] extends (...args: infer UArgs) => infer UResult
98
- ? (next: MiddlewareNext<UResult>, ...args: UArgs) => UResult
99
- : never
100
- >;
101
- };
102
- */
103
97
};
104
98
}
105
99
}
106
100
}
101
+ ```
107
102
108
- /** *** getMiddleware.ts *****/
109
-
103
+ ``` ts title="src/getMiddleware.ts"
110
104
import { Middleware , orderedApply , resolvePreset } from " graphile-config" ;
111
105
112
106
export function getMiddleware(resolvedPreset : GraphileConfig .ResolvedPreset ) {
@@ -122,9 +116,9 @@ export function getMiddleware(resolvedPreset: GraphileConfig.ResolvedPreset) {
122
116
},
123
117
);
124
118
}
119
+ ```
125
120
126
- /** *** main.ts *****/
127
-
121
+ ``` ts title="src/main.ts"
128
122
// Get the user's Graphile Config from somewhere, e.g.
129
123
import config from " ./graphile.config.js" ;
130
124
@@ -140,10 +134,12 @@ const result = await middleware.run(
140
134
" someAction" ,
141
135
{ someParameter: 42 }, // < `event` object
142
136
async (event ) => {
143
- // Call the underlying method to perform the action.
144
137
// Note: `event` will be the same object as above, but its contents may
145
138
// have been modified by middlewares.
146
- return await someAction (event .someParameter );
139
+ const { someParameter } = event ;
140
+
141
+ // Call the underlying method to perform the action.
142
+ return await someAction (someParameter );
147
143
},
148
144
);
149
145
// The value of `result` should match the return value of `someAction(...)`
0 commit comments