@@ -24,20 +24,22 @@ import { DataSourceMapping } from "./DataSourceMapping";
24
24
25
25
const debug = _debug ( "greldal:MappedDataSource" ) ;
26
26
27
- type DataSourceAssociationType < T extends DataSourceMapping , K extends keyof T [ "associations" ] > = MaybeArrayItem <
28
- ReturnType < NNil < T [ "associations" ] > > [ K ]
29
- > ;
27
+ type AssociationsIn < T extends DataSourceMapping > = ReturnType < NNil < T [ "associations" ] > > ;
30
28
31
- type AssociatedDataSource < T extends DataSourceMapping , K extends keyof T [ "associations" ] > = ReturnType <
32
- DataSourceAssociationType < T , K > [ "target" ]
33
- > ;
29
+ type FieldsIn < T extends DataSourceMapping > = ReturnType < NNil < T [ "fields" ] > > ;
30
+
31
+ type AssociationKeysIn < T extends DataSourceMapping > = keyof AssociationsIn < T > ;
32
+
33
+ type FieldKeysIn < T extends DataSourceMapping > = keyof FieldsIn < T > ;
34
+
35
+ type AssociatedDataSource < T extends DataSourceMapping , K extends AssociationKeysIn < T > > = AssociationsIn < T > [ K ] [ "target" ] ;
34
36
35
37
type ShallowEntityType < T extends DataSourceMapping > = {
36
- [ K in keyof ReturnType < NNil < T [ "fields" ] > > ] : t . TypeOf < ReturnType < NNil < T [ "fields" ] > > [ K ] [ "type" ] >
38
+ [ K in FieldKeysIn < T > ] : t . TypeOf < FieldsIn < T > [ K ] [ "type" ] >
37
39
} ;
38
40
39
41
type NestedEntityType < T extends DataSourceMapping > = ShallowEntityType < T > &
40
- { [ K in keyof T [ "associations" ] ] : AssociatedDataSource < T , K > [ "EntityType" ] } ;
42
+ { [ K in AssociationKeysIn < T > ] : AssociatedDataSource < T , K > [ "EntityType" ] } ;
41
43
42
44
/**
43
45
* Represents mapping between a relational data source and associated GraphQL types
@@ -365,15 +367,9 @@ export class MappedDataSource<T extends DataSourceMapping = any> {
365
367
}
366
368
367
369
/**
368
- * Map a relational data source using specified configuration
369
- *
370
- * Refer the guide on [Mapping Data Sources](/mapping-data-sources) for detailed examples
371
- *
372
- * ## Args:
373
- * - mapping: [DataSourceMapping](api:DataSourceMapping) Mapping configuration
370
+ * Used to map a relational data source using specified configuration (of type [DataSourceMapping](api:DataSourceMapping)).
374
371
*
375
- * ## Returns:
376
- * - [MappedDataSource](api:MappedDataSource)
372
+ * Refer the guide on [Mapping Data Sources](guide:mapping-data-sources) for detailed explanation and examples.
377
373
*
378
374
* @api -category PrimaryAPI
379
375
*/
0 commit comments