# 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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
- Session & cookies
- Passport.js
- TypeORM
- Mongoose
- GraphQL
- Socket.io
- Swagger
- AJV
- Multer
- Serve static files
- Templating
- Throw HTTP Exceptions
- Customize 404
- AWS
- Jest
- Seq
- Controllers
- Providers
- Model
- Converters
- Middlewares
- Pipes
- Interceptors
- Authentication
- Hooks
- Injection scopes
- Custom providers
- Custom endpoint decorator
- Testing