@lewebsimple/nuxt-graphql 0.3.1 → 0.3.3
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/module.json +1 -1
- package/dist/module.mjs +42 -16
- package/package.json +1 -1
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -215,6 +215,24 @@ function getRemoteExecMiddlewareProxy(middlewarePath) {
|
|
|
215
215
|
].join("\n");
|
|
216
216
|
}
|
|
217
217
|
|
|
218
|
+
function getDummySchemaProxy() {
|
|
219
|
+
return [
|
|
220
|
+
`import { createSchema } from "graphql-yoga";`,
|
|
221
|
+
``,
|
|
222
|
+
`export const schema = createSchema({`,
|
|
223
|
+
` typeDefs: /* GraphQL */ \``,
|
|
224
|
+
` type Query {`,
|
|
225
|
+
` hello: String!`,
|
|
226
|
+
` } `,
|
|
227
|
+
` \`,`,
|
|
228
|
+
` resolvers: {`,
|
|
229
|
+
` Query: {`,
|
|
230
|
+
` hello: () => "Hello world!",`,
|
|
231
|
+
` },`,
|
|
232
|
+
` },`,
|
|
233
|
+
`});`
|
|
234
|
+
].join("\n");
|
|
235
|
+
}
|
|
218
236
|
async function getLocalSchemaProxy({ layerRootDirs, schemaDef }) {
|
|
219
237
|
const schemaPath = await findSingleFile(layerRootDirs, schemaDef.path, true);
|
|
220
238
|
const content = [
|
|
@@ -310,7 +328,9 @@ const module$1 = defineNuxtModule({
|
|
|
310
328
|
name: "@lewebsimple/nuxt-graphql",
|
|
311
329
|
configKey: "graphql"
|
|
312
330
|
},
|
|
313
|
-
defaults: {
|
|
331
|
+
defaults: {
|
|
332
|
+
schemas: {}
|
|
333
|
+
},
|
|
314
334
|
async setup(options, nuxt) {
|
|
315
335
|
const { resolve } = createResolver(import.meta.url);
|
|
316
336
|
const { buildDir, rootDir } = nuxt.options;
|
|
@@ -326,24 +346,30 @@ const module$1 = defineNuxtModule({
|
|
|
326
346
|
}
|
|
327
347
|
serverProxies["context"] = getGraphQLContextProxy(contextPath);
|
|
328
348
|
serverProxies["remote-executor"] = getGenericServerProxy(resolve("./runtime/server/lib/remote-executor.ts"));
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
349
|
+
if (Object.keys(options.schemas || {}).length === 0) {
|
|
350
|
+
logger.warn("No GraphQL schemas defined in nuxt.config.ts, using dummy schema.");
|
|
351
|
+
serverProxies["schemas/dummy"] = getDummySchemaProxy();
|
|
352
|
+
serverProxies["schema"] = await getStitchedSchemaProxy({ schemaNames: ["dummy"] });
|
|
353
|
+
} else {
|
|
354
|
+
for (const [schemaName, schemaDef] of Object.entries(options.schemas)) {
|
|
355
|
+
switch (schemaDef.type) {
|
|
356
|
+
case "local": {
|
|
357
|
+
serverProxies[`schemas/${schemaName}`] = await getLocalSchemaProxy({ layerRootDirs, schemaDef });
|
|
358
|
+
break;
|
|
359
|
+
}
|
|
360
|
+
case "remote": {
|
|
361
|
+
const { middlewareContent, sdlContent, schemaContent } = await getRemoteSchemaProxy({ rootDir, schemaName, schemaDef });
|
|
362
|
+
serverProxies[`schemas/${schemaName}-middleware`] = middlewareContent;
|
|
363
|
+
serverProxies[`schemas/${schemaName}-sdl`] = sdlContent;
|
|
364
|
+
serverProxies[`schemas/${schemaName}`] = schemaContent;
|
|
365
|
+
break;
|
|
366
|
+
}
|
|
367
|
+
default:
|
|
368
|
+
throw new Error(`Unsupported GraphQL schema type: ${schemaDef.type}`);
|
|
341
369
|
}
|
|
342
|
-
default:
|
|
343
|
-
throw new Error(`Unsupported GraphQL schema type: ${schemaDef.type}`);
|
|
344
370
|
}
|
|
371
|
+
serverProxies["schema"] = await getStitchedSchemaProxy({ schemaNames: Object.keys(options.schemas) });
|
|
345
372
|
}
|
|
346
|
-
serverProxies["schema"] = await getStitchedSchemaProxy({ schemaNames: Object.keys(options.schemas) });
|
|
347
373
|
if (options.middleware) {
|
|
348
374
|
const yogaMiddlewarePath = await findSingleFile(layerRootDirs, options.middleware, true);
|
|
349
375
|
logger.info(`GraphQL Yoga middleware registered: ${cyan}${toRelativePath(nuxt.options.rootDir, yogaMiddlewarePath)}${reset}`);
|