承接 plmrlnsnts/typewriter 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

plmrlnsnts/typewriter

最新稳定版本:v0.0.3

Composer 安装命令:

composer require plmrlnsnts/typewriter

包简介

A tool for generating PHP code based on a GraphQL schema and GraphQL operations.

README 文档

README

Typewriter is a GraphQL code generation tool to easily generate PHP classes and enums from your GraphQL schema and GraphQL operations.

vendor/bin/typewriter

Features

  • Converts GraphQL schemas and operations into strongly-typed PHP code
  • Generates classes, enums, and input types for your GraphQL client
  • Supports custom type casting and namespace organization
  • Automates code generation for GraphQL queries

Installation

composer require --dev plmrlnsnts/typewriter

vendor/bin/typewriter init

Configuration

After installation, a typewriter.json configuration file is created in your project root.

{
  "schemas": [
    {
      "source": "schema.json",
      "enums": {
        "directory": "app/Graphql/Enums",
        "namespace": "App\\Graphql\\Enums"
      },
      "inputs": {
        "directory": "app/Graphql/Inputs",
        "namespace": "App\\Graphql\\Inputs"
      },
      "entrypoints": [
        {
          "input": "app",
          "output": "app/Graphql/Data",
          "namespace": "App\\Graphql\\Data"
        }
      ]
    }
  ]
}

Available Options

  • schemas: List of schema configurations. Each object describes how to generate code for a GraphQL schema.
    • source: Path to your GraphQL introspection JSON file (e.g., schema.json).
    • enums: Where to generate PHP enums.
      • directory: Output directory for generated enum classes.
      • namespace: PHP namespace for generated enums.
    • inputs: Where to generate PHP input classes.
      • directory: Output directory for generated input classes.
      • namespace: PHP namespace for generated inputs.
    • entrypoints: List of entrypoints for code generation. Each entrypoint defines a set of GraphQL operations to generate code for.
      • input: Directory or file containing GraphQL operation documents (e.g., queries, mutations).
      • output: Output directory for generated data classes.
      • namespace: PHP namespace for generated data classes.

Custom Casts

You can customize how GraphQL scalar types are mapped to PHP types or classes by using the casts option in your schema configuration. This is useful when you want to use custom value objects, type wrappers, or specific PHP classes for certain GraphQL scalars (e.g., mapping DateTime to a custom DateTime class instead of a string).

Add a casts object inside your schema configuration, where each key is a GraphQL scalar type and each value is the fully qualified PHP class name to use for that type.

{
  "casts": {
    "DateTime": "App\\Graphql\\Casts\\DateTime",
    "ID": "App\\Graphql\\Casts\\Identity"
  }
}

Extending Types

You can customize the base class that all generated types will extend by specifying the type option in your schema configuration. By default, generated classes extend the built-in Plmrlnsnts\Typewriter\Type, but you may want to use your own. For example, using spatie/laravel-data:

{
  "type": "Spatie\\LaravelData\\Data"
}

Downloading schema.json

To generate a schema.json from your GraphQL endpoint, you can use get-graphql-schema or similar tools.

npm install -g get-graphql-schema

get-graphql-schema https://your.graphql.endpoint > schema.json

Author

Paul Santos paulmarlonsantos@gmail.com

统计信息

  • 总下载量: 3
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固