graphile-config
Advanced tools
Comparing version 0.0.1-beta.8 to 0.0.1-beta.9
# graphile-config | ||
## 0.0.1-beta.9 | ||
### Patch Changes | ||
- [#2071](https://github.com/graphile/crystal/pull/2071) | ||
[`582bd768f`](https://github.com/graphile/crystal/commit/582bd768fec403ce3284f293b85b9fd86e4d3f40) | ||
Thanks [@benjie](https://github.com/benjie)! - `GrafastExecutionArgs` now | ||
accepts `resolvedPreset` and `requestContext` directly; passing these through | ||
additional arguments is now deprecated and support will be removed in a future | ||
revision. This affects: | ||
- `grafast()` | ||
- `execute()` | ||
- `subscribe()` | ||
- `hookArgs()` | ||
`graphile-config` has gained a middleware system which is more powerful than | ||
it's AsyncHooks system. Old hooks can be emulated through the middleware | ||
system safely since middleware is a superset of hooks' capabilities. | ||
`applyHooks` has been renamed to `orderedApply` (because it applies to more | ||
than just hooks), calling `applyHooks` will still work but is deprecated. | ||
🚨 `grafast` no longer automatically reads your `graphile.config.ts` or | ||
similar; you must do that yourself and pass the `resolvedPreset` to grafast | ||
via the `args`. This is to aid in bundling of grafast since it should not need | ||
to read from filesystem or dynamically load modules. | ||
`grafast` no longer outputs performance warning when you set | ||
`GRAPHILE_ENV=development`. | ||
🚨 `plugin.grafast.hooks.args` is now `plugin.grafast.middleware.prepareArgs`, | ||
and the signature has changed - you must be sure to call the `next()` function | ||
and ctx/resolvedPreset can be extracted directly from `args`: | ||
```diff | ||
const plugin = { | ||
grafast: { | ||
- hooks: { | ||
+ middleware: { | ||
- args({ args, ctx, resolvedPreset }) { | ||
+ prepareArgs(next, { args }) { | ||
+ const { requestContext: ctx, resolvedPreset } = args; | ||
// ... | ||
+ return next(); | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
Many more middleware have been added; use TypeScript's autocomplete to see | ||
what's available until we have proper documentation for them. | ||
`plugin.grafserv.hooks.*` are still supported but deprecated; instead use | ||
middleware `plugin.grafserv.middleware.*` (note that call signatures have | ||
changed slightly, similar to the diff above): | ||
- `hooks.init` -> `middleware.setPreset` | ||
- `hooks.processGraphQLRequestBody` -> `middleware.processGraphQLRequestBody` | ||
- `hooks.ruruHTMLParts` -> `middleware.ruruHTMLParts` | ||
A few TypeScript types related to Hooks have been renamed, but their old names | ||
are still available, just deprecated. They will be removed in a future update: | ||
- `HookObject` -> `FunctionalityObject` | ||
- `PluginHook` -> `CallbackOrDescriptor` | ||
- `PluginHookObject` -> `CallbackDescriptor` | ||
- `PluginHookCallback` -> `UnwrapCallback` | ||
## 0.0.1-beta.8 | ||
@@ -4,0 +73,0 @@ |
@@ -1,8 +0,8 @@ | ||
import type { PluginHook } from "./interfaces.js"; | ||
export type HookObject<T> = Record<keyof T, PluginHook<(...args: any[]) => any>>; | ||
export declare class AsyncHooks<THooks extends HookObject<THooks>> { | ||
import { orderedApply } from "./functionality.js"; | ||
import type { CallbackDescriptor, CallbackOrDescriptor, FunctionalityObject, PromiseOrDirect, UnwrapCallback } from "./interfaces.js"; | ||
export declare class AsyncHooks<THooks extends FunctionalityObject<THooks>> { | ||
callbacks: { | ||
[key in keyof THooks]?: Array<THooks[keyof THooks] extends PluginHook<infer U> ? U : never>; | ||
[key in keyof THooks]?: Array<THooks[keyof THooks] extends CallbackOrDescriptor<infer U> ? U : never>; | ||
}; | ||
hook<THookName extends keyof THooks>(event: THookName, fn: THooks[THookName] extends PluginHook<infer U> ? U : never): void; | ||
hook<THookName extends keyof THooks>(event: THookName, fn: THooks[THookName] extends CallbackOrDescriptor<infer U> ? U : never): void; | ||
/** | ||
@@ -12,5 +12,14 @@ * Hooks can _mutate_ the argument, they cannot return a replacement. This | ||
*/ | ||
process<THookName extends keyof THooks>(event: THookName, ...args: Parameters<THooks[THookName] extends PluginHook<infer U> ? U : never>): void | Promise<void>; | ||
process<THookName extends keyof THooks>(hookName: THookName, ...args: Parameters<THooks[THookName] extends CallbackOrDescriptor<infer U> ? U : never>): void | Promise<void>; | ||
} | ||
export declare function applyHooks<THooks extends HookObject<THooks>>(plugins: readonly GraphileConfig.Plugin[] | undefined, hooksRetriever: (plugin: GraphileConfig.Plugin) => Partial<THooks> | undefined, applyHookCallback: <THookName extends keyof THooks>(hookName: THookName, hookFn: THooks[THookName] extends PluginHook<infer U> ? U : never, plugin: GraphileConfig.Plugin) => void): void; | ||
/** @deprecated Use FunctionalityObject */ | ||
export type HookObject<T> = FunctionalityObject<T>; | ||
/** @deprecated Use `orderedApply` */ | ||
export declare const applyHooks: typeof orderedApply; | ||
/** @deprecated Use CallbackDescriptor */ | ||
export type PluginHookObject<T extends (...args: any[]) => any> = CallbackDescriptor<T>; | ||
/** @deprecated Use CallbackOrDescriptor */ | ||
export type PluginHook<T extends (...args: any[]) => PromiseOrDirect<UnwrapCallback<any> | void>> = CallbackOrDescriptor<T>; | ||
/** @deprecated Use UnwrapCallback */ | ||
export type PluginHookCallback<T extends CallbackOrDescriptor<(...args: any[]) => any>> = UnwrapCallback<T>; | ||
//# sourceMappingURL=hooks.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.applyHooks = exports.AsyncHooks = void 0; | ||
const sort_js_1 = require("./sort.js"); | ||
const functionality_js_1 = require("./functionality.js"); | ||
const isDev = process.env.GRAPHILE_ENV === "development"; | ||
@@ -18,4 +18,4 @@ class AsyncHooks { | ||
*/ | ||
process(event, ...args) { | ||
const callbacks = this.callbacks[event]; | ||
process(hookName, ...args) { | ||
const callbacks = this.callbacks[hookName]; | ||
if (!callbacks) { | ||
@@ -35,3 +35,3 @@ return; | ||
if (isDev && typeof result.then !== "function") { | ||
throw new Error(`Hook '${event}' returned invalid value of type ${typeof result} - must be 'undefined' or a Promise/PromiseLike.`); | ||
throw new Error(`Hook '${hookName}' returned invalid value of type ${typeof result} - must be 'undefined' or a Promise/PromiseLike.`); | ||
} | ||
@@ -46,55 +46,4 @@ chain = result; | ||
exports.AsyncHooks = AsyncHooks; | ||
function applyHooks(plugins, hooksRetriever, applyHookCallback) { | ||
// Normalize all the hooks and gather them into collections | ||
const allHooks = Object.create(null); | ||
let uid = 0; | ||
if (plugins) { | ||
for (const plugin of plugins) { | ||
const hooks = hooksRetriever(plugin); | ||
if (!hooks) { | ||
continue; | ||
} | ||
const keys = Object.keys(hooks); | ||
for (const key of keys) { | ||
const hookSpecRaw = hooks[key]; | ||
if (!hookSpecRaw) { | ||
continue; | ||
} | ||
// TypeScript nonsense | ||
const isPluginHookObject = (v) => typeof v !== "function"; | ||
const isPluginHookFunction = (v) => typeof v === "function"; | ||
const callback = (isPluginHookFunction(hookSpecRaw) ? hookSpecRaw : hookSpecRaw.callback); | ||
const { provides, before, after } = isPluginHookObject(hookSpecRaw) | ||
? hookSpecRaw | ||
: {}; | ||
if (!allHooks[key]) { | ||
allHooks[key] = []; | ||
} | ||
// We need to give each hook a unique ID | ||
const id = String(uid++); | ||
allHooks[key].push({ | ||
id, | ||
plugin, | ||
callback, | ||
provides: [...(provides || []), id, plugin.name], | ||
before: before || [], | ||
after: after || [], | ||
}); | ||
} | ||
} | ||
} | ||
// Sort the collections according to provides, before and after. | ||
for (const hookName in allHooks) { | ||
const hooks = allHooks[hookName]; | ||
if (!hooks) { | ||
continue; | ||
} | ||
const final = (0, sort_js_1.sortWithBeforeAfterProvides)(hooks, "id"); | ||
// Finally we can register the hooks | ||
for (const hook of final) { | ||
applyHookCallback(hookName, hook.callback, hook.plugin); | ||
} | ||
} | ||
} | ||
exports.applyHooks = applyHooks; | ||
/** @deprecated Use `orderedApply` */ | ||
exports.applyHooks = functionality_js_1.orderedApply; | ||
//# sourceMappingURL=hooks.js.map |
import "./interfaces.js"; | ||
export { GraphileConfig }; | ||
export { applyHooks, AsyncHooks, HookObject } from "./hooks.js"; | ||
export type { PluginHook, PluginHookObject } from "./interfaces.js"; | ||
export { orderedApply } from "./functionality.js"; | ||
export { applyHooks, AsyncHooks, HookObject, PluginHook, PluginHookObject, } from "./hooks.js"; | ||
export type { CallbackDescriptor, CallbackOrDescriptor, FunctionalityObject, } from "./interfaces.js"; | ||
export type { MiddlewareNext } from "./middleware.js"; | ||
export { Middleware } from "./middleware.js"; | ||
export { isResolvedPreset, resolvePresets } from "./resolvePresets.js"; | ||
@@ -6,0 +9,0 @@ export declare function sortedPlugins(plugins: GraphileConfig.Plugin[] | undefined): GraphileConfig.Plugin[]; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.sortedPlugins = exports.resolvePresets = exports.isResolvedPreset = exports.AsyncHooks = exports.applyHooks = void 0; | ||
exports.sortedPlugins = exports.resolvePresets = exports.isResolvedPreset = exports.Middleware = exports.AsyncHooks = exports.applyHooks = exports.orderedApply = void 0; | ||
require("./interfaces.js"); | ||
const sort_js_1 = require("./sort.js"); | ||
var functionality_js_1 = require("./functionality.js"); | ||
Object.defineProperty(exports, "orderedApply", { enumerable: true, get: function () { return functionality_js_1.orderedApply; } }); | ||
var hooks_js_1 = require("./hooks.js"); | ||
Object.defineProperty(exports, "applyHooks", { enumerable: true, get: function () { return hooks_js_1.applyHooks; } }); | ||
Object.defineProperty(exports, "AsyncHooks", { enumerable: true, get: function () { return hooks_js_1.AsyncHooks; } }); | ||
var middleware_js_1 = require("./middleware.js"); | ||
Object.defineProperty(exports, "Middleware", { enumerable: true, get: function () { return middleware_js_1.Middleware; } }); | ||
var resolvePresets_js_1 = require("./resolvePresets.js"); | ||
@@ -10,0 +14,0 @@ Object.defineProperty(exports, "isResolvedPreset", { enumerable: true, get: function () { return resolvePresets_js_1.isResolvedPreset; } }); |
@@ -1,2 +0,3 @@ | ||
export type PluginHookObject<T extends (...args: any[]) => any> = { | ||
export type AnyCallback = (...args: any[]) => any; | ||
export type CallbackDescriptor<T extends AnyCallback> = { | ||
provides?: string[]; | ||
@@ -7,4 +8,6 @@ before?: string[]; | ||
}; | ||
export type PluginHook<T extends (...args: any[]) => any> = T | PluginHookObject<T>; | ||
export type PluginHookCallback<T extends PluginHook<(...args: any[]) => any>> = T extends PluginHook<infer U> ? U : never; | ||
export type PromiseOrDirect<T> = T | PromiseLike<T>; | ||
export type CallbackOrDescriptor<T extends AnyCallback> = T | CallbackDescriptor<T>; | ||
export type UnwrapCallback<T extends CallbackOrDescriptor<AnyCallback>> = T extends CallbackOrDescriptor<infer U> ? U : never; | ||
export type FunctionalityObject<T> = Record<keyof T, CallbackOrDescriptor<AnyCallback>>; | ||
//# sourceMappingURL=interfaces.d.ts.map |
{ | ||
"name": "graphile-config", | ||
"version": "0.0.1-beta.8", | ||
"version": "0.0.1-beta.9", | ||
"description": "Standard plugin interface and helpers to be used across the Graphile stack.", | ||
@@ -5,0 +5,0 @@ "type": "commonjs", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
82738
44
785