0.1.7 • Published 6 years ago

typegraph v0.1.7

Weekly downloads
13
License
MIT
Repository
github
Last release
6 years ago

!> Note: this library is under active development, breaking changes may occur

TypeGraph

TypeGraph generates GraphQL queries from decorated TypeScript classes, eliminating the need to write both queries to get data and interfaces to describe the results.

Getting Started

Install

npm install typegraph --save

Decorate your classes / entities

Using a class instead of a typescript interface allows access during runtime

import { Entity } from 'typegraph';

@Entity({one: "company", many: "companies"})
class Company {

    @Field()
    id: number;

    @Field()
    name: string;

    @Field()
    industry: string;
}

Getting the query

You can get the query as a string using the generateQuery function.

One

import { generateQuery, QueryType } from 'typegraph';

const queryOne: string = generateQuery(Company, QueryType.ONE);

Produces:

{ 
    company {
        id
        name
        industry
    }
}

Many

import { generateQuery, QueryType } from 'typegraph';

const queryMany: string = generateQuery(Company, QueryType.MANY);

Produces:

{
    companies {
        id
        name
        industry
    }
}

With Params

import { generateQuery, QueryType } from 'typegraph';

const queryOneWithProps: string = generateQuery(Company, QueryType.ONE, {name: "doge", industry: "dogs"});

Produces:

{
    company(name: "doge", industry: "dogs") {
        id
        name
        industry
    }
}

Upcoming improvements

  • Support for mutations
  • Support for params on sub fields
  • Support for GraphQL Variables
  • Connect components to data! See NEXT.md
0.1.7

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

7 years ago

0.1.0

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago