@lewebsimple/nuxt-graphql 0.7.10 → 0.7.11
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/README.md
CHANGED
|
@@ -381,15 +381,20 @@ export default defineRemoteExecutorHooks({
|
|
|
381
381
|
});
|
|
382
382
|
},
|
|
383
383
|
|
|
384
|
-
onResult(result, context) {
|
|
384
|
+
onResult(result, context, meta) {
|
|
385
385
|
// You can also access context in onResult
|
|
386
386
|
console.log("User from context:", context?.user);
|
|
387
387
|
console.log("Result:", result.data);
|
|
388
|
+
// Upstream HTTP response metadata (headers + status)
|
|
389
|
+
const session = meta.headers.get("woocommerce-session");
|
|
390
|
+
if (session) context?.setSession?.(session);
|
|
388
391
|
},
|
|
389
392
|
|
|
390
|
-
onError(error, context) {
|
|
393
|
+
onError(error, context, meta) {
|
|
391
394
|
// And in onError for logging/monitoring
|
|
392
|
-
|
|
395
|
+
// `meta` is undefined when the failure happened before the HTTP response
|
|
396
|
+
// (e.g. fetch/network error); defined for non-2xx or JSON parse errors.
|
|
397
|
+
console.error("Remote execution failed for user:", context?.user?.id, meta?.status);
|
|
393
398
|
},
|
|
394
399
|
});
|
|
395
400
|
```
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -16,7 +16,7 @@ import zodPreset from '@lewebsimple/graphql-codegen-zod';
|
|
|
16
16
|
import { createRequire } from 'node:module';
|
|
17
17
|
import { resolveCacheConfig } from '../dist/runtime/app/lib/cache-config.js';
|
|
18
18
|
|
|
19
|
-
const version = "0.7.
|
|
19
|
+
const version = "0.7.11";
|
|
20
20
|
|
|
21
21
|
const buildCache = /* @__PURE__ */ new Map();
|
|
22
22
|
function getCachedLoader(baseKey, loader) {
|
|
@@ -15,14 +15,25 @@ export type GraphQLRemoteExecutorRequest<TContext extends Record<string, unknown
|
|
|
15
15
|
/** Execution context. */
|
|
16
16
|
context?: TContext;
|
|
17
17
|
};
|
|
18
|
+
/** Metadata from the upstream HTTP response. */
|
|
19
|
+
export type GraphQLRemoteExecutorResponseMeta = {
|
|
20
|
+
/** Response headers from the upstream endpoint. */
|
|
21
|
+
headers: Headers;
|
|
22
|
+
/** HTTP status code from the upstream endpoint. */
|
|
23
|
+
status: number;
|
|
24
|
+
};
|
|
18
25
|
/** Remote executor hook handlers. */
|
|
19
26
|
export type GraphQLRemoteExecutorHook<TContext extends Record<string, unknown> = GraphQLContext> = {
|
|
20
27
|
/** Called before sending remote request. */
|
|
21
28
|
onRequest?: (request: GraphQLRemoteExecutorRequest<TContext>, context: TContext | undefined) => void | Promise<void>;
|
|
22
|
-
/** Called after receiving a result. */
|
|
23
|
-
onResult?: (result: unknown, context: TContext | undefined) => void | Promise<void>;
|
|
24
|
-
/**
|
|
25
|
-
|
|
29
|
+
/** Called after receiving a result, with the upstream response metadata. */
|
|
30
|
+
onResult?: (result: unknown, context: TContext | undefined, meta: GraphQLRemoteExecutorResponseMeta) => void | Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Called when execution throws. `meta` is provided when the failure happened
|
|
33
|
+
* after the HTTP response was received (non-2xx, JSON parse error, hook
|
|
34
|
+
* error); it is `undefined` for fetch/network failures.
|
|
35
|
+
*/
|
|
36
|
+
onError?: (error: unknown, context: TContext | undefined, meta?: GraphQLRemoteExecutorResponseMeta) => void | Promise<void>;
|
|
26
37
|
};
|
|
27
38
|
/** Remote executor factory input. */
|
|
28
39
|
type RemoteExecutorInput<TContext extends Record<string, unknown> = GraphQLContext> = {
|
|
@@ -6,6 +6,7 @@ export function getRemoteExecutor({
|
|
|
6
6
|
}) {
|
|
7
7
|
return async function execute(request) {
|
|
8
8
|
const context = request.context;
|
|
9
|
+
let meta;
|
|
9
10
|
try {
|
|
10
11
|
for (const hook of hooks) {
|
|
11
12
|
await hook.onRequest?.(request, context);
|
|
@@ -23,17 +24,18 @@ export function getRemoteExecutor({
|
|
|
23
24
|
operationName: request.operationName
|
|
24
25
|
})
|
|
25
26
|
});
|
|
27
|
+
meta = { headers: response.headers, status: response.status };
|
|
26
28
|
if (!response.ok) {
|
|
27
29
|
throw new Error(`GraphQL HTTP ${response.status}`);
|
|
28
30
|
}
|
|
29
31
|
const result = await response.json();
|
|
30
32
|
for (const hook of hooks) {
|
|
31
|
-
await hook.onResult?.(result, context);
|
|
33
|
+
await hook.onResult?.(result, context, meta);
|
|
32
34
|
}
|
|
33
35
|
return result;
|
|
34
36
|
} catch (error) {
|
|
35
37
|
for (const hook of hooks) {
|
|
36
|
-
await hook.onError?.(error, context);
|
|
38
|
+
await hook.onError?.(error, context, meta);
|
|
37
39
|
}
|
|
38
40
|
throw error;
|
|
39
41
|
}
|