DataSource
@tsed/apollo
Usage
typescript
import { DataSource } from "@tsed/apollo";
See /packages/graphql/apollo/src/types/decorators/dataSource.ts.
Overview
ts
function DataSource(name?: string): ClassDecorator;
Description
Create a new injectable DataSource.
typescript
import { DataSourceService } from "@tsed/graphql";
import { RESTDataSource } from '@apollo/datasource-rest';
@DataSource()
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}`);
}
}