@lewebsimple/nuxt-graphql 0.6.14 → 0.6.16

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
@@ -363,20 +363,34 @@ const result = await mutate({ title: "New Film" });
363
363
 
364
364
  You can define custom logic around the remote executor for each remote schema by using the auto-imported `defineRemoteExecutorHooks` helper.
365
365
 
366
+ All hooks receive the GraphQL context as a second parameter for convenient access.
367
+
366
368
  For the example configuration above, create [server/graphql/swapi-hooks.ts](server/graphql/swapi-hooks.ts):
367
369
 
368
370
  ```ts
369
371
  import { defu } from "defu";
370
372
 
371
373
  export default defineRemoteExecutorHooks({
372
- onRequest(request) {
373
- const { remoteAuthToken } = request.context || {};
374
+ onRequest(request, context) {
375
+ // Context is available as second parameter
376
+ const { remoteAuthToken } = context || {};
374
377
  request.extensions = defu(request.extensions, {
375
378
  headers: {
376
379
  "XAuthorization": `Bearer ${remoteAuthToken || ""}`,
377
380
  },
378
381
  });
379
382
  },
383
+
384
+ onResult(result, context) {
385
+ // You can also access context in onResult
386
+ console.log("User from context:", context?.user);
387
+ console.log("Result:", result.data);
388
+ },
389
+
390
+ onError(error, context) {
391
+ // And in onError for logging/monitoring
392
+ console.error("Remote execution failed for user:", context?.user?.id);
393
+ },
380
394
  });
381
395
  ```
382
396
 
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lewebsimple/nuxt-graphql",
3
3
  "configKey": "graphql",
4
- "version": "0.6.14",
4
+ "version": "0.6.16",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
package/dist/module.mjs CHANGED
@@ -203,7 +203,7 @@ function addUniversalTemplate({ filename, getContents, emitTs }) {
203
203
  return modulePath;
204
204
  }
205
205
 
206
- const version = "0.6.14";
206
+ const version = "0.6.16";
207
207
 
208
208
  async function getDocuments(documentsGlob) {
209
209
  try {
@@ -2,13 +2,13 @@ import type { QueryName, ResultOf, VariablesOf } from "#graphql/registry";
2
2
  import { type ComputedRef, type MaybeRef, type Ref } from "#imports";
3
3
  type PageInfoFragment = {
4
4
  hasNextPage: boolean;
5
- endCursor: string | undefined;
5
+ endCursor: string | null | undefined;
6
6
  };
7
7
  type Connection<TItem> = {
8
8
  nodes: TItem[];
9
9
  pageInfo: PageInfoFragment;
10
10
  };
11
- export declare function useGraphQLLoadMore<TQueryName extends QueryName, TConnection extends Connection<unknown>>(queryName: TQueryName, inputVars: MaybeRef<Omit<VariablesOf<TQueryName>, "after">>, getConnection: (data?: ResultOf<TQueryName>) => TConnection | undefined): Promise<{
11
+ export declare function useGraphQLLoadMore<TQueryName extends QueryName, TConnection extends Connection<unknown>>(queryName: TQueryName, inputVars: MaybeRef<Omit<VariablesOf<TQueryName>, "after">>, getConnection: (data?: ResultOf<TQueryName>) => TConnection | null | undefined): Promise<{
12
12
  items: Ref<TConnection["nodes"][number][], TConnection["nodes"][number][]>;
13
13
  pending: Ref<boolean, boolean>;
14
14
  error: Ref<import("../../shared/lib/error.js").NormalizedError | undefined, import("../../shared/lib/error.js").NormalizedError | undefined>;
@@ -13,9 +13,9 @@ type GraphQLExecutionResult<TData = unknown> = ExecutionResult<TData> & {
13
13
  };
14
14
  };
15
15
  export type GraphQLRemoteExecHooks<TData = unknown> = {
16
- onRequest?: (request: GraphQLExecutionRequest) => void | Promise<void>;
17
- onResult?: (result: GraphQLExecutionResult<TData>) => void | Promise<void>;
18
- onError?: (error: unknown) => void | Promise<void>;
16
+ onRequest?: (request: GraphQLExecutionRequest, context: GraphQLContext | undefined) => void | Promise<void>;
17
+ onResult?: (result: GraphQLExecutionResult<TData>, context: GraphQLContext | undefined) => void | Promise<void>;
18
+ onError?: (error: unknown, context: GraphQLContext | undefined) => void | Promise<void>;
19
19
  };
20
20
  export type RemoteExecutorInput = {
21
21
  endpoint: string;
@@ -3,8 +3,9 @@ import { mergeHeaders } from "../../shared/lib/headers.js";
3
3
  export function getRemoteExecutor({ endpoint, headers, hooks }) {
4
4
  return async function execute(request) {
5
5
  try {
6
+ const context = request.context;
6
7
  for (const hook of hooks) {
7
- await hook.onRequest?.(request);
8
+ await hook.onRequest?.(request, context);
8
9
  }
9
10
  const response = await fetch(endpoint, {
10
11
  method: "POST",
@@ -27,12 +28,13 @@ export function getRemoteExecutor({ endpoint, headers, hooks }) {
27
28
  headers: responseHeaders
28
29
  };
29
30
  for (const hook of hooks) {
30
- await hook.onResult?.(result);
31
+ await hook.onResult?.(result, context);
31
32
  }
32
33
  return result;
33
34
  } catch (error) {
35
+ const context = request.context;
34
36
  for (const hook of hooks) {
35
- await hook.onError?.(error);
37
+ await hook.onError?.(error, context);
36
38
  }
37
39
  throw error;
38
40
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lewebsimple/nuxt-graphql",
3
- "version": "0.6.14",
3
+ "version": "0.6.16",
4
4
  "description": "Opinionated Nuxt module for using GraphQL",
5
5
  "repository": "lewebsimple/nuxt-graphql",
6
6
  "license": "AGPL-3.0-only",