@@ -44,6 +44,7 @@ import {
44
44
} from './index'
45
45
46
46
const abis = require ( './abis/abis.json' )
47
+ const MAX_BATCH_QUERY = 1000
47
48
48
49
export type IArcOptions = IApolloClientOptions & {
49
50
/** Information about the contracts. Cf. [[setContractInfos]] and [[fetchContractInfos]] */
@@ -203,14 +204,20 @@ export class Arc extends GraphNodeObserver {
203
204
204
205
/**
205
206
* fetch contractInfos from the subgraph
207
+ * we skip the first max batch query each iteration to avoid hitting subgraph limit
206
208
* @return a list of IContractInfo instances
207
209
*/
208
210
public async fetchContractInfos (
209
211
apolloQueryOptions : IApolloQueryOptions = { }
210
212
) : Promise < IContractInfo [ ] > {
211
- const query = gql `
213
+ const allContractInfos = [ ]
214
+ let contractInfos = [ ]
215
+ let skip = 0
216
+
217
+ do {
218
+ const query = gql `
212
219
query AllContractInfos {
213
- contractInfos(first: 1000 ) {
220
+ contractInfos(first: ${ MAX_BATCH_QUERY } skip: ${ skip * MAX_BATCH_QUERY } ) {
214
221
id
215
222
name
216
223
version
@@ -219,25 +226,36 @@ export class Arc extends GraphNodeObserver {
219
226
}
220
227
}
221
228
`
222
- // const result = await this.getObservableList(query, itemMap, apolloQueryOptions).pipe(first()).toPromise()
223
- const response = await this . sendQuery ( query , apolloQueryOptions )
224
- const contractInfos = response . data . contractInfos as IContractInfo [ ]
229
+ const response = await this . sendQuery ( query , apolloQueryOptions )
230
+ contractInfos = response . data . contractInfos as IContractInfo [ ]
231
+ if ( contractInfos . length > 0 ) {
232
+ allContractInfos . push ( ...contractInfos )
233
+ }
234
+ skip ++
235
+ } while ( contractInfos . length === MAX_BATCH_QUERY )
236
+
225
237
const universalContractInfos = await this . fetchUniversalContractInfos ( )
226
- contractInfos . push ( ...universalContractInfos )
227
- this . setContractInfos ( contractInfos )
228
- return contractInfos
238
+ allContractInfos . push ( ...universalContractInfos )
239
+ this . setContractInfos ( allContractInfos )
240
+ return allContractInfos
229
241
}
230
242
231
243
/**
232
244
* fetch universalContractInfos from the subgraph
245
+ * we skip the first max batch query each iteration to avoid hitting subgraph limit
233
246
* @return a list of IContractInfo instances
234
247
*/
235
248
public async fetchUniversalContractInfos (
236
249
apolloQueryOptions : IApolloQueryOptions = { }
237
250
) : Promise < IContractInfo [ ] > {
238
- const query = gql `
251
+ const allUniversalContractInfos = [ ]
252
+ let universalContractInfos = [ ]
253
+ let skip = 0
254
+
255
+ do {
256
+ const query = gql `
239
257
query AllUniversalContractInfos {
240
- universalContractInfos(first: 1000 ) {
258
+ universalContractInfos(first: ${ MAX_BATCH_QUERY } skip: ${ skip * MAX_BATCH_QUERY } ) {
241
259
id
242
260
name
243
261
version
@@ -246,9 +264,15 @@ export class Arc extends GraphNodeObserver {
246
264
}
247
265
}
248
266
`
249
- const response = await this . sendQuery ( query , apolloQueryOptions )
250
- const result = response . data . universalContractInfos as IContractInfo [ ]
251
- return result
267
+ const response = await this . sendQuery ( query , apolloQueryOptions )
268
+ universalContractInfos = response . data . universalContractInfos as IContractInfo [ ]
269
+ if ( universalContractInfos . length > 0 ) {
270
+ allUniversalContractInfos . push ( ...universalContractInfos )
271
+ }
272
+ skip ++
273
+ } while ( universalContractInfos . length === MAX_BATCH_QUERY )
274
+
275
+ return allUniversalContractInfos
252
276
}
253
277
254
278
/**
0 commit comments