Claude-skill-registry deno-graphql-backend
Deno GraphQL 后端接口的完整开发指南. 当需要创建、修改后端 API 接口时使用此技能
install
source · Clone the upstream repo
git clone https://github.com/majiayu000/claude-skill-registry
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/majiayu000/claude-skill-registry "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/data/deno-graphql-backend" ~/.claude/skills/majiayu000-claude-skill-registry-deno-graphql-backend && rm -rf "$T"
manifest:
skills/data/deno-graphql-backend/SKILL.mdsource content
Deno GraphQL 后端开发
三层架构
src/{mod}/{table}/ ├── {table}.graphql.ts # Schema 定义 ├── {table}.model.ts # Model 定义(可选) ├── {table}.resolver.ts # 参数处理、事务/认证设置 └── {table}.service.ts # 业务逻辑、调用 DAO
快速模板
1. GraphQL Schema
import { defineGraphql } from "/lib/context.ts"; import * as resolver from "./{table}.resolver.ts"; defineGraphql(resolver, /* GraphQL */ ` type {Table}Model { id: {Table}Id! lbl: String! } input {Table}Input { lbl: String! } input {Table}Search { lbl: String } type Query { "查询" get{Table}(id: {Table}Id!): {Table}Model "列表" findAll{Table}(search: {Table}Search): [{Table}Model!]! } type Mutation { "创建" create{Table}(input: {Table}Input!): {Table}Id! "更新" update{Table}(id: {Table}Id!, input: {Table}Input!): Boolean! "删除" delete{Table}(ids: [{Table}Id!]!): Int! } `);
2. Resolver
import { useContext, } from "/lib/context.ts"; import type { {Table}Id, {Table}Input, {Table}Search, } from "/gen/types.ts"; // 查询 - 不需要事务 export async function get{Table}( id: {Table}Id, ) { const { get{Table}, } = await import("./{table}.service.ts"); return await get{Table}(id); } // 修改 - 需要事务 export async function create{Table}(input: {Table}Input) { const { create{Table}, } = await import("./{table}.service.ts"); const context = useContext(); context.is_tran = true; // 开启事务 return await create{Table}(input); }
3. Service
import { isEmpty, } from "/lib/util/string_util.ts"; import { findById{Table}, create{Table}, } from "/gen/{mod}/{table}/{table}.dao.ts"; import type { {Table}Id, {Table}Input } from "/gen/types.ts"; export async function create{Table}( input: {Table}Input, ) { if (isEmpty(input.lbl)) { throw "名称不能为空"; // 业务错误用中文 } return await create{Table}(input); }
4. 注册模块
在
src/{mod}/graphql.ts 添加:
import "./{table}/{table}.graphql.ts";
核心规则
| 规则 | 说明 |
|---|---|
| 事务 | 增删改 ,查询不设置 |
| 认证 | 默认需登录,公开接口设 |
| 错误 | 业务错误, 系统错误 |
| DAO | 从 导入 |