https://github.com/labd/schema-generate
A library and CLI tool to generate various schemas based off of TypeScript interfaces.
https://github.com/labd/schema-generate
amplience graphql typescript
Last synced: about 1 year ago
JSON representation
A library and CLI tool to generate various schemas based off of TypeScript interfaces.
- Host: GitHub
- URL: https://github.com/labd/schema-generate
- Owner: labd
- License: mit
- Created: 2021-02-17T13:41:38.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-07-08T12:57:27.000Z (almost 4 years ago)
- Last Synced: 2025-04-10T23:18:32.863Z (about 1 year ago)
- Topics: amplience, graphql, typescript
- Language: TypeScript
- Homepage:
- Size: 249 KB
- Stars: 5
- Watchers: 4
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Schema Generate
This repository can generate schema files based on Typescript files containing interfaces.
Currently it only supports GraphQL types.
## GraphQL
The GraphQL schema generator takes Typescript files with interfaces as input and generates GraphQL types as a result.
For example, given the following file called `books.ts`.
```ts
export type CustomScalar = string & {__scalar?: undefined}
export interface Author {
name: string
custom: CustomScalar
}
export interface Chapter {
startPage: number
}
export interface Book {
id: string
author: Author
title: string
subTitle?: string
/** @float */
pages: number
chapters: Chapter[]
}
export interface Game {
title: string
}
export type Product = Book | Game
```
You can generate the following GraphQL types:
```graphql
scalar CustomScalar
union Product = Book | Game
type Author {
name: String!
custom: CustomScalar!
}
type Chapter {
startPage: Int!
}
type Book {
id: ID!
author: Author!
title: String!
subTitle: String
pages: Float!
chapters: [Chapter!]!
}
type Product {
title: String!
}
```
Either by using the CLI
```bash
yarn schema-generate graphql books.ts
# or
yarn schema-generate graphql books.ts -o schema.graphql
```
Or calling the function directly
```ts
import { generateGraphqlTypes } from 'schema-generate/graphql'
const graphqlTypeString = generateGraphqlTypes(['books.ts'])
```
# How to release
First increase the version in package.json, then use that version to create a release with that number in Github.