0.0.7 • Published 6 years ago

barnaclejs v0.0.7

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

barnacle

CircleCI npm version

Barnacle is a very simple GraphQL helper for Typescript. It exposes several decorators which allow you to automatically build GraphQL type definitions from Typescript classes.

Warning

Barnacle is in very early stages - each version should be stable for use in production, but breaking API changes are likely to occur semi-regularly between versions. This will be the case until v0.2.0 is released, at which point the API will be stable based on the minor version. (When v1.0.0 is released, the API will be stable based on the major version - but that's a long way away.)

Usage

Make sure you have the reflect-metadata package installed (npm i reflect-metadata), then do npm i barnaclejs.

import "reflect-metadata";
import * as barnacle from "barnaclejs";

class User {
    // nullable: false by default
    @barnacle.field()
    id!: number;

    @barnacle.field({ nullable: true })
    lastIP?: string;

    // manually override type inference (because Typescript doesn't automagically emit all types :( )
    @barnacle.field({ type: "[String]" })
    phoneNumbers!: string[];

    // not a GraphQL property, no decorator
    getName() {
        return "Bob";
    }

    // infers methods too!
    @barnacle.field()
    getEmail(actual: boolean): string {
        return actual ? "me@barnacle.com" : "not-me@barnacle.com";
    }
}

console.log(barnacle.toSchema(User)); /* should output:
type User {
    id: Int!
    lastIP: String
    phoneNumbers: [String]!
    getEmail(actual: Boolean!): String!
}
*/
0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago