@@ -9,6 +9,7 @@ function wrapRequest (state, request, options) {
99async function doRequest ( state , request , options ) {
1010 const isWrite = options . method !== 'GET' && options . method !== 'HEAD'
1111 const isSearch = options . method === 'GET' && options . url . startsWith ( '/search/' )
12+ const isGraphQL = options . url . startsWith ( '/graphql' )
1213
1314 const retryCount = ~ ~ options . request . retryCount
1415 const jobOptions = retryCount > 0 ? { priority : 0 , weight : 0 } : { }
@@ -19,7 +20,8 @@ async function doRequest (state, request, options) {
1920 }
2021
2122 // Guarantee at least 1000ms between writes
22- if ( isWrite ) {
23+ // GraphQL can also trigger writes
24+ if ( isWrite || isGraphQL ) {
2325 await state . write . key ( state . id ) . schedule ( jobOptions , noop )
2426 }
2527
@@ -28,9 +30,20 @@ async function doRequest (state, request, options) {
2830 await state . notifications . key ( state . id ) . schedule ( jobOptions , noop )
2931 }
3032
33+ // Guarantee at least 2000ms between search requests
3134 if ( isSearch ) {
3235 await state . search . key ( state . id ) . schedule ( jobOptions , noop )
3336 }
3437
35- return state . global . key ( state . id ) . schedule ( jobOptions , request , options )
38+ const req = state . global . key ( state . id ) . schedule ( jobOptions , request , options )
39+ if ( isGraphQL ) {
40+ const res = await req
41+ if ( res . data . errors != null && res . data . errors . some ( ( err ) => err . type === 'RATE_LIMITED' ) ) {
42+ const err = new Error ( 'GraphQL Rate Limit Exceeded' )
43+ err . headers = res . headers
44+ err . data = res . data
45+ throw err
46+ }
47+ }
48+ return req
3649}
0 commit comments