Skip to content

Commit cc2b547

Browse files
committed
wip
1 parent dc082a4 commit cc2b547

File tree

4 files changed

+51
-60
lines changed

4 files changed

+51
-60
lines changed

src/app/api/contributors/route.ts

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,32 +32,25 @@ export async function GET(request: NextRequest) {
3232
const { searchParams } = new URL(request.url)
3333
const first = Math.max(
3434
1,
35-
Math.min(100, parseInt(searchParams.get("first") || "20")),
35+
Math.min(100, parseInt(searchParams.get("first") || "5")),
3636
)
3737
const after = searchParams.get("after") || ""
38-
const repository = searchParams.get("repository") || ""
38+
const project = searchParams.get("project") || ""
3939

40-
if (!repository) {
40+
if (!project) {
4141
return NextResponse.json(
4242
{
4343
error: "Bad request",
4444
message: "Repository parameter is required",
4545
},
46-
{
47-
status: 400,
48-
headers,
49-
},
46+
{ status: 400, headers },
5047
)
5148
}
5249

5350
const data = getContributorData()
54-
const repositoryContributors = data[repository]
55-
56-
if (!repositoryContributors) {
57-
return NextResponse.json([], { headers })
58-
}
51+
const allContributors = data[project] || []
5952

60-
const sortedContributors = [...repositoryContributors].sort((a, b) => {
53+
const sortedContributors = allContributors.sort((a, b) => {
6154
if (b.contributions !== a.contributions) {
6255
return b.contributions - a.contributions
6356
}
@@ -85,10 +78,7 @@ export async function GET(request: NextRequest) {
8578
error: "Internal server error",
8679
message: "Failed to fetch contributors data",
8780
},
88-
{
89-
status: 500,
90-
headers,
91-
},
81+
{ status: 500, headers },
9282
)
9383
}
9484
}

src/components/index-page/how-it-works/schema.ts

Lines changed: 36 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
GraphQLList,
77
GraphQLInt,
88
GraphQLID,
9+
GraphQLError,
910
} from "graphql"
1011

1112
const PROJECT_NAME = "GraphQL"
@@ -27,18 +28,21 @@ const projects: Project[] = [
2728
{
2829
name: PROJECT_NAME,
2930
tagline: PROJECT_TAGLINE,
31+
contributors: [],
3032
},
3133
{
3234
name: "GraphiQL",
3335
tagline: "Ecosystem for building browser & IDE tools.",
36+
contributors: [],
3437
},
3538
{
3639
name: "graphql-js",
3740
tagline: "A reference implementation of GraphQL for JavaScript",
41+
contributors: [],
3842
},
3943
]
4044

41-
interface User {
45+
interface Contributor {
4246
id: string
4347
website?: string | null
4448
contributions: number
@@ -47,14 +51,15 @@ interface User {
4751
interface Project {
4852
name: string
4953
tagline: string
54+
contributors: Contributor[]
5055
}
5156

5257
interface PaginationArgs {
5358
first?: number | null
5459
after?: string | null
5560
}
5661

57-
const UserType = new GraphQLObjectType<User>({
62+
const UserType = new GraphQLObjectType<Contributor>({
5863
name: "User",
5964
fields: {
6065
id: {
@@ -96,11 +101,26 @@ const ProjectType = new GraphQLObjectType<Project>({
96101
description: "Cursor (User.id) after which to start",
97102
},
98103
},
99-
resolve: (project, args) => {
100-
return getContributorsForProject(project, {
101-
first: args?.first,
102-
after: args?.after ?? null,
103-
})
104+
resolve: async (project, args: PaginationArgs) => {
105+
try {
106+
const params = new URLSearchParams()
107+
108+
if (args.first) params.set("first", args.first.toString())
109+
if (args.after) params.set("after", args.after)
110+
params.set("project", project.name)
111+
112+
const response = await fetch(`/api/contributors?${params.toString()}`)
113+
114+
if (!response.ok) {
115+
console.error(`Failed to fetch contributors: ${response.status}`)
116+
return []
117+
}
118+
119+
return response.json()
120+
} catch (error) {
121+
console.error("Error fetching contributors:", error)
122+
return []
123+
}
104124
},
105125
},
106126
},
@@ -118,9 +138,17 @@ const QueryType = new GraphQLObjectType({
118138
},
119139
},
120140
resolve: (_, args) => {
121-
return projects.find(
141+
const project = projects.find(
122142
project => project.name.toLowerCase() === args.name.toLowerCase(),
123143
)
144+
145+
if (!project) {
146+
throw new GraphQLError(
147+
"To learn about more GraphQL projects, visit graphql.org/code/ or github.com/topics/graphql. In this playground, try 'GraphiQL', 'graphql-js' or 'graphiql'.",
148+
)
149+
}
150+
151+
return project
124152
},
125153
},
126154
projects: {
@@ -131,40 +159,6 @@ const QueryType = new GraphQLObjectType({
131159
},
132160
})
133161

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-
168162
export const projectsSchema = new GraphQLSchema({
169163
query: QueryType,
170164
})

src/components/index-page/what-is-graphql/wires.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,7 @@ export function Wires({ className }: { className?: string }) {
555555
<SVGDefinitions />
556556
</svg>
557557

558+
{/* TODO: This needs to be turned on in Safari as it doesn't support repeatEvent. */}
558559
{process.env.NODE_ENV === "development" && (
559560
<NextStepButton onClick={inc} />
560561
)}

src/components/interactive-code-block/result-viewer.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,12 @@ export class ResultViewer extends Component<ResultViewerProps> {
6464
if (this.props.vainlyExtractData) {
6565
try {
6666
const json = JSON.parse(value)
67-
if (json && typeof json === "object" && "data" in json) {
67+
if (
68+
json &&
69+
typeof json === "object" &&
70+
"data" in json &&
71+
!("errors" in json)
72+
) {
6873
value = JSON.stringify(json.data, null, 2)
6974
}
7075
} catch {
@@ -84,6 +89,7 @@ export class ResultViewer extends Component<ResultViewerProps> {
8489
render() {
8590
return (
8691
<div
92+
// eslint-disable-next-line tailwindcss/no-custom-classname
8793
className="result-window h-full"
8894
ref={e => {
8995
this.domNode = e

0 commit comments

Comments
 (0)