-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1f88c60
commit ef6f286
Showing
4 changed files
with
81 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,36 @@ | ||
export function writeQuery( | ||
entity: string, | ||
fields: string, | ||
querySize: number, | ||
offset: number, | ||
alias?: string, | ||
) { | ||
import { QUERY_SIZE } from './queryFromIndexer'; | ||
|
||
export function writeQuery({ | ||
entity, | ||
alias, | ||
fields, | ||
querySize = QUERY_SIZE, | ||
offset = 0, | ||
filter, | ||
fragments, | ||
}: { | ||
entity: string; | ||
alias?: string; | ||
fields: string[]; | ||
querySize?: number; | ||
offset?: number; | ||
filter?: string; | ||
fragments?: string[]; | ||
}) { | ||
// BlockIDs are strings, this means that "42" > "1000" | ||
// Sadly, time_stamps can only be use to order queries of blocks. | ||
// Specially for queries with many matches, it is important to request an order of the results, to avoid duplicates and assure totality. | ||
// It does not matter what the order criterion is as long as it is consistent. | ||
// ID_ASC exists for all entities, so it should work as a general approach. | ||
return ` | ||
query { | ||
${alias ? alias + ':' : ''} ${entity}(orderBy: ID_ASC, first: ${querySize}, offset: ${offset}) { | ||
${alias ? alias + ':' : ''} ${entity}(orderBy: ID_ASC, first: ${querySize}, offset: ${offset}, ${filter ? 'filter: ' + filter : ''}) { | ||
totalCount | ||
nodes { | ||
${fields} | ||
${fields.join('\n ')} | ||
} | ||
} | ||
} | ||
${fragments ? fragments.join('\n') : ''} | ||
`; | ||
} |