nuxt-graphql-middleware 5.0.0-alpha.9 → 5.0.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 (51) hide show
  1. package/README.md +101 -19
  2. package/dist/client/200.html +8 -8
  3. package/dist/client/404.html +8 -8
  4. package/dist/client/_nuxt/{CPyoLiCY.js → BM34SYth.js} +1 -1
  5. package/dist/client/_nuxt/CROlboVl.js +1 -0
  6. package/dist/client/_nuxt/D5hBL5aZ.js +25 -0
  7. package/dist/client/_nuxt/{BLvMh1Ga.js → FTbv7CO6.js} +1 -1
  8. package/dist/client/_nuxt/builds/latest.json +1 -1
  9. package/dist/client/_nuxt/builds/meta/83f9fcd5-bd28-4608-b499-05e08fe0f7d0.json +1 -0
  10. package/dist/client/_nuxt/error-404.ehK72JOs.css +1 -0
  11. package/dist/client/_nuxt/error-500._g0akJim.css +1 -0
  12. package/dist/client/_nuxt/{C9pb_2rp.js → lIgCBhS_.js} +2 -2
  13. package/dist/client/index.html +8 -8
  14. package/dist/client-options.d.mts +6 -0
  15. package/dist/client-options.mjs +5 -0
  16. package/dist/module.d.mts +63 -181
  17. package/dist/module.json +3 -3
  18. package/dist/module.mjs +338 -90
  19. package/dist/runtime/components/CodeFrame.vue +19 -28
  20. package/dist/runtime/components/CodeFrame.vue.d.ts +7 -0
  21. package/dist/runtime/components/DevModeOverlay.vue +25 -33
  22. package/dist/runtime/components/DevModeOverlay.vue.d.ts +3 -0
  23. package/dist/runtime/components/ErrorExtensions.vue +9 -11
  24. package/dist/runtime/components/ErrorExtensions.vue.d.ts +5 -0
  25. package/dist/runtime/components/ErrorGroup.vue +28 -39
  26. package/dist/runtime/components/ErrorGroup.vue.d.ts +9 -0
  27. package/dist/runtime/server/api/mutation.js +2 -1
  28. package/dist/runtime/server/api/query.js +2 -1
  29. package/dist/runtime/server/utils/doGraphqlRequest.js +5 -4
  30. package/dist/runtime/types.d.ts +2 -2
  31. package/dist/server-options.d.mts +8 -0
  32. package/dist/server-options.mjs +5 -0
  33. package/dist/shared/nuxt-graphql-middleware.cXfDI4U3.d.mts +517 -0
  34. package/dist/types.d.mts +1 -7
  35. package/dist/utils.d.mts +15 -0
  36. package/dist/utils.mjs +18 -0
  37. package/package.json +34 -30
  38. package/dist/client/_nuxt/CBwfSTyQ.js +0 -1
  39. package/dist/client/_nuxt/VpkRx2_e.js +0 -25
  40. package/dist/client/_nuxt/builds/meta/826a43da-d42c-4fbf-8dfd-2572141eaf8f.json +0 -1
  41. package/dist/client/_nuxt/error-404.BJkSn6RI.css +0 -1
  42. package/dist/client/_nuxt/error-500.TOCKLquH.css +0 -1
  43. package/dist/module.cjs +0 -5
  44. package/dist/module.d.ts +0 -210
  45. package/dist/runtime/clientOptions/index.d.ts +0 -2
  46. package/dist/runtime/clientOptions/index.js +0 -3
  47. package/dist/runtime/serverOptions/defineGraphqlServerOptions.d.ts +0 -4
  48. package/dist/runtime/serverOptions/defineGraphqlServerOptions.js +0 -3
  49. package/dist/runtime/serverOptions/index.d.ts +0 -2
  50. package/dist/runtime/serverOptions/index.js +0 -2
  51. package/dist/types.d.ts +0 -7
@@ -23,39 +23,30 @@
23
23
  </div>
24
24
  </template>
25
25
 
26
- <script setup lang="ts">
27
- import { computed } from '#imports'
28
-
29
- const props = defineProps<{
30
- source: string
31
- line: number
32
- column: number
33
- }>()
34
-
35
- const before = 20
36
- const after = 20
37
-
26
+ <script setup>
27
+ import { computed } from "#imports";
28
+ const props = defineProps({
29
+ source: { type: String, required: true },
30
+ line: { type: Number, required: true },
31
+ column: { type: Number, required: true }
32
+ });
33
+ const before = 20;
34
+ const after = 20;
38
35
  const lines = computed(() => {
39
- const fullLines = props.source.split('\n')
40
- const indexStart = Math.max(props.line - before - 1, 0)
41
- const indexEnd = Math.min(props.line + after, fullLines.length)
42
-
43
- // Take only the lines we care about
44
- const sliced = fullLines.slice(indexStart, indexEnd)
45
-
46
- // Remove trailing empty lines
36
+ const fullLines = props.source.split("\n");
37
+ const indexStart = Math.max(props.line - before - 1, 0);
38
+ const indexEnd = Math.min(props.line + after, fullLines.length);
39
+ const sliced = fullLines.slice(indexStart, indexEnd);
47
40
  while (sliced.length && !sliced[sliced.length - 1]?.trim()) {
48
- sliced.pop()
41
+ sliced.pop();
49
42
  }
50
-
51
- // Map to your final structure
52
43
  return sliced.map((code, i) => {
53
- const lineNumber = indexStart + i + 1
44
+ const lineNumber = indexStart + i + 1;
54
45
  return {
55
46
  lineNumber,
56
47
  code,
57
- isHighlighted: lineNumber === props.line,
58
- }
59
- })
60
- })
48
+ isHighlighted: lineNumber === props.line
49
+ };
50
+ });
51
+ });
61
52
  </script>
@@ -0,0 +1,7 @@
1
+ type __VLS_Props = {
2
+ source: string;
3
+ line: number;
4
+ column: number;
5
+ };
6
+ declare const _default: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
7
+ export default _default;
@@ -21,40 +21,32 @@
21
21
  </div>
22
22
  </template>
23
23
 
24
- <script setup lang="ts">
25
- import './../css/output.css'
26
- import { useState, computed } from '#imports'
27
-
28
- import type { OperationResponseError } from '../types'
29
- import ErrorGroup from './ErrorGroup.vue'
30
-
31
- const errors = useState<OperationResponseError[]>(
32
- 'nuxt-graphql-middleware-errors',
33
- () => [],
34
- )
35
-
36
- const groups = computed<OperationResponseError[]>(() => {
24
+ <script setup>
25
+ import "./../css/output.css";
26
+ import { useState, computed } from "#imports";
27
+ import ErrorGroup from "./ErrorGroup.vue";
28
+ const errors = useState(
29
+ "nuxt-graphql-middleware-errors",
30
+ () => []
31
+ );
32
+ const groups = computed(() => {
37
33
  return [
38
- ...errors.value
39
- .reduce<Map<string, OperationResponseError>>((acc, v) => {
40
- const key = `${v.operation}_${v.operationName}`
41
- if (!acc.has(key)) {
42
- acc.set(key, {
43
- operation: v.operation,
44
- operationName: v.operationName,
45
- errors: [],
46
- stack: v.stack,
47
- })
48
- }
49
- acc.get(key)!.errors.push(...v.errors)
50
- return acc
51
- }, new Map())
52
- .values(),
53
- ]
54
- })
55
-
56
- /** Clear the error state => close/hide the overlay */
34
+ ...errors.value.reduce((acc, v) => {
35
+ const key = `${v.operation}_${v.operationName}`;
36
+ if (!acc.has(key)) {
37
+ acc.set(key, {
38
+ operation: v.operation,
39
+ operationName: v.operationName,
40
+ errors: [],
41
+ stack: v.stack
42
+ });
43
+ }
44
+ acc.get(key).errors.push(...v.errors);
45
+ return acc;
46
+ }, /* @__PURE__ */ new Map()).values()
47
+ ];
48
+ });
57
49
  function clearErrors() {
58
- errors.value = []
50
+ errors.value = [];
59
51
  }
60
52
  </script>
@@ -0,0 +1,3 @@
1
+ import './../css/output.css.js';
2
+ declare const _default: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
3
+ export default _default;
@@ -5,19 +5,17 @@
5
5
  </tr>
6
6
  </template>
7
7
 
8
- <script setup lang="ts">
9
- import { computed } from '#imports'
10
-
11
- const props = defineProps<{
12
- extensions?: Record<string, unknown>
13
- }>()
14
-
8
+ <script setup>
9
+ import { computed } from "#imports";
10
+ const props = defineProps({
11
+ extensions: { type: Object, required: false }
12
+ });
15
13
  const mapped = computed(() => {
16
14
  if (!props.extensions) {
17
- return []
15
+ return [];
18
16
  }
19
17
  return Object.entries(props.extensions).map(([key, value]) => {
20
- return { key, value }
21
- })
22
- })
18
+ return { key, value };
19
+ });
20
+ });
23
21
  </script>
@@ -0,0 +1,5 @@
1
+ type __VLS_Props = {
2
+ extensions?: Record<string, unknown>;
3
+ };
4
+ declare const _default: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
5
+ export default _default;
@@ -23,7 +23,7 @@
23
23
  <template v-for="error in uniqueErrors" :key="error.key">
24
24
  <tr>
25
25
  <td>Path</td>
26
- <td>{{ error.path.join(' - ') }}</td>
26
+ <td>{{ error.path.join(" - ") }}</td>
27
27
  </tr>
28
28
  <tr>
29
29
  <td colspan="2" class="ngm-large">{{ error.message }}</td>
@@ -46,44 +46,33 @@
46
46
  </table>
47
47
  </template>
48
48
 
49
- <script lang="ts" setup>
50
- import type { GraphqlResponseError } from '../types'
51
- import { documents } from '#nuxt-graphql-middleware/documents'
52
- import { operationSources } from '#nuxt-graphql-middleware/sources'
53
- import { computed } from '#imports'
54
- import CodeFrame from './CodeFrame.vue'
55
- import ErrorExtensions from './ErrorExtensions.vue'
56
-
57
- type MappedError = GraphqlResponseError & { count: number; key: string }
58
-
59
- const props = defineProps<{
60
- operation: string
61
- operationName: string
62
- errors: GraphqlResponseError[]
63
- stack?: string
64
- }>()
65
-
66
- const key = computed(() => props.operation + '_' + props.operationName)
67
-
49
+ <script setup>
50
+ import { documents } from "#nuxt-graphql-middleware/documents";
51
+ import { operationSources } from "#nuxt-graphql-middleware/sources";
52
+ import { computed } from "#imports";
53
+ import CodeFrame from "./CodeFrame.vue";
54
+ import ErrorExtensions from "./ErrorExtensions.vue";
55
+ const props = defineProps({
56
+ operation: { type: String, required: true },
57
+ operationName: { type: String, required: true },
58
+ errors: { type: Array, required: true },
59
+ stack: { type: String, required: false }
60
+ });
61
+ const key = computed(() => props.operation + "_" + props.operationName);
68
62
  const filePath = computed(() => {
69
- return operationSources[key.value]
70
- })
71
-
63
+ return operationSources[key.value];
64
+ });
72
65
  const source = computed(
73
- () => (documents as any)[props.operation]?.[props.operationName],
74
- )
75
-
76
- const uniqueErrors = computed<MappedError[]>(() => {
77
- return props.errors
78
- .reduce<Map<string, MappedError>>((acc, v) => {
79
- const key = v.message
80
- if (!acc.has(key)) {
81
- acc.set(key, { ...v, key, count: 0 })
82
- }
83
- acc.get(key)!.count++
84
- return acc
85
- }, new Map())
86
- .values()
87
- .toArray()
88
- })
66
+ () => documents[props.operation]?.[props.operationName]
67
+ );
68
+ const uniqueErrors = computed(() => {
69
+ return props.errors.reduce((acc, v) => {
70
+ const key2 = v.message;
71
+ if (!acc.has(key2)) {
72
+ acc.set(key2, { ...v, key: key2, count: 0 });
73
+ }
74
+ acc.get(key2).count++;
75
+ return acc;
76
+ }, /* @__PURE__ */ new Map()).values().toArray();
77
+ });
89
78
  </script>
@@ -0,0 +1,9 @@
1
+ import type { GraphqlResponseError } from '../types.js';
2
+ type __VLS_Props = {
3
+ operation: string;
4
+ operationName: string;
5
+ errors: GraphqlResponseError[];
6
+ stack?: string;
7
+ };
8
+ declare const _default: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
9
+ export default _default;
@@ -20,7 +20,8 @@ export default defineEventHandler(async (event) => {
20
20
  {
21
21
  query: operationDocument,
22
22
  variables,
23
- operation: GraphqlMiddlewareOperation.Mutation
23
+ operation: GraphqlMiddlewareOperation.Mutation,
24
+ operationName
24
25
  },
25
26
  context,
26
27
  event
@@ -21,7 +21,8 @@ export default defineEventHandler(async (event) => {
21
21
  {
22
22
  query: operationDocument,
23
23
  variables,
24
- operation: GraphqlMiddlewareOperation.Query
24
+ operation: GraphqlMiddlewareOperation.Query,
25
+ operationName
25
26
  },
26
27
  context,
27
28
  event
@@ -8,9 +8,7 @@ import {
8
8
  onServerResponse
9
9
  } from "../helpers/index.js";
10
10
  export async function doGraphqlRequest(body, context = null, providedEvent = null) {
11
- const operationName = body.operationName || null;
12
11
  const event = providedEvent ?? useEvent();
13
- const runtimeConfig = useRuntimeConfig().graphqlMiddleware;
14
12
  if (serverOptions.doGraphqlRequest) {
15
13
  return serverOptions.doGraphqlRequest({
16
14
  event,
@@ -21,6 +19,9 @@ export async function doGraphqlRequest(body, context = null, providedEvent = nul
21
19
  context: context || {}
22
20
  });
23
21
  }
22
+ const operation = body.operation || null;
23
+ const operationName = body.operationName || null;
24
+ const runtimeConfig = useRuntimeConfig().graphqlMiddleware;
24
25
  const endpoint = await getEndpoint(
25
26
  runtimeConfig,
26
27
  serverOptions,
@@ -50,7 +51,7 @@ export async function doGraphqlRequest(body, context = null, providedEvent = nul
50
51
  serverOptions,
51
52
  event,
52
53
  response,
53
- null,
54
+ operation,
54
55
  operationName,
55
56
  context
56
57
  );
@@ -59,7 +60,7 @@ export async function doGraphqlRequest(body, context = null, providedEvent = nul
59
60
  serverOptions,
60
61
  event,
61
62
  error,
62
- null,
63
+ operation,
63
64
  operationName,
64
65
  context
65
66
  );
@@ -88,8 +88,8 @@ export type GraphqlClientOptions<T extends ContextType = ContextType> = {
88
88
  export type GraphqlMiddlewareRequestContext<C extends ContextType = ContextType> = {
89
89
  client?: Partial<C>;
90
90
  };
91
- export type GraphqlMiddlewareGraphqlEndpointMethod<C extends ContextType> = (event?: H3Event, operation?: string | null, operationName?: string | null, context?: GraphqlMiddlewareRequestContext<C> | null) => string | Promise<string> | undefined;
92
- export type GraphqlMiddlewareServerFetchOptionsMethod<C extends ContextType> = (event?: H3Event, operation?: string | null, operationName?: string | null, context?: GraphqlMiddlewareRequestContext<C> | null) => FetchOptions | Promise<FetchOptions>;
91
+ export type GraphqlMiddlewareGraphqlEndpointMethod<C extends ContextType> = (event: H3Event, operation?: string | null, operationName?: string | null, context?: GraphqlMiddlewareRequestContext<C> | null) => string | Promise<string> | undefined;
92
+ export type GraphqlMiddlewareServerFetchOptionsMethod<C extends ContextType> = (event: H3Event, operation?: string | null, operationName?: string | null, context?: GraphqlMiddlewareRequestContext<C> | null) => FetchOptions | Promise<FetchOptions>;
93
93
  export type GraphqlMiddlewareOnServerResponseMethod<ServerReponse, T, C extends ContextType> = (event: H3Event, response: FetchResponse<ServerReponse>, operation?: string | null, operationName?: string | null, context?: GraphqlMiddlewareRequestContext<C> | null) => T | Promise<T>;
94
94
  export type GraphqlMiddlewareOnServerErrorMethod<C extends ContextType> = (event: H3Event, error: FetchError, operation?: string | null, operationName?: string | null, context?: GraphqlMiddlewareRequestContext<C> | null) => any | Promise<any>;
95
95
  export type GraphqlMiddlewareDoRequestMethodContext<C extends ContextType> = {
@@ -0,0 +1,8 @@
1
+ import { GraphqlClientContext } from '#nuxt-graphql-middleware/client-options';
2
+ import { GraphqlMiddlewareResponseUnion } from '#nuxt-graphql-middleware/response';
3
+ import { GraphqlMiddlewareServerOptions } from '../dist/runtime/types.js';
4
+ export { GraphqlMiddlewareServerOptions } from '../dist/runtime/types.js';
5
+
6
+ declare function defineGraphqlServerOptions<T extends object = object>(options: GraphqlMiddlewareServerOptions<T, GraphqlMiddlewareResponseUnion, GraphqlClientContext>): GraphqlMiddlewareServerOptions<T, GraphqlMiddlewareResponseUnion, GraphqlClientContext>;
7
+
8
+ export { defineGraphqlServerOptions };
@@ -0,0 +1,5 @@
1
+ function defineGraphqlServerOptions(options) {
2
+ return options;
3
+ }
4
+
5
+ export { defineGraphqlServerOptions };