feat: added graphql warning at the top (#117)

(cherry picked from commit fe9a3017e5)
This commit is contained in:
Kyrch
2025-07-27 19:27:53 -03:00
committed by Maniload
parent f129648c3e
commit c2b90daf0d
6 changed files with 1985 additions and 1917 deletions
+4
View File
@@ -1,4 +1,5 @@
import 'dotenv/config';
import graphqlWarnPlugin from './theme/graphql-warn-plugin';
const referenceSidebarItems = [
{
@@ -511,6 +512,9 @@ const referenceSidebarItems = [
];
export default {
vite: {
plugins: [graphqlWarnPlugin()],
},
base: process.env.VITEPRESS_BASE,
lang: 'en-US',
lastUpdated: true,
@@ -0,0 +1,38 @@
import path from "path";
export default function graphqlWarnPlugin() {
return {
name: "graphql-warn-plugin",
enforce: "pre",
transform(code, id) {
if (!id.endsWith(".md")) return;
const relativePath = path.relative(process.cwd(), id);
if (!relativePath.includes("graphql")) return;
const warningBlock = [
"::: warning",
"⚠️ The GraphQL API is experimental and subject to change without notice.",
":::",
"",
].join("\n");
if (code.startsWith("---")) {
const endOfFrontmatter = code.indexOf("---", 3);
if (endOfFrontmatter !== -1) {
const before = code.slice(0, endOfFrontmatter + 3);
const after = code.slice(endOfFrontmatter + 3);
return {
code: `${before}\n\n${warningBlock}${after}`,
map: null,
};
}
}
return {
code: warningBlock + code,
map: null,
};
},
};
}