@lewebsimple/nuxt-graphql 0.1.3 → 0.1.4
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/README.md +3 -1
- package/dist/module.json +1 -1
- package/dist/module.mjs +1 -29
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -25,8 +25,9 @@ Define your GraphQL schema in `server/graphql/schema.ts`:
|
|
|
25
25
|
|
|
26
26
|
```ts
|
|
27
27
|
import { createSchema } from "graphql-yoga";
|
|
28
|
+
import type { GraphQLContext } from "./context";
|
|
28
29
|
|
|
29
|
-
export const schema = createSchema({
|
|
30
|
+
export const schema = createSchema<GraphQLContext>({
|
|
30
31
|
typeDefs: /* GraphQL */ `
|
|
31
32
|
type Query {
|
|
32
33
|
hello: String!
|
|
@@ -51,6 +52,7 @@ export async function createContext(_event: H3Event) {
|
|
|
51
52
|
};
|
|
52
53
|
}
|
|
53
54
|
|
|
55
|
+
export type GraphQLContext = Awaited<ReturnType<typeof createContext>>;
|
|
54
56
|
```
|
|
55
57
|
|
|
56
58
|
That's it! You can now use Nuxt GraphQL in your Nuxt app ✨
|
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, addServerTemplate, addServerHandler, addPlugin } from '@nuxt/kit';
|
|
2
2
|
import { existsSync } from 'node:fs';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
4
|
|
|
@@ -35,38 +35,10 @@ const module$1 = defineNuxtModule({
|
|
|
35
35
|
const layerDirs = [...getLayerDirectories(nuxt), { server: serverDir.replace(rootDir, `${rootDir}/playground`) }];
|
|
36
36
|
const schemaPath = findServerFile(layerDirs, "graphql/schema");
|
|
37
37
|
const contextPath = findServerFile(layerDirs, "graphql/context");
|
|
38
|
-
addTypeTemplate({
|
|
39
|
-
filename: "types/graphql-runtime.d.ts",
|
|
40
|
-
getContents: () => `
|
|
41
|
-
import type { schema as userSchema } from "${schemaPath}";
|
|
42
|
-
import type { createContext as userCreateContext } from "${contextPath}";
|
|
43
|
-
|
|
44
|
-
type UserCreateContext = typeof userCreateContext;
|
|
45
|
-
|
|
46
|
-
export type GraphQLContext = Awaited<ReturnType<UserCreateContext>>;
|
|
47
|
-
|
|
48
|
-
declare module "#graphql/schema" {
|
|
49
|
-
export const schema: typeof userSchema;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
declare module "#graphql/context" {
|
|
53
|
-
export const createContext: UserCreateContext;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
declare module "#graphql/runtime" {
|
|
57
|
-
export type { GraphQLContext };
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export {};
|
|
61
|
-
`.trim()
|
|
62
|
-
});
|
|
63
38
|
nuxt.hook("nitro:config", (nitroConfig) => {
|
|
64
39
|
nitroConfig.alias ||= {};
|
|
65
40
|
nitroConfig.alias["#graphql/schema"] = schemaPath;
|
|
66
41
|
nitroConfig.alias["#graphql/context"] = contextPath;
|
|
67
|
-
nitroConfig.alias["#graphql/runtime"] = resolve(nuxt.options.buildDir, "types/graphql-runtime.d.ts");
|
|
68
|
-
nitroConfig.virtual ||= {};
|
|
69
|
-
nitroConfig.virtual["#graphql/runtime"] = "export {};";
|
|
70
42
|
});
|
|
71
43
|
const endpoint = options.yoga?.endpoint ?? "/api/graphql";
|
|
72
44
|
addServerTemplate({
|