GraphQL模式生成器Skill graphql-schema-generator

GraphQL模式生成器是一款自动化工具,能够从数据模型快速生成GraphQL SDL模式,支持类型推断、解析器存根生成、模式验证和Apollo联邦。适用于API设计和后端开发,提升开发效率,确保模式一致性。关键词:GraphQL模式生成,API设计,后端开发,数据模型转换,Apollo联邦,解析器生成,类型推断,模式验证。

后端开发 0 次安装 0 次浏览 更新于 2/26/2026

名称: graphql-schema-generator 描述: 从数据模型生成GraphQL模式,包含解析器存根和联邦支持 允许使用的工具:

  • Bash
  • 读取
  • 写入
  • 全局匹配

GraphQL模式生成器技能

概述

从数据模型生成GraphQL SDL模式,具备类型推断、解析器存根生成、模式验证和Apollo联邦支持。

能力

  • 从数据模型生成GraphQL SDL
  • 从现有数据结构进行类型推断
  • 解析器存根生成
  • 模式验证和代码检查
  • Apollo联邦支持
  • 订阅类型生成
  • 输入类型和变更生成

目标流程

  • api-design-specification

输入模式

{
  "type": "object",
  "required": ["dataModels"],
  "properties": {
    "dataModels": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "name": { "type": "string" },
          "fields": { "type": "array" },
          "relationships": { "type": "array" }
        }
      }
    },
    "outputPath": {
      "type": "string",
      "description": "输出模式文件路径"
    },
    "options": {
      "type": "object",
      "properties": {
        "generateResolvers": {
          "type": "boolean",
          "default": true
        },
        "federation": {
          "type": "boolean",
          "default": false
        },
        "generateSubscriptions": {
          "type": "boolean",
          "default": false
        },
        "generateInputTypes": {
          "type": "boolean",
          "default": true
        }
      }
    }
  }
}

输出模式

{
  "type": "object",
  "properties": {
    "schemaPath": {
      "type": "string"
    },
    "resolversPath": {
      "type": "string"
    },
    "types": {
      "type": "array",
      "items": { "type": "string" }
    },
    "queries": {
      "type": "array"
    },
    "mutations": {
      "type": "array"
    }
  }
}

使用示例

{
  kind: 'skill',
  skill: {
    name: 'graphql-schema-generator',
    context: {
      dataModels: [
        { name: 'User', fields: ['id', 'name', 'email'] },
        { name: 'Post', fields: ['id', 'title', 'authorId'] }
      ],
      outputPath: 'graphql/schema.graphql',
      options: {
        generateResolvers: true,
        federation: false
      }
    }
  }
}