@@ -30,7 +30,7 @@ type GraphQLNodeDefinitions<TContext> = {|
3030 * interface without a provided `resolveType` method.
3131 */
3232export function nodeDefinitions < TContext > (
33- idFetcher : ( id : string , context : TContext , info : GraphQLResolveInfo ) = > any ,
33+ fetchById : ( id : string , context : TContext , info : GraphQLResolveInfo ) = > mixed ,
3434 typeResolver ? : GraphQLTypeResolver < any , TContext > ,
3535) : GraphQLNodeDefinitions < TContext > {
3636 const nodeInterface = new GraphQLInterfaceType ( {
@@ -54,7 +54,7 @@ export function nodeDefinitions<TContext>(
5454 description : 'The ID of an object' ,
5555 } ,
5656 } ,
57- resolve : ( _obj , { id } , context , info ) => idFetcher ( id , context , info ) ,
57+ resolve : ( _obj , { id } , context , info ) => fetchById ( id , context , info ) ,
5858 } ;
5959
6060 const nodesField = {
@@ -69,7 +69,7 @@ export function nodeDefinitions<TContext>(
6969 } ,
7070 } ,
7171 resolve : ( _obj , { ids } , context , info ) =>
72- ids . map ( ( id ) => idFetcher ( id , context , info ) ) ,
72+ ids . map ( ( id ) => fetchById ( id , context , info ) ) ,
7373 } ;
7474
7575 return { nodeInterface, nodeField, nodesField } ;
@@ -84,8 +84,8 @@ type ResolvedGlobalId = {|
8484 * Takes a type name and an ID specific to that type name, and returns a
8585 * "global ID" that is unique among all types.
8686 */
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 ( ':' ) ) ;
8989}
9090
9191/**
@@ -107,10 +107,14 @@ export function fromGlobalId(globalId: string): ResolvedGlobalId {
107107 * by calling idFetcher on the object, or if not provided, by accessing the `id`
108108 * property on the object.
109109 */
110- export function globalIdField (
110+ export function globalIdField < TContext > (
111111 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 > {
114118 return {
115119 description : 'The ID of an object' ,
116120 type : new GraphQLNonNull ( GraphQLID ) ,
0 commit comments