@@ -4,11 +4,12 @@ import {
44 GraphQLString ,
55 GraphQLNonNull ,
66 GraphQLList ,
7+ GraphQLInt ,
8+ GraphQLID ,
79} from "graphql"
810
911const PROJECT_NAME = "GraphQL"
1012const PROJECT_TAGLINE = "A query language for APIs"
11- const PROJECT_WEBSITE = "https://graphql.org"
1213
1314export const INITIAL_QUERY_TEXT = `{
1415 project(name: "${ PROJECT_NAME } ") {
@@ -22,30 +23,74 @@ export const INITIAL_RESULTS_TEXT = `{
2223 }
2324}`
2425
26+ /**
27+ * NOTE:
28+ * Contributors data will be synced from scripts/sync-landing-schema/data.json
29+ * and should provide GitHub handles and (optionally) websites for each user.
30+ */
31+ interface User {
32+ id : string
33+ website ?: string
34+ }
35+
2536interface Project {
2637 name : string
2738 tagline : string
28- website : string
2939}
3040
3141const projects : Project [ ] = [
3242 {
3343 name : PROJECT_NAME ,
3444 tagline : PROJECT_TAGLINE ,
35- website : PROJECT_WEBSITE ,
3645 } ,
3746 {
3847 name : "GraphiQL" ,
3948 tagline : "Ecosystem for building browser & IDE tools." ,
40- website : "https://github.com/graphql/graphiql" ,
4149 } ,
4250 {
4351 name : "graphql-js" ,
4452 tagline : "A reference implementation of GraphQL for JavaScript" ,
45- website : "https://graphql.org/graphql-js/" ,
4653 } ,
4754]
4855
56+ const UserType = new GraphQLObjectType < User > ( {
57+ name : "User" ,
58+ fields : {
59+ id : {
60+ type : new GraphQLNonNull ( GraphQLString ) ,
61+ description : "GitHub handle of the contributor" ,
62+ } ,
63+ website : {
64+ type : GraphQLString ,
65+ description : "Personal website of the contributor" ,
66+ } ,
67+ } ,
68+ } )
69+
70+ function getContributorsForProject (
71+ project : Project ,
72+ opts : { first ?: number ; after ?: string | null } = { } ,
73+ ) : User [ ] {
74+ // TODO: Load from scripts/sync-landing-schema/data.json once available
75+ const all : User [ ] = [ ]
76+ const { first, after } = opts
77+
78+ let startIndex = 0
79+ if ( after ) {
80+ const idx = all . findIndex ( u => u . id === after )
81+ if ( idx === - 1 ) {
82+ return [ ]
83+ }
84+ startIndex = idx + 1
85+ }
86+
87+ const sliced = all . slice ( startIndex )
88+ if ( typeof first === "number" && first >= 0 ) {
89+ return sliced . slice ( 0 , first )
90+ }
91+ return sliced
92+ }
93+
4994const ProjectType = new GraphQLObjectType < Project > ( {
5095 name : "Project" ,
5196 fields : {
@@ -57,9 +102,25 @@ const ProjectType = new GraphQLObjectType<Project>({
57102 type : GraphQLString ,
58103 description : "A short description of what the project does" ,
59104 } ,
60- website : {
61- type : GraphQLString ,
62- description : "The project website URL" ,
105+ contributors : {
106+ type : new GraphQLNonNull ( new GraphQLList ( new GraphQLNonNull ( UserType ) ) ) ,
107+ description : "List of contributors to the project" ,
108+ args : {
109+ first : {
110+ type : GraphQLInt ,
111+ description : "Limits the number of contributors returned" ,
112+ } ,
113+ after : {
114+ type : GraphQLID ,
115+ description : "Cursor (User.handle) after which to start" ,
116+ } ,
117+ } ,
118+ resolve : ( project , args ) => {
119+ return getContributorsForProject ( project , {
120+ first : args ?. first ,
121+ after : args ?. after ?? null ,
122+ } )
123+ } ,
63124 } ,
64125 } ,
65126} )
0 commit comments