@@ -7,30 +7,30 @@ export interface IGraphQLComponentConfigObject {
77 component : IGraphQLComponent ;
88 configuration ?: SubschemaConfig ;
99}
10- type GlobalContext = {
11- [ key : string ] : unknown ;
12- } ;
13- export type ContextFunction = ( ( ctx : GlobalContext ) => any ) ;
10+ export interface ComponentContext extends Record < string , unknown > {
11+ dataSources : DataSourceMap ;
12+ }
13+ export type ContextFunction = ( ( context : Record < string , unknown > ) => any ) ;
1414export interface IDataSource {
1515 name : string ;
1616}
1717export type DataSource < T > = {
18- [ P in keyof T ] : T [ P ] extends ( ctx : GlobalContext , ...p : infer P ) => infer R ? ( ...p : P ) => R : never ;
18+ [ P in keyof T ] : T [ P ] extends ( context : ComponentContext , ...p : infer P ) => infer R ? ( ...p : P ) => R : never ;
1919} ;
2020export type DataSourceMap = {
2121 [ key : string ] : IDataSource ;
2222} ;
23- export type DataSourceInjectionFunction = ( ( ctx : GlobalContext ) => DataSourceMap ) ;
23+ export type DataSourceInjectionFunction = ( ( context : Record < string , unknown > ) => DataSourceMap ) ;
2424export interface IContextConfig {
2525 namespace : string ;
2626 factory : ContextFunction ;
2727}
2828export interface IContextWrapper extends ContextFunction {
2929 use : ( name : string | ContextFunction | null , fn ?: ContextFunction | string ) => void ;
3030}
31- export interface IGraphQLComponentOptions {
31+ export interface IGraphQLComponentOptions < TContextType extends ComponentContext = ComponentContext > {
3232 types ?: TypeSource ;
33- resolvers ?: IResolvers < any , any > ;
33+ resolvers ?: IResolvers < any , TContextType > ;
3434 mocks ?: boolean | IMocks ;
3535 imports ?: ( IGraphQLComponent | IGraphQLComponentConfigObject ) [ ] ;
3636 context ?: IContextConfig ;
@@ -41,21 +41,21 @@ export interface IGraphQLComponentOptions {
4141 federation ?: boolean ;
4242 transforms ?: SchemaMapper [ ] ;
4343}
44- export interface IGraphQLComponent {
44+ export interface IGraphQLComponent < TContextType extends ComponentContext = ComponentContext > {
4545 readonly name : string ;
4646 readonly schema : GraphQLSchema ;
4747 readonly context : IContextWrapper ;
4848 readonly types : TypeSource ;
49- readonly resolvers : IResolvers < any , any > ;
49+ readonly resolvers : IResolvers < any , TContextType > ;
5050 readonly imports ?: ( IGraphQLComponent | IGraphQLComponentConfigObject ) [ ] ;
5151 readonly dataSources ?: IDataSource [ ] ;
5252 readonly dataSourceOverrides ?: IDataSource [ ] ;
5353 federation ?: boolean ;
5454}
55- export default class GraphQLComponent implements IGraphQLComponent {
55+ export default class GraphQLComponent < TContextType extends ComponentContext = ComponentContext > implements IGraphQLComponent {
5656 _schema : GraphQLSchema ;
5757 _types : TypeSource ;
58- _resolvers : IResolvers < any , any > ;
58+ _resolvers : IResolvers < any , TContextType > ;
5959 _mocks : boolean | IMocks ;
6060 _imports : IGraphQLComponentConfigObject [ ] ;
6161 _context : ContextFunction ;
@@ -71,11 +71,10 @@ export default class GraphQLComponent implements IGraphQLComponent {
7171 get name ( ) : string ;
7272 get schema ( ) : GraphQLSchema ;
7373 get types ( ) : TypeSource ;
74- get resolvers ( ) : IResolvers ;
74+ get resolvers ( ) : IResolvers < any , TContextType > ;
7575 get imports ( ) : IGraphQLComponentConfigObject [ ] ;
7676 get dataSources ( ) : IDataSource [ ] ;
7777 get dataSourceOverrides ( ) : IDataSource [ ] ;
7878 set federation ( flag : boolean ) ;
7979 get federation ( ) : boolean ;
8080}
81- export { } ;
0 commit comments