@metaengine/graphql-angular
v1.0.0
Published
Generate Angular TypeScript services and models from GraphQL schemas with native Angular DI, typed queries, mutations & subscriptions, and HTTP error handling
Maintainers
Readme
@metaengine/graphql-angular
Generate Angular TypeScript services and models from GraphQL schemas.
Typed queries, mutations & subscriptions, native Angular dependency injection, and HttpClient-based data fetching.
Install
npm install --save-dev @metaengine/graphql-angularOr use directly with npx:
npx @metaengine/graphql-angular <input> <output>Requirements
- Node.js 18.0 or later
- .NET 8.0 or later runtime (Download)
Quick start
npx @metaengine/graphql-angular schema.graphql ./src/api \
--inject-function \
--provided-in root \
--documentationCLI options
| Option | Description | Default |
|--------|-------------|---------|
| --fragments | Emit reusable named fragments for object-type selections | false |
| --one-of-inputs | Generate idiomatic @oneOf input types (tagged-union inputs) | false |
| --custom-scalar <Scalar=target> | Map a GraphQL custom scalar to a TS type. Repeatable. See Custom scalar mappings | - |
| --provided-in <scope> | Angular injection scope (root, any, platform) | - |
| --base-url-token <name> | Injection token name for base URL | BASE_URL |
| --inject-function | Use inject() instead of constructor injection | false |
| --interceptors | Generate Angular interceptors for cross-cutting concerns | false |
| --error-handling | Smart error handling based on HTTP status semantics | false |
| --retries <max-attempts> | Enable retries with exponential backoff (status codes 429, 503) | - |
| --documentation | Generate JSDoc comments from SDL descriptions | false |
| --date-transformation | Convert Date-typed scalar fields (e.g. DateTime) in responses to Date objects | false |
| --options-threshold <n> | Parameter count for options object | 4 |
| --types-barrel | Emit an index.ts barrel per folder plus a root index.ts re-exporting everything | false |
| --clean | Clean output directory (remove files not in generation) | false |
| --verbose | Enable verbose logging | false |
| --help, -h | Show help message | - |
Custom scalar mappings
GraphQL custom scalars resolve to idiomatic TypeScript types. Well-known scalars are mapped out of the box; any other custom scalar defaults to string.
| GraphQL scalar | TypeScript type |
|----------------|-----------------|
| DateTime, Date, Time, DateTimeOffset | Date |
| Decimal, Long, BigInt, ULong, UInt, Short, Byte | number |
| UUID, Guid, Email, URL, URI | string |
Use --custom-scalar to override the TS type emitted for a scalar. Repeatable. Unsupported targets are hard errors.
| Target | Emitted TS type |
|--------|-----------------|
| string | string |
| number | number |
| boolean | boolean |
| Date | Date |
npx @metaengine/graphql-angular schema.graphql ./src/api \
--custom-scalar DateTime=string \
--custom-scalar UUID=stringInteger-like scalars (
Long,BigInt,ULong) map tonumberby design so requestvariablessurviveJSON.stringify.
See it live
Try the generator with your own schema at https://www.metaengine.eu/converters.
License
MIT
Support
For issues and feature requests, please visit: https://github.com/meta-engine/graphql-angular/issues
