schema-generate v0.2.12
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
.
type CustomScalar = string & {__scalar?: undefined}
interface Author {
name: string
custom: CustomScalar
}
interface Chapter {
startPage: number
}
interface Book {
id: string
author: Author
title: string
subTitle?: string
/** @float */
pages: number
chapters: Chapter[]
}
interface Game {
title: string
}
type Product = Book | Game
You can generate the following GraphQL types:
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
yarn schema-generate graphql books.ts
# or
yarn schema-generate graphql books.ts -o schema.graphql
Or calling the function directly
import { generateGraphqlTypes } from 'schema-generate/graphql'
const graphqlTypeString = generateGraphqlTypes(['books.ts'])
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago