Skip to content

captain-refactor/graphql-compose-typescript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

93 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GraphQL-compose-typescript

Build Status codecov npm Maintainability Keep in mind, that this module is in early stage of development. Feel free to create issue or pr.

Examples

import 'reflect-metadata';
import {graphql} from "graphql";
import {schemaComposer} from "graphql-compose";
import {$field, $resolver, GraphqlComposeTypescript} from "graphql-compose-typescript";

class Order {
    @$field() id: string;
    @$field() quantity: number;

    constructor(id: string, quantity: number){
        this.id = id;
        this.quantity = quantity;
    }
}

class OrderService {
    @$resolver(()=> Order)
    getOrders(): Order[]{
        return [new Order('a', 1), new Order('b',2)];
    }
}

async function main(){
    let orderService = new OrderService();

    let compose = GraphqlComposeTypescript.create()
    let typeComposer = compose.getComposer(orderService);
    schemaComposer.Query.setField('getOrders', typeComposer.getResolver('getOrders'));
    let schema = schemaComposer.buildSchema();
    let result = await graphql(schema, `{
        getOrders{
            id
            quantity
        }
    }`);
    console.log(JSON.stringify(result.data.getOrders));
    /**
     * [{"id":"a","quantity":1},{"id":"b","quantity":2}]
     */
}
main();

Roadmap

  • using whole type configs in decorators
  • enums
  • solve argument names without explicit declaration

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published