GraphQL beta Contributors are welcome

GraphQL is a query language for APIs and a runtime for fulfilling those queries with your existing data. GraphQL provides a complete and understandable description of the data in your API, gives clients the power to ask for exactly what they need and nothing more, makes it easier to evolve APIs over time, and enables powerful developer tools.


Currently, @tsed/graphql allows you to configure a graphql server in your project. This package use apollo-server-express to create GraphQL server and type-graphql for the decorators.


To begin, install the GraphQL module for TS.ED:

npm install --save @tsed/graphql

Type-graphql require to update your tsconfig.json by adding extra options as following:

  "target": "es2016",
  "lib": ["es2016", "esnext.asynciterable"],
  "allowSyntheticDefaultImports": true

Now, we can configure the Ts.ED server by importing @tsed/graphql in your ServerLoader:

import {ServerLoader, ServerSettings} from "@tsed/common";
import {IGraphQLSettings} from "@tsed/graphql"; 

   graphql: {
    'server1': {
  } as IGraphQLSettings
export class Server extends ServerLoader {



GraphQlService let you to retrieve an instance of ApolloServer.

import {Service, AfterRoutesInit} from "@tsed/common";
import {graphQLService} from "@tsed/graphql";
import {ApolloServer} from "apollo-server-express";

export class UsersService implements AfterRoutesInit {
    private server: ApolloServer;
    constructor(private graphQLService: graphQLService) {


    $afterRoutesInit() {
        this.server = this.graphQLService.get("server1");

For more information about ApolloServer look his documentation here;



We want to get equivalent of this type described in SDL:

type Recipe {
  id: ID!
  title: String!
  description: String
  creationDate: Date!
  ingredients: [String!]!

So we create the Recipe class with all properties and types:

class Recipe {
  id: string;
  title: string;
  description?: string;
  creationDate: Date;
  ingredients: string[];

Then we decorate the class and it properties with decorators:

import {ObjectType, ID, Field} from "type-graphql"

export class Recipe {
  @Field(type => ID)
  id: string;

  title: string;

  @Field({ nullable: true })
  description?: string;

  creationDate: Date;

  @Field(type => [String])
  ingredients: string[];

The detailed rules when to use nullable, array and others are described in fields and types docs.


After that we want to create typical crud queries and mutation. To do that we create the resolver (controller) class that will have injected RecipeService in constructor:

import {Resolver, Query, Arg, Args, Mutation, Authorized, Ctx} from "type-graphql";
import {ResolverService} from "@tsed/graphql"
import {Recipe} from "../types/Recipe";  
import {RecipeService} from "../services/RecipeService";  
import {RecipeNotFoundError} from "../errors/RecipeNotFoundError";  

export class RecipeResolver { 
  constructor(private recipeService: RecipeService) {}

  @Query(returns => Recipe)
  async recipe(@Arg("id") id: string) {
    const recipe = await this.recipeService.findById(id);
    if (recipe === undefined) {
      throw new RecipeNotFoundError(id);
    return recipe;

  @Query(returns => [Recipe])
  recipes(@Args() { skip, take }: RecipesArgs) {
    return this.recipeService.findAll({ skip, take });