@lewebsimple/nuxt-graphql 0.2.2 → 0.3.0

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.
Files changed (63) hide show
  1. package/README.md +361 -55
  2. package/dist/module.d.mts +33 -21
  3. package/dist/module.json +1 -1
  4. package/dist/module.mjs +337 -373
  5. package/dist/runtime/app/composables/useGraphQLCache.client.d.ts +10 -0
  6. package/dist/runtime/app/composables/useGraphQLCache.client.js +41 -0
  7. package/dist/runtime/app/composables/useGraphQLMutation.d.ts +17 -8
  8. package/dist/runtime/app/composables/useGraphQLMutation.js +10 -9
  9. package/dist/runtime/app/composables/useGraphQLQuery.d.ts +5 -12
  10. package/dist/runtime/app/composables/useGraphQLQuery.js +74 -28
  11. package/dist/runtime/app/composables/useGraphQLSubscription.d.ts +5 -6
  12. package/dist/runtime/app/composables/useGraphQLSubscription.js +13 -12
  13. package/dist/runtime/app/lib/graphql-cache.d.ts +7 -0
  14. package/dist/runtime/app/lib/graphql-cache.js +24 -0
  15. package/dist/runtime/app/lib/persisted.d.ts +4 -0
  16. package/dist/runtime/app/lib/persisted.js +70 -0
  17. package/dist/runtime/app/plugins/graphql-request.d.ts +7 -0
  18. package/dist/runtime/app/plugins/graphql-request.js +21 -0
  19. package/dist/runtime/app/plugins/graphql-sse.client.d.ts +7 -0
  20. package/dist/runtime/app/plugins/graphql-sse.client.js +15 -0
  21. package/dist/runtime/app/types/nuxt-graphql.d.ts +37 -0
  22. package/dist/runtime/server/api/yoga-handler.js +42 -0
  23. package/dist/runtime/server/lib/define-graphql-context.d.ts +5 -0
  24. package/dist/runtime/server/lib/define-graphql-context.js +4 -0
  25. package/dist/runtime/server/lib/define-remote-exec-middleware.d.ts +30 -0
  26. package/dist/runtime/server/lib/define-remote-exec-middleware.js +3 -0
  27. package/dist/runtime/server/lib/define-yoga-middleware.d.ts +21 -0
  28. package/dist/runtime/server/lib/define-yoga-middleware.js +3 -0
  29. package/dist/runtime/server/lib/execute-server-graphql.d.ts +7 -0
  30. package/dist/runtime/server/lib/execute-server-graphql.js +34 -0
  31. package/dist/runtime/server/lib/remote-executor.d.ts +35 -0
  32. package/dist/runtime/server/lib/remote-executor.js +64 -0
  33. package/dist/runtime/server/tsconfig.json +1 -1
  34. package/dist/runtime/server/utils/useServerGraphQLMutation.d.ts +8 -14
  35. package/dist/runtime/server/utils/useServerGraphQLMutation.js +8 -11
  36. package/dist/runtime/server/utils/useServerGraphQLQuery.d.ts +2 -10
  37. package/dist/runtime/server/utils/useServerGraphQLQuery.js +3 -4
  38. package/dist/runtime/shared/lib/graphql-error.d.ts +17 -0
  39. package/dist/runtime/shared/lib/graphql-error.js +28 -0
  40. package/dist/runtime/shared/lib/headers.d.ts +3 -0
  41. package/dist/runtime/shared/lib/headers.js +39 -0
  42. package/dist/types.d.mts +13 -1
  43. package/package.json +10 -14
  44. package/dist/runtime/app/composables/useGraphQLCache.d.ts +0 -10
  45. package/dist/runtime/app/composables/useGraphQLCache.js +0 -15
  46. package/dist/runtime/app/plugins/graphql.d.ts +0 -31
  47. package/dist/runtime/app/plugins/graphql.js +0 -42
  48. package/dist/runtime/app/utils/graphql-cache.d.ts +0 -36
  49. package/dist/runtime/app/utils/graphql-cache.js +0 -65
  50. package/dist/runtime/app/utils/graphql-error.d.ts +0 -12
  51. package/dist/runtime/app/utils/graphql-error.js +0 -24
  52. package/dist/runtime/server/api/graphql-handler.js +0 -15
  53. package/dist/runtime/server/lib/constants.d.ts +0 -1
  54. package/dist/runtime/server/lib/constants.js +0 -1
  55. package/dist/runtime/server/lib/create-yoga.d.ts +0 -1
  56. package/dist/runtime/server/lib/create-yoga.js +0 -17
  57. package/dist/runtime/server/lib/default-context.d.ts +0 -7
  58. package/dist/runtime/server/lib/default-context.js +0 -1
  59. package/dist/runtime/server/utils/graphql-client.d.ts +0 -14
  60. package/dist/runtime/server/utils/graphql-client.js +0 -14
  61. package/dist/runtime/server/utils/remote-middleware.d.ts +0 -18
  62. package/dist/runtime/server/utils/remote-middleware.js +0 -0
  63. /package/dist/runtime/server/api/{graphql-handler.d.ts → yoga-handler.d.ts} +0 -0
@@ -1,15 +0,0 @@
1
- import { defineEventHandler, toWebRequest, sendWebResponse, createError } from "h3";
2
- import { getYoga } from "../lib/create-yoga.js";
3
- import { createContext } from "#graphql/context";
4
- export default defineEventHandler(async (event) => {
5
- try {
6
- const request = toWebRequest(event);
7
- const context = await createContext(event);
8
- const response = await getYoga().handleRequest(request, context);
9
- return sendWebResponse(event, response);
10
- } catch (error) {
11
- const message = error instanceof Error ? error.message : String(error);
12
- console.error("GraphQL Server Error:", message);
13
- throw createError({ statusCode: 500, message: "GraphQL server error" });
14
- }
15
- });
@@ -1 +0,0 @@
1
- export declare const GRAPHQL_ENDPOINT = "/api/graphql";
@@ -1 +0,0 @@
1
- export const GRAPHQL_ENDPOINT = "/api/graphql";
@@ -1 +0,0 @@
1
- export declare function getYoga(): import("graphql-yoga").YogaServerInstance<Record<string, any>, Record<string, any>>;
@@ -1,17 +0,0 @@
1
- import { createYoga } from "graphql-yoga";
2
- import { schema } from "#graphql/schema";
3
- import { GRAPHQL_ENDPOINT } from "./constants.js";
4
- let yoga = null;
5
- export function getYoga() {
6
- if (!yoga) {
7
- yoga = createYoga({
8
- schema,
9
- graphqlEndpoint: GRAPHQL_ENDPOINT,
10
- fetchAPI: globalThis,
11
- graphiql: process.env.NODE_ENV !== "production",
12
- // @ts-expect-error Subscriptions type missing in module context
13
- subscriptions: { protocol: "SSE" }
14
- });
15
- }
16
- return yoga;
17
- }
@@ -1,7 +0,0 @@
1
- import type { H3Event } from "h3";
2
- export declare const createContext: (event: H3Event) => {
3
- event: H3Event<import("h3").EventHandlerRequest>;
4
- };
5
- export type GraphQLContext = {
6
- event: H3Event;
7
- };
@@ -1 +0,0 @@
1
- export const createContext = (event) => ({ event });
@@ -1,14 +0,0 @@
1
- import type { H3Event } from "h3";
2
- import { GraphQLClient } from "graphql-request";
3
- /**
4
- * Get or create a server-side GraphQL client for an H3 event
5
- *
6
- * @param event H3 event
7
- * @returns GraphQL client instance
8
- */
9
- export declare function getGraphQLClient(event: H3Event): GraphQLClient;
10
- declare module "h3" {
11
- interface H3EventContext {
12
- __nuxtGraphQLClient?: GraphQLClient;
13
- }
14
- }
@@ -1,14 +0,0 @@
1
- import { getRequestHeaders, getRequestURL } from "h3";
2
- import { GraphQLClient } from "graphql-request";
3
- import { useRuntimeConfig } from "#imports";
4
- export function getGraphQLClient(event) {
5
- if (event.context.__nuxtGraphQLClient) {
6
- return event.context.__nuxtGraphQLClient;
7
- }
8
- const { public: { graphql: { endpoint } } } = useRuntimeConfig();
9
- const { origin } = getRequestURL(event);
10
- const url = `${origin}${endpoint}`;
11
- const headers = getRequestHeaders(event);
12
- event.context.__nuxtGraphQLClient = new GraphQLClient(url, { headers });
13
- return event.context.__nuxtGraphQLClient;
14
- }
@@ -1,18 +0,0 @@
1
- import type { GraphQLContext } from "#graphql/context";
2
- type Awaitable<T> = T | Promise<T>;
3
- export type RemoteMiddlewareContext = {
4
- remoteName: string;
5
- operationName?: string | null;
6
- context: GraphQLContext;
7
- };
8
- export type RemoteMiddlewareRequestContext = RemoteMiddlewareContext & {
9
- fetchOptions: RequestInit;
10
- };
11
- export type RemoteMiddlewareResponseContext = RemoteMiddlewareRequestContext & {
12
- response: Response;
13
- };
14
- export type RemoteMiddleware = {
15
- onRequest?: (context: RemoteMiddlewareRequestContext) => Awaitable<RequestInit | undefined>;
16
- onResponse?: (context: RemoteMiddlewareResponseContext) => Awaitable<void>;
17
- };
18
- export {};
File without changes