Skip to content

Commit 0a62056

Browse files
committed
Tidy
1 parent 2894b0e commit 0a62056

File tree

1 file changed

+18
-22
lines changed

1 file changed

+18
-22
lines changed

utils/website/graphile-config/library-authors.md

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,14 @@ By convention, scopes are camelCase strings. Scopes should be descriptive enough
1717
to reduce the chance of either conflicts across libraries or conflicts with
1818
future additions to Graphile Config.
1919

20+
<details>
21+
22+
<summary>Click for specifically reserved scope names</summary>
23+
2024
The following strings are reserved by Graphile Config, and should not be used as
2125
preset scopes or plugin scopes:
2226

27+
- Anything beginning with an underscore (`_`)
2328
- after
2429
- appendPlugins (to avoid confusion with PostGraphile v4 plugins)
2530
- before
@@ -47,6 +52,8 @@ preset scopes or plugin scopes:
4752
- skipPlugins (to avoid confusion with PostGraphile v4 plugins)
4853
- title
4954

55+
</details>
56+
5057
## Middleware
5158

5259
(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
5663
something along these lines (replacing `libraryName` with the name of your
5764
library):
5865

59-
```ts
60-
/***** interfaces.ts *****/
61-
66+
```ts title="src/interfaces.ts"
6267
// Define the middlewares that you support, their event type and their return type
6368
export interface MyMiddleware {
6469
someAction(event: SomeActionEvent): PromiseOrDirect<SomeActionResult>;
@@ -78,9 +83,9 @@ interface SomeActionEvent {
7883
type SomeActionResult = number;
7984

8085
export type PromiseOrDirect<T> = Promise<T> | T;
86+
```
8187

82-
/***** index.ts *****/
83-
88+
```ts title="src/index.ts"
8489
import type { MiddlewareHandlers } from "graphile-config";
8590

8691
// Extend Plugin with support for registering handlers for the middleware activities:
@@ -89,24 +94,13 @@ declare global {
8994
interface Plugin {
9095
libraryName?: {
9196
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-
*/
10397
};
10498
}
10599
}
106100
}
101+
```
107102

108-
/***** getMiddleware.ts *****/
109-
103+
```ts title="src/getMiddleware.ts"
110104
import { Middleware, orderedApply, resolvePreset } from "graphile-config";
111105

112106
export function getMiddleware(resolvedPreset: GraphileConfig.ResolvedPreset) {
@@ -122,9 +116,9 @@ export function getMiddleware(resolvedPreset: GraphileConfig.ResolvedPreset) {
122116
},
123117
);
124118
}
119+
```
125120

126-
/***** main.ts *****/
127-
121+
```ts title="src/main.ts"
128122
// Get the user's Graphile Config from somewhere, e.g.
129123
import config from "./graphile.config.js";
130124

@@ -140,10 +134,12 @@ const result = await middleware.run(
140134
"someAction",
141135
{ someParameter: 42 }, // < `event` object
142136
async (event) => {
143-
// Call the underlying method to perform the action.
144137
// Note: `event` will be the same object as above, but its contents may
145138
// 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);
147143
},
148144
);
149145
// The value of `result` should match the return value of `someAction(...)`

0 commit comments

Comments
 (0)