This repository has been archived by the owner on Apr 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 73
/
GraphbackProxyService.ts
55 lines (43 loc) · 2.22 KB
/
GraphbackProxyService.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { GraphQLResolveInfo } from 'graphql';
import { GraphbackCRUDService, ResultList } from './GraphbackCRUDService';
import { QueryFilter } from './QueryFilter';
import { GraphbackContext, FindByArgs } from './interfaces';
/**
* ProxyService that can be used by any services that wish to extend
* Graphback functionality.
* Service works by proxying method requests to another service or
* datastore.
*/
export class GraphbackProxyService<Type = any> implements GraphbackCRUDService<Type> {
protected proxiedService: GraphbackCRUDService;
public constructor(service: GraphbackCRUDService) {
this.proxiedService = service;
}
public create(data: Type, context?: GraphbackContext, info?: GraphQLResolveInfo): Promise<Type> {
return this.proxiedService.create(data, context, info);
}
public update(data: Type, context?: GraphbackContext, info?: GraphQLResolveInfo): Promise<Type> {
return this.proxiedService.update(data, context, info);
}
public delete(data: Type, context?: GraphbackContext, info?: GraphQLResolveInfo): Promise<Type> {
return this.proxiedService.delete(data, context, info);
}
public findOne(args: Partial<Type>, context?: GraphbackContext, info?: GraphQLResolveInfo): Promise<Type> {
return this.proxiedService.findOne(args, context, info);
}
public findBy(args?: FindByArgs, context?: GraphbackContext, info?: GraphQLResolveInfo, path?: string): Promise<ResultList<Type>> {
return this.proxiedService.findBy(args, context, info, path);
}
public subscribeToCreate(filter?: QueryFilter, context?: GraphbackContext): AsyncIterator<Type> {
return this.proxiedService.subscribeToCreate(filter, context)
}
public subscribeToUpdate(filter?: QueryFilter, context?: GraphbackContext): AsyncIterator<Type> {
return this.proxiedService.subscribeToUpdate(filter, context)
}
public subscribeToDelete(filter?: QueryFilter, context?: GraphbackContext): AsyncIterator<Type> {
return this.proxiedService.subscribeToDelete(filter, context)
}
public batchLoadData(relationField: string, id: string | number, filter: QueryFilter, context: GraphbackContext, info?: GraphQLResolveInfo) {
return this.proxiedService.batchLoadData(relationField, id, filter, context, info)
}
}