# DataSourceService Decorator graphql

Module
import { DataSourceService } from "@tsed/graphql"
Source/packages/graphql/src/decorators/dataSourceService.ts

# Overview

function DataSourceService(): ClassDecorator;

# Description

Create a new DataSource binded with Tsed DI.

import { DataSourceService } from "@tsed/graphql";
import { RESTDataSource } from 'apollo-datasource-rest';

@DataSourceService()
export class MyDataSource extends RESTDataSource {
   constructor() {
     super();
     this.baseURL = 'https://awesome-api.example.com';
   }

   willSendRequest(request) {
     request.headers.set('Authorization', this.context.token);
   }

   getMyData(id: string) {
     return this.get(`/v1/my_rest_data/${id}`);
   }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18