Skip to content

feat(graphql): 由 Vercel Serverless function 驱动的 GraphQL API#28

Open
ANGJustinl wants to merge 19 commits intodatawhalechina:mainfrom
ANGJustinl:main
Open

feat(graphql): 由 Vercel Serverless function 驱动的 GraphQL API#28
ANGJustinl wants to merge 19 commits intodatawhalechina:mainfrom
ANGJustinl:main

Conversation

@ANGJustinl
Copy link

@ANGJustinl ANGJustinl commented Feb 12, 2026

API 文档参见: https://members-visualization.vercel.app/api/docs
Playground位于: https://members-visualization.vercel.app/api/graphql

描述

1. ♻️ 创建 GraphQL API 架构

  • 架构变更:使用 Vercel Serverless API (/api/graphql)。
  • 客户端更新:更新了 client.js,现在通过 fetch 请求后端 API。

2. 📝 文档结构调整

  • 路径迁移:将 GraphQL API 文档从根目录移至 /api/docs,降低对普通用户的干扰。
  • 入口调整:将 API 文档入口从主导航栏移至"相关链接"下拉菜单中。
  • 内容更新:更新了 API 文档以反映新的 Serverless 架构,增加了 curl/fetch/Python 的调用示例。

部署相关 (后端部分需要部署Vercel平台)

关于 Vercel 部署

无需额外配置,只需将代码合并至 main 分支。Vercel 会自动读取 vercel.json 和 api 目录进行部署。

  • Vercel 预设环境变量 VERCEL=1 会被构建脚本自动识别,从而正确设置网站根路径。

关于本地开发

由于 API 现在的运行依赖于 Serverless Function 环境,在本地开发时如果需要调试 API 相关功能,建议使用 Vercel CLI:

npm i -g vercel
vercel dev

如果直接运行 npm run docs:dev,页面浏览正常,但涉及 GraphQL 的数据请求可能会因为没有后端环境而失败(除非配置了代理)。


Check List

  • 修复 Vercel 资源加载路径
  • 迁移 GraphQL 到 Serverless 模式
  • 更新 API 文档及路由
  • 构建测试通过

ANGJustinl and others added 19 commits January 12, 2026 12:06
- Add GraphQL schema definition with Member, DomainStat, Leaderboard, and ProjectInfo types
- Implement DataSource module for data loading and caching from static JSON files
- Create Resolvers module with filtering, sorting, pagination, and leaderboard calculation logic
- Add GraphQL Client with convenient JavaScript API methods for common queries
- Implement 5 leaderboard algorithms: popularity, productivity, social, rising star, and comprehensive
- Add comprehensive GraphQL API documentation with architecture overview and usage examples
- Create GraphQLDemo Vue component for interactive API demonstrations
- Update VitePress config to include GraphQL API navigation link
- Add graphql and graphql-js dependencies to package.json
- Enable frontend-only GraphQL queries without requiring backend server
- Add graphql ^16.8.1 as a new dependency
- Update mdast-util-to-hast from 13.2.0 to 13.2.1
- Update preact from 10.27.1 to 10.28.2
- Update vite from 5.4.20 to 5.4.21
- Remove peer dependency flags from @algolia/client-search, algoliasearch, echarts, focus-trap, and vue
- Resolve dependency conflicts and ensure compatibility with GraphQL API implementation
Simplify .gitignore and remove diff.txt
…ation

* 'main' of https://github.com/ANGJustinl/members-visualization: (69 commits)
  🤖 Auto-update member data and avatars - 2026-02-11 22:29:59 UTC
  🤖 Auto-update member data and avatars - 2026-02-10 22:41:18 UTC
  Update bot_filter.py
  🤖 Auto-update member data and avatars - 2026-02-09 22:36:08 UTC
  📊 Update quarterly contributors data - 2026-02-09 07:26:43 UTC
  Update daily-data-update.yml
  🤖 Auto-update member data and avatars - 2026-02-08 22:27:24 UTC
  🤖 Auto-update member data and avatars - 2026-02-07 22:26:27 UTC
  🤖 Auto-update member data and avatars - 2026-02-06 22:26:39 UTC
  📊 Update quarterly contributors data - 2026-02-06 17:31:56 UTC
  Simplify .gitignore and remove diff.txt
  📊 Update quarterly contributors data - 2026-02-06 10:09:05 UTC
  Update quarterly-contributors.yml
  📊 Update quarterly contributors data - 2026-02-06 09:51:12 UTC
  Update README.md
  Update index.md
  Update quarterly-contributors.yml
  📊 Update quarterly contributors data - 2026-02-06 08:45:23 UTC
  Limit workflow add, move cache, skip bots
  Update QuarterlyContributors.vue
  ...
… documentation

- Deleted the GraphQL schema definition file to streamline the project structure.
- Introduced a new API documentation file detailing the GraphQL API features, usage, and query examples.
- Updated existing documentation to reflect changes in the API structure and usage patterns.
@ANGJustinl
Copy link
Author

[Edit Require] 文档中调用示例部分还需要改为实际的url

@ANGJustinl ANGJustinl marked this pull request as ready for review February 12, 2026 11:42
Copilot AI review requested due to automatic review settings February 12, 2026 11:42
@ANGJustinl

This comment was marked as duplicate.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

该 PR 将原本的 GraphQL 能力调整为由 Vercel Serverless Function 提供的后端 API(/api/graphql),并同步更新前端调用方式与文档入口/路径,以适配 Vercel 部署与本地 vercel dev 调试流程。

Changes:

  • 新增 Vercel 部署配置(vercel.json),并加入 Serverless Function 的运行时配置。
  • 新增 Serverless GraphQL API(schema/resolvers/dataSource + handler),前端 GraphQL client 改为 fetch('/api/graphql') 调用。
  • 调整/新增 GraphQL API 文档路径与站点导航入口(迁移到 /api/docs)。

Reviewed changes

Copilot reviewed 14 out of 15 changed files in this pull request and generated 13 comments.

Show a summary per file
File Description
vercel.json 配置 Vercel 的 VitePress 构建输出与函数超时等参数
package.json 增加 graphql 依赖以支持后端 schema 执行
package-lock.json 锁文件更新以反映依赖变更
docs/.vitepress/config.mjs 增加对 VERCEL 环境的 base 路径判断,并调整 API 文档入口位置
docs/api/docs.md 新增(或迁移后的)GraphQL API 文档页面(目标路径 /api/docs
docs/graphql-api.md 新增根目录的 GraphQL 文档页(与“迁移到 /api/docs”的目标存在重叠)
docs/.vitepress/graphql/client.js 新增 fetch-based GraphQL 客户端封装与便捷查询方法
docs/.vitepress/graphql/index.js GraphQL 客户端入口导出文件
docs/.vitepress/graphql/README.md GraphQL 相关实现说明文档
docs/.vitepress/theme/graphql-demo/GraphQLDemo.vue GraphQL 查询演示组件(UI + 调用 client)
api/package.json api/ 目录设为 ESM 并声明函数依赖
api/graphql.js Vercel Serverless Function:GraphQL handler + GraphiQL + CORS
api/_lib/schema.js GraphQL schema(GraphQL.js)定义
api/_lib/resolvers.js GraphQL resolvers 业务逻辑实现
api/_lib/dataSource.js Serverless 侧数据加载与缓存逻辑(从静态数据源 fetch)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@1985312383 1985312383 added the enhancement New feature or request label Feb 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants