nitro-graphql 0.0.4 → 0.0.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/_virtual/rolldown_runtime.js +37 -0
- package/dist/client-codegen.js +50 -15
- package/dist/codegen.d.ts +2 -8
- package/dist/codegen.js +2 -1
- package/dist/ecosystem/nuxt.d.ts +7 -0
- package/dist/ecosystem/nuxt.js +29 -0
- package/dist/graphql.d.ts +13 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +75 -128
- package/dist/internal/create-merged-schema.d.ts +7 -0
- package/dist/internal/create-merged-schema.js +23 -0
- package/dist/internal/index.d.ts +2 -0
- package/dist/internal/index.js +3 -0
- package/dist/node_modules/.pnpm/@graphql-codegen_add@3.2.3_graphql@16.11.0/node_modules/@graphql-codegen/add/esm/config.js +9 -0
- package/dist/node_modules/.pnpm/@graphql-codegen_add@3.2.3_graphql@16.11.0/node_modules/@graphql-codegen/add/esm/index.js +17 -0
- package/dist/node_modules/.pnpm/@graphql-codegen_import-types-preset@3.0.1_graphql@16.11.0/node_modules/@graphql-codegen/import-types-preset/esm/index.js +38 -0
- package/dist/node_modules/.pnpm/@graphql-codegen_plugin-helpers@3.1.2_graphql@16.11.0/node_modules/@graphql-codegen/plugin-helpers/esm/federation.js +22 -0
- package/dist/node_modules/.pnpm/@graphql-codegen_plugin-helpers@3.1.2_graphql@16.11.0/node_modules/@graphql-codegen/plugin-helpers/esm/getCachedDocumentNodeFromSchema.js +6 -0
- package/dist/node_modules/.pnpm/@graphql-codegen_plugin-helpers@3.1.2_graphql@16.11.0/node_modules/@graphql-codegen/plugin-helpers/esm/helpers.js +79 -0
- package/dist/node_modules/.pnpm/@graphql-codegen_plugin-helpers@3.1.2_graphql@16.11.0/node_modules/@graphql-codegen/plugin-helpers/esm/index.js +6 -0
- package/dist/node_modules/.pnpm/@graphql-codegen_plugin-helpers@3.1.2_graphql@16.11.0/node_modules/@graphql-codegen/plugin-helpers/esm/oldVisit.js +1 -0
- package/dist/node_modules/.pnpm/@graphql-codegen_plugin-helpers@3.1.2_graphql@16.11.0/node_modules/@graphql-codegen/plugin-helpers/esm/resolve-external-module-and-fn.js +7 -0
- package/dist/node_modules/.pnpm/@graphql-codegen_plugin-helpers@3.1.2_graphql@16.11.0/node_modules/@graphql-codegen/plugin-helpers/esm/utils.js +13 -0
- package/dist/node_modules/.pnpm/camel-case@4.1.2/node_modules/camel-case/dist/index.js +33 -0
- package/dist/node_modules/.pnpm/capital-case@1.0.4/node_modules/capital-case/dist/index.js +32 -0
- package/dist/node_modules/.pnpm/change-case-all@1.0.15/node_modules/change-case-all/dist/index.js +56 -0
- package/dist/node_modules/.pnpm/change-case@4.1.2/node_modules/change-case/dist/index.js +37 -0
- package/dist/node_modules/.pnpm/constant-case@3.0.4/node_modules/constant-case/dist/index.js +28 -0
- package/dist/node_modules/.pnpm/dot-case@3.0.4/node_modules/dot-case/dist/index.js +23 -0
- package/dist/node_modules/.pnpm/header-case@2.0.4/node_modules/header-case/dist/index.js +23 -0
- package/dist/node_modules/.pnpm/is-lower-case@2.0.2/node_modules/is-lower-case/dist/index.js +21 -0
- package/dist/node_modules/.pnpm/is-upper-case@2.0.2/node_modules/is-upper-case/dist/index.js +21 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_Hash.js +37 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_ListCache.js +37 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_Map.js +15 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_MapCache.js +37 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_Stack.js +34 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_Symbol.js +15 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_Uint8Array.js +15 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_apply.js +30 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_arrayLikeKeys.js +35 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_assignMergeValue.js +26 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_assignValue.js +32 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_assocIndexOf.js +26 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseAssignValue.js +31 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseCreate.js +34 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseFor.js +25 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseGetTag.js +30 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseIsArguments.js +26 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseIsNative.js +44 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseIsTypedArray.js +32 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseKeysIn.js +32 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseMerge.js +42 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseMergeDeep.js +75 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseRest.js +26 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseSetToString.js +31 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseTimes.js +25 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseUnary.js +23 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_cloneArrayBuffer.js +25 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_cloneBuffer.js +35 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_cloneTypedArray.js +25 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_copyArray.js +25 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_copyObject.js +37 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_coreJsData.js +15 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_createAssigner.js +37 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_createBaseFor.js +28 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_defineProperty.js +20 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_freeGlobal.js +13 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_getMapData.js +25 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_getNative.js +26 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_getPrototype.js +15 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_getRawTag.js +43 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_getValue.js +22 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_hashClear.js +24 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_hashDelete.js +26 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_hashGet.js +36 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_hashHas.js +30 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_hashSet.js +31 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_initCloneObject.js +25 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_isIndex.js +28 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_isIterateeCall.js +32 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_isKeyable.js +22 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_isMasked.js +28 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_isPrototype.js +24 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_listCacheClear.js +22 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_listCacheDelete.js +35 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_listCacheGet.js +26 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_listCacheHas.js +25 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_listCacheSet.js +31 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_mapCacheClear.js +30 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_mapCacheDelete.js +27 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_mapCacheGet.js +25 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_mapCacheHas.js +25 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_mapCacheSet.js +29 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_nativeCreate.js +14 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_nativeKeysIn.js +25 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_nodeUtil.js +29 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_objectToString.js +29 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_overArg.js +24 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_overRest.js +35 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_root.js +17 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_safeGet.js +24 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_setToString.js +23 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_shortOut.js +34 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_stackClear.js +24 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_stackDelete.js +25 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_stackGet.js +23 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_stackHas.js +23 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_stackSet.js +42 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_toSource.js +33 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/constant.js +35 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/eq.js +46 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/identity.js +30 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/isArguments.js +43 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/isArray.js +35 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/isArrayLike.js +42 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/isArrayLikeObject.js +42 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/isBuffer.js +41 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/isFunction.js +38 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/isLength.js +42 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/isObject.js +40 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/isObjectLike.js +38 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/isPlainObject.js +60 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/isTypedArray.js +34 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/keysIn.js +41 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/merge.js +48 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/stubFalse.js +27 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/toPlainObject.js +41 -0
- package/dist/node_modules/.pnpm/lower-case-first@2.0.2/node_modules/lower-case-first/dist/index.js +21 -0
- package/dist/node_modules/.pnpm/lower-case@2.0.2/node_modules/lower-case/dist/index.js +64 -0
- package/dist/node_modules/.pnpm/no-case@3.0.4/node_modules/no-case/dist/index.js +41 -0
- package/dist/node_modules/.pnpm/param-case@3.0.4/node_modules/param-case/dist/index.js +23 -0
- package/dist/node_modules/.pnpm/pascal-case@3.1.2/node_modules/pascal-case/dist/index.js +37 -0
- package/dist/node_modules/.pnpm/path-case@3.0.4/node_modules/path-case/dist/index.js +23 -0
- package/dist/node_modules/.pnpm/sentence-case@3.0.4/node_modules/sentence-case/dist/index.js +34 -0
- package/dist/node_modules/.pnpm/snake-case@3.0.4/node_modules/snake-case/dist/index.js +23 -0
- package/dist/node_modules/.pnpm/sponge-case@1.0.1/node_modules/sponge-case/dist/index.js +20 -0
- package/dist/node_modules/.pnpm/swap-case@2.0.2/node_modules/swap-case/dist/index.js +23 -0
- package/dist/node_modules/.pnpm/title-case@3.0.3/node_modules/title-case/dist/index.js +35 -0
- package/dist/node_modules/.pnpm/tslib@2.8.1/node_modules/tslib/tslib.es6.js +547 -0
- package/dist/node_modules/.pnpm/upper-case-first@2.0.2/node_modules/upper-case-first/dist/index.js +21 -0
- package/dist/node_modules/.pnpm/upper-case@2.0.2/node_modules/upper-case/dist/index.js +56 -0
- package/dist/rollup.js +84 -0
- package/dist/routes/graphql.d.ts +6 -0
- package/dist/routes/graphql.js +54 -0
- package/dist/types.d.ts +31 -4
- package/dist/utils/index.d.ts +21 -0
- package/dist/utils/index.js +72 -0
- package/dist/utils/server-type-generation.js +52 -0
- package/package.json +23 -11
- package/dist/client-watcher.d.ts +0 -7
- package/dist/client-watcher.js +0 -100
- package/dist/dev.js +0 -95
- package/dist/prerender.js +0 -279
- package/dist/scanner.js +0 -118
- package/dist/utils.d.ts +0 -13
- package/dist/utils.js +0 -23
package/dist/prerender.js
DELETED
|
@@ -1,279 +0,0 @@
|
|
|
1
|
-
import { scanGraphQLFiles } from "./scanner.js";
|
|
2
|
-
import { generateTypes } from "./codegen.js";
|
|
3
|
-
import { mkdir, writeFile } from "node:fs/promises";
|
|
4
|
-
import { mergeTypeDefs } from "@graphql-tools/merge";
|
|
5
|
-
import { makeExecutableSchema } from "@graphql-tools/schema";
|
|
6
|
-
import { consola } from "consola";
|
|
7
|
-
import { join } from "pathe";
|
|
8
|
-
|
|
9
|
-
//#region src/prerender.ts
|
|
10
|
-
const logger = consola.withTag("graphql");
|
|
11
|
-
async function prerender(nitro, options) {
|
|
12
|
-
const scanResult = await scanGraphQLFiles(nitro);
|
|
13
|
-
if (scanResult.resolvers.length > 0) logger.success(`Found ${scanResult.resolvers.length} resolvers`);
|
|
14
|
-
if (scanResult.typeDefs.length > 0) {
|
|
15
|
-
const mergedTypeDefs = mergeTypeDefs(scanResult.typeDefs);
|
|
16
|
-
const schema = makeExecutableSchema({
|
|
17
|
-
typeDefs: mergedTypeDefs,
|
|
18
|
-
resolvers: {}
|
|
19
|
-
});
|
|
20
|
-
const generatedTypes = await generateTypes(schema);
|
|
21
|
-
const outputPath = join(nitro.options.buildDir, "types", "graphql-types.generated.ts");
|
|
22
|
-
const typesDir = join(nitro.options.buildDir, "types");
|
|
23
|
-
await mkdir(typesDir, { recursive: true });
|
|
24
|
-
await writeFile(outputPath, generatedTypes);
|
|
25
|
-
const graphqlDtsPath = join(typesDir, "graphql.d.ts");
|
|
26
|
-
const graphqlDtsContent = `// Auto-generated by nitro-graphql
|
|
27
|
-
import type { Resolvers as Test } from './graphql-types.generated'
|
|
28
|
-
|
|
29
|
-
declare module 'nitro-graphql/types' {
|
|
30
|
-
interface Resolvers extends Test {}
|
|
31
|
-
}
|
|
32
|
-
`;
|
|
33
|
-
await writeFile(graphqlDtsPath, graphqlDtsContent);
|
|
34
|
-
logger.success("Types generated");
|
|
35
|
-
} else {
|
|
36
|
-
const typesDir = join(nitro.options.buildDir, "types");
|
|
37
|
-
await mkdir(typesDir, { recursive: true });
|
|
38
|
-
const minimalTypes = `// Generated by nitro-graphql (no schema found)
|
|
39
|
-
export type Resolvers = any
|
|
40
|
-
`;
|
|
41
|
-
const outputPath = join(typesDir, "graphql-types.generated.ts");
|
|
42
|
-
await writeFile(outputPath, minimalTypes);
|
|
43
|
-
const graphqlDtsPath = join(typesDir, "graphql.d.ts");
|
|
44
|
-
const graphqlDtsContent = `// Auto-generated by nitro-graphql
|
|
45
|
-
import type { Resolvers as Test } from './graphql-types.generated'
|
|
46
|
-
|
|
47
|
-
declare module 'nitro-graphql/types' {
|
|
48
|
-
interface Resolvers extends Test {}
|
|
49
|
-
}
|
|
50
|
-
`;
|
|
51
|
-
await writeFile(graphqlDtsPath, graphqlDtsContent);
|
|
52
|
-
logger.info("Created minimal types (no schema found)");
|
|
53
|
-
}
|
|
54
|
-
nitro.options.virtual["#nitro-graphql/handler"] = () => `
|
|
55
|
-
import { createYoga } from 'graphql-yoga'
|
|
56
|
-
import { defineEventHandler, readRawBody, setHeader, setResponseStatus } from 'h3'
|
|
57
|
-
import { useStorage } from 'nitro/runtime'
|
|
58
|
-
import { makeExecutableSchema } from '@graphql-tools/schema'
|
|
59
|
-
import { mergeTypeDefs, mergeResolvers } from '@graphql-tools/merge'
|
|
60
|
-
import { join } from 'pathe'
|
|
61
|
-
// Types are generated at build time to .nitro/graphql-types.generated.ts
|
|
62
|
-
|
|
63
|
-
// GraphQL Context type is injected via context module
|
|
64
|
-
|
|
65
|
-
// Create resolver helper
|
|
66
|
-
globalThis.defineResolver = function(resolvers) {
|
|
67
|
-
return resolvers
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// Dynamic schema loading function
|
|
71
|
-
async function loadTypeDefs() {
|
|
72
|
-
const schemaPath = join('${nitro.options.srcDir}', 'graphql', '**', '*.graphql')
|
|
73
|
-
const { loadFilesSync } = await import('@graphql-tools/load-files')
|
|
74
|
-
return loadFilesSync(schemaPath, {
|
|
75
|
-
recursive: true,
|
|
76
|
-
})
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// Load resolvers using dynamic imports (Nitro handles the bundling)
|
|
80
|
-
const resolverImports = [
|
|
81
|
-
${scanResult.resolvers.map((resolver) => ` () => import('${resolver.path}')`).join(",\n")}
|
|
82
|
-
]
|
|
83
|
-
|
|
84
|
-
// Async function to load resolvers
|
|
85
|
-
async function loadResolvers() {
|
|
86
|
-
let resolvers = {}
|
|
87
|
-
try {
|
|
88
|
-
if (resolverImports.length > 0) {
|
|
89
|
-
const resolverModules = []
|
|
90
|
-
|
|
91
|
-
for (let i = 0; i < resolverImports.length; i++) {
|
|
92
|
-
try {
|
|
93
|
-
const resolverModule = await resolverImports[i]()
|
|
94
|
-
const resolver = resolverModule.default || resolverModule
|
|
95
|
-
|
|
96
|
-
if (resolver) {
|
|
97
|
-
resolverModules.push(resolver)
|
|
98
|
-
}
|
|
99
|
-
} catch (error) {
|
|
100
|
-
console.warn('[graphql] Failed to load resolver:', i, error.message)
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if (resolverModules.length > 0) {
|
|
105
|
-
resolvers = mergeResolvers(resolverModules)
|
|
106
|
-
} else {
|
|
107
|
-
console.warn('[graphql] No resolvers could be loaded')
|
|
108
|
-
resolvers = { Query: {}, Mutation: {} }
|
|
109
|
-
}
|
|
110
|
-
} else {
|
|
111
|
-
console.warn('[graphql] No resolvers found')
|
|
112
|
-
resolvers = { Query: {}, Mutation: {} }
|
|
113
|
-
}
|
|
114
|
-
} catch (error) {
|
|
115
|
-
console.warn('[graphql] Error loading resolvers:', error.message)
|
|
116
|
-
resolvers = { Query: {}, Mutation: {} }
|
|
117
|
-
}
|
|
118
|
-
return resolvers
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// Apollo Sandbox HTML with 1 week cache
|
|
122
|
-
const apolloSandboxHtml = \`<!DOCTYPE html>
|
|
123
|
-
<html lang="en">
|
|
124
|
-
<body style="margin: 0; overflow-x: hidden; overflow-y: hidden">
|
|
125
|
-
<div id="sandbox" style="height:100vh; width:100vw;"></div>
|
|
126
|
-
<script src="https://embeddable-sandbox.cdn.apollographql.com/02e2da0fccbe0240ef03d2396d6c98559bab5b06/embeddable-sandbox.umd.production.min.js"><\/script>
|
|
127
|
-
<script>
|
|
128
|
-
new window.EmbeddedSandbox({
|
|
129
|
-
target: "#sandbox",
|
|
130
|
-
initialEndpoint: window.location.href,
|
|
131
|
-
hideCookieToggle: false,
|
|
132
|
-
initialState: {
|
|
133
|
-
includeCookies: true
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
<\/script>
|
|
137
|
-
</body>
|
|
138
|
-
</html>\`
|
|
139
|
-
|
|
140
|
-
// Set cache headers for Apollo Sandbox HTML (1 week = 604800 seconds)
|
|
141
|
-
function setApolloSandboxCacheHeaders(event) {
|
|
142
|
-
setHeader(event, 'Cache-Control', 'public, max-age=604800, s-maxage=604800')
|
|
143
|
-
setHeader(event, 'Expires', new Date(Date.now() + 604800000).toUTCString())
|
|
144
|
-
setHeader(event, 'ETag', \`"apollo-sandbox-\${Date.now()}"\`)
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
// Lazy initialization
|
|
148
|
-
let yoga = null
|
|
149
|
-
let initPromise = null
|
|
150
|
-
|
|
151
|
-
async function getYoga() {
|
|
152
|
-
// In development mode, always reload schema for hot updates
|
|
153
|
-
const isDev = ${nitro.options.dev}
|
|
154
|
-
if (yoga && !isDev) return yoga
|
|
155
|
-
|
|
156
|
-
if (!initPromise || isDev) {
|
|
157
|
-
// Reset yoga instance in development mode
|
|
158
|
-
if (isDev) {
|
|
159
|
-
yoga = null
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
initPromise = (async () => {
|
|
163
|
-
// Load custom yoga config first (separate from resolvers)
|
|
164
|
-
let customYogaConfig = {}
|
|
165
|
-
${scanResult.yogaConfigPath ? `
|
|
166
|
-
try {
|
|
167
|
-
const yogaConfigModule = await import('${scanResult.yogaConfigPath}')
|
|
168
|
-
customYogaConfig = yogaConfigModule.default || yogaConfigModule
|
|
169
|
-
} catch (error) {
|
|
170
|
-
console.warn('[graphql] Failed to load yoga config:', error.message)
|
|
171
|
-
}` : ""}
|
|
172
|
-
|
|
173
|
-
const resolvers = await loadResolvers()
|
|
174
|
-
const typeDefs = await loadTypeDefs()
|
|
175
|
-
|
|
176
|
-
// Merge schema and resolvers (without yoga config interfering)
|
|
177
|
-
const schema = makeExecutableSchema({
|
|
178
|
-
typeDefs: mergeTypeDefs(typeDefs),
|
|
179
|
-
resolvers,
|
|
180
|
-
})
|
|
181
|
-
|
|
182
|
-
// Default yoga configuration
|
|
183
|
-
const defaultYogaConfig = {
|
|
184
|
-
schema,
|
|
185
|
-
context: async ({ request }) => {
|
|
186
|
-
const event = request.$$event
|
|
187
|
-
return {
|
|
188
|
-
event,
|
|
189
|
-
request,
|
|
190
|
-
storage: useStorage(),
|
|
191
|
-
}
|
|
192
|
-
},
|
|
193
|
-
graphqlEndpoint: '${options.endpoint || "/api/graphql"}',
|
|
194
|
-
graphiql: ${options.playground !== false},
|
|
195
|
-
renderGraphiQL: () => apolloSandboxHtml,
|
|
196
|
-
landingPage: false,
|
|
197
|
-
cors: ${JSON.stringify(options.cors || false)},
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
// Clean up custom config (remove properties that could be mistaken for GraphQL resolvers)
|
|
201
|
-
const cleanCustomConfig = { ...customYogaConfig }
|
|
202
|
-
|
|
203
|
-
// Remove empty arrays and functions that GraphQL Tools might confuse with resolvers
|
|
204
|
-
if (Array.isArray(cleanCustomConfig.plugins) && cleanCustomConfig.plugins.length === 0) {
|
|
205
|
-
delete cleanCustomConfig.plugins
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
// Remove these yoga-specific configs from resolver merging
|
|
209
|
-
const yogaOnlyConfigs = ['context', 'plugins', 'maskedErrors', 'graphiql', 'cors']
|
|
210
|
-
const cleanResolverConfig = { ...cleanCustomConfig }
|
|
211
|
-
yogaOnlyConfigs.forEach(key => {
|
|
212
|
-
delete cleanResolverConfig[key]
|
|
213
|
-
})
|
|
214
|
-
|
|
215
|
-
// Merge custom config with defaults
|
|
216
|
-
const yogaConfig = {
|
|
217
|
-
...defaultYogaConfig,
|
|
218
|
-
...cleanCustomConfig,
|
|
219
|
-
// Always override schema and endpoint from default config
|
|
220
|
-
schema,
|
|
221
|
-
graphqlEndpoint: '${options.endpoint || "/api/graphql"}',
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
yoga = createYoga(yogaConfig)
|
|
225
|
-
|
|
226
|
-
return yoga
|
|
227
|
-
})()
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
return initPromise
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
export default defineEventHandler(async (event) => {
|
|
234
|
-
const { req } = event.node
|
|
235
|
-
const host = req.headers.host || 'localhost'
|
|
236
|
-
const protocol = 'http'
|
|
237
|
-
const url = new URL(req.url || '/', protocol + '://' + host)
|
|
238
|
-
|
|
239
|
-
// Attach event to request for context
|
|
240
|
-
req.$$event = event
|
|
241
|
-
|
|
242
|
-
const yogaInstance = await getYoga()
|
|
243
|
-
const response = await yogaInstance.fetch(url.toString(), {
|
|
244
|
-
method: req.method || 'GET',
|
|
245
|
-
headers: req.headers,
|
|
246
|
-
body: req.method !== 'GET' && req.method !== 'HEAD' ? await readRawBody(event) : undefined,
|
|
247
|
-
}, {
|
|
248
|
-
event,
|
|
249
|
-
})
|
|
250
|
-
|
|
251
|
-
// Set response headers
|
|
252
|
-
response.headers.forEach((value, key) => {
|
|
253
|
-
setHeader(event, key, value)
|
|
254
|
-
})
|
|
255
|
-
|
|
256
|
-
// Set status code
|
|
257
|
-
setResponseStatus(event, response.status)
|
|
258
|
-
|
|
259
|
-
// Return response body
|
|
260
|
-
if (response.body) {
|
|
261
|
-
const contentType = response.headers.get('content-type')
|
|
262
|
-
if (contentType?.includes('text/html')) {
|
|
263
|
-
// Set cache headers for Apollo Sandbox HTML
|
|
264
|
-
setApolloSandboxCacheHeaders(event)
|
|
265
|
-
return await response.text()
|
|
266
|
-
}
|
|
267
|
-
if (contentType?.includes('application/json')) {
|
|
268
|
-
return await response.text()
|
|
269
|
-
}
|
|
270
|
-
return response.body
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
return null
|
|
274
|
-
})
|
|
275
|
-
`;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
//#endregion
|
|
279
|
-
export { prerender };
|
package/dist/scanner.js
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { consola } from "consola";
|
|
2
|
-
import { basename, join, relative } from "pathe";
|
|
3
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
4
|
-
import { glob } from "tinyglobby";
|
|
5
|
-
|
|
6
|
-
//#region src/scanner.ts
|
|
7
|
-
async function scanGraphQLFiles(nitro) {
|
|
8
|
-
try {
|
|
9
|
-
const graphqlFiles = await scanGraphQLFilesWithResolvers(nitro);
|
|
10
|
-
const typeDefs = graphqlFiles.map((f) => f.typeDefs).filter(Boolean);
|
|
11
|
-
const resolvers = await scanResolverFiles(nitro);
|
|
12
|
-
const resolverPaths = resolvers.map((r) => r.path);
|
|
13
|
-
const yogaConfigPath = await scanForYogaConfig(nitro);
|
|
14
|
-
consola.info(`[graphql] Found ${typeDefs.length} schema files and ${resolvers.length} resolvers`);
|
|
15
|
-
return {
|
|
16
|
-
typeDefs,
|
|
17
|
-
resolverPaths,
|
|
18
|
-
resolvers,
|
|
19
|
-
graphqlFiles,
|
|
20
|
-
yogaConfigPath
|
|
21
|
-
};
|
|
22
|
-
} catch (error) {
|
|
23
|
-
consola.warn("[graphql] Error scanning files:", error);
|
|
24
|
-
return {
|
|
25
|
-
typeDefs: [],
|
|
26
|
-
resolverPaths: [],
|
|
27
|
-
resolvers: [],
|
|
28
|
-
graphqlFiles: []
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
async function scanResolverFiles(nitro) {
|
|
33
|
-
const NITRO_GLOB_PATTERN = "**/*.{js,mjs,cjs,ts,mts,cts,tsx,jsx}";
|
|
34
|
-
const resolverFiles = await Promise.all(nitro.options.scanDirs.map(async (scanDir) => {
|
|
35
|
-
const graphqlDir = join(scanDir, "graphql");
|
|
36
|
-
if (!existsSync(graphqlDir)) return [];
|
|
37
|
-
return glob([
|
|
38
|
-
join(graphqlDir, NITRO_GLOB_PATTERN),
|
|
39
|
-
`!${join(graphqlDir, "**/*.d.ts")}`,
|
|
40
|
-
`!${join(graphqlDir, "**/*.test.*")}`,
|
|
41
|
-
`!${join(graphqlDir, "**/*.spec.*")}`,
|
|
42
|
-
`!${join(graphqlDir, "**/yoga.config.ts")}`
|
|
43
|
-
], {
|
|
44
|
-
cwd: scanDir,
|
|
45
|
-
dot: true,
|
|
46
|
-
ignore: nitro.options.ignore || [],
|
|
47
|
-
absolute: true
|
|
48
|
-
});
|
|
49
|
-
})).then((results) => results.flat());
|
|
50
|
-
const resolvers = [];
|
|
51
|
-
for (const filePath of resolverFiles) {
|
|
52
|
-
const scanDir = nitro.options.scanDirs.find((dir) => filePath.startsWith(dir));
|
|
53
|
-
if (!scanDir) continue;
|
|
54
|
-
const graphqlDir = join(scanDir, "graphql");
|
|
55
|
-
const relativePath = relative(graphqlDir, filePath);
|
|
56
|
-
const fileName = basename(relativePath, ".ts") || basename(relativePath, ".js") || basename(relativePath, ".mjs");
|
|
57
|
-
const importPath = relativePath.replace(/\.(ts|js|mjs|tsx|jsx|cjs|mts|cts)$/, "");
|
|
58
|
-
resolvers.push({
|
|
59
|
-
path: filePath,
|
|
60
|
-
relativePath,
|
|
61
|
-
name: fileName,
|
|
62
|
-
importPath,
|
|
63
|
-
isGraphQLFile: false
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
return resolvers;
|
|
67
|
-
}
|
|
68
|
-
async function scanGraphQLFilesWithResolvers(nitro) {
|
|
69
|
-
const graphqlFiles = await Promise.all(nitro.options.scanDirs.map(async (scanDir) => {
|
|
70
|
-
const graphqlDir = join(scanDir, "graphql");
|
|
71
|
-
if (!existsSync(graphqlDir)) return [];
|
|
72
|
-
return glob([join(graphqlDir, "**/*.graphql"), join(graphqlDir, "**/*.gql")], {
|
|
73
|
-
cwd: scanDir,
|
|
74
|
-
dot: true,
|
|
75
|
-
ignore: nitro.options.ignore || [],
|
|
76
|
-
absolute: true
|
|
77
|
-
});
|
|
78
|
-
})).then((results) => results.flat());
|
|
79
|
-
const files = [];
|
|
80
|
-
for (const filePath of graphqlFiles) {
|
|
81
|
-
const scanDir = nitro.options.scanDirs.find((dir) => filePath.startsWith(dir));
|
|
82
|
-
if (!scanDir) continue;
|
|
83
|
-
const graphqlDir = join(scanDir, "graphql");
|
|
84
|
-
const relativePath = relative(graphqlDir, filePath);
|
|
85
|
-
const contentStr = readFileSync(filePath, "utf-8");
|
|
86
|
-
const hasResolvers = contentStr.includes("# @resolver") || contentStr.includes("# @resolvers");
|
|
87
|
-
let typeDefs = contentStr;
|
|
88
|
-
if (hasResolvers) {
|
|
89
|
-
const lines = contentStr.split("\n");
|
|
90
|
-
const schemaLines = [];
|
|
91
|
-
for (const line of lines) {
|
|
92
|
-
if (line.match(/^#\s*@resolver/)) break;
|
|
93
|
-
schemaLines.push(line);
|
|
94
|
-
}
|
|
95
|
-
typeDefs = schemaLines.join("\n").trim();
|
|
96
|
-
}
|
|
97
|
-
files.push({
|
|
98
|
-
path: filePath,
|
|
99
|
-
relativePath,
|
|
100
|
-
content: contentStr,
|
|
101
|
-
hasResolvers,
|
|
102
|
-
typeDefs
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
return files;
|
|
106
|
-
}
|
|
107
|
-
async function scanForYogaConfig(nitro) {
|
|
108
|
-
const configFileName = "yoga.config.ts";
|
|
109
|
-
for (const scanDir of nitro.options.scanDirs) {
|
|
110
|
-
const graphqlDir = join(scanDir, "graphql");
|
|
111
|
-
const configPath = join(graphqlDir, configFileName);
|
|
112
|
-
if (existsSync(configPath)) return configPath;
|
|
113
|
-
}
|
|
114
|
-
return void 0;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
//#endregion
|
|
118
|
-
export { scanGraphQLFiles };
|
package/dist/utils.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { YogaServerOptions } from "graphql-yoga";
|
|
2
|
-
import { GraphQLSchemaConfig, Resolvers } from "nitro-graphql/types";
|
|
3
|
-
|
|
4
|
-
//#region src/utils.d.ts
|
|
5
|
-
declare function defineGraphQLSchema(config: GraphQLSchemaConfig): GraphQLSchemaConfig;
|
|
6
|
-
declare function defineResolver(resolvers: Resolvers): Resolvers;
|
|
7
|
-
/**
|
|
8
|
-
* Helper function to define GraphQL Yoga configuration with type safety
|
|
9
|
-
*/
|
|
10
|
-
declare function defineYogaConfig<TServerContext = any, TUserContext = any>(config: Partial<YogaServerOptions<TServerContext, TUserContext>>): Partial<YogaServerOptions<TServerContext, TUserContext>>;
|
|
11
|
-
declare function relativeWithDot(from: string, to: string): string;
|
|
12
|
-
//#endregion
|
|
13
|
-
export { defineGraphQLSchema, defineResolver, defineYogaConfig, relativeWithDot };
|
package/dist/utils.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { relative } from "pathe";
|
|
2
|
-
|
|
3
|
-
//#region src/utils.ts
|
|
4
|
-
function defineGraphQLSchema(config) {
|
|
5
|
-
return config;
|
|
6
|
-
}
|
|
7
|
-
function defineResolver(resolvers) {
|
|
8
|
-
return resolvers;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Helper function to define GraphQL Yoga configuration with type safety
|
|
12
|
-
*/
|
|
13
|
-
function defineYogaConfig(config) {
|
|
14
|
-
return config;
|
|
15
|
-
}
|
|
16
|
-
const RELATIVE_RE = /^\.{1,2}\//;
|
|
17
|
-
function relativeWithDot(from, to) {
|
|
18
|
-
const rel = relative(from, to);
|
|
19
|
-
return RELATIVE_RE.test(rel) ? rel : `./${rel}`;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
//#endregion
|
|
23
|
-
export { defineGraphQLSchema, defineResolver, defineYogaConfig, relativeWithDot };
|