nitro-graphql 0.4.1 → 1.0.0
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 +1 -2
- package/dist/ecosystem/nuxt.d.ts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/rollup.js +1 -1
- package/dist/routes/apollo-server.d.ts +2 -2
- package/dist/routes/graphql-yoga.d.ts +2 -2
- package/dist/utils/client-codegen.js +7 -2
- package/dist/utils/{server-type-generation.d.ts → type-generation.d.ts} +1 -1
- package/dist/utils/{server-type-generation.js → type-generation.js} +34 -1
- package/package.json +11 -11
package/README.md
CHANGED
|
@@ -15,8 +15,7 @@
|
|
|
15
15
|
|
|
16
16
|
---
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
> This project is actively under development. We're always open to new ideas, different perspectives, and feature suggestions! If you have a suggestion, please first [open an issue](https://github.com/productdevbook/nitro-graphql/issues) to discuss it, then you can contribute with a PR.
|
|
18
|
+
*"GraphQL is not just a query language; it's a new way to think about APIs and client-server interaction."*
|
|
20
19
|
|
|
21
20
|
## ✨ Features
|
|
22
21
|
|
package/dist/ecosystem/nuxt.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as _nuxt_schema0 from "@nuxt/schema";
|
|
2
2
|
|
|
3
3
|
//#region src/ecosystem/nuxt.d.ts
|
|
4
4
|
interface ModuleOptions {}
|
|
5
|
-
declare const _default:
|
|
5
|
+
declare const _default: _nuxt_schema0.NuxtModule<ModuleOptions, ModuleOptions, false>;
|
|
6
6
|
//#endregion
|
|
7
7
|
export { ModuleOptions, _default as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { StandardSchemaV1 } from "./types/standard-schema.js";
|
|
2
2
|
import { CodegenClientConfig, CodegenServerConfig, GenImport, NitroGraphQLOptions } from "./types/index.js";
|
|
3
|
-
import * as
|
|
3
|
+
import * as nitropack1 from "nitropack";
|
|
4
4
|
|
|
5
5
|
//#region src/index.d.ts
|
|
6
6
|
type GraphQLFramework = 'graphql-yoga';
|
|
7
|
-
declare const _default:
|
|
7
|
+
declare const _default: nitropack1.NitroModule;
|
|
8
8
|
//#endregion
|
|
9
9
|
export { CodegenClientConfig, CodegenServerConfig, GenImport, GraphQLFramework, NitroGraphQLOptions, StandardSchemaV1, _default as default };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { relativeWithDot, scanDocs, scanResolvers, scanSchemas } from "./utils/index.js";
|
|
2
|
-
import { clientTypeGeneration, serverTypeGeneration } from "./utils/
|
|
2
|
+
import { clientTypeGeneration, serverTypeGeneration } from "./utils/type-generation.js";
|
|
3
3
|
import { rollupConfig } from "./rollup.js";
|
|
4
4
|
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
package/dist/rollup.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getImportId, scanGraphql } from "./utils/index.js";
|
|
2
|
-
import { clientTypeGeneration, serverTypeGeneration } from "./utils/
|
|
2
|
+
import { clientTypeGeneration, serverTypeGeneration } from "./utils/type-generation.js";
|
|
3
3
|
import { resolve } from "pathe";
|
|
4
4
|
import { readFile } from "node:fs/promises";
|
|
5
5
|
import { parse } from "graphql";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as h34 from "h3";
|
|
2
2
|
|
|
3
3
|
//#region src/routes/apollo-server.d.ts
|
|
4
|
-
declare const _default:
|
|
4
|
+
declare const _default: h34.EventHandler<h34.EventHandlerRequest, any>;
|
|
5
5
|
//#endregion
|
|
6
6
|
export { _default as default };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as h36 from "h3";
|
|
2
2
|
|
|
3
3
|
//#region src/routes/graphql-yoga.d.ts
|
|
4
|
-
declare const _default:
|
|
4
|
+
declare const _default: h36.EventHandler<h36.EventHandlerRequest, Promise<Response>>;
|
|
5
5
|
//#endregion
|
|
6
6
|
export { _default as default };
|
|
@@ -92,17 +92,22 @@ async function generateClientTypes(schema, docs, config = {}, outputPath) {
|
|
|
92
92
|
schema: parse(printSchemaWithDirectives(schema)),
|
|
93
93
|
documents: [...docs],
|
|
94
94
|
config: {
|
|
95
|
+
fetcher: "function",
|
|
95
96
|
documentMode: "string",
|
|
96
97
|
pureMagicComment: true,
|
|
97
98
|
strictScalars: true,
|
|
99
|
+
avoidOptionals: true,
|
|
100
|
+
useTypeImports: true,
|
|
101
|
+
dedupeOperationSuffix: true,
|
|
102
|
+
exportFragmentSpreadSubTypes: true,
|
|
103
|
+
enumsAsTypes: true,
|
|
98
104
|
scalars: {
|
|
99
105
|
DateTime: "Date",
|
|
100
106
|
JSON: "any",
|
|
101
107
|
UUID: "string",
|
|
102
108
|
NonEmptyString: "string",
|
|
103
109
|
Currency: "string"
|
|
104
|
-
}
|
|
105
|
-
useTypeImports: true
|
|
110
|
+
}
|
|
106
111
|
},
|
|
107
112
|
presetConfig: { typesPath: "#graphql/client" },
|
|
108
113
|
plugins: [{ pluginContent: {} }, { typescriptGenericSdk: { rawRequest: false } }],
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Nitro } from "nitropack";
|
|
2
2
|
|
|
3
|
-
//#region src/utils/
|
|
3
|
+
//#region src/utils/type-generation.d.ts
|
|
4
4
|
declare function serverTypeGeneration(app: Nitro): Promise<void>;
|
|
5
5
|
declare function clientTypeGeneration(nitro: Nitro): Promise<void>;
|
|
6
6
|
//#endregion
|
|
@@ -8,7 +8,39 @@ import { loadFilesSync } from "@graphql-tools/load-files";
|
|
|
8
8
|
import { mergeTypeDefs } from "@graphql-tools/merge";
|
|
9
9
|
import { printSchemaWithDirectives } from "@graphql-tools/utils";
|
|
10
10
|
|
|
11
|
-
//#region src/utils/
|
|
11
|
+
//#region src/utils/type-generation.ts
|
|
12
|
+
function generateNuxtOfetchClient(clientDir) {
|
|
13
|
+
const ofetchPath = resolve(clientDir, "ofetch.ts");
|
|
14
|
+
if (!existsSync(ofetchPath)) {
|
|
15
|
+
const ofetchContent = `// This file is auto-generated once by nitro-graphql for quick start
|
|
16
|
+
// You can modify this file according to your needs
|
|
17
|
+
import type { ExecutionResult } from 'graphql'
|
|
18
|
+
import type { Requester } from './sdk'
|
|
19
|
+
import { getSdk } from './sdk'
|
|
20
|
+
|
|
21
|
+
export function createGraphQLClient(endpoint: string): Requester {
|
|
22
|
+
return async <R>(doc: string, vars?: any): Promise<R> => {
|
|
23
|
+
const headers = import.meta.server ? useRequestHeaders() : undefined
|
|
24
|
+
|
|
25
|
+
const result = await $fetch(endpoint, {
|
|
26
|
+
method: 'POST',
|
|
27
|
+
body: { query: doc, variables: vars },
|
|
28
|
+
headers: {
|
|
29
|
+
'Content-Type': 'application/json',
|
|
30
|
+
...headers,
|
|
31
|
+
},
|
|
32
|
+
}) as ExecutionResult
|
|
33
|
+
|
|
34
|
+
return result.errors?.length
|
|
35
|
+
? Promise.reject(new Error(result.errors[0]?.message || 'GraphQL error'))
|
|
36
|
+
: result.data as R
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const $sdk = getSdk(createGraphQLClient('/api/graphql'))`;
|
|
41
|
+
writeFileSync(ofetchPath, ofetchContent, "utf-8");
|
|
42
|
+
}
|
|
43
|
+
}
|
|
12
44
|
async function serverTypeGeneration(app) {
|
|
13
45
|
try {
|
|
14
46
|
const schemas = app.scanSchemas || [];
|
|
@@ -51,6 +83,7 @@ async function clientTypeGeneration(nitro) {
|
|
|
51
83
|
const sdkTypesPath = resolve(nitro.graphql.clientDir, "sdk.ts");
|
|
52
84
|
writeFileSync(clientTypesPath, types.types, "utf-8");
|
|
53
85
|
writeFileSync(sdkTypesPath, types.sdk, "utf-8");
|
|
86
|
+
if (nitro.options.framework?.name === "nuxt") generateNuxtOfetchClient(nitro.graphql.clientDir);
|
|
54
87
|
} catch (error) {
|
|
55
88
|
consola.error("Client schema generation error:", error);
|
|
56
89
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nitro-graphql",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "1.0.0",
|
|
5
5
|
"description": "GraphQL integration for Nitro",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"sideEffects": false,
|
|
@@ -66,12 +66,12 @@
|
|
|
66
66
|
"@graphql-codegen/typescript-generic-sdk": "^4.0.2",
|
|
67
67
|
"@graphql-codegen/typescript-operations": "^4.6.1",
|
|
68
68
|
"@graphql-codegen/typescript-resolvers": "^4.5.1",
|
|
69
|
-
"@graphql-tools/graphql-file-loader": "^8.0.
|
|
70
|
-
"@graphql-tools/load": "^8.1.
|
|
69
|
+
"@graphql-tools/graphql-file-loader": "^8.0.21",
|
|
70
|
+
"@graphql-tools/load": "^8.1.1",
|
|
71
71
|
"@graphql-tools/load-files": "^7.0.1",
|
|
72
|
-
"@graphql-tools/merge": "^9.0
|
|
73
|
-
"@graphql-tools/schema": "^10.0.
|
|
74
|
-
"@graphql-tools/utils": "^10.
|
|
72
|
+
"@graphql-tools/merge": "^9.1.0",
|
|
73
|
+
"@graphql-tools/schema": "^10.0.24",
|
|
74
|
+
"@graphql-tools/utils": "^10.9.0",
|
|
75
75
|
"chokidar": "^4.0.3",
|
|
76
76
|
"consola": "^3.4.2",
|
|
77
77
|
"defu": "^6.1.4",
|
|
@@ -79,17 +79,17 @@
|
|
|
79
79
|
"graphql-scalars": "^1.24.2",
|
|
80
80
|
"knitwork": "^1.2.0",
|
|
81
81
|
"ohash": "^2.0.11",
|
|
82
|
-
"oxc-parser": "^0.77.
|
|
82
|
+
"oxc-parser": "^0.77.2",
|
|
83
83
|
"pathe": "^2.0.3",
|
|
84
84
|
"tinyglobby": "^0.2.14"
|
|
85
85
|
},
|
|
86
86
|
"devDependencies": {
|
|
87
|
-
"@antfu/eslint-config": "^4.
|
|
88
|
-
"@apollo/server": "^
|
|
87
|
+
"@antfu/eslint-config": "^4.17.0",
|
|
88
|
+
"@apollo/server": "^5.0.0",
|
|
89
89
|
"@graphql-codegen/import-types-preset": "^3.0.1",
|
|
90
90
|
"@nuxt/kit": "4.0.0-rc.0",
|
|
91
91
|
"@nuxt/schema": "4.0.0-rc.0",
|
|
92
|
-
"@types/node": "^20.19.
|
|
92
|
+
"@types/node": "^20.19.9",
|
|
93
93
|
"bumpp": "^10.2.0",
|
|
94
94
|
"changelogen": "^0.6.2",
|
|
95
95
|
"crossws": "0.3.5",
|
|
@@ -97,7 +97,7 @@
|
|
|
97
97
|
"graphql": "^16.11.0",
|
|
98
98
|
"graphql-yoga": "^5.15.1",
|
|
99
99
|
"h3": "^1.15.3",
|
|
100
|
-
"nitropack": "^2.
|
|
100
|
+
"nitropack": "^2.12.3",
|
|
101
101
|
"tsdown": "^0.12.9",
|
|
102
102
|
"typescript": "^5.8.3"
|
|
103
103
|
},
|