@@ -40,14 +40,20 @@ const projects: Project[] = [
4040
4141interface User {
4242 id : string
43- website ?: string
43+ website ?: string | null
44+ contributions : number
4445}
4546
4647interface Project {
4748 name : string
4849 tagline : string
4950}
5051
52+ interface PaginationArgs {
53+ first ?: number | null
54+ after ?: string | null
55+ }
56+
5157const UserType = new GraphQLObjectType < User > ( {
5258 name : "User" ,
5359 fields : {
@@ -59,6 +65,10 @@ const UserType = new GraphQLObjectType<User>({
5965 type : GraphQLString ,
6066 description : "Personal website of the contributor" ,
6167 } ,
68+ contributions : {
69+ type : new GraphQLNonNull ( GraphQLInt ) ,
70+ description : "Number of contributions made to the project" ,
71+ } ,
6272 } ,
6373} )
6474
@@ -121,6 +131,40 @@ const QueryType = new GraphQLObjectType({
121131 } ,
122132} )
123133
134+ async function getContributorsForProject (
135+ project : Project ,
136+ args : PaginationArgs ,
137+ ) : Promise < User [ ] > {
138+ try {
139+ const params = new URLSearchParams ( )
140+
141+ if ( args . first ) {
142+ params . set ( "first" , args . first . toString ( ) )
143+ }
144+
145+ if ( args . after ) {
146+ params . set ( "after" , args . after )
147+ }
148+
149+ params . set ( "repository" , project . name )
150+
151+ const response = await fetch ( `/api/contributors?${ params . toString ( ) } ` )
152+
153+ if ( ! response . ok ) {
154+ console . error ( `Failed to fetch contributors: ${ response . status } ` )
155+ return [ ]
156+ }
157+
158+ const contributors : User [ ] = await response . json ( )
159+
160+ // Map contributors to User format (they have the same structure now)
161+ return contributors
162+ } catch ( error ) {
163+ console . error ( "Error fetching contributors:" , error )
164+ return [ ]
165+ }
166+ }
167+
124168export const projectsSchema = new GraphQLSchema ( {
125169 query : QueryType ,
126170} )
0 commit comments