0.2.12 • Published 2 years ago

schema-generate v0.2.12

Weekly downloads
264
License
MIT
Repository
github
Last release
2 years ago

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'])
0.2.12

2 years ago

0.2.11

2 years ago

0.2.10

2 years ago

0.2.9

2 years ago

0.2.7

2 years ago

0.2.8

2 years ago

0.2.4

2 years ago

0.2.3

3 years ago

0.2.2

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.19

3 years ago

0.1.18

3 years ago

0.1.17

3 years ago

0.1.13

3 years ago

0.1.14

3 years ago

0.1.11

3 years ago

0.1.12

3 years ago

0.1.10

3 years ago

0.1.8

3 years ago

0.1.9

3 years ago

0.1.7

3 years ago

0.1.4

3 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.3

3 years ago

0.0.12

3 years ago

0.0.10

3 years ago

0.0.11

3 years ago

0.0.9

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.1

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.4

3 years ago

0.2.5

3 years ago