-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tally-fetch): added fetch from subgraph
- Loading branch information
Showing
3 changed files
with
60 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { config } from "~/config"; | ||
|
||
import type { Tally } from "./types"; | ||
|
||
import { createCachedFetch } from "./fetch"; | ||
|
||
const cachedFetch = createCachedFetch({ ttl: 1000 * 60 * 10 }); | ||
|
||
export interface GraphQLResponse { | ||
data?: { | ||
tally: Tally; | ||
}; | ||
} | ||
|
||
const tallyQuery = ` | ||
query Tally { | ||
tally (id: $id) { | ||
id | ||
results { | ||
id | ||
result | ||
} | ||
} | ||
} | ||
`; | ||
|
||
/** | ||
* Fetches the tally data from the subgraph | ||
* | ||
* @returns The tally data | ||
*/ | ||
export async function fetchTally(id: string): Promise<Tally | undefined> { | ||
return cachedFetch<{ tally: Tally }>(config.maciSubgraphUrl, { | ||
method: "POST", | ||
body: JSON.stringify({ | ||
query: tallyQuery.replace("id: $id", `id: "${id}"`), | ||
}), | ||
}).then((response: GraphQLResponse) => response.data?.tally); | ||
} |
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