Download the PHP package plmrlnsnts/typewriter without Composer
On this page you can find all versions of the php package plmrlnsnts/typewriter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download plmrlnsnts/typewriter
More information about plmrlnsnts/typewriter
Files in plmrlnsnts/typewriter
Package typewriter
Short Description A tool for generating PHP code based on a GraphQL schema and GraphQL operations.
License MIT
Informations about the package typewriter
⌨️ Typewriter
Typewriter is a GraphQL code generation tool to easily generate PHP classes and enums from your GraphQL schema and GraphQL operations.
Features
- [x] Converts GraphQL schemas and operations into strongly-typed PHP code
- [x] Generates classes, enums, and input types for your GraphQL client
- [x] Supports custom type casting and namespace organization
- [x] Automates code generation for GraphQL queries
Installation
Configuration
After installation, a typewriter.json configuration file is created in your project root.
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.
- source: Path to your GraphQL introspection JSON file (e.g.,
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.
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:
Downloading schema.json
To generate a schema.json from your GraphQL endpoint, you can use get-graphql-schema or similar tools.
Author
Paul Santos [email protected]