nuxt-graphql-middleware 5.0.0-alpha.4 → 5.0.0-alpha.5
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 +2 -2
- package/dist/client/404.html +2 -2
- package/dist/client/_nuxt/builds/latest.json +1 -1
- package/dist/client/_nuxt/builds/meta/c22c2916-33e9-427d-b6fe-10f11766c207.json +1 -0
- package/dist/client/index.html +2 -2
- package/dist/module.d.mts +15 -5
- package/dist/module.d.ts +15 -5
- package/dist/module.json +2 -2
- package/dist/module.mjs +228 -207
- 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 +19 -18
- package/dist/runtime/composables/useAsyncGraphqlQuery.d.ts +7 -7
- package/dist/runtime/composables/useAsyncGraphqlQuery.js +1 -1
- 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/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/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/serverHandler/debug.js +3 -7
- package/dist/runtime/serverHandler/helpers/index.d.ts +2 -2
- package/dist/runtime/serverHandler/index.js +4 -4
- package/dist/runtime/serverHandler/upload.js +4 -4
- package/dist/runtime/serverOptions/defineGraphqlServerOptions.d.ts +3 -2
- package/dist/runtime/settings/index.d.ts +24 -3
- package/dist/runtime/settings/index.js +8 -2
- package/dist/runtime/types.d.ts +8 -2
- package/package.json +14 -4
- package/dist/client/_nuxt/builds/meta/106a09af-649a-473b-b0c7-0e4ce5709429.json +0 -1
package/dist/module.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { loadSchema } from '@graphql-tools/load';
|
|
|
2
2
|
import { fileURLToPath } from 'url';
|
|
3
3
|
import { relative } from 'pathe';
|
|
4
4
|
import { defu } from 'defu';
|
|
5
|
-
import { useLogger, resolveFiles, defineNuxtModule, resolveAlias, createResolver, addImports, addServerImports, addTemplate, addServerHandler, addPlugin } from '@nuxt/kit';
|
|
5
|
+
import { useLogger, resolveFiles, defineNuxtModule, resolveAlias, createResolver, addImports, addServerImports, addTypeTemplate, addTemplate, addServerHandler, addPlugin } from '@nuxt/kit';
|
|
6
6
|
import { onDevToolsInitialized, extendServerRpc } from '@nuxt/devtools-kit';
|
|
7
7
|
import { existsSync } from 'fs';
|
|
8
8
|
import { GraphqlMiddlewareTemplate } from '../dist/runtime/settings/index.js';
|
|
@@ -11,14 +11,13 @@ import { existsSync as existsSync$1, promises } from 'node:fs';
|
|
|
11
11
|
import { generate } from '@graphql-codegen/cli';
|
|
12
12
|
import * as PluginSchemaAst from '@graphql-codegen/schema-ast';
|
|
13
13
|
import { basename } from 'node:path';
|
|
14
|
-
import { printSourceLocation, parse, Source } from 'graphql';
|
|
14
|
+
import { printSourceLocation, parse, OperationTypeNode, Source } from 'graphql';
|
|
15
15
|
import { Generator, FieldNotFoundError, TypeNotFoundError, FragmentNotFoundError } from 'graphql-typescript-deluxe';
|
|
16
|
-
import { pascalCase } from 'change-case-all';
|
|
17
16
|
import colors from 'picocolors';
|
|
18
17
|
import { validateGraphQlDocuments } from '@graphql-tools/utils';
|
|
19
18
|
|
|
20
19
|
const name = "nuxt-graphql-middleware";
|
|
21
|
-
const version = "5.0.0-alpha.
|
|
20
|
+
const version = "5.0.0-alpha.5";
|
|
22
21
|
|
|
23
22
|
const DEVTOOLS_UI_ROUTE = "/__nuxt-graphql-middleware";
|
|
24
23
|
const DEVTOOLS_UI_LOCAL_PORT = 3300;
|
|
@@ -98,7 +97,8 @@ const defaultOptions = {
|
|
|
98
97
|
debug: false,
|
|
99
98
|
includeComposables: true,
|
|
100
99
|
documents: [],
|
|
101
|
-
devtools: true
|
|
100
|
+
devtools: true,
|
|
101
|
+
errorOverlay: true
|
|
102
102
|
};
|
|
103
103
|
function validateOptions(options) {
|
|
104
104
|
if (!options.graphqlEndpoint) {
|
|
@@ -136,111 +136,19 @@ const fileExists = (path, extensions = ["js", "ts", "mjs"]) => {
|
|
|
136
136
|
return extension ? `${path}.${extension}` : null;
|
|
137
137
|
};
|
|
138
138
|
|
|
139
|
-
function
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
result[op.operationType][op.graphqlName] = {
|
|
147
|
-
hasVariables: op.hasVariables,
|
|
148
|
-
variablesOptional: !op.needsVariables
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
return result;
|
|
152
|
-
}
|
|
153
|
-
function buildOperationTypeCode(operationMetadata, typeName, serverApiPrefix) {
|
|
154
|
-
const imports = [];
|
|
155
|
-
const resultTypes = [];
|
|
156
|
-
let code = "";
|
|
157
|
-
let nitroCode = "";
|
|
158
|
-
const operationNames = Object.keys(operationMetadata);
|
|
159
|
-
if (operationNames.length === 0) {
|
|
160
|
-
return { code, nitroCode, imports, resultTypes };
|
|
161
|
-
}
|
|
162
|
-
const lines = [];
|
|
163
|
-
const nitroLines = [];
|
|
164
|
-
for (const name of operationNames) {
|
|
165
|
-
const nameResult = pascalCase(`${name}${typeName}`);
|
|
166
|
-
const nameVariables = pascalCase(`${name}${typeName}Variables`);
|
|
167
|
-
resultTypes.push(nameResult);
|
|
168
|
-
imports.push(nameResult);
|
|
169
|
-
const { hasVariables, variablesOptional } = operationMetadata[name];
|
|
170
|
-
if (hasVariables) {
|
|
171
|
-
imports.push(nameVariables);
|
|
172
|
-
}
|
|
173
|
-
const variablesType = hasVariables ? nameVariables : "null";
|
|
174
|
-
lines.push(
|
|
175
|
-
` ${name}: [${variablesType}, ${variablesOptional ? "true" : "false"}, ${nameResult}]`
|
|
176
|
-
);
|
|
177
|
-
nitroLines.push(`
|
|
178
|
-
'${serverApiPrefix}/${typeName.toLowerCase()}/${name}': {
|
|
179
|
-
'default': GraphqlResponse<${nameResult}>
|
|
180
|
-
}`);
|
|
181
|
-
}
|
|
182
|
-
code += ` export type GraphqlMiddleware${typeName} = {
|
|
183
|
-
${lines.join(",\n")}
|
|
184
|
-
}
|
|
185
|
-
`;
|
|
186
|
-
nitroCode += nitroLines.join("\n");
|
|
187
|
-
return { code, nitroCode, imports, resultTypes };
|
|
188
|
-
}
|
|
189
|
-
function generateContextTemplate(collectedOperations, serverApiPrefix) {
|
|
190
|
-
const grouped = groupOperationsByType(collectedOperations);
|
|
191
|
-
const queryResult = buildOperationTypeCode(
|
|
192
|
-
grouped.query,
|
|
193
|
-
"Query",
|
|
194
|
-
serverApiPrefix
|
|
195
|
-
);
|
|
196
|
-
const mutationResult = buildOperationTypeCode(
|
|
197
|
-
grouped.mutation,
|
|
198
|
-
"Mutation",
|
|
199
|
-
serverApiPrefix
|
|
200
|
-
);
|
|
201
|
-
const subscriptionResult = buildOperationTypeCode(
|
|
202
|
-
grouped.subscription,
|
|
203
|
-
"Subscription",
|
|
204
|
-
serverApiPrefix
|
|
205
|
-
);
|
|
206
|
-
const allImports = [
|
|
207
|
-
...queryResult.imports,
|
|
208
|
-
...mutationResult.imports,
|
|
209
|
-
...subscriptionResult.imports
|
|
210
|
-
];
|
|
211
|
-
const allResultTypes = [
|
|
212
|
-
...queryResult.resultTypes,
|
|
213
|
-
...mutationResult.resultTypes,
|
|
214
|
-
...subscriptionResult.resultTypes
|
|
215
|
-
];
|
|
216
|
-
const combinedCode = [
|
|
217
|
-
queryResult.code,
|
|
218
|
-
mutationResult.code,
|
|
219
|
-
subscriptionResult.code
|
|
220
|
-
].filter(Boolean).join("\n");
|
|
221
|
-
const combinedNitroCode = [
|
|
222
|
-
queryResult.nitroCode,
|
|
223
|
-
mutationResult.nitroCode,
|
|
224
|
-
subscriptionResult.nitroCode
|
|
225
|
-
].join("\n");
|
|
226
|
-
const typeImports = allImports.length ? `import type {
|
|
227
|
-
${allImports.join(",\n ")}
|
|
228
|
-
} from './../graphql-operations'` : "";
|
|
229
|
-
return `
|
|
230
|
-
import type { GraphqlResponse } from '#graphql-middleware-server-options-build'
|
|
231
|
-
${typeImports}
|
|
139
|
+
function generateResponseTypeTemplate(operations, context) {
|
|
140
|
+
const allTypes = operations.map((v) => v.typeName).sort();
|
|
141
|
+
return `import type {
|
|
142
|
+
${allTypes.join(",\n ")}
|
|
143
|
+
} from './../graphql-operations'
|
|
144
|
+
import type { GraphqlResponseAdditions } from './server-options'
|
|
145
|
+
import type { GraphqlServerResponse } from '${context.runtimeTypesPath}'
|
|
232
146
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
${combinedCode}
|
|
236
|
-
}
|
|
147
|
+
export type GraphqlMiddlewareResponseUnion =
|
|
148
|
+
| ${allTypes.join("\n | ") || "never"}
|
|
237
149
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
${combinedNitroCode}
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
`;
|
|
150
|
+
export type GraphqlResponse<T> = GraphqlServerResponse<T> & GraphqlResponseAdditions
|
|
151
|
+
export type GraphqlResponseTyped = GraphqlResponse<GraphqlMiddlewareResponseUnion>`;
|
|
244
152
|
}
|
|
245
153
|
|
|
246
154
|
const SYMBOL_CROSS = "x";
|
|
@@ -330,6 +238,45 @@ class CollectedFile {
|
|
|
330
238
|
}
|
|
331
239
|
}
|
|
332
240
|
|
|
241
|
+
function generateNitroTypes(operations, serverApiPrefix) {
|
|
242
|
+
const endpoints = [];
|
|
243
|
+
const imports = [];
|
|
244
|
+
for (const operation of operations) {
|
|
245
|
+
imports.push(operation.typeName);
|
|
246
|
+
const method = operation.operationType === OperationTypeNode.QUERY ? "get" : "post";
|
|
247
|
+
endpoints.push(
|
|
248
|
+
` '${serverApiPrefix}/${operation.operationType}/${operation.graphqlName}': {
|
|
249
|
+
'${method}': GraphqlResponse<${operation.typeName}>
|
|
250
|
+
}`
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
return `import type { GraphqlResponse } from './response'
|
|
254
|
+
import type {
|
|
255
|
+
${imports.sort().join(",\n ")}
|
|
256
|
+
} from './../graphql-operations'
|
|
257
|
+
|
|
258
|
+
declare module 'nitropack/types' {
|
|
259
|
+
interface InternalApi {
|
|
260
|
+
${endpoints.sort().join("\n")}
|
|
261
|
+
}
|
|
262
|
+
}`;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function generateSourcesTemplate(operations, srcDir) {
|
|
266
|
+
const lines = [];
|
|
267
|
+
for (const operation of operations) {
|
|
268
|
+
const filePath = relative(srcDir, operation.filePath);
|
|
269
|
+
lines.push(
|
|
270
|
+
`${operation.operationType}_${operation.graphqlName}: '${filePath}',`
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
return `
|
|
274
|
+
export const operationSources = {
|
|
275
|
+
${lines.join("\n ")}
|
|
276
|
+
}
|
|
277
|
+
`;
|
|
278
|
+
}
|
|
279
|
+
|
|
333
280
|
class Collector {
|
|
334
281
|
constructor(schema, context, nuxtConfigDocuments = [], generatorOptions = {}) {
|
|
335
282
|
this.schema = schema;
|
|
@@ -374,10 +321,22 @@ class Collector {
|
|
|
374
321
|
* The generated oeprations file.
|
|
375
322
|
*/
|
|
376
323
|
outputOperations = "";
|
|
324
|
+
/**
|
|
325
|
+
* The generated oepration types file.
|
|
326
|
+
*/
|
|
327
|
+
outputOperationTypes = "";
|
|
377
328
|
/**
|
|
378
329
|
* The generated context template file.
|
|
379
330
|
*/
|
|
380
|
-
|
|
331
|
+
outputResponseTypes = "";
|
|
332
|
+
/**
|
|
333
|
+
* The generated nitro template file.
|
|
334
|
+
*/
|
|
335
|
+
outputNitroTypes = "";
|
|
336
|
+
/**
|
|
337
|
+
* The generated nitro template file.
|
|
338
|
+
*/
|
|
339
|
+
outputSources = "";
|
|
381
340
|
filePathToBuildRelative(filePath) {
|
|
382
341
|
return "./" + relative(this.context.buildDir, filePath);
|
|
383
342
|
}
|
|
@@ -410,13 +369,27 @@ class Collector {
|
|
|
410
369
|
const output = this.generator.build();
|
|
411
370
|
const operations = output.getCollectedOperations();
|
|
412
371
|
const generatedCode = output.getGeneratedCode();
|
|
413
|
-
this.outputOperations = output.getOperationsFile(
|
|
372
|
+
this.outputOperations = output.getOperationsFile({
|
|
373
|
+
exportName: "documents",
|
|
374
|
+
minify: !this.context.isDev
|
|
375
|
+
}).getSource();
|
|
376
|
+
this.outputOperationTypes = output.getOperationTypesFile({
|
|
377
|
+
importFrom: "./../graphql-operations"
|
|
378
|
+
}).getSource();
|
|
414
379
|
this.outputEnums = output.buildFile(["enum"]).getSource();
|
|
415
380
|
this.outputTypes = this.buildOutputTypes(output.getTypes());
|
|
416
|
-
this.
|
|
381
|
+
this.outputResponseTypes = generateResponseTypeTemplate(
|
|
382
|
+
operations,
|
|
383
|
+
this.context
|
|
384
|
+
);
|
|
385
|
+
this.outputNitroTypes = generateNitroTypes(
|
|
417
386
|
operations,
|
|
418
387
|
this.context.serverApiPrefix
|
|
419
388
|
);
|
|
389
|
+
this.outputSources = generateSourcesTemplate(
|
|
390
|
+
operations,
|
|
391
|
+
this.context.rootDir
|
|
392
|
+
);
|
|
420
393
|
const fragmentMap = /* @__PURE__ */ new Map();
|
|
421
394
|
const operationSourceMap = /* @__PURE__ */ new Map();
|
|
422
395
|
for (const code of generatedCode) {
|
|
@@ -636,8 +609,8 @@ class Collector {
|
|
|
636
609
|
/**
|
|
637
610
|
* Get the context template contents.
|
|
638
611
|
*/
|
|
639
|
-
|
|
640
|
-
return this.
|
|
612
|
+
getTemplateResponseTypes() {
|
|
613
|
+
return this.outputResponseTypes;
|
|
641
614
|
}
|
|
642
615
|
/**
|
|
643
616
|
* Get the operations template contents.
|
|
@@ -645,6 +618,37 @@ class Collector {
|
|
|
645
618
|
getTemplateOperations() {
|
|
646
619
|
return this.outputOperations;
|
|
647
620
|
}
|
|
621
|
+
/**
|
|
622
|
+
* Get the operation types template contents.
|
|
623
|
+
*/
|
|
624
|
+
getTemplateOperationTypes() {
|
|
625
|
+
return this.outputOperationTypes;
|
|
626
|
+
}
|
|
627
|
+
/**
|
|
628
|
+
* Get the nitro types template contents.
|
|
629
|
+
*/
|
|
630
|
+
getTemplateNitroTypes() {
|
|
631
|
+
return this.outputNitroTypes;
|
|
632
|
+
}
|
|
633
|
+
/**
|
|
634
|
+
* Get the nitro types template contents.
|
|
635
|
+
*/
|
|
636
|
+
getTemplateSources() {
|
|
637
|
+
return this.outputSources;
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
function generateDocumentTypesTemplate() {
|
|
642
|
+
return `
|
|
643
|
+
import type { Query, Mutation } from './operations'
|
|
644
|
+
|
|
645
|
+
declare module '#nuxt-graphql-middleware/documents' {
|
|
646
|
+
export type Documents = {
|
|
647
|
+
query: Record<keyof Query, string>
|
|
648
|
+
mutation: Record<keyof Mutation, string>
|
|
649
|
+
}
|
|
650
|
+
export const documents: Documents
|
|
651
|
+
}`;
|
|
648
652
|
}
|
|
649
653
|
|
|
650
654
|
function useViteWebSocket(nuxt) {
|
|
@@ -661,15 +665,19 @@ const module = defineNuxtModule({
|
|
|
661
665
|
configKey: "graphqlMiddleware",
|
|
662
666
|
version,
|
|
663
667
|
compatibility: {
|
|
664
|
-
nuxt: ">=3.
|
|
668
|
+
nuxt: ">=3.15.0"
|
|
665
669
|
}
|
|
666
670
|
},
|
|
667
671
|
defaults: defaultOptions,
|
|
668
672
|
async setup(passedOptions, nuxt) {
|
|
669
673
|
const options = defu({}, passedOptions, defaultOptions);
|
|
670
|
-
function addAlias(name2,
|
|
671
|
-
|
|
672
|
-
|
|
674
|
+
function addAlias(name2, path) {
|
|
675
|
+
nuxt.options.alias[name2] = path;
|
|
676
|
+
}
|
|
677
|
+
function inlineNitroExternals(path) {
|
|
678
|
+
nuxt.options.nitro.externals = nuxt.options.nitro.externals || {};
|
|
679
|
+
nuxt.options.nitro.externals.inline = nuxt.options.nitro.externals.inline || [];
|
|
680
|
+
nuxt.options.nitro.externals.inline.push(path);
|
|
673
681
|
}
|
|
674
682
|
const isModuleBuild = process.env.MODULE_BUILD === "true" && nuxt.options._prepare;
|
|
675
683
|
if (isModuleBuild) {
|
|
@@ -709,17 +717,30 @@ const module = defineNuxtModule({
|
|
|
709
717
|
});
|
|
710
718
|
const runtimeDir = fileURLToPath(new URL("./runtime", import.meta.url));
|
|
711
719
|
nuxt.options.build.transpile.push(runtimeDir);
|
|
720
|
+
const nuxtGraphqlMiddlewareBuildDir = nuxt.options.buildDir + "/nuxt-graphql-middleware";
|
|
721
|
+
const operationTypesBuildDir = nuxt.options.buildDir + "/graphql-operations";
|
|
722
|
+
const toBuildRelative = (path) => {
|
|
723
|
+
return relative(nuxtGraphqlMiddlewareBuildDir, path);
|
|
724
|
+
};
|
|
725
|
+
addAlias("#nuxt-graphql-middleware", nuxtGraphqlMiddlewareBuildDir);
|
|
726
|
+
addAlias("#graphql-operations", operationTypesBuildDir);
|
|
727
|
+
const context = {
|
|
728
|
+
isDev: nuxt.options.dev,
|
|
729
|
+
patterns: options.autoImportPatterns || [],
|
|
730
|
+
srcDir: nuxt.options.srcDir,
|
|
731
|
+
rootDir: nuxt.options.rootDir,
|
|
732
|
+
buildDir: srcResolver.resolve(nuxt.options.buildDir),
|
|
733
|
+
nuxtConfigPath: rootResolver.resolve("nuxt.config.ts"),
|
|
734
|
+
schemaPath,
|
|
735
|
+
serverApiPrefix: options.serverApiPrefix,
|
|
736
|
+
logOnlyErrors: !!options.logOnlyErrors,
|
|
737
|
+
runtimeTypesPath: toBuildRelative(
|
|
738
|
+
moduleResolver.resolve("./runtime/types.ts")
|
|
739
|
+
)
|
|
740
|
+
};
|
|
712
741
|
const collector = new Collector(
|
|
713
742
|
schema,
|
|
714
|
-
|
|
715
|
-
patterns: options.autoImportPatterns || [],
|
|
716
|
-
srcDir: nuxt.options.srcDir,
|
|
717
|
-
buildDir: srcResolver.resolve(nuxt.options.buildDir),
|
|
718
|
-
nuxtConfigPath: rootResolver.resolve("nuxt.config.ts"),
|
|
719
|
-
schemaPath,
|
|
720
|
-
serverApiPrefix: options.serverApiPrefix,
|
|
721
|
-
logOnlyErrors: !!options.logOnlyErrors
|
|
722
|
-
},
|
|
743
|
+
context,
|
|
723
744
|
options.documents,
|
|
724
745
|
options.codegenConfig
|
|
725
746
|
);
|
|
@@ -741,9 +762,6 @@ const module = defineNuxtModule({
|
|
|
741
762
|
});
|
|
742
763
|
});
|
|
743
764
|
}
|
|
744
|
-
nuxt.options.runtimeConfig.public["nuxt-graphql-middleware"] = {
|
|
745
|
-
serverApiPrefix: options.serverApiPrefix
|
|
746
|
-
};
|
|
747
765
|
nuxt.options.appConfig.graphqlMiddleware = {
|
|
748
766
|
clientCacheEnabled: !!options.clientCache?.enabled,
|
|
749
767
|
clientCacheMaxSize: options.clientCache?.maxSize || 100
|
|
@@ -777,55 +795,74 @@ const module = defineNuxtModule({
|
|
|
777
795
|
);
|
|
778
796
|
addServerImports(serverUtils);
|
|
779
797
|
}
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
addTemplate({
|
|
783
|
-
filename: GraphqlMiddlewareTemplate.OperationTypes,
|
|
784
|
-
write: true,
|
|
785
|
-
getContents: () => collector.getTemplateTypes()
|
|
786
|
-
})
|
|
787
|
-
);
|
|
788
|
-
addAlias(
|
|
789
|
-
"#graphql-operations/enums",
|
|
790
|
-
addTemplate({
|
|
791
|
-
filename: GraphqlMiddlewareTemplate.Enums,
|
|
792
|
-
write: true,
|
|
793
|
-
getContents: () => collector.getTemplateEnums()
|
|
794
|
-
})
|
|
795
|
-
);
|
|
796
|
-
const templateDocuments = addTemplate({
|
|
797
|
-
filename: GraphqlMiddlewareTemplate.Documents,
|
|
798
|
-
write: true,
|
|
799
|
-
getContents: () => collector.getTemplateOperations()
|
|
800
|
-
});
|
|
801
|
-
addAlias("#graphql-documents", templateDocuments.dst);
|
|
802
|
-
const templateContext = addTemplate({
|
|
803
|
-
filename: GraphqlMiddlewareTemplate.ComposableContext,
|
|
798
|
+
addTypeTemplate({
|
|
799
|
+
filename: GraphqlMiddlewareTemplate.OperationTypes,
|
|
804
800
|
write: true,
|
|
805
|
-
getContents: () => collector.
|
|
801
|
+
getContents: () => collector.getTemplateTypes()
|
|
806
802
|
});
|
|
807
|
-
|
|
808
|
-
|
|
803
|
+
addTypeTemplate({
|
|
804
|
+
filename: GraphqlMiddlewareTemplate.Types,
|
|
809
805
|
write: true,
|
|
810
|
-
filename: "nuxt-graphql-middleware/graphql-documents.d.ts",
|
|
811
806
|
getContents: () => {
|
|
812
807
|
return `
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
GraphqlMiddlewareMutation,
|
|
816
|
-
} from '#nuxt-graphql-middleware/generated-types'
|
|
817
|
-
|
|
818
|
-
declare module '#graphql-documents' {
|
|
819
|
-
type Operations = {
|
|
820
|
-
query: GraphqlMiddlewareQuery
|
|
821
|
-
mutation: GraphqlMiddlewareMutation
|
|
822
|
-
}
|
|
823
|
-
const operations: Operations
|
|
824
|
-
export { operations, Operations }
|
|
808
|
+
declare module '#nuxt-graphql-middleware/sources' {
|
|
809
|
+
export const operationSources: Record<string, string>
|
|
825
810
|
}
|
|
826
811
|
`;
|
|
827
812
|
}
|
|
828
813
|
});
|
|
814
|
+
addTemplate({
|
|
815
|
+
filename: GraphqlMiddlewareTemplate.Enums,
|
|
816
|
+
write: true,
|
|
817
|
+
getContents: () => collector.getTemplateEnums()
|
|
818
|
+
});
|
|
819
|
+
addTemplate({
|
|
820
|
+
filename: GraphqlMiddlewareTemplate.OperationSources,
|
|
821
|
+
write: true,
|
|
822
|
+
getContents: () => collector.getTemplateSources()
|
|
823
|
+
});
|
|
824
|
+
addTemplate({
|
|
825
|
+
filename: GraphqlMiddlewareTemplate.Helpers,
|
|
826
|
+
write: true,
|
|
827
|
+
getContents: () => `export const serverApiPrefix = '${context.serverApiPrefix}'
|
|
828
|
+
export function getEndpoint(operation, operationName) {
|
|
829
|
+
return '${context.serverApiPrefix}' + '/' + operation + '/' + operationName
|
|
830
|
+
}
|
|
831
|
+
`
|
|
832
|
+
});
|
|
833
|
+
addTypeTemplate({
|
|
834
|
+
filename: GraphqlMiddlewareTemplate.HelpersTypes,
|
|
835
|
+
write: true,
|
|
836
|
+
getContents: () => `export const serverApiPrefix: string;
|
|
837
|
+
export function getEndpoint(operation: string, operationName: string): string
|
|
838
|
+
`
|
|
839
|
+
});
|
|
840
|
+
addTypeTemplate({
|
|
841
|
+
filename: GraphqlMiddlewareTemplate.NitroTypes,
|
|
842
|
+
write: true,
|
|
843
|
+
getContents: () => collector.getTemplateNitroTypes()
|
|
844
|
+
});
|
|
845
|
+
addTypeTemplate({
|
|
846
|
+
filename: GraphqlMiddlewareTemplate.OperationTypesAll,
|
|
847
|
+
write: true,
|
|
848
|
+
getContents: () => collector.getTemplateOperationTypes()
|
|
849
|
+
});
|
|
850
|
+
const templateDocuments = addTemplate({
|
|
851
|
+
filename: GraphqlMiddlewareTemplate.Documents,
|
|
852
|
+
write: true,
|
|
853
|
+
getContents: () => collector.getTemplateOperations()
|
|
854
|
+
});
|
|
855
|
+
inlineNitroExternals(templateDocuments.dst);
|
|
856
|
+
addTypeTemplate({
|
|
857
|
+
filename: GraphqlMiddlewareTemplate.ResponseTypes,
|
|
858
|
+
write: true,
|
|
859
|
+
getContents: () => collector.getTemplateResponseTypes()
|
|
860
|
+
});
|
|
861
|
+
addTypeTemplate({
|
|
862
|
+
write: true,
|
|
863
|
+
filename: "nuxt-graphql-middleware/documents.d.ts",
|
|
864
|
+
getContents: () => generateDocumentTypesTemplate()
|
|
865
|
+
});
|
|
829
866
|
const findServerOptions = () => {
|
|
830
867
|
const newPath = serverResolver.resolve("graphqlMiddleware.serverOptions");
|
|
831
868
|
const serverPath = fileExists(newPath);
|
|
@@ -850,13 +887,10 @@ declare module '#graphql-documents' {
|
|
|
850
887
|
logger.info("No graphqlMiddleware.serverOptions file found.");
|
|
851
888
|
};
|
|
852
889
|
const resolvedServerOptionsPath = findServerOptions();
|
|
853
|
-
const moduleTypesPath =
|
|
854
|
-
|
|
855
|
-
moduleResolver.resolve("./types")
|
|
856
|
-
);
|
|
857
|
-
const resolvedPathRelative = resolvedServerOptionsPath ? relative(nuxt.options.buildDir, resolvedServerOptionsPath) : null;
|
|
890
|
+
const moduleTypesPath = toBuildRelative(moduleResolver.resolve("./types"));
|
|
891
|
+
const resolvedPathRelative = resolvedServerOptionsPath ? toBuildRelative(resolvedServerOptionsPath) : null;
|
|
858
892
|
const template = addTemplate({
|
|
859
|
-
filename: "
|
|
893
|
+
filename: "nuxt-graphql-middleware/server-options.mjs",
|
|
860
894
|
write: true,
|
|
861
895
|
getContents: () => {
|
|
862
896
|
const serverOptionsLine = resolvedPathRelative ? `import serverOptions from '${resolvedPathRelative}'` : `const serverOptions = {}`;
|
|
@@ -866,26 +900,20 @@ export { serverOptions }
|
|
|
866
900
|
`;
|
|
867
901
|
}
|
|
868
902
|
});
|
|
903
|
+
inlineNitroExternals(template.dst);
|
|
869
904
|
addTemplate({
|
|
870
|
-
filename: "
|
|
905
|
+
filename: "nuxt-graphql-middleware/server-options.d.ts",
|
|
871
906
|
write: true,
|
|
872
907
|
getContents: () => {
|
|
873
908
|
const serverOptionsLineTypes = resolvedPathRelative ? `import serverOptions from '${resolvedPathRelative}'` : `const serverOptions: GraphqlMiddlewareServerOptions = {}`;
|
|
874
909
|
return `
|
|
875
910
|
import type { GraphqlMiddlewareServerOptions } from '${moduleTypesPath}'
|
|
876
911
|
${serverOptionsLineTypes}
|
|
877
|
-
import type { GraphqlServerResponse } from '${runtimeTypesPath}'
|
|
878
|
-
import type { GraphqlMiddlewareResponseUnion } from '#nuxt-graphql-middleware/generated-types'
|
|
879
912
|
|
|
880
|
-
type GraphqlResponseAdditions =
|
|
913
|
+
export type GraphqlResponseAdditions =
|
|
881
914
|
typeof serverOptions extends GraphqlMiddlewareServerOptions<infer R, any, any> ? R : {}
|
|
882
915
|
|
|
883
|
-
export
|
|
884
|
-
|
|
885
|
-
export type GraphqlResponseTyped = GraphqlResponse<GraphqlMiddlewareResponseUnion>
|
|
886
|
-
|
|
887
|
-
export { serverOptions }
|
|
888
|
-
`;
|
|
916
|
+
export { serverOptions }`;
|
|
889
917
|
}
|
|
890
918
|
});
|
|
891
919
|
const getClientOptionsImport = () => {
|
|
@@ -893,13 +921,13 @@ export { serverOptions }
|
|
|
893
921
|
"graphqlMiddleware.clientOptions"
|
|
894
922
|
);
|
|
895
923
|
if (fileExists(clientOptionsPath)) {
|
|
896
|
-
const pathRelative =
|
|
924
|
+
const pathRelative = toBuildRelative(clientOptionsPath);
|
|
897
925
|
return `import clientOptions from '${pathRelative}'`;
|
|
898
926
|
}
|
|
899
927
|
};
|
|
900
928
|
const clientOptionsImport = getClientOptionsImport();
|
|
901
|
-
|
|
902
|
-
filename: "
|
|
929
|
+
addTemplate({
|
|
930
|
+
filename: "nuxt-graphql-middleware/client-options.mjs",
|
|
903
931
|
write: true,
|
|
904
932
|
getContents: () => {
|
|
905
933
|
if (clientOptionsImport) {
|
|
@@ -909,39 +937,25 @@ export { clientOptions }`;
|
|
|
909
937
|
return `export const clientOptions = {}`;
|
|
910
938
|
}
|
|
911
939
|
});
|
|
912
|
-
const runtimeTypesPath = relative(
|
|
913
|
-
nuxt.options.buildDir,
|
|
914
|
-
moduleResolver.resolve("./runtime/types.ts")
|
|
915
|
-
);
|
|
916
940
|
addTemplate({
|
|
917
|
-
filename: "
|
|
941
|
+
filename: "nuxt-graphql-middleware/client-options.d.ts",
|
|
918
942
|
write: true,
|
|
919
943
|
getContents: () => {
|
|
920
944
|
if (clientOptionsImport) {
|
|
921
|
-
return `import type { GraphqlClientOptions } from '${runtimeTypesPath}'
|
|
945
|
+
return `import type { GraphqlClientOptions } from '${context.runtimeTypesPath}'
|
|
922
946
|
${clientOptionsImport}
|
|
923
947
|
|
|
924
948
|
export type GraphqlClientContext = typeof clientOptions extends GraphqlClientOptions<infer R> ? R : {}
|
|
925
949
|
|
|
926
950
|
export { clientOptions }`;
|
|
927
951
|
}
|
|
928
|
-
return `import type { GraphqlClientOptions } from '${runtimeTypesPath}'
|
|
952
|
+
return `import type { GraphqlClientOptions } from '${context.runtimeTypesPath}'
|
|
929
953
|
export const clientOptions: GraphqlClientOptions
|
|
930
954
|
|
|
931
955
|
export type GraphqlClientContext = {}
|
|
932
956
|
`;
|
|
933
957
|
}
|
|
934
958
|
});
|
|
935
|
-
addAlias("#graphql-middleware-client-options", clientOptionsTemplate.dst);
|
|
936
|
-
nuxt.options.nitro.externals = nuxt.options.nitro.externals || {};
|
|
937
|
-
nuxt.options.nitro.externals.inline = nuxt.options.nitro.externals.inline || [];
|
|
938
|
-
nuxt.options.nitro.externals.inline.push(template.dst);
|
|
939
|
-
nuxt.options.nitro.externals.inline.push(templateDocuments.dst);
|
|
940
|
-
addAlias("#graphql-middleware-server-options-build", template.dst);
|
|
941
|
-
addAlias(
|
|
942
|
-
"#graphql-middleware/types",
|
|
943
|
-
moduleResolver.resolve("./runtime/types.ts")
|
|
944
|
-
);
|
|
945
959
|
addServerHandler({
|
|
946
960
|
handler: moduleResolver.resolve("./runtime/serverHandler/index"),
|
|
947
961
|
route: options.serverApiPrefix + "/:operation/:name"
|
|
@@ -955,6 +969,11 @@ export type GraphqlClientContext = {}
|
|
|
955
969
|
addPlugin(moduleResolver.resolve("./runtime/plugins/provideState"), {
|
|
956
970
|
append: false
|
|
957
971
|
});
|
|
972
|
+
if (context.isDev && options.errorOverlay) {
|
|
973
|
+
addPlugin(moduleResolver.resolve("./runtime/plugins/devMode"), {
|
|
974
|
+
append: false
|
|
975
|
+
});
|
|
976
|
+
}
|
|
958
977
|
nuxt.hook("nitro:config", (nitroConfig) => {
|
|
959
978
|
nitroConfig.externals = defu(
|
|
960
979
|
typeof nitroConfig.externals === "object" ? nitroConfig.externals : {},
|
|
@@ -994,8 +1013,10 @@ export type GraphqlClientContext = {}
|
|
|
994
1013
|
if (error) {
|
|
995
1014
|
sendError(error);
|
|
996
1015
|
}
|
|
997
|
-
if (hasChanged
|
|
998
|
-
rpc
|
|
1016
|
+
if (hasChanged) {
|
|
1017
|
+
if (rpc) {
|
|
1018
|
+
rpc.broadcast.documentsUpdated([...collector.rpcItems.values()]);
|
|
1019
|
+
}
|
|
999
1020
|
}
|
|
1000
1021
|
});
|
|
1001
1022
|
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="nuxt-graphql-middleware-errors-code">
|
|
3
|
+
<div>
|
|
4
|
+
<div
|
|
5
|
+
v-for="(l, i) in lines"
|
|
6
|
+
:key="'lineNumber' + i"
|
|
7
|
+
class="nuxt-graphql-middleware-errors-code-line-number"
|
|
8
|
+
:class="{ 'ngm-is-highlighted': l.isHighlighted }"
|
|
9
|
+
>
|
|
10
|
+
<div v-html="l.lineNumber" />
|
|
11
|
+
</div>
|
|
12
|
+
</div>
|
|
13
|
+
<div>
|
|
14
|
+
<div
|
|
15
|
+
v-for="(l, i) in lines"
|
|
16
|
+
:key="'code' + i"
|
|
17
|
+
class="nuxt-graphql-middleware-errors-code-code"
|
|
18
|
+
:class="{ 'ngm-is-highlighted': l.isHighlighted }"
|
|
19
|
+
>
|
|
20
|
+
<div v-html="l.code" />
|
|
21
|
+
</div>
|
|
22
|
+
</div>
|
|
23
|
+
</div>
|
|
24
|
+
</template>
|
|
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
|
+
|
|
38
|
+
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
|
|
47
|
+
while (sliced.length && !sliced[sliced.length - 1].trim()) {
|
|
48
|
+
sliced.pop()
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Map to your final structure
|
|
52
|
+
return sliced.map((code, i) => {
|
|
53
|
+
const lineNumber = indexStart + i + 1
|
|
54
|
+
return {
|
|
55
|
+
lineNumber,
|
|
56
|
+
code,
|
|
57
|
+
isHighlighted: lineNumber === props.line,
|
|
58
|
+
}
|
|
59
|
+
})
|
|
60
|
+
})
|
|
61
|
+
</script>
|