@@ -6,6 +6,81 @@ import {
66import { fetchWithRetry } from '#site/next.fetch.mjs' ;
77import { shuffle } from '#site/util/array' ;
88
9+ const SPONSORSHIPS_QUERY = `
10+ query ($cursor: String) {
11+ organization(login: "nodejs") {
12+ sponsorshipsAsMaintainer(
13+ first: 100
14+ includePrivate: false
15+ after: $cursor
16+ activeOnly: false
17+ ) {
18+ nodes {
19+ sponsor: sponsorEntity {
20+ ...on User {
21+ id: databaseId
22+ name
23+ login
24+ avatarUrl
25+ url
26+ websiteUrl
27+ }
28+ ...on Organization {
29+ id: databaseId
30+ name
31+ login
32+ avatarUrl
33+ url
34+ websiteUrl
35+ }
36+ }
37+ }
38+ pageInfo {
39+ endCursor
40+ startCursor
41+ hasNextPage
42+ hasPreviousPage
43+ }
44+ }
45+ }
46+ }
47+ ` ;
48+
49+ const DONATIONS_QUERY = `
50+ query {
51+ organization(login: "nodejs") {
52+ sponsorsActivities(first: 100, includePrivate: false) {
53+ nodes {
54+ id
55+ sponsor {
56+ ...on User {
57+ id: databaseId
58+ name
59+ login
60+ avatarUrl
61+ url
62+ websiteUrl
63+ }
64+ ...on Organization {
65+ id: databaseId
66+ name
67+ login
68+ avatarUrl
69+ url
70+ websiteUrl
71+ }
72+ }
73+ timestamp
74+ tier: sponsorsTier {
75+ monthlyPriceInDollars
76+ isOneTime
77+ }
78+ }
79+ }
80+ }
81+ }
82+ ` ;
83+
984/**
1085 * Fetches supporters data from Open Collective API, filters active backers,
1186 * and maps it to the Supporters type.
@@ -50,8 +125,7 @@ async function fetchGithubSponsorsData() {
50125 let cursor = null ;
51126
52127 while ( true ) {
53- const query = sponsorshipsQuery ( cursor ) ;
54- const data = await graphql ( query ) ;
128+ const data = await graphql ( SPONSORSHIPS_QUERY , { cursor } ) ;
55129
56130 if ( data . errors ) {
57131 throw new Error ( JSON . stringify ( data . errors ) ) ;
@@ -82,8 +156,7 @@ async function fetchGithubSponsorsData() {
82156 cursor = pageInfo . endCursor ;
83157 }
84158
85- const query = donationsQuery ( ) ;
86- const data = await graphql ( query ) ;
159+ const data = await graphql ( DONATIONS_QUERY ) ;
87160
88161 if ( data . errors ) {
89162 throw new Error ( JSON . stringify ( data . errors ) ) ;
@@ -110,78 +183,6 @@ async function fetchGithubSponsorsData() {
110183 return sponsors ;
111184}
112185
113- function sponsorshipsQuery ( cursor = null ) {
114- return `
115- query {
116- organization(login: "nodejs") {
117- sponsorshipsAsMaintainer (first: 100, includePrivate: false, after: "${ cursor } ", activeOnly: false) {
118- nodes {
119- sponsor: sponsorEntity {
120- ...on User {
121- id: databaseId,
122- name,
123- login,
124- avatarUrl,
125- url,
126- websiteUrl
127- }
128- ...on Organization {
129- id: databaseId,
130- name,
131- login,
132- avatarUrl,
133- url,
134- websiteUrl
135- }
136- },
137- }
138- pageInfo {
139- endCursor
140- startCursor
141- hasNextPage
142- hasPreviousPage
143- }
144- }
145- }
146- }` ;
147- }
148-
149- function donationsQuery ( ) {
150- return `
151- query {
152- organization(login: "nodejs") {
153- sponsorsActivities (first: 100, includePrivate: false) {
154- nodes {
155- id
156- sponsor {
157- ...on User {
158- id: databaseId,
159- name,
160- login,
161- avatarUrl,
162- url,
163- websiteUrl
164- }
165- ...on Organization {
166- id: databaseId,
167- name,
168- login,
169- avatarUrl,
170- url,
171- websiteUrl
172- }
173- },
174- timestamp
175- tier: sponsorsTier {
176- monthlyPriceInDollars,
177- isOneTime
178- }
179- }
180- }
181- }
182- }` ;
183- }
184-
185186const graphql = async ( query , variables = { } ) => {
186187 const res = await fetch ( GITHUB_GRAPHQL_URL , {
187188 method : 'POST' ,
0 commit comments