@@ -30,7 +30,7 @@ type GraphQLNodeDefinitions<TContext> = {|
30
30
* interface without a provided `resolveType` method.
31
31
*/
32
32
export function nodeDefinitions < TContext > (
33
- idFetcher : ( id : string , context : TContext , info : GraphQLResolveInfo ) = > any ,
33
+ fetchById : ( id : string , context : TContext , info : GraphQLResolveInfo ) = > mixed ,
34
34
typeResolver ? : GraphQLTypeResolver < any , TContext > ,
35
35
) : GraphQLNodeDefinitions < TContext > {
36
36
const nodeInterface = new GraphQLInterfaceType ( {
@@ -54,7 +54,7 @@ export function nodeDefinitions<TContext>(
54
54
description : 'The ID of an object' ,
55
55
} ,
56
56
} ,
57
- resolve : ( _obj , { id } , context , info ) => idFetcher ( id , context , info ) ,
57
+ resolve : ( _obj , { id } , context , info ) => fetchById ( id , context , info ) ,
58
58
} ;
59
59
60
60
const nodesField = {
@@ -69,7 +69,7 @@ export function nodeDefinitions<TContext>(
69
69
} ,
70
70
} ,
71
71
resolve : ( _obj , { ids } , context , info ) =>
72
- ids . map ( ( id ) => idFetcher ( id , context , info ) ) ,
72
+ ids . map ( ( id ) => fetchById ( id , context , info ) ) ,
73
73
} ;
74
74
75
75
return { nodeInterface, nodeField, nodesField } ;
@@ -84,8 +84,8 @@ type ResolvedGlobalId = {|
84
84
* Takes a type name and an ID specific to that type name, and returns a
85
85
* "global ID" that is unique among all types.
86
86
*/
87
- export function toGlobalId ( type : string , id : string ) : string {
88
- return base64 ( [ type , id ] . join ( ':' ) ) ;
87
+ export function toGlobalId ( type : string , id : string | number ) : string {
88
+ return base64 ( [ type , GraphQLID . serialize ( id ) ] . join ( ':' ) ) ;
89
89
}
90
90
91
91
/**
@@ -107,10 +107,14 @@ export function fromGlobalId(globalId: string): ResolvedGlobalId {
107
107
* by calling idFetcher on the object, or if not provided, by accessing the `id`
108
108
* property on the object.
109
109
*/
110
- export function globalIdField (
110
+ export function globalIdField < TContext > (
111
111
typeName ? : string ,
112
- idFetcher ?: ( object : any , context : any , info : GraphQLResolveInfo ) => string ,
113
- ) : GraphQLFieldConfig < any , mixed > {
112
+ idFetcher ?: (
113
+ obj : any ,
114
+ context : TContext ,
115
+ info : GraphQLResolveInfo ,
116
+ ) => string | number ,
117
+ ) : GraphQLFieldConfig < any , TContext > {
114
118
return {
115
119
description : 'The ID of an object' ,
116
120
type : new GraphQLNonNull ( GraphQLID ) ,
0 commit comments