nitro-graphql 0.0.4 → 0.0.6
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 -30
- package/dist/_virtual/rolldown_runtime.js +37 -0
- package/dist/ecosystem/nuxt.d.ts +7 -0
- package/dist/ecosystem/nuxt.js +30 -0
- package/dist/graphql/index.d.ts +5 -0
- package/dist/graphql/server.d.ts +5 -0
- package/dist/index.d.ts +9 -3
- package/dist/index.js +125 -135
- 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 +87 -0
- package/dist/routes/apollo-server.d.ts +6 -0
- package/dist/routes/apollo-server.js +39 -0
- package/dist/routes/graphql-yoga.d.ts +6 -0
- package/dist/routes/graphql-yoga.js +56 -0
- package/dist/routes/health.d.ts +10 -0
- package/dist/routes/health.js +44 -0
- package/dist/types/index.d.ts +67 -0
- package/dist/types/standard-schema.d.ts +59 -0
- package/dist/utils/apollo.js +62 -0
- package/dist/{client-codegen.js → utils/client-codegen.js} +52 -16
- package/dist/utils/define.d.ts +17 -0
- package/dist/utils/define.js +25 -0
- package/dist/utils/index.d.ts +15 -0
- package/dist/utils/index.js +107 -0
- package/dist/{codegen.js → utils/server-codegen.js} +55 -35
- package/dist/utils/server-type-generation.js +52 -0
- package/package.json +37 -13
- package/dist/client-watcher.d.ts +0 -7
- package/dist/client-watcher.js +0 -100
- package/dist/codegen.d.ts +0 -13
- package/dist/context.d.ts +0 -10
- package/dist/dev.js +0 -95
- package/dist/prerender.js +0 -279
- package/dist/scanner.js +0 -118
- package/dist/types.d.ts +0 -46
- package/dist/utils.d.ts +0 -13
- package/dist/utils.js +0 -23
- /package/dist/{context.js → graphql/index.js} +0 -0
- /package/dist/{types.js → graphql/server.js} +0 -0
package/dist/rollup.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { getImportId, scanGraphql } from "./utils/index.js";
|
|
2
|
+
import { serverTypeGeneration } from "./utils/server-type-generation.js";
|
|
3
|
+
import { readFile } from "node:fs/promises";
|
|
4
|
+
import { parse } from "graphql";
|
|
5
|
+
import { genImport } from "knitwork";
|
|
6
|
+
|
|
7
|
+
//#region src/rollup.ts
|
|
8
|
+
async function rollupConfig(app) {
|
|
9
|
+
virtualDefs(app);
|
|
10
|
+
virtualResolvers(app);
|
|
11
|
+
app.hooks.hook("rollup:before", (nitro, rollupConfig$1) => {
|
|
12
|
+
rollupConfig$1.plugins = rollupConfig$1.plugins || [];
|
|
13
|
+
const { include = /\.(graphql|gql)$/i, exclude, validate = false } = app.options.graphql?.loader || {};
|
|
14
|
+
if (Array.isArray(rollupConfig$1.plugins)) {
|
|
15
|
+
rollupConfig$1.plugins.push({
|
|
16
|
+
name: "nitro-graphql",
|
|
17
|
+
async load(id) {
|
|
18
|
+
if (exclude?.test?.(id)) return null;
|
|
19
|
+
if (!include.test(id)) return null;
|
|
20
|
+
try {
|
|
21
|
+
const content = await readFile(id, "utf-8");
|
|
22
|
+
if (validate) parse(content);
|
|
23
|
+
return `export default ${JSON.stringify(content)}`;
|
|
24
|
+
} catch (error) {
|
|
25
|
+
if (error.code === "ENOENT") return null;
|
|
26
|
+
this.error(`Failed to read GraphQL file ${id}: ${error.message}`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
rollupConfig$1.plugins.push({
|
|
31
|
+
name: "nitro-graphql-watcher",
|
|
32
|
+
async buildStart() {
|
|
33
|
+
const graphqlFiles = await scanGraphql(nitro);
|
|
34
|
+
for (const file of graphqlFiles) this.addWatchFile(file);
|
|
35
|
+
this.addWatchFile("server/graphql/");
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
app.hooks.hook("dev:reload", async () => {
|
|
41
|
+
await serverTypeGeneration(app);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
function virtualDefs(app) {
|
|
45
|
+
const getDefs = () => {
|
|
46
|
+
const defs = [...app.scanDefs, ...app.options.graphql?.typedefs ?? []];
|
|
47
|
+
return defs;
|
|
48
|
+
};
|
|
49
|
+
app.options.virtual ??= {};
|
|
50
|
+
app.options.virtual["#nitro-internal-virtual/server-defs"] = () => {
|
|
51
|
+
const imports = getDefs();
|
|
52
|
+
const code = `
|
|
53
|
+
${imports.map((handler) => `import ${getImportId(handler)} from '${handler}';`).join("\n")}
|
|
54
|
+
|
|
55
|
+
export const defs = [
|
|
56
|
+
${imports.map((h) => `{ def: ${getImportId(h)} }`).join(",\n")}
|
|
57
|
+
];
|
|
58
|
+
`;
|
|
59
|
+
return code;
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function virtualResolvers(app) {
|
|
63
|
+
const getResolvers = () => {
|
|
64
|
+
const resolvers = [...app.scanResolvers];
|
|
65
|
+
return resolvers;
|
|
66
|
+
};
|
|
67
|
+
app.options.virtual ??= {};
|
|
68
|
+
app.options.virtual["#nitro-internal-virtual/server-resolvers"] = () => {
|
|
69
|
+
const imports = getResolvers();
|
|
70
|
+
const importsContent = [...imports.map(({ specifier, imports: imports$1, options }) => {
|
|
71
|
+
return genImport(specifier, imports$1, options);
|
|
72
|
+
})];
|
|
73
|
+
const data = imports.map(({ imports: imports$1 }) => imports$1.map((i) => `{ resolver: ${i.as} }`).join(",\n")).filter(Boolean).join(",\n");
|
|
74
|
+
const content = [
|
|
75
|
+
"export const resolvers = [",
|
|
76
|
+
data,
|
|
77
|
+
"]",
|
|
78
|
+
""
|
|
79
|
+
];
|
|
80
|
+
content.unshift(...importsContent);
|
|
81
|
+
const code = content.join("\n");
|
|
82
|
+
return code;
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
//#endregion
|
|
87
|
+
export { rollupConfig };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { startServerAndCreateH3Handler } from "../utils/apollo.js";
|
|
2
|
+
import { mergeResolvers, mergeTypeDefs } from "@graphql-tools/merge";
|
|
3
|
+
import { defs } from "#nitro-internal-virtual/server-defs";
|
|
4
|
+
import { resolvers } from "#nitro-internal-virtual/server-resolvers";
|
|
5
|
+
import { ApolloServer } from "@apollo/server";
|
|
6
|
+
import { ApolloServerPluginLandingPageLocalDefault } from "@apollo/server/plugin/landingPage/default";
|
|
7
|
+
|
|
8
|
+
//#region src/routes/apollo-server.ts
|
|
9
|
+
function createMergedSchema() {
|
|
10
|
+
try {
|
|
11
|
+
const mergedDefs = defs.map((schema) => schema.def).join("\n\n");
|
|
12
|
+
const typeDefs = mergeTypeDefs([mergedDefs]);
|
|
13
|
+
const mergedResolvers = mergeResolvers(resolvers.map((r) => r.resolver));
|
|
14
|
+
return {
|
|
15
|
+
typeDefs,
|
|
16
|
+
resolvers: mergedResolvers
|
|
17
|
+
};
|
|
18
|
+
} catch (error) {
|
|
19
|
+
console.error("Schema merge error:", error);
|
|
20
|
+
throw error;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
let apolloServer;
|
|
24
|
+
function createApolloServer() {
|
|
25
|
+
if (!apolloServer) {
|
|
26
|
+
const { typeDefs, resolvers: mergedResolvers } = createMergedSchema();
|
|
27
|
+
apolloServer = new ApolloServer({
|
|
28
|
+
typeDefs,
|
|
29
|
+
resolvers: mergedResolvers,
|
|
30
|
+
introspection: true,
|
|
31
|
+
plugins: [ApolloServerPluginLandingPageLocalDefault({ embed: true })]
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
return apolloServer;
|
|
35
|
+
}
|
|
36
|
+
var apollo_server_default = startServerAndCreateH3Handler(createApolloServer, { context: async (event) => ({ event }) });
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
export { apollo_server_default as default };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { mergeResolvers, mergeTypeDefs } from "@graphql-tools/merge";
|
|
2
|
+
import { defs } from "#nitro-internal-virtual/server-defs";
|
|
3
|
+
import { resolvers } from "#nitro-internal-virtual/server-resolvers";
|
|
4
|
+
import { defineEventHandler, toWebRequest } from "h3";
|
|
5
|
+
import { createSchema, createYoga } from "graphql-yoga";
|
|
6
|
+
|
|
7
|
+
//#region src/routes/graphql-yoga.ts
|
|
8
|
+
const apolloSandboxHtml = `<!DOCTYPE html>
|
|
9
|
+
<html lang="en">
|
|
10
|
+
<body style="margin: 0; overflow-x: hidden; overflow-y: hidden">
|
|
11
|
+
<div id="sandbox" style="height:100vh; width:100vw;"></div>
|
|
12
|
+
<script src="https://embeddable-sandbox.cdn.apollographql.com/02e2da0fccbe0240ef03d2396d6c98559bab5b06/embeddable-sandbox.umd.production.min.js"><\/script>
|
|
13
|
+
<script>
|
|
14
|
+
new window.EmbeddedSandbox({
|
|
15
|
+
target: "#sandbox",
|
|
16
|
+
initialEndpoint: window.location.href,
|
|
17
|
+
hideCookieToggle: false,
|
|
18
|
+
initialState: {
|
|
19
|
+
includeCookies: true
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
<\/script>
|
|
23
|
+
</body>
|
|
24
|
+
</html>`;
|
|
25
|
+
function createMergedSchema() {
|
|
26
|
+
try {
|
|
27
|
+
const mergedDefs = defs.map((schema) => schema.def).join("\n\n");
|
|
28
|
+
const typeDefs = mergeTypeDefs([mergedDefs]);
|
|
29
|
+
const mergedResolvers = mergeResolvers(resolvers.map((r) => r.resolver));
|
|
30
|
+
return createSchema({
|
|
31
|
+
typeDefs,
|
|
32
|
+
resolvers: mergedResolvers
|
|
33
|
+
});
|
|
34
|
+
} catch (error) {
|
|
35
|
+
console.error("Schema merge error:", error);
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
let yoga;
|
|
40
|
+
var graphql_yoga_default = defineEventHandler(async (event) => {
|
|
41
|
+
if (!yoga) {
|
|
42
|
+
const schema = createMergedSchema();
|
|
43
|
+
yoga = createYoga({
|
|
44
|
+
schema,
|
|
45
|
+
graphqlEndpoint: "/api/graphql",
|
|
46
|
+
landingPage: false,
|
|
47
|
+
renderGraphiQL: () => apolloSandboxHtml
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
const request = toWebRequest(event);
|
|
51
|
+
const response = await yoga.handleRequest(request, event);
|
|
52
|
+
return new Response(response.body, response);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
//#endregion
|
|
56
|
+
export { graphql_yoga_default as default };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { defineEventHandler, setResponseStatus } from "h3";
|
|
2
|
+
import { useRuntimeConfig } from "nitropack/runtime";
|
|
3
|
+
|
|
4
|
+
//#region src/routes/health.ts
|
|
5
|
+
var health_default = defineEventHandler(async (event) => {
|
|
6
|
+
const runtime = useRuntimeConfig();
|
|
7
|
+
if (!runtime.graphql || !runtime.graphql.endpoint?.graphql) {
|
|
8
|
+
setResponseStatus(event, 404);
|
|
9
|
+
return {
|
|
10
|
+
status: "error",
|
|
11
|
+
message: "GraphQL health check endpoint is not configured",
|
|
12
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
try {
|
|
16
|
+
const response = await $fetch(runtime.graphql.endpoint?.graphql, {
|
|
17
|
+
method: "POST",
|
|
18
|
+
body: {
|
|
19
|
+
query: "query Health { __typename }",
|
|
20
|
+
operationName: "Health"
|
|
21
|
+
},
|
|
22
|
+
headers: {
|
|
23
|
+
"Content-Type": "application/json",
|
|
24
|
+
"Accept": "application/json"
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
if (response && typeof response === "object" && "data" in response) return {
|
|
28
|
+
status: "healthy",
|
|
29
|
+
message: "GraphQL server is running",
|
|
30
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
31
|
+
};
|
|
32
|
+
throw new Error("Invalid response from GraphQL server");
|
|
33
|
+
} catch (error) {
|
|
34
|
+
setResponseStatus(event, 503);
|
|
35
|
+
return {
|
|
36
|
+
status: "unhealthy",
|
|
37
|
+
message: error instanceof Error ? error.message : "GraphQL server is not responding",
|
|
38
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
//#endregion
|
|
44
|
+
export { health_default as default };
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { StandardSchemaV1 } from "./standard-schema.js";
|
|
2
|
+
import { ESMCodeGenOptions } from "knitwork";
|
|
3
|
+
import { IResolvers } from "@graphql-tools/utils";
|
|
4
|
+
import { TypeScriptPluginConfig } from "@graphql-codegen/typescript";
|
|
5
|
+
import { TypeScriptDocumentsPluginConfig } from "@graphql-codegen/typescript-operations";
|
|
6
|
+
import { TypeScriptResolversPluginConfig } from "@graphql-codegen/typescript-resolvers";
|
|
7
|
+
|
|
8
|
+
//#region src/types/index.d.ts
|
|
9
|
+
type CodegenServerConfig = TypeScriptPluginConfig & TypeScriptResolversPluginConfig;
|
|
10
|
+
interface IESMImport {
|
|
11
|
+
name: string;
|
|
12
|
+
as?: string;
|
|
13
|
+
type: 'resolver' | 'query' | 'mutation' | 'type' | 'subscription';
|
|
14
|
+
}
|
|
15
|
+
interface GenImport {
|
|
16
|
+
specifier: string;
|
|
17
|
+
imports: IESMImport[];
|
|
18
|
+
options?: ESMCodeGenOptions;
|
|
19
|
+
}
|
|
20
|
+
declare module 'nitropack/types' {
|
|
21
|
+
interface Nitro {
|
|
22
|
+
scanDefs: string[];
|
|
23
|
+
scanResolvers: GenImport[];
|
|
24
|
+
graphql: {
|
|
25
|
+
buildDir: string;
|
|
26
|
+
watchDirs: string[];
|
|
27
|
+
clientDir: string;
|
|
28
|
+
serverDir: string;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
declare module 'nitropack' {
|
|
33
|
+
interface NitroOptions {
|
|
34
|
+
graphql?: NitroGraphQLOptions;
|
|
35
|
+
}
|
|
36
|
+
interface NitroRuntimeConfig {
|
|
37
|
+
graphql?: NitroGraphQLOptions;
|
|
38
|
+
}
|
|
39
|
+
interface NitroConfig {
|
|
40
|
+
graphql?: NitroGraphQLOptions;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
interface CodegenClientConfig extends TypeScriptPluginConfig, TypeScriptDocumentsPluginConfig {
|
|
44
|
+
endpoint?: string;
|
|
45
|
+
documentMode?: 'string' | 'graphQLTag' | 'documentNode' | 'documentNodeImportFragments' | 'external';
|
|
46
|
+
}
|
|
47
|
+
interface NitroGraphQLOptions {
|
|
48
|
+
framework: 'graphql-yoga' | 'apollo-server';
|
|
49
|
+
endpoint?: {
|
|
50
|
+
graphql?: string;
|
|
51
|
+
healthCheck?: string;
|
|
52
|
+
};
|
|
53
|
+
playground?: boolean;
|
|
54
|
+
typedefs?: string[];
|
|
55
|
+
resolvers?: Array<IResolvers<any, any>>;
|
|
56
|
+
loader?: {
|
|
57
|
+
include?: RegExp;
|
|
58
|
+
exclude?: RegExp;
|
|
59
|
+
validate?: boolean;
|
|
60
|
+
};
|
|
61
|
+
codegen?: {
|
|
62
|
+
server?: CodegenServerConfig;
|
|
63
|
+
client?: CodegenClientConfig;
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
//#endregion
|
|
67
|
+
export { CodegenClientConfig, CodegenServerConfig, GenImport, NitroGraphQLOptions };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
//#region src/types/standard-schema.d.ts
|
|
2
|
+
/** The Standard Schema interface. */
|
|
3
|
+
interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
4
|
+
/** The Standard Schema properties. */
|
|
5
|
+
readonly '~standard': StandardSchemaV1.Props<Input, Output>;
|
|
6
|
+
}
|
|
7
|
+
declare namespace StandardSchemaV1 {
|
|
8
|
+
/** The Standard Schema properties interface. */
|
|
9
|
+
export interface Props<Input = unknown, Output = Input> {
|
|
10
|
+
/** The version number of the standard. */
|
|
11
|
+
readonly version: 1;
|
|
12
|
+
/** The vendor name of the schema library. */
|
|
13
|
+
readonly vendor: string;
|
|
14
|
+
/** Validates unknown input values. */
|
|
15
|
+
readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
|
|
16
|
+
/** Inferred types associated with the schema. */
|
|
17
|
+
readonly types?: Types<Input, Output> | undefined;
|
|
18
|
+
}
|
|
19
|
+
/** The result interface of the validate function. */
|
|
20
|
+
export type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
21
|
+
/** The result interface if validation succeeds. */
|
|
22
|
+
export interface SuccessResult<Output> {
|
|
23
|
+
/** The typed output value. */
|
|
24
|
+
readonly value: Output;
|
|
25
|
+
/** The non-existent issues. */
|
|
26
|
+
readonly issues?: undefined;
|
|
27
|
+
}
|
|
28
|
+
/** The result interface if validation fails. */
|
|
29
|
+
export interface FailureResult {
|
|
30
|
+
/** The issues of failed validation. */
|
|
31
|
+
readonly issues: ReadonlyArray<Issue>;
|
|
32
|
+
}
|
|
33
|
+
/** The issue interface of the failure output. */
|
|
34
|
+
export interface Issue {
|
|
35
|
+
/** The error message of the issue. */
|
|
36
|
+
readonly message: string;
|
|
37
|
+
/** The path of the issue, if any. */
|
|
38
|
+
readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
|
|
39
|
+
}
|
|
40
|
+
/** The path segment interface of the issue. */
|
|
41
|
+
export interface PathSegment {
|
|
42
|
+
/** The key representing a path segment. */
|
|
43
|
+
readonly key: PropertyKey;
|
|
44
|
+
}
|
|
45
|
+
/** The Standard Schema types interface. */
|
|
46
|
+
export interface Types<Input = unknown, Output = Input> {
|
|
47
|
+
/** The input type of the schema. */
|
|
48
|
+
readonly input: Input;
|
|
49
|
+
/** The output type of the schema. */
|
|
50
|
+
readonly output: Output;
|
|
51
|
+
}
|
|
52
|
+
/** Infers the input type of a Standard Schema. */
|
|
53
|
+
export type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['input'];
|
|
54
|
+
/** Infers the output type of a Standard Schema. */
|
|
55
|
+
export type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['output'];
|
|
56
|
+
export {};
|
|
57
|
+
}
|
|
58
|
+
//#endregion
|
|
59
|
+
export { StandardSchemaV1 };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { HeaderMap } from "@apollo/server";
|
|
2
|
+
import { eventHandler, getHeaders, isMethod, readBody, setHeaders } from "h3";
|
|
3
|
+
|
|
4
|
+
//#region src/utils/apollo.ts
|
|
5
|
+
function startServerAndCreateH3Handler(server, options) {
|
|
6
|
+
const apolloServer = typeof server === "function" ? server() : server;
|
|
7
|
+
apolloServer.startInBackgroundHandlingStartupErrorsByLoggingAndFailingAllRequests();
|
|
8
|
+
const defaultContext = () => Promise.resolve({});
|
|
9
|
+
const contextFunction = options?.context ?? defaultContext;
|
|
10
|
+
return eventHandler({
|
|
11
|
+
handler: async (event) => {
|
|
12
|
+
if (isMethod(event, "OPTIONS")) return null;
|
|
13
|
+
try {
|
|
14
|
+
const graphqlRequest = await toGraphqlRequest(event);
|
|
15
|
+
const { body, headers, status } = await apolloServer.executeHTTPGraphQLRequest({
|
|
16
|
+
httpGraphQLRequest: graphqlRequest,
|
|
17
|
+
context: () => contextFunction({ event })
|
|
18
|
+
});
|
|
19
|
+
if (body.kind === "chunked") throw new Error("Incremental delivery not implemented");
|
|
20
|
+
setHeaders(event, Object.fromEntries(headers));
|
|
21
|
+
event.res.statusCode = status || 200;
|
|
22
|
+
return body.string;
|
|
23
|
+
} catch (error) {
|
|
24
|
+
if (error instanceof SyntaxError) {
|
|
25
|
+
event.res.statusCode = 400;
|
|
26
|
+
return error.message;
|
|
27
|
+
} else throw error;
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
websocket: options?.websocket
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
async function toGraphqlRequest(event) {
|
|
34
|
+
return {
|
|
35
|
+
method: event.req.method || "POST",
|
|
36
|
+
headers: normalizeHeaders(getHeaders(event)),
|
|
37
|
+
search: normalizeQueryString(event.req.url),
|
|
38
|
+
body: await normalizeBody(event)
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function normalizeHeaders(headers) {
|
|
42
|
+
const headerMap = new HeaderMap();
|
|
43
|
+
for (const [key, value] of Object.entries(headers)) if (Array.isArray(value)) headerMap.set(key, value.join(","));
|
|
44
|
+
else if (value) headerMap.set(key, value);
|
|
45
|
+
return headerMap;
|
|
46
|
+
}
|
|
47
|
+
function normalizeQueryString(url) {
|
|
48
|
+
if (!url) return "";
|
|
49
|
+
return url.split("?")[1] || "";
|
|
50
|
+
}
|
|
51
|
+
async function normalizeBody(event) {
|
|
52
|
+
const PayloadMethods = [
|
|
53
|
+
"PATCH",
|
|
54
|
+
"POST",
|
|
55
|
+
"PUT",
|
|
56
|
+
"DELETE"
|
|
57
|
+
];
|
|
58
|
+
if (isMethod(event, PayloadMethods)) return await readBody(event);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
//#endregion
|
|
62
|
+
export { startServerAndCreateH3Handler };
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { preset } from "../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";
|
|
2
|
+
import { defu as defu$1 } from "defu";
|
|
3
|
+
import { parse } from "graphql";
|
|
4
|
+
import { printSchemaWithDirectives } from "@graphql-tools/utils";
|
|
5
|
+
import { consola as consola$1 } from "consola";
|
|
2
6
|
import { codegen } from "@graphql-codegen/core";
|
|
3
7
|
import { plugin } from "@graphql-codegen/typescript";
|
|
4
|
-
import { printSchemaWithDirectives } from "@graphql-tools/utils";
|
|
5
|
-
import { defu } from "defu";
|
|
6
|
-
import { parse } from "graphql";
|
|
7
8
|
import { plugin as plugin$1 } from "@graphql-codegen/typescript-generic-sdk";
|
|
8
9
|
import { plugin as plugin$2 } from "@graphql-codegen/typescript-operations";
|
|
9
10
|
import { GraphQLFileLoader } from "@graphql-tools/graphql-file-loader";
|
|
10
11
|
import { loadDocuments } from "@graphql-tools/load";
|
|
11
12
|
|
|
12
|
-
//#region src/client-codegen.ts
|
|
13
|
+
//#region src/utils/client-codegen.ts
|
|
13
14
|
function pluginContent(_schema, _documents, _config, _info) {
|
|
14
15
|
return {
|
|
15
16
|
prepend: [
|
|
@@ -31,13 +32,12 @@ async function loadGraphQLDocuments(patterns) {
|
|
|
31
32
|
else throw e;
|
|
32
33
|
}
|
|
33
34
|
}
|
|
34
|
-
async function generateClientTypes(schema,
|
|
35
|
-
const docs = await loadGraphQLDocuments(patterns);
|
|
35
|
+
async function generateClientTypes(schema, docs, config = {}, outputPath) {
|
|
36
36
|
if (docs.length === 0) {
|
|
37
|
-
consola.info("[graphql] No client GraphQL files found. Skipping client type generation.");
|
|
38
|
-
return
|
|
37
|
+
consola$1.info("[graphql] No client GraphQL files found. Skipping client type generation.");
|
|
38
|
+
return false;
|
|
39
39
|
}
|
|
40
|
-
consola.info(`[graphql] Found ${docs.length} client GraphQL documents`);
|
|
40
|
+
consola$1.info(`[graphql] Found ${docs.length} client GraphQL documents`);
|
|
41
41
|
const defaultConfig = {
|
|
42
42
|
documentMode: "string",
|
|
43
43
|
emitLegacyCommonJSImports: false,
|
|
@@ -54,7 +54,7 @@ async function generateClientTypes(schema, patterns, config = {}, outputPath) {
|
|
|
54
54
|
Currency: "string"
|
|
55
55
|
}
|
|
56
56
|
};
|
|
57
|
-
const mergedConfig = defu(config, defaultConfig);
|
|
57
|
+
const mergedConfig = defu$1(config, defaultConfig);
|
|
58
58
|
try {
|
|
59
59
|
const output = await codegen({
|
|
60
60
|
filename: outputPath || "client-types.generated.ts",
|
|
@@ -64,22 +64,58 @@ async function generateClientTypes(schema, patterns, config = {}, outputPath) {
|
|
|
64
64
|
plugins: [
|
|
65
65
|
{ pluginContent: {} },
|
|
66
66
|
{ typescript: {} },
|
|
67
|
+
{ typescriptOperations: {} }
|
|
68
|
+
],
|
|
69
|
+
pluginMap: {
|
|
70
|
+
pluginContent: { plugin: pluginContent },
|
|
71
|
+
typescript: { plugin },
|
|
72
|
+
typescriptOperations: { plugin: plugin$2 }
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
const sdkOutput = await preset.buildGeneratesSection({
|
|
76
|
+
baseOutputDir: outputPath || "client-types.generated.ts",
|
|
77
|
+
schema: parse(printSchemaWithDirectives(schema)),
|
|
78
|
+
documents: [...docs],
|
|
79
|
+
config: {
|
|
80
|
+
documentMode: "string",
|
|
81
|
+
pureMagicComment: true,
|
|
82
|
+
strictScalars: true,
|
|
83
|
+
scalars: {
|
|
84
|
+
DateTime: "Date",
|
|
85
|
+
JSON: "any",
|
|
86
|
+
UUID: "string",
|
|
87
|
+
NonEmptyString: "string",
|
|
88
|
+
Currency: "string"
|
|
89
|
+
},
|
|
90
|
+
useTypeImports: true
|
|
91
|
+
},
|
|
92
|
+
presetConfig: { typesPath: "#graphql/client" },
|
|
93
|
+
plugins: [
|
|
94
|
+
{ pluginContent: {} },
|
|
67
95
|
{ typescriptOperations: {} },
|
|
68
96
|
{ typescriptGenericSdk: { rawRequest: false } }
|
|
69
97
|
],
|
|
70
98
|
pluginMap: {
|
|
71
99
|
pluginContent: { plugin: pluginContent },
|
|
72
|
-
typescript: { plugin },
|
|
73
100
|
typescriptOperations: { plugin: plugin$2 },
|
|
74
101
|
typescriptGenericSdk: { plugin: plugin$1 }
|
|
75
102
|
}
|
|
76
103
|
});
|
|
77
|
-
|
|
104
|
+
const results = await Promise.all(sdkOutput.map(async (config$1) => {
|
|
105
|
+
return {
|
|
106
|
+
file: config$1.filename,
|
|
107
|
+
content: await codegen(config$1)
|
|
108
|
+
};
|
|
109
|
+
}));
|
|
110
|
+
return {
|
|
111
|
+
types: output,
|
|
112
|
+
sdk: results[0]?.content || ""
|
|
113
|
+
};
|
|
78
114
|
} catch (error) {
|
|
79
|
-
consola.warn("[graphql] Client type generation failed:", error);
|
|
80
|
-
return
|
|
115
|
+
consola$1.warn("[graphql] Client type generation failed:", error);
|
|
116
|
+
return false;
|
|
81
117
|
}
|
|
82
118
|
}
|
|
83
119
|
|
|
84
120
|
//#endregion
|
|
85
|
-
export { generateClientTypes };
|
|
121
|
+
export { generateClientTypes, loadGraphQLDocuments };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ApolloServerOptions, BaseContext } from "@apollo/server";
|
|
2
|
+
import { YogaServerOptions } from "graphql-yoga";
|
|
3
|
+
import { ResolversTypes, StandardSchemaV1 } from "#graphql/server";
|
|
4
|
+
import { GraphQLFramework, Resolvers } from "nitro-graphql";
|
|
5
|
+
|
|
6
|
+
//#region src/utils/define.d.ts
|
|
7
|
+
type Flatten<T> = T extends infer U ? { [K in keyof U]: U[K] } : never;
|
|
8
|
+
declare function defineSchema<T extends Partial<Record<keyof ResolversTypes, StandardSchemaV1>>>(config: T): Flatten<T>;
|
|
9
|
+
declare function defineResolver(resolvers: Resolvers): Resolvers;
|
|
10
|
+
declare function defineQuery(resolvers?: Resolvers['Query']): Resolvers;
|
|
11
|
+
declare function defineMutation(resolvers?: Resolvers['Mutation']): Resolvers;
|
|
12
|
+
declare function defineSubscription(resolvers?: Resolvers['Subscription']): Resolvers;
|
|
13
|
+
declare function defineType(resolvers: Resolvers): Resolvers;
|
|
14
|
+
type DefineServerConfig = GraphQLFramework extends 'graphql-yoga' ? Partial<YogaServerOptions<any, any>> : GraphQLFramework extends 'apollo-server' ? Partial<ApolloServerOptions<BaseContext>> : Record<string, any>;
|
|
15
|
+
declare function defineGraphQLConfig(config: Partial<DefineServerConfig>): Partial<DefineServerConfig>;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { defineGraphQLConfig, defineMutation, defineQuery, defineResolver, defineSchema, defineSubscription, defineType };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//#region src/utils/define.ts
|
|
2
|
+
function defineSchema(config) {
|
|
3
|
+
return config;
|
|
4
|
+
}
|
|
5
|
+
function defineResolver(resolvers) {
|
|
6
|
+
return resolvers;
|
|
7
|
+
}
|
|
8
|
+
function defineQuery(resolvers = {}) {
|
|
9
|
+
return { Query: { ...resolvers } };
|
|
10
|
+
}
|
|
11
|
+
function defineMutation(resolvers = {}) {
|
|
12
|
+
return { Mutation: { ...resolvers } };
|
|
13
|
+
}
|
|
14
|
+
function defineSubscription(resolvers = {}) {
|
|
15
|
+
return { Subscription: { ...resolvers } };
|
|
16
|
+
}
|
|
17
|
+
function defineType(resolvers) {
|
|
18
|
+
return resolvers;
|
|
19
|
+
}
|
|
20
|
+
function defineGraphQLConfig(config) {
|
|
21
|
+
return config;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
export { defineGraphQLConfig, defineMutation, defineQuery, defineResolver, defineSchema, defineSubscription, defineType };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { GenImport } from "../types/index.js";
|
|
2
|
+
import { Nitro } from "nitropack";
|
|
3
|
+
|
|
4
|
+
//#region src/utils/index.d.ts
|
|
5
|
+
declare const GLOB_SCAN_PATTERN = "**/*.{graphql,gql,js,mjs,cjs,ts,mts,cts,tsx,jsx}";
|
|
6
|
+
declare function getImportId(p: string, lazy?: boolean): string;
|
|
7
|
+
declare function relativeWithDot(from: string, to: string): string;
|
|
8
|
+
declare function scanGraphql(nitro: Nitro): Promise<string[]>;
|
|
9
|
+
declare function scanResolvers(nitro: Nitro): Promise<GenImport[]>;
|
|
10
|
+
declare function scanDirectives(nitro: Nitro): Promise<string[]>;
|
|
11
|
+
declare function scanTypeDefs(nitro: Nitro): Promise<string[]>;
|
|
12
|
+
declare function scanDefs(nitro: Nitro): Promise<string[]>;
|
|
13
|
+
declare function unique(arr: any[]): any[];
|
|
14
|
+
//#endregion
|
|
15
|
+
export { GLOB_SCAN_PATTERN, getImportId, relativeWithDot, scanDefs, scanDirectives, scanGraphql, scanResolvers, scanTypeDefs, unique };
|