@lewebsimple/nuxt-graphql 0.6.15 → 0.6.17

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.15",
4
+ "version": "0.6.17",
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.15";
206
+ const version = "0.6.17";
207
207
 
208
208
  async function getDocuments(documentsGlob) {
209
209
  try {
@@ -238,7 +238,7 @@ async function getOperationsTemplate({ loadSchema, loadDocuments, documentGlob }
238
238
  defaultValue: false
239
239
  },
240
240
  defaultScalarType: "never",
241
- enumsAsTypes: true,
241
+ enumsAsConst: true,
242
242
  preResolveTypes: false,
243
243
  strictScalars: true,
244
244
  useTypeImports: true
@@ -253,7 +253,7 @@ async function getOperationsTemplate({ loadSchema, loadDocuments, documentGlob }
253
253
  defaultValue: false
254
254
  },
255
255
  defaultScalarType: "never",
256
- enumsAsTypes: true,
256
+ enumsAsConst: true,
257
257
  exportFragmentSpreadSubTypes: true,
258
258
  inlineFragmentTypes: "combine",
259
259
  operationResultSuffix: "Result",
@@ -6,7 +6,7 @@ import type { IsEmptyObject } from "../../shared/lib/types.js";
6
6
  * @returns Cache manipulation helpers.
7
7
  */
8
8
  export declare function useGraphQLCache(): {
9
- readonly cacheConfig: import("../../shared/lib/types.js").CacheConfig;
9
+ readonly cacheConfig: any;
10
10
  readonly read: <TName extends QueryName>(operation: TName, ...args: IsEmptyObject<VariablesOf<TName>> extends true ? [variables?: VariablesOf<TName>] : [variables: VariablesOf<TName>]) => ResultOf<TName> | undefined;
11
11
  readonly write: <TName extends QueryName>(operation: TName, variables: VariablesOf<TName>, value: ResultOf<TName> | ((current: ResultOf<TName> | undefined) => ResultOf<TName>)) => void;
12
12
  readonly update: <TName extends QueryName>(operation: TName, variables: VariablesOf<TName>, value: ResultOf<TName> | ((current: ResultOf<TName> | undefined) => ResultOf<TName>)) => Promise<void>;
@@ -10,8 +10,8 @@ type Connection<TItem> = {
10
10
  };
11
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
- pending: Ref<boolean, boolean>;
14
- error: Ref<import("../../shared/lib/error.js").NormalizedError | undefined, import("../../shared/lib/error.js").NormalizedError | undefined>;
13
+ pending: any;
14
+ error: any;
15
15
  reset: (clearProducts?: boolean) => void;
16
16
  hasNextPage: ComputedRef<boolean>;
17
17
  isLoadingMore: Ref<boolean, boolean>;
@@ -52,6 +52,6 @@ export type MutationOptions<TName extends MutationName, TContext = unknown> = {
52
52
  * @returns Mutation state and mutate function.
53
53
  */
54
54
  export declare function useGraphQLMutation<TName extends MutationName, TContext = unknown>(operationName: TName, options?: MutationOptions<TName, TContext>): {
55
- pending: import("vue").Ref<boolean, boolean>;
55
+ pending: import("@vue/reactivity").Ref<boolean, boolean>;
56
56
  mutate: (...args: IsEmptyObject<VariablesOf<TName>> extends true ? [variables?: VariablesOf<TName>] : [variables: VariablesOf<TName>]) => Promise<ExecuteGraphQLResult<ResultOf<TName>>>;
57
57
  };
@@ -1,9 +1,5 @@
1
1
  import type { ExecuteGraphQLInput, ExecuteGraphQLResult, GraphQLVariables } from "../../shared/lib/types.js";
2
- declare const _default: import("#app").Plugin<{
3
- executeGraphQL: <TResult = unknown, TVariables extends GraphQLVariables = GraphQLVariables>({ query, variables, operationName }: ExecuteGraphQLInput<TVariables>) => Promise<ExecuteGraphQLResult<TResult>>;
4
- }> & import("#app").ObjectPlugin<{
5
- executeGraphQL: <TResult = unknown, TVariables extends GraphQLVariables = GraphQLVariables>({ query, variables, operationName }: ExecuteGraphQLInput<TVariables>) => Promise<ExecuteGraphQLResult<TResult>>;
6
- }>;
2
+ declare const _default: any;
7
3
  export default _default;
8
4
  type ExecuteGraphQL = <TResult = unknown, TVariables extends GraphQLVariables = GraphQLVariables>(input: ExecuteGraphQLInput<TVariables>) => Promise<ExecuteGraphQLResult<TResult>>;
9
5
  declare module "#app/nuxt" {
@@ -4,11 +4,7 @@ import { type Client as SSEClient } from "graphql-sse";
4
4
  *
5
5
  * @returns Nuxt plugin with SSE client provider.
6
6
  */
7
- declare const _default: import("#app").Plugin<{
8
- getGraphQLSSEClient: () => SSEClient;
9
- }> & import("#app").ObjectPlugin<{
10
- getGraphQLSSEClient: () => SSEClient;
11
- }>;
7
+ declare const _default: any;
12
8
  export default _default;
13
9
  declare module "#app/nuxt" {
14
10
  interface NuxtApp {
@@ -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.15",
3
+ "version": "0.6.17",
4
4
  "description": "Opinionated Nuxt module for using GraphQL",
5
5
  "repository": "lewebsimple/nuxt-graphql",
6
6
  "license": "AGPL-3.0-only",
@@ -27,9 +27,9 @@
27
27
  ],
28
28
  "dependencies": {
29
29
  "@graphql-codegen/core": "^5.0.0",
30
- "@graphql-codegen/typed-document-node": "^6.1.5",
31
- "@graphql-codegen/typescript": "^5.0.7",
32
- "@graphql-codegen/typescript-operations": "^5.0.7",
30
+ "@graphql-codegen/typed-document-node": "^6.1.6",
31
+ "@graphql-codegen/typescript": "^5.0.8",
32
+ "@graphql-codegen/typescript-operations": "^5.0.8",
33
33
  "@graphql-tools/graphql-file-loader": "^8.1.9",
34
34
  "@graphql-tools/load": "^8.1.8",
35
35
  "@graphql-tools/schema": "^10.0.31",