nuxt-graphql-middleware 5.0.0-alpha.1 → 5.0.0-alpha.12
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/dist/client/200.html +11 -0
- package/dist/client/404.html +11 -0
- package/dist/client/_nuxt/AZpplOcD.js +1 -0
- package/dist/client/_nuxt/B2Rg1ezw.js +1 -0
- package/dist/client/_nuxt/Bt6N0bOg.js +2 -0
- package/dist/client/_nuxt/M311G39J.js +25 -0
- package/dist/client/_nuxt/builds/latest.json +1 -0
- package/dist/client/_nuxt/builds/meta/88c25798-8ea2-4139-90f2-506f3146e7b3.json +1 -0
- package/dist/client/_nuxt/entry.Cn9qfNGa.css +1 -0
- package/dist/client/_nuxt/error-404.ehK72JOs.css +1 -0
- package/dist/client/_nuxt/error-500._g0akJim.css +1 -0
- package/dist/client/_nuxt/index.DGEN-H8t.css +1 -0
- package/dist/client/_nuxt/u9er1db2.js +1 -0
- package/dist/client/index.html +11 -0
- package/dist/module.d.mts +57 -205
- package/dist/module.d.ts +57 -205
- package/dist/module.json +2 -2
- package/dist/module.mjs +1138 -563
- package/dist/runtime/components/CodeFrame.vue +61 -0
- package/dist/runtime/components/DevModeOverlay.vue +60 -0
- package/dist/runtime/components/ErrorExtensions.vue +23 -0
- package/dist/runtime/components/ErrorGroup.vue +89 -0
- package/dist/runtime/composables/nuxtApp.d.ts +2 -2
- package/dist/runtime/composables/nuxtApp.js +21 -1
- package/dist/runtime/composables/useAsyncGraphqlQuery.d.ts +7 -7
- package/dist/runtime/composables/useAsyncGraphqlQuery.js +10 -2
- package/dist/runtime/composables/useGraphqlMutation.d.ts +4 -4
- package/dist/runtime/composables/useGraphqlMutation.js +1 -1
- package/dist/runtime/composables/useGraphqlQuery.d.ts +4 -4
- package/dist/runtime/composables/useGraphqlQuery.js +1 -1
- package/dist/runtime/composables/useGraphqlState.d.ts +1 -1
- package/dist/runtime/composables/useGraphqlState.js +1 -1
- package/dist/runtime/composables/useGraphqlUploadMutation.d.ts +4 -4
- package/dist/runtime/composables/useGraphqlUploadMutation.js +2 -2
- package/dist/runtime/css/output.css +1 -0
- package/dist/runtime/helpers/composables.d.ts +17 -20
- package/dist/runtime/helpers/composables.js +0 -5
- package/dist/runtime/plugins/devMode.d.ts +2 -0
- package/dist/runtime/plugins/devMode.js +23 -0
- package/dist/runtime/plugins/provideState.d.ts +1 -1
- package/dist/runtime/{serverHandler → server/api}/debug.js +3 -7
- package/dist/runtime/server/api/mutation.js +28 -0
- package/dist/runtime/server/api/query.js +29 -0
- package/dist/runtime/server/api/upload.d.ts +2 -0
- package/dist/runtime/{serverHandler → server/api}/upload.js +13 -11
- package/dist/runtime/{serverHandler → server}/helpers/index.d.ts +10 -12
- package/dist/runtime/{serverHandler → server}/helpers/index.js +9 -26
- package/dist/runtime/server/utils/doGraphqlRequest.d.ts +18 -0
- package/dist/runtime/server/utils/doGraphqlRequest.js +67 -0
- package/dist/runtime/server/utils/index.d.ts +1 -1
- package/dist/runtime/server/utils/index.js +1 -1
- package/dist/runtime/server/utils/useGraphqlMutation.d.ts +4 -4
- package/dist/runtime/server/utils/useGraphqlQuery.d.ts +4 -4
- package/dist/runtime/serverOptions/defineGraphqlServerOptions.d.ts +4 -3
- package/dist/runtime/settings/index.d.ts +0 -14
- package/dist/runtime/settings/index.js +0 -6
- package/dist/runtime/types.d.ts +204 -3
- package/dist/types.d.mts +5 -5
- package/dist/types.d.ts +5 -5
- package/package.json +39 -36
- package/dist/runtime/serverHandler/index.js +0 -78
- package/dist/runtime/serverHandler/tsconfig.json +0 -3
- /package/dist/runtime/{serverHandler → server/api}/debug.d.ts +0 -0
- /package/dist/runtime/{serverHandler/index.d.ts → server/api/mutation.d.ts} +0 -0
- /package/dist/runtime/{serverHandler/upload.d.ts → server/api/query.d.ts} +0 -0
package/dist/module.d.mts
CHANGED
|
@@ -1,203 +1,10 @@
|
|
|
1
1
|
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
|
+
import { HookResult } from 'nuxt/schema';
|
|
3
|
+
import { OperationResponseError } from '../dist/runtime/types.js';
|
|
4
|
+
export { GraphqlMiddlewareServerOptions } from '../dist/runtime/types.js';
|
|
2
5
|
import { Types } from '@graphql-codegen/plugin-helpers';
|
|
3
6
|
import { SchemaASTConfig } from '@graphql-codegen/schema-ast';
|
|
4
7
|
import { GeneratorOptions } from 'graphql-typescript-deluxe';
|
|
5
|
-
import { H3Event } from 'h3';
|
|
6
|
-
import { FetchOptions, FetchResponse, FetchError } from 'ofetch';
|
|
7
|
-
import { ContextType, GraphqlServerResponse } from '#graphql-middleware/types';
|
|
8
|
-
import { GraphqlMiddlewareResponseUnion } from '#nuxt-graphql-middleware/generated-types';
|
|
9
|
-
|
|
10
|
-
type GraphqlMiddlewareRequestContext<C extends ContextType = ContextType> = {
|
|
11
|
-
client?: Partial<C>;
|
|
12
|
-
};
|
|
13
|
-
type GraphqlMiddlewareGraphqlEndpointMethod<C extends ContextType> = (event?: H3Event, operation?: string, operationName?: string, context?: GraphqlMiddlewareRequestContext<C>) => string | Promise<string> | undefined;
|
|
14
|
-
type GraphqlMiddlewareServerFetchOptionsMethod<C extends ContextType> = (event?: H3Event, operation?: string, operationName?: string, context?: GraphqlMiddlewareRequestContext<C>) => FetchOptions | Promise<FetchOptions>;
|
|
15
|
-
type GraphqlMiddlewareOnServerResponseMethod<ServerReponse, T, C extends ContextType> = (event: H3Event, response: FetchResponse<ServerReponse>, operation?: string, operationName?: string, context?: GraphqlMiddlewareRequestContext<C>) => T | Promise<T>;
|
|
16
|
-
type GraphqlMiddlewareOnServerErrorMethod<C extends ContextType> = (event: H3Event, error: FetchError, operation?: string, operationName?: string, context?: GraphqlMiddlewareRequestContext<C>) => any | Promise<any>;
|
|
17
|
-
type GraphqlMiddlewareDoRequestMethodContext<C extends ContextType> = {
|
|
18
|
-
/**
|
|
19
|
-
* The incoming request event from H3.
|
|
20
|
-
*/
|
|
21
|
-
event: H3Event;
|
|
22
|
-
/**
|
|
23
|
-
* The type of operation.
|
|
24
|
-
*/
|
|
25
|
-
operation: 'query' | 'mutation';
|
|
26
|
-
/**
|
|
27
|
-
* The name of the operation.
|
|
28
|
-
*/
|
|
29
|
-
operationName: string;
|
|
30
|
-
/**
|
|
31
|
-
* The operation document (the raw GraphQL query/mutation as a string).
|
|
32
|
-
*/
|
|
33
|
-
operationDocument: string;
|
|
34
|
-
/**
|
|
35
|
-
* Variables for the operation.
|
|
36
|
-
*/
|
|
37
|
-
variables: Record<string, any>;
|
|
38
|
-
/**
|
|
39
|
-
* For file uploads (which are done using FormData), this contains the full
|
|
40
|
-
* form data with these keys:
|
|
41
|
-
*
|
|
42
|
-
* - operations: string
|
|
43
|
-
* A JSON string of an object with "query", "variables" and "operationName" properties.
|
|
44
|
-
* Example:
|
|
45
|
-
* operations='{ "query": "mutation ($id: String!, $file: Upload!) { uploadFile(id: $id, file: $file) { id filename } }", "variables": { "file": null, "id": "1" } }'
|
|
46
|
-
* - map: string
|
|
47
|
-
* A JSON string of an object whose keys are strings starting at '0' and the values being an array with a single string:
|
|
48
|
-
* Example:
|
|
49
|
-
* map='{ "0": ["variables.file"] }'
|
|
50
|
-
* - [number]
|
|
51
|
-
* For every file there is a FormData entry with a name that matches the key in `map`.
|
|
52
|
-
* Example:
|
|
53
|
-
* 0=[Binary File]
|
|
54
|
-
*/
|
|
55
|
-
formData?: FormData;
|
|
56
|
-
context: GraphqlMiddlewareRequestContext<C>;
|
|
57
|
-
};
|
|
58
|
-
type GraphqlMiddlewareDoRequestMethod<T, C extends ContextType> = (context: GraphqlMiddlewareDoRequestMethodContext<C>) => Promise<T>;
|
|
59
|
-
/**
|
|
60
|
-
* Configuration options during runtime.
|
|
61
|
-
*/
|
|
62
|
-
type GraphqlMiddlewareServerOptions<Additions extends object = object, C extends ContextType = ContextType, CustomResponse = GraphqlServerResponse<GraphqlMiddlewareResponseUnion> & Additions> = {
|
|
63
|
-
/**
|
|
64
|
-
* Custom callback to return the GraphQL endpoint per request.
|
|
65
|
-
*
|
|
66
|
-
* The method is only called if no `doGraphqlRequest` method is implemented.
|
|
67
|
-
*
|
|
68
|
-
* @default undefined
|
|
69
|
-
*
|
|
70
|
-
* @example
|
|
71
|
-
* ```ts
|
|
72
|
-
* function graphqlEndpoint(event, operation, operationName) {
|
|
73
|
-
* const language = getLanguageFromRequest(event)
|
|
74
|
-
* return `https://api.example.com/${language}/graphql`
|
|
75
|
-
* }
|
|
76
|
-
* ```
|
|
77
|
-
*/
|
|
78
|
-
graphqlEndpoint?: GraphqlMiddlewareGraphqlEndpointMethod<C>;
|
|
79
|
-
/**
|
|
80
|
-
* Provide the options for the ofetch request to the GraphQL server.
|
|
81
|
-
*
|
|
82
|
-
* The method is only called if no `doGraphqlRequest` method is implemented.
|
|
83
|
-
*
|
|
84
|
-
* @default undefined
|
|
85
|
-
*
|
|
86
|
-
* @example
|
|
87
|
-
* ```ts
|
|
88
|
-
* import { getHeader } from 'h3'
|
|
89
|
-
*
|
|
90
|
-
* // Pass the cookie from the client request to the GraphQL request.
|
|
91
|
-
* function serverFetchOptions(event, operation, operationName) {
|
|
92
|
-
* return {
|
|
93
|
-
* headers: {
|
|
94
|
-
* Cookie: getHeader(event, 'cookie')
|
|
95
|
-
* }
|
|
96
|
-
* }
|
|
97
|
-
* }
|
|
98
|
-
* ```
|
|
99
|
-
*/
|
|
100
|
-
serverFetchOptions?: GraphqlMiddlewareServerFetchOptionsMethod<C>;
|
|
101
|
-
/**
|
|
102
|
-
* Handle the response from the GraphQL server.
|
|
103
|
-
*
|
|
104
|
-
* The method is only called if no `doGraphqlRequest` method is implemented.
|
|
105
|
-
*
|
|
106
|
-
* You can alter the response, add additional properties to the data, get
|
|
107
|
-
* and set headers, etc.
|
|
108
|
-
*
|
|
109
|
-
* ```ts
|
|
110
|
-
* import type { H3Event } from 'h3'
|
|
111
|
-
* import type { FetchResponse } from 'ofetch'
|
|
112
|
-
*
|
|
113
|
-
* function onServerResponse(event: H3Event, graphqlResponse: FetchResponse) {
|
|
114
|
-
* // Set a static header.
|
|
115
|
-
* event.node.res.setHeader('x-nuxt-custom-header', 'A custom header value')
|
|
116
|
-
*
|
|
117
|
-
* // Pass the set-cookie header from the GraphQL response to the client.
|
|
118
|
-
* const setCookie = graphqlResponse.headers.get('set-cookie')
|
|
119
|
-
* if (setCookie) {
|
|
120
|
-
* event.node.res.setHeader('set-cookie', setCookie)
|
|
121
|
-
* }
|
|
122
|
-
*
|
|
123
|
-
* // Add additional properties to the response.
|
|
124
|
-
* graphqlResponse._data.__customProperty = ['My', 'values']
|
|
125
|
-
*
|
|
126
|
-
* // Return the GraphQL response.
|
|
127
|
-
* return graphqlResponse._data
|
|
128
|
-
* }
|
|
129
|
-
* ```
|
|
130
|
-
*/
|
|
131
|
-
onServerResponse?: GraphqlMiddlewareOnServerResponseMethod<GraphqlServerResponse<GraphqlMiddlewareResponseUnion>, CustomResponse, C>;
|
|
132
|
-
/**
|
|
133
|
-
* Handle a fetch error from the GraphQL request.
|
|
134
|
-
*
|
|
135
|
-
* The method is only called if no `doGraphqlRequest` method is implemented.
|
|
136
|
-
*
|
|
137
|
-
* Note that errors are only thrown for responses that are not status
|
|
138
|
-
* 200-299. See https://github.com/unjs/ofetch#%EF%B8%8F-handling-errors for
|
|
139
|
-
* more information.
|
|
140
|
-
*
|
|
141
|
-
* ```ts
|
|
142
|
-
* import { createError } from 'h3'
|
|
143
|
-
* import type { H3Event } from 'h3'
|
|
144
|
-
* import type { FetchError } from 'ofetch'
|
|
145
|
-
*
|
|
146
|
-
* function onServerError(
|
|
147
|
-
* event: H3Event,
|
|
148
|
-
* error: FetchError,
|
|
149
|
-
* operation: string,
|
|
150
|
-
* operationName: string,
|
|
151
|
-
* ) {
|
|
152
|
-
* // Throw a h3 error.
|
|
153
|
-
* throw createError({
|
|
154
|
-
* statusCode: 500,
|
|
155
|
-
* statusMessage: `Couldn't execute GraphQL ${operation} "${operationName}".`,
|
|
156
|
-
* data: error.message
|
|
157
|
-
* })
|
|
158
|
-
* }
|
|
159
|
-
* ```
|
|
160
|
-
*/
|
|
161
|
-
onServerError?: GraphqlMiddlewareOnServerErrorMethod<C>;
|
|
162
|
-
/**
|
|
163
|
-
* Provide a custom fetch method for requests to the GraphQL server.
|
|
164
|
-
*
|
|
165
|
-
* This can be used if onServerError, onServerResponse, serverFetchOptions
|
|
166
|
-
* and graphqlEndpoint are not enough to meet your requirements.
|
|
167
|
-
*
|
|
168
|
-
* When this method is implemented, all other methods are not called.
|
|
169
|
-
*
|
|
170
|
-
* The method will be called in the /api/graphql server route and should
|
|
171
|
-
* perform the GraphQL request and return the response.
|
|
172
|
-
*
|
|
173
|
-
* An example use case might be to handle expired tokens.
|
|
174
|
-
*
|
|
175
|
-
* * ```ts
|
|
176
|
-
* async function doGraphqlRequest({
|
|
177
|
-
* event,
|
|
178
|
-
* operation,
|
|
179
|
-
* operationName,
|
|
180
|
-
* operationDocument,
|
|
181
|
-
* variables,
|
|
182
|
-
* }) {
|
|
183
|
-
* const result = await $fetch.raw('https://example.com/graphql', {
|
|
184
|
-
* method: 'POST'
|
|
185
|
-
* body: {
|
|
186
|
-
* query: operationDocument,
|
|
187
|
-
* variables,
|
|
188
|
-
* operationName
|
|
189
|
-
* },
|
|
190
|
-
* headers: {
|
|
191
|
-
* 'custom-header': 'foobar'
|
|
192
|
-
* }
|
|
193
|
-
* })
|
|
194
|
-
*
|
|
195
|
-
* return result._data
|
|
196
|
-
* }
|
|
197
|
-
* ```
|
|
198
|
-
*/
|
|
199
|
-
doGraphqlRequest?: GraphqlMiddlewareDoRequestMethod<CustomResponse, C>;
|
|
200
|
-
};
|
|
201
8
|
|
|
202
9
|
interface ModuleOptions {
|
|
203
10
|
/**
|
|
@@ -220,6 +27,14 @@ interface ModuleOptions {
|
|
|
220
27
|
* ```
|
|
221
28
|
*/
|
|
222
29
|
autoImportPatterns?: string[];
|
|
30
|
+
/**
|
|
31
|
+
* The path where your graphql.config.ts is, relative to the location of nuxt.config.ts.
|
|
32
|
+
*
|
|
33
|
+
* Used to generate the correct paths in the graphql.config.ts file generated by the module.
|
|
34
|
+
*
|
|
35
|
+
* @default "./graphql.config.ts"
|
|
36
|
+
*/
|
|
37
|
+
graphqlConfigFilePath?: string;
|
|
223
38
|
/**
|
|
224
39
|
* Additional raw documents to include.
|
|
225
40
|
*
|
|
@@ -264,6 +79,10 @@ interface ModuleOptions {
|
|
|
264
79
|
* @default false
|
|
265
80
|
*/
|
|
266
81
|
debug?: boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Displays GraphQL response errors in an overlay in dev mode.
|
|
84
|
+
*/
|
|
85
|
+
errorOverlay?: boolean;
|
|
267
86
|
/**
|
|
268
87
|
* The URL of the GraphQL server.
|
|
269
88
|
*
|
|
@@ -275,9 +94,20 @@ interface ModuleOptions {
|
|
|
275
94
|
/**
|
|
276
95
|
* Download the GraphQL schema and store it on disk.
|
|
277
96
|
*
|
|
97
|
+
* Usually you'll want to only enable this during dev mode.
|
|
98
|
+
*
|
|
278
99
|
* @default true
|
|
279
100
|
*/
|
|
280
101
|
downloadSchema?: boolean;
|
|
102
|
+
/**
|
|
103
|
+
* Path to the GraphQL schema file.
|
|
104
|
+
*
|
|
105
|
+
* If `downloadSchema` is `true`, the downloaded schema is written to this specified path.
|
|
106
|
+
* If `downloadSchema` is `false`, this file must be present in order to generate types.
|
|
107
|
+
*
|
|
108
|
+
* @default './schema.graphql'
|
|
109
|
+
*/
|
|
110
|
+
schemaPath?: string;
|
|
281
111
|
/**
|
|
282
112
|
* The prefix for the server route.
|
|
283
113
|
*
|
|
@@ -287,14 +117,12 @@ interface ModuleOptions {
|
|
|
287
117
|
*/
|
|
288
118
|
serverApiPrefix?: string;
|
|
289
119
|
/**
|
|
290
|
-
*
|
|
291
|
-
*
|
|
292
|
-
* If `downloadSchema` is `true`, the downloaded schema is written to this specified path.
|
|
293
|
-
* If `downloadSchema` is `false`, this file must be present in order to generate types.
|
|
120
|
+
* Logs only errors.
|
|
294
121
|
*
|
|
295
|
-
*
|
|
122
|
+
* When enabled only errors are logged to the console when generating the GraphQL operations.
|
|
123
|
+
* If false, all operations are logged, including valid ones.
|
|
296
124
|
*/
|
|
297
|
-
|
|
125
|
+
logOnlyErrors?: boolean;
|
|
298
126
|
/**
|
|
299
127
|
* Options for graphql-typescript-deluxe code generator.
|
|
300
128
|
*/
|
|
@@ -342,17 +170,41 @@ interface ModuleOptions {
|
|
|
342
170
|
maxSize?: number;
|
|
343
171
|
};
|
|
344
172
|
}
|
|
345
|
-
|
|
346
|
-
}
|
|
173
|
+
|
|
347
174
|
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
|
|
348
175
|
|
|
349
176
|
declare module '@nuxt/schema' {
|
|
350
177
|
interface AppConfig {
|
|
351
178
|
graphqlMiddleware: {
|
|
179
|
+
/**
|
|
180
|
+
* Whether the client cache is enabled.
|
|
181
|
+
*/
|
|
352
182
|
clientCacheEnabled: boolean;
|
|
183
|
+
/**
|
|
184
|
+
* The max number of items in the cache.
|
|
185
|
+
*/
|
|
353
186
|
clientCacheMaxSize: number;
|
|
354
187
|
};
|
|
355
188
|
}
|
|
356
189
|
}
|
|
190
|
+
declare module '#app' {
|
|
191
|
+
interface RuntimeNuxtHooks {
|
|
192
|
+
/**
|
|
193
|
+
* Emitted when any GraphQL response contains errors.
|
|
194
|
+
*/
|
|
195
|
+
'nuxt-graphql-middleware:errors': (errors: OperationResponseError) => HookResult;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
declare module 'vite/types/customEvent.d.ts' {
|
|
199
|
+
interface CustomEventMap {
|
|
200
|
+
/**
|
|
201
|
+
* Emitted when GraphQL operations have been updated.
|
|
202
|
+
*/
|
|
203
|
+
'nuxt-graphql-middleware:reload': {
|
|
204
|
+
operations: string[];
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
}
|
|
357
208
|
|
|
358
|
-
export {
|
|
209
|
+
export { _default as default };
|
|
210
|
+
export type { ModuleOptions };
|
package/dist/module.d.ts
CHANGED
|
@@ -1,203 +1,10 @@
|
|
|
1
1
|
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
|
+
import { HookResult } from 'nuxt/schema';
|
|
3
|
+
import { OperationResponseError } from '../dist/runtime/types.js';
|
|
4
|
+
export { GraphqlMiddlewareServerOptions } from '../dist/runtime/types.js';
|
|
2
5
|
import { Types } from '@graphql-codegen/plugin-helpers';
|
|
3
6
|
import { SchemaASTConfig } from '@graphql-codegen/schema-ast';
|
|
4
7
|
import { GeneratorOptions } from 'graphql-typescript-deluxe';
|
|
5
|
-
import { H3Event } from 'h3';
|
|
6
|
-
import { FetchOptions, FetchResponse, FetchError } from 'ofetch';
|
|
7
|
-
import { ContextType, GraphqlServerResponse } from '#graphql-middleware/types';
|
|
8
|
-
import { GraphqlMiddlewareResponseUnion } from '#nuxt-graphql-middleware/generated-types';
|
|
9
|
-
|
|
10
|
-
type GraphqlMiddlewareRequestContext<C extends ContextType = ContextType> = {
|
|
11
|
-
client?: Partial<C>;
|
|
12
|
-
};
|
|
13
|
-
type GraphqlMiddlewareGraphqlEndpointMethod<C extends ContextType> = (event?: H3Event, operation?: string, operationName?: string, context?: GraphqlMiddlewareRequestContext<C>) => string | Promise<string> | undefined;
|
|
14
|
-
type GraphqlMiddlewareServerFetchOptionsMethod<C extends ContextType> = (event?: H3Event, operation?: string, operationName?: string, context?: GraphqlMiddlewareRequestContext<C>) => FetchOptions | Promise<FetchOptions>;
|
|
15
|
-
type GraphqlMiddlewareOnServerResponseMethod<ServerReponse, T, C extends ContextType> = (event: H3Event, response: FetchResponse<ServerReponse>, operation?: string, operationName?: string, context?: GraphqlMiddlewareRequestContext<C>) => T | Promise<T>;
|
|
16
|
-
type GraphqlMiddlewareOnServerErrorMethod<C extends ContextType> = (event: H3Event, error: FetchError, operation?: string, operationName?: string, context?: GraphqlMiddlewareRequestContext<C>) => any | Promise<any>;
|
|
17
|
-
type GraphqlMiddlewareDoRequestMethodContext<C extends ContextType> = {
|
|
18
|
-
/**
|
|
19
|
-
* The incoming request event from H3.
|
|
20
|
-
*/
|
|
21
|
-
event: H3Event;
|
|
22
|
-
/**
|
|
23
|
-
* The type of operation.
|
|
24
|
-
*/
|
|
25
|
-
operation: 'query' | 'mutation';
|
|
26
|
-
/**
|
|
27
|
-
* The name of the operation.
|
|
28
|
-
*/
|
|
29
|
-
operationName: string;
|
|
30
|
-
/**
|
|
31
|
-
* The operation document (the raw GraphQL query/mutation as a string).
|
|
32
|
-
*/
|
|
33
|
-
operationDocument: string;
|
|
34
|
-
/**
|
|
35
|
-
* Variables for the operation.
|
|
36
|
-
*/
|
|
37
|
-
variables: Record<string, any>;
|
|
38
|
-
/**
|
|
39
|
-
* For file uploads (which are done using FormData), this contains the full
|
|
40
|
-
* form data with these keys:
|
|
41
|
-
*
|
|
42
|
-
* - operations: string
|
|
43
|
-
* A JSON string of an object with "query", "variables" and "operationName" properties.
|
|
44
|
-
* Example:
|
|
45
|
-
* operations='{ "query": "mutation ($id: String!, $file: Upload!) { uploadFile(id: $id, file: $file) { id filename } }", "variables": { "file": null, "id": "1" } }'
|
|
46
|
-
* - map: string
|
|
47
|
-
* A JSON string of an object whose keys are strings starting at '0' and the values being an array with a single string:
|
|
48
|
-
* Example:
|
|
49
|
-
* map='{ "0": ["variables.file"] }'
|
|
50
|
-
* - [number]
|
|
51
|
-
* For every file there is a FormData entry with a name that matches the key in `map`.
|
|
52
|
-
* Example:
|
|
53
|
-
* 0=[Binary File]
|
|
54
|
-
*/
|
|
55
|
-
formData?: FormData;
|
|
56
|
-
context: GraphqlMiddlewareRequestContext<C>;
|
|
57
|
-
};
|
|
58
|
-
type GraphqlMiddlewareDoRequestMethod<T, C extends ContextType> = (context: GraphqlMiddlewareDoRequestMethodContext<C>) => Promise<T>;
|
|
59
|
-
/**
|
|
60
|
-
* Configuration options during runtime.
|
|
61
|
-
*/
|
|
62
|
-
type GraphqlMiddlewareServerOptions<Additions extends object = object, C extends ContextType = ContextType, CustomResponse = GraphqlServerResponse<GraphqlMiddlewareResponseUnion> & Additions> = {
|
|
63
|
-
/**
|
|
64
|
-
* Custom callback to return the GraphQL endpoint per request.
|
|
65
|
-
*
|
|
66
|
-
* The method is only called if no `doGraphqlRequest` method is implemented.
|
|
67
|
-
*
|
|
68
|
-
* @default undefined
|
|
69
|
-
*
|
|
70
|
-
* @example
|
|
71
|
-
* ```ts
|
|
72
|
-
* function graphqlEndpoint(event, operation, operationName) {
|
|
73
|
-
* const language = getLanguageFromRequest(event)
|
|
74
|
-
* return `https://api.example.com/${language}/graphql`
|
|
75
|
-
* }
|
|
76
|
-
* ```
|
|
77
|
-
*/
|
|
78
|
-
graphqlEndpoint?: GraphqlMiddlewareGraphqlEndpointMethod<C>;
|
|
79
|
-
/**
|
|
80
|
-
* Provide the options for the ofetch request to the GraphQL server.
|
|
81
|
-
*
|
|
82
|
-
* The method is only called if no `doGraphqlRequest` method is implemented.
|
|
83
|
-
*
|
|
84
|
-
* @default undefined
|
|
85
|
-
*
|
|
86
|
-
* @example
|
|
87
|
-
* ```ts
|
|
88
|
-
* import { getHeader } from 'h3'
|
|
89
|
-
*
|
|
90
|
-
* // Pass the cookie from the client request to the GraphQL request.
|
|
91
|
-
* function serverFetchOptions(event, operation, operationName) {
|
|
92
|
-
* return {
|
|
93
|
-
* headers: {
|
|
94
|
-
* Cookie: getHeader(event, 'cookie')
|
|
95
|
-
* }
|
|
96
|
-
* }
|
|
97
|
-
* }
|
|
98
|
-
* ```
|
|
99
|
-
*/
|
|
100
|
-
serverFetchOptions?: GraphqlMiddlewareServerFetchOptionsMethod<C>;
|
|
101
|
-
/**
|
|
102
|
-
* Handle the response from the GraphQL server.
|
|
103
|
-
*
|
|
104
|
-
* The method is only called if no `doGraphqlRequest` method is implemented.
|
|
105
|
-
*
|
|
106
|
-
* You can alter the response, add additional properties to the data, get
|
|
107
|
-
* and set headers, etc.
|
|
108
|
-
*
|
|
109
|
-
* ```ts
|
|
110
|
-
* import type { H3Event } from 'h3'
|
|
111
|
-
* import type { FetchResponse } from 'ofetch'
|
|
112
|
-
*
|
|
113
|
-
* function onServerResponse(event: H3Event, graphqlResponse: FetchResponse) {
|
|
114
|
-
* // Set a static header.
|
|
115
|
-
* event.node.res.setHeader('x-nuxt-custom-header', 'A custom header value')
|
|
116
|
-
*
|
|
117
|
-
* // Pass the set-cookie header from the GraphQL response to the client.
|
|
118
|
-
* const setCookie = graphqlResponse.headers.get('set-cookie')
|
|
119
|
-
* if (setCookie) {
|
|
120
|
-
* event.node.res.setHeader('set-cookie', setCookie)
|
|
121
|
-
* }
|
|
122
|
-
*
|
|
123
|
-
* // Add additional properties to the response.
|
|
124
|
-
* graphqlResponse._data.__customProperty = ['My', 'values']
|
|
125
|
-
*
|
|
126
|
-
* // Return the GraphQL response.
|
|
127
|
-
* return graphqlResponse._data
|
|
128
|
-
* }
|
|
129
|
-
* ```
|
|
130
|
-
*/
|
|
131
|
-
onServerResponse?: GraphqlMiddlewareOnServerResponseMethod<GraphqlServerResponse<GraphqlMiddlewareResponseUnion>, CustomResponse, C>;
|
|
132
|
-
/**
|
|
133
|
-
* Handle a fetch error from the GraphQL request.
|
|
134
|
-
*
|
|
135
|
-
* The method is only called if no `doGraphqlRequest` method is implemented.
|
|
136
|
-
*
|
|
137
|
-
* Note that errors are only thrown for responses that are not status
|
|
138
|
-
* 200-299. See https://github.com/unjs/ofetch#%EF%B8%8F-handling-errors for
|
|
139
|
-
* more information.
|
|
140
|
-
*
|
|
141
|
-
* ```ts
|
|
142
|
-
* import { createError } from 'h3'
|
|
143
|
-
* import type { H3Event } from 'h3'
|
|
144
|
-
* import type { FetchError } from 'ofetch'
|
|
145
|
-
*
|
|
146
|
-
* function onServerError(
|
|
147
|
-
* event: H3Event,
|
|
148
|
-
* error: FetchError,
|
|
149
|
-
* operation: string,
|
|
150
|
-
* operationName: string,
|
|
151
|
-
* ) {
|
|
152
|
-
* // Throw a h3 error.
|
|
153
|
-
* throw createError({
|
|
154
|
-
* statusCode: 500,
|
|
155
|
-
* statusMessage: `Couldn't execute GraphQL ${operation} "${operationName}".`,
|
|
156
|
-
* data: error.message
|
|
157
|
-
* })
|
|
158
|
-
* }
|
|
159
|
-
* ```
|
|
160
|
-
*/
|
|
161
|
-
onServerError?: GraphqlMiddlewareOnServerErrorMethod<C>;
|
|
162
|
-
/**
|
|
163
|
-
* Provide a custom fetch method for requests to the GraphQL server.
|
|
164
|
-
*
|
|
165
|
-
* This can be used if onServerError, onServerResponse, serverFetchOptions
|
|
166
|
-
* and graphqlEndpoint are not enough to meet your requirements.
|
|
167
|
-
*
|
|
168
|
-
* When this method is implemented, all other methods are not called.
|
|
169
|
-
*
|
|
170
|
-
* The method will be called in the /api/graphql server route and should
|
|
171
|
-
* perform the GraphQL request and return the response.
|
|
172
|
-
*
|
|
173
|
-
* An example use case might be to handle expired tokens.
|
|
174
|
-
*
|
|
175
|
-
* * ```ts
|
|
176
|
-
* async function doGraphqlRequest({
|
|
177
|
-
* event,
|
|
178
|
-
* operation,
|
|
179
|
-
* operationName,
|
|
180
|
-
* operationDocument,
|
|
181
|
-
* variables,
|
|
182
|
-
* }) {
|
|
183
|
-
* const result = await $fetch.raw('https://example.com/graphql', {
|
|
184
|
-
* method: 'POST'
|
|
185
|
-
* body: {
|
|
186
|
-
* query: operationDocument,
|
|
187
|
-
* variables,
|
|
188
|
-
* operationName
|
|
189
|
-
* },
|
|
190
|
-
* headers: {
|
|
191
|
-
* 'custom-header': 'foobar'
|
|
192
|
-
* }
|
|
193
|
-
* })
|
|
194
|
-
*
|
|
195
|
-
* return result._data
|
|
196
|
-
* }
|
|
197
|
-
* ```
|
|
198
|
-
*/
|
|
199
|
-
doGraphqlRequest?: GraphqlMiddlewareDoRequestMethod<CustomResponse, C>;
|
|
200
|
-
};
|
|
201
8
|
|
|
202
9
|
interface ModuleOptions {
|
|
203
10
|
/**
|
|
@@ -220,6 +27,14 @@ interface ModuleOptions {
|
|
|
220
27
|
* ```
|
|
221
28
|
*/
|
|
222
29
|
autoImportPatterns?: string[];
|
|
30
|
+
/**
|
|
31
|
+
* The path where your graphql.config.ts is, relative to the location of nuxt.config.ts.
|
|
32
|
+
*
|
|
33
|
+
* Used to generate the correct paths in the graphql.config.ts file generated by the module.
|
|
34
|
+
*
|
|
35
|
+
* @default "./graphql.config.ts"
|
|
36
|
+
*/
|
|
37
|
+
graphqlConfigFilePath?: string;
|
|
223
38
|
/**
|
|
224
39
|
* Additional raw documents to include.
|
|
225
40
|
*
|
|
@@ -264,6 +79,10 @@ interface ModuleOptions {
|
|
|
264
79
|
* @default false
|
|
265
80
|
*/
|
|
266
81
|
debug?: boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Displays GraphQL response errors in an overlay in dev mode.
|
|
84
|
+
*/
|
|
85
|
+
errorOverlay?: boolean;
|
|
267
86
|
/**
|
|
268
87
|
* The URL of the GraphQL server.
|
|
269
88
|
*
|
|
@@ -275,9 +94,20 @@ interface ModuleOptions {
|
|
|
275
94
|
/**
|
|
276
95
|
* Download the GraphQL schema and store it on disk.
|
|
277
96
|
*
|
|
97
|
+
* Usually you'll want to only enable this during dev mode.
|
|
98
|
+
*
|
|
278
99
|
* @default true
|
|
279
100
|
*/
|
|
280
101
|
downloadSchema?: boolean;
|
|
102
|
+
/**
|
|
103
|
+
* Path to the GraphQL schema file.
|
|
104
|
+
*
|
|
105
|
+
* If `downloadSchema` is `true`, the downloaded schema is written to this specified path.
|
|
106
|
+
* If `downloadSchema` is `false`, this file must be present in order to generate types.
|
|
107
|
+
*
|
|
108
|
+
* @default './schema.graphql'
|
|
109
|
+
*/
|
|
110
|
+
schemaPath?: string;
|
|
281
111
|
/**
|
|
282
112
|
* The prefix for the server route.
|
|
283
113
|
*
|
|
@@ -287,14 +117,12 @@ interface ModuleOptions {
|
|
|
287
117
|
*/
|
|
288
118
|
serverApiPrefix?: string;
|
|
289
119
|
/**
|
|
290
|
-
*
|
|
291
|
-
*
|
|
292
|
-
* If `downloadSchema` is `true`, the downloaded schema is written to this specified path.
|
|
293
|
-
* If `downloadSchema` is `false`, this file must be present in order to generate types.
|
|
120
|
+
* Logs only errors.
|
|
294
121
|
*
|
|
295
|
-
*
|
|
122
|
+
* When enabled only errors are logged to the console when generating the GraphQL operations.
|
|
123
|
+
* If false, all operations are logged, including valid ones.
|
|
296
124
|
*/
|
|
297
|
-
|
|
125
|
+
logOnlyErrors?: boolean;
|
|
298
126
|
/**
|
|
299
127
|
* Options for graphql-typescript-deluxe code generator.
|
|
300
128
|
*/
|
|
@@ -342,17 +170,41 @@ interface ModuleOptions {
|
|
|
342
170
|
maxSize?: number;
|
|
343
171
|
};
|
|
344
172
|
}
|
|
345
|
-
|
|
346
|
-
}
|
|
173
|
+
|
|
347
174
|
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
|
|
348
175
|
|
|
349
176
|
declare module '@nuxt/schema' {
|
|
350
177
|
interface AppConfig {
|
|
351
178
|
graphqlMiddleware: {
|
|
179
|
+
/**
|
|
180
|
+
* Whether the client cache is enabled.
|
|
181
|
+
*/
|
|
352
182
|
clientCacheEnabled: boolean;
|
|
183
|
+
/**
|
|
184
|
+
* The max number of items in the cache.
|
|
185
|
+
*/
|
|
353
186
|
clientCacheMaxSize: number;
|
|
354
187
|
};
|
|
355
188
|
}
|
|
356
189
|
}
|
|
190
|
+
declare module '#app' {
|
|
191
|
+
interface RuntimeNuxtHooks {
|
|
192
|
+
/**
|
|
193
|
+
* Emitted when any GraphQL response contains errors.
|
|
194
|
+
*/
|
|
195
|
+
'nuxt-graphql-middleware:errors': (errors: OperationResponseError) => HookResult;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
declare module 'vite/types/customEvent.d.ts' {
|
|
199
|
+
interface CustomEventMap {
|
|
200
|
+
/**
|
|
201
|
+
* Emitted when GraphQL operations have been updated.
|
|
202
|
+
*/
|
|
203
|
+
'nuxt-graphql-middleware:reload': {
|
|
204
|
+
operations: string[];
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
}
|
|
357
208
|
|
|
358
|
-
export {
|
|
209
|
+
export { _default as default };
|
|
210
|
+
export type { ModuleOptions };
|
package/dist/module.json
CHANGED