@lewebsimple/nuxt-graphql 0.1.1 → 0.1.2
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 +26 -15
- package/dist/runtime/server/shims.d.ts +13 -0
- package/dist/runtime/server/tsconfig.json +1 -1
- package/dist/runtime/server/yoga-handler.js +16 -0
- package/dist/runtime/types/graphql-runtime.d.ts +18 -0
- package/package.json +1 -1
- package/dist/runtime/server/handler.js +0 -10
- package/dist/runtime/types/graphql-schema.d.ts +0 -5
- /package/dist/runtime/server/{handler.d.ts → yoga-handler.d.mts} +0 -0
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useLogger, defineNuxtModule, createResolver, getLayerDirectories,
|
|
1
|
+
import { useLogger, defineNuxtModule, createResolver, getLayerDirectories, addTypeTemplate, addServerTemplate, addServerHandler, addPlugin } from '@nuxt/kit';
|
|
2
2
|
import { existsSync, readFileSync } from 'node:fs';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
4
|
|
|
@@ -30,25 +30,36 @@ const module$1 = defineNuxtModule({
|
|
|
30
30
|
}
|
|
31
31
|
},
|
|
32
32
|
async setup(options, nuxt) {
|
|
33
|
-
const
|
|
33
|
+
const { resolve } = createResolver(import.meta.url);
|
|
34
34
|
const { rootDir, serverDir } = nuxt.options;
|
|
35
35
|
const layerDirs = [...getLayerDirectories(nuxt), { server: serverDir.replace(rootDir, `${rootDir}/playground`) }];
|
|
36
36
|
const schemaPath = findServerFile(layerDirs, "graphql/schema");
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
const contextPath = findServerFile(layerDirs, "graphql/context");
|
|
38
|
+
addTypeTemplate({
|
|
39
|
+
filename: "types/graphql-runtime.d.ts",
|
|
40
|
+
getContents: () => readFileSync(resolve("./runtime/types/graphql-runtime.d.ts"), "utf-8").replace("{{schemaPath}}", schemaPath.replace(/\.ts$/, "")).replace("{{contextPath}}", contextPath.replace(/\.ts$/, ""))
|
|
41
|
+
});
|
|
42
|
+
nuxt.hook("nitro:prepare:types", ({ references }) => {
|
|
43
|
+
references.push({ path: resolve(nuxt.options.buildDir, "types/graphql-runtime.d.ts") });
|
|
44
|
+
});
|
|
45
|
+
nuxt.hook("nitro:config", (nitroConfig) => {
|
|
46
|
+
nitroConfig.alias ||= {};
|
|
47
|
+
nitroConfig.alias["#graphql/schema"] = schemaPath;
|
|
48
|
+
nitroConfig.alias["#graphql/context"] = contextPath;
|
|
49
|
+
nitroConfig.alias["#graphql/runtime"] = resolve(nuxt.options.buildDir, "types/graphql-runtime.d.ts");
|
|
50
|
+
nitroConfig.virtual ||= {};
|
|
51
|
+
nitroConfig.virtual["#graphql/runtime"] = () => "export {};";
|
|
52
|
+
});
|
|
40
53
|
const endpoint = options.yoga?.endpoint ?? "/api/graphql";
|
|
41
|
-
|
|
42
|
-
filename: "graphql/handler
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
54
|
+
addServerTemplate({
|
|
55
|
+
filename: "graphql/yoga-handler",
|
|
56
|
+
getContents: () => readFileSync(resolve("./runtime/server/yoga-handler.mjs"), "utf-8").replace("{{endpoint}}", endpoint)
|
|
57
|
+
});
|
|
58
|
+
addServerHandler({ route: endpoint, handler: "graphql/yoga-handler" });
|
|
59
|
+
nuxt.hook("listen", (_server, { url }) => {
|
|
60
|
+
logger.success(`GraphQL Yoga available at ${cyan}${url.replace(/\/$/, "") + endpoint}${reset}`);
|
|
48
61
|
});
|
|
49
|
-
|
|
50
|
-
logger.success(`GraphQL Yoga server handler added at ${cyan}${endpoint}${reset}`);
|
|
51
|
-
addPlugin(resolver.resolve("./runtime/plugin"));
|
|
62
|
+
addPlugin(resolve("./runtime/plugin"));
|
|
52
63
|
}
|
|
53
64
|
});
|
|
54
65
|
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
declare module "#graphql/schema" {
|
|
2
|
+
import type { GraphQLSchema } from "graphql";
|
|
3
|
+
|
|
4
|
+
const schema: GraphQLSchema;
|
|
5
|
+
export { schema };
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
declare module "#graphql/context" {
|
|
9
|
+
import type { H3Event } from "h3";
|
|
10
|
+
|
|
11
|
+
function createContext(event: H3Event): Promise<Record<string, unknown>>;
|
|
12
|
+
export { createContext };
|
|
13
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createYoga } from "graphql-yoga";
|
|
2
|
+
import { defineEventHandler, toWebRequest, sendWebResponse } from "h3";
|
|
3
|
+
import { schema } from "#graphql/schema";
|
|
4
|
+
import { createContext } from "#graphql/context";
|
|
5
|
+
|
|
6
|
+
const yoga = createYoga({
|
|
7
|
+
schema,
|
|
8
|
+
graphqlEndpoint: "{{endpoint}}",
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
export default defineEventHandler(async (event) => {
|
|
12
|
+
const context = await createContext(event);
|
|
13
|
+
const request = toWebRequest(event);
|
|
14
|
+
const response = await yoga.handleRequest(request, context);
|
|
15
|
+
return sendWebResponse(event, response);
|
|
16
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type * as UserSchema from "{{schemaPath}}";
|
|
2
|
+
import type * as UserContext from "{{contextPath}}";
|
|
3
|
+
|
|
4
|
+
type UserCreateContext = typeof UserContext.createContext;
|
|
5
|
+
|
|
6
|
+
export type GraphQLContext = Awaited<ReturnType<UserCreateContext>>;
|
|
7
|
+
|
|
8
|
+
declare module "#graphql/schema" {
|
|
9
|
+
export const schema: UserSchema.schema;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
declare module "#graphql/context" {
|
|
13
|
+
export const createContext: UserCreateContext;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
declare module "#graphql/runtime" {
|
|
17
|
+
export type { GraphQLContext };
|
|
18
|
+
}
|
package/package.json
CHANGED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { createYoga } from "graphql-yoga";
|
|
2
|
-
import { defineEventHandler } from "h3";
|
|
3
|
-
import { schema } from "#graphql/schema";
|
|
4
|
-
const yoga = createYoga({
|
|
5
|
-
schema,
|
|
6
|
-
graphqlEndpoint: "{{endpoint}}"
|
|
7
|
-
});
|
|
8
|
-
export default defineEventHandler(async (event) => {
|
|
9
|
-
return yoga.handle(event.node.req, event.node.res);
|
|
10
|
-
});
|
|
File without changes
|