@@ -40,14 +40,20 @@ const projects: Project[] = [
40
40
41
41
interface User {
42
42
id : string
43
- website ?: string
43
+ website ?: string | null
44
+ contributions : number
44
45
}
45
46
46
47
interface Project {
47
48
name : string
48
49
tagline : string
49
50
}
50
51
52
+ interface PaginationArgs {
53
+ first ?: number | null
54
+ after ?: string | null
55
+ }
56
+
51
57
const UserType = new GraphQLObjectType < User > ( {
52
58
name : "User" ,
53
59
fields : {
@@ -59,6 +65,10 @@ const UserType = new GraphQLObjectType<User>({
59
65
type : GraphQLString ,
60
66
description : "Personal website of the contributor" ,
61
67
} ,
68
+ contributions : {
69
+ type : new GraphQLNonNull ( GraphQLInt ) ,
70
+ description : "Number of contributions made to the project" ,
71
+ } ,
62
72
} ,
63
73
} )
64
74
@@ -121,6 +131,40 @@ const QueryType = new GraphQLObjectType({
121
131
} ,
122
132
} )
123
133
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
+
124
168
export const projectsSchema = new GraphQLSchema ( {
125
169
query : QueryType ,
126
170
} )
0 commit comments